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 <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Paul Tan committed Jun 18, 2015 at 18:54 UTC 4a4cf9e821f604b79817bc37b475828f3fb8b0a4
3 files changed +18
advice.c
+8
@@ -96,6 +96,14 @@ void NORETURN die_resolve_conflict(const char *me)
96 die("Exiting because of an unresolved conflict.");
97 }
98
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 +
107 void detach_advice(const char *new_name)
108 {
109 const char fmt[] =
advice.h
+1
@@ -24,6 +24,7 @@ __attribute__((format (printf, 1, 2)))
24 void advise(const char *advice, ...);
25 int error_resolve_conflict(const char *me);
26 extern void NORETURN die_resolve_conflict(const char *me);
27 +void NORETURN die_conclude_merge(void);
28 void detach_advice(const char *new_name);
29
30 #endif /* ADVICE_H */
builtin/pull.c
+9
@@ -12,6 +12,7 @@
12 #include "run-command.h"
13 #include "sha1-array.h"
14 #include "remote.h"
15 +#include "dir.h"
16
17 static const char * const pull_usage[] = {
18 N_("git pull [options] [<repository> [<refspec>...]]"),
@@ -426,6 +427,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
427 if (!opt_ff)
428 opt_ff = xstrdup_or_null(config_get_ff());
429
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 +
438 if (run_fetch(repo, refspecs))
439 return 1;
440