pull: check if in unresolved merge state
authorPaul Tan <pyokagan@gmail.com>
Thu, 18 Jun 2015 10:54:04 +0000 (18:54 +0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Jun 2015 20:17:16 +0000 (13:17 -0700)
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>
advice.c
advice.h
builtin/pull.c
index 575bec20b35a31e653e49125386f3dcee880c217..4965686e19cbb44b86d48363f8f3e289bebef94d 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -96,6 +96,14 @@ void NORETURN die_resolve_conflict(const char *me)
        die("Exiting because of an unresolved conflict.");
 }
 
+void NORETURN die_conclude_merge(void)
+{
+       error(_("You have not concluded your merge (MERGE_HEAD exists)."));
+       if (advice_resolve_conflict)
+               advise(_("Please, commit your changes before you can merge."));
+       die(_("Exiting because of unfinished merge."));
+}
+
 void detach_advice(const char *new_name)
 {
        const char fmt[] =
index 5ecc6c154e5a7207d18bbb05da5e35b2b4eae230..b341a55ce7c250cc34b49dc06a2843b5a5df1aac 100644 (file)
--- a/advice.h
+++ b/advice.h
@@ -24,6 +24,7 @@ __attribute__((format (printf, 1, 2)))
 void advise(const char *advice, ...);
 int error_resolve_conflict(const char *me);
 extern void NORETURN die_resolve_conflict(const char *me);
+void NORETURN die_conclude_merge(void);
 void detach_advice(const char *new_name);
 
 #endif /* ADVICE_H */
index b61cff5d87656d9f9394f815dde10647a8819f4c..1e688be4504d914774fa2629b3198f82a259fc0b 100644 (file)
@@ -12,6 +12,7 @@
 #include "run-command.h"
 #include "sha1-array.h"
 #include "remote.h"
+#include "dir.h"
 
 static const char * const pull_usage[] = {
        N_("git pull [options] [<repository> [<refspec>...]]"),
@@ -426,6 +427,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
        if (!opt_ff)
                opt_ff = xstrdup_or_null(config_get_ff());
 
+       git_config(git_default_config, NULL);
+
+       if (read_cache_unmerged())
+               die_resolve_conflict("Pull");
+
+       if (file_exists(git_path("MERGE_HEAD")))
+               die_conclude_merge();
+
        if (run_fetch(repo, refspecs))
                return 1;