]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pull: cleanup autostash check
authorFelipe Contreras <felipe.contreras@gmail.com>
Thu, 17 Jun 2021 16:17:08 +0000 (11:17 -0500)
committerJunio C Hamano <gitster@pobox.com>
Sat, 19 Jun 2021 07:36:16 +0000 (16:36 +0900)
Currently "git pull --rebase" takes a shortcut in the case a
fast-forward merge is possible; run_merge() is called with --ff-only.

However, "git merge" didn't have an --autostash option, so, when "git
pull --rebase --autostash" was called *and* the fast-forward merge
shortcut was taken, then the pull failed.

This was fixed in commit f15e7cf5cc (pull: ff --rebase --autostash
works in dirty repo, 2017-06-01) by simply skipping the fast-forward
merge shortcut.

Later on "git merge" learned the --autostash option [a03b55530a
(merge: teach --autostash option, 2020-04-07)], and so did "git pull"
[d9f15d37f1 (pull: pass --autostash to merge, 2020-04-07)].

Therefore it's not necessary to skip the fast-forward merge shortcut
anymore when called with --rebase --autostash.

Let's always take the fast-forward merge shortcut by essentially
reverting f15e7cf5cc.

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

index e8927fc2ffe3398de10b2a695f5b6346ac5a540c..a22293b7dba0e488c7fbeb35f84e09da69f8376c 100644 (file)
@@ -947,7 +947,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
        struct oid_array merge_heads = OID_ARRAY_INIT;
        struct object_id orig_head, curr_head;
        struct object_id rebase_fork_point;
-       int autostash;
        int rebase_unspecified = 0;
        int can_ff;
 
@@ -982,8 +981,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
        if (get_oid("HEAD", &orig_head))
                oidclr(&orig_head);
 
-       autostash = config_autostash;
        if (opt_rebase) {
+               int autostash = config_autostash;
                if (opt_autostash != -1)
                        autostash = opt_autostash;
 
@@ -1065,13 +1064,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
                     recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) &&
                    submodule_touches_in_range(the_repository, &upstream, &curr_head))
                        die(_("cannot rebase with locally recorded submodule modifications"));
-               if (!autostash) {
-                       if (can_ff) {
-                               /* we can fast-forward this without invoking rebase */
-                               opt_ff = "--ff-only";
-                               ran_ff = 1;
-                               ret = run_merge();
-                       }
+
+               if (can_ff) {
+                       /* we can fast-forward this without invoking rebase */
+                       opt_ff = "--ff-only";
+                       ran_ff = 1;
+                       ret = run_merge();
                }
                if (!ran_ff)
                        ret = run_rebase(&newbase, &upstream);