pull: check if in unresolved merge state
[gitweb.git] / builtin / pull.c
index 647bcb9f3a44b0cd37f98110820c0f5cd42a2c7f..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>...]]"),
@@ -166,6 +167,32 @@ static void argv_push_force(struct argv_array *arr)
                argv_array_push(arr, "-f");
 }
 
+/**
+ * If pull.ff is unset, returns NULL. If pull.ff is "true", returns "--ff". If
+ * pull.ff is "false", returns "--no-ff". If pull.ff is "only", returns
+ * "--ff-only". Otherwise, if pull.ff is set to an invalid value, die with an
+ * error.
+ */
+static const char *config_get_ff(void)
+{
+       const char *value;
+
+       if (git_config_get_value("pull.ff", &value))
+               return NULL;
+
+       switch (git_config_maybe_bool("pull.ff", value)) {
+       case 0:
+               return "--no-ff";
+       case 1:
+               return "--ff";
+       }
+
+       if (!strcmp(value, "only"))
+               return "--ff-only";
+
+       die(_("Invalid value for pull.ff: %s"), value);
+}
+
 /**
  * Appends merge candidates from FETCH_HEAD that are not marked not-for-merge
  * into merge_heads.
@@ -397,6 +424,17 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 
        parse_repo_refspecs(argc, argv, &repo, &refspecs);
 
+       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;