Skip to content

Commit 4a4cf9e

Browse files
pyokagangitster
authored andcommitted
pull: check if in unresolved merge state
Since d38a30d (Be more user-friendly when refusing to do something because of conflict., 2010-01-12), git-pull will error out with user-friendly advices if the user is in the middle of a merge or has unmerged files. Re-implement this behavior. While the "has unmerged files" case can be handled by die_resolve_conflict(), we introduce a new function die_conclude_merge() for printing a different error message for when there are no unmerged files but the merge has not been finished. Signed-off-by: Paul Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a9de989 commit 4a4cf9e

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

advice.c

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ void NORETURN die_resolve_conflict(const char *me)
9696
die("Exiting because of an unresolved conflict.");
9797
}
9898

99+
void NORETURN die_conclude_merge(void)
100+
{
101+
error(_("You have not concluded your merge (MERGE_HEAD exists)."));
102+
if (advice_resolve_conflict)
103+
advise(_("Please, commit your changes before you can merge."));
104+
die(_("Exiting because of unfinished merge."));
105+
}
106+
99107
void detach_advice(const char *new_name)
100108
{
101109
const char fmt[] =

advice.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ __attribute__((format (printf, 1, 2)))
2424
void advise(const char *advice, ...);
2525
int error_resolve_conflict(const char *me);
2626
extern void NORETURN die_resolve_conflict(const char *me);
27+
void NORETURN die_conclude_merge(void);
2728
void detach_advice(const char *new_name);
2829

2930
#endif /* ADVICE_H */

builtin/pull.c

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "run-command.h"
1313
#include "sha1-array.h"
1414
#include "remote.h"
15+
#include "dir.h"
1516

1617
static const char * const pull_usage[] = {
1718
N_("git pull [options] [<repository> [<refspec>...]]"),
@@ -426,6 +427,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
426427
if (!opt_ff)
427428
opt_ff = xstrdup_or_null(config_get_ff());
428429

430+
git_config(git_default_config, NULL);
431+
432+
if (read_cache_unmerged())
433+
die_resolve_conflict("Pull");
434+
435+
if (file_exists(git_path("MERGE_HEAD")))
436+
die_conclude_merge();
437+
429438
if (run_fetch(repo, refspecs))
430439
return 1;
431440

0 commit comments

Comments
 (0)