]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pull: give the advice for choosing rebase/merge much later
authorFelipe Contreras <felipe.contreras@gmail.com>
Sat, 12 Dec 2020 16:52:07 +0000 (10:52 -0600)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 Dec 2020 17:03:17 +0000 (09:03 -0800)
Eventually we want to be omit the advice when we can fast-forward
in which case there is no reason to require the user to choose
between rebase or merge.

In order to do so, we need to delay giving the advice up to the
point where we can check if we can fast-forward or not.

Additionally, config_get_rebase() was probably never its true home.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pull.c

index 03e6d53243ae6ef1e1bcd87301e49d1b6278248c..ff8e3ce13797c8a3fd5d519b52f7060a40dbf5bc 100644 (file)
@@ -27,6 +27,8 @@
 #include "commit-reach.h"
 #include "sequencer.h"
 
+static int default_mode;
+
 /**
  * Parses the value of --rebase. If value is a false value, returns
  * REBASE_FALSE. If value is a true value, returns REBASE_TRUE. If value is
@@ -344,20 +346,7 @@ static enum rebase_type config_get_rebase(void)
        if (!git_config_get_value("pull.rebase", &value))
                return parse_config_rebase("pull.rebase", value, 1);
 
-       if (opt_verbosity >= 0 && !opt_ff) {
-               advise(_("Pulling without specifying how to reconcile divergent branches is\n"
-                        "discouraged. You can squelch this message by running one of the following\n"
-                        "commands sometime before your next pull:\n"
-                        "\n"
-                        "  git config pull.rebase false  # merge (the default strategy)\n"
-                        "  git config pull.rebase true   # rebase\n"
-                        "  git config pull.ff only       # fast-forward only\n"
-                        "\n"
-                        "You can replace \"git config\" with \"git config --global\" to set a default\n"
-                        "preference for all repositories. You can also pass --rebase, --no-rebase,\n"
-                        "or --ff-only on the command line to override the configured default per\n"
-                        "invocation.\n"));
-       }
+       default_mode = 1;
 
        return REBASE_FALSE;
 }
@@ -1040,6 +1029,21 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
        if (opt_rebase && merge_heads.nr > 1)
                die(_("Cannot rebase onto multiple branches."));
 
+       if (default_mode && opt_verbosity >= 0 && !opt_ff) {
+               advise(_("Pulling without specifying how to reconcile divergent branches is\n"
+                        "discouraged. You can squelch this message by running one of the following\n"
+                        "commands sometime before your next pull:\n"
+                        "\n"
+                        "  git config pull.rebase false  # merge (the default strategy)\n"
+                        "  git config pull.rebase true   # rebase\n"
+                        "  git config pull.ff only       # fast-forward only\n"
+                        "\n"
+                        "You can replace \"git config\" with \"git config --global\" to set a default\n"
+                        "preference for all repositories. You can also pass --rebase, --no-rebase,\n"
+                        "or --ff-only on the command line to override the configured default per\n"
+                        "invocation.\n"));
+       }
+
        if (opt_rebase) {
                int ret = 0;
                int ran_ff = 0;