pull: cleanup autostash check

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>

Felipe Contreras committed Jun 17, 2021 at 11:17 UTC 340062243a474b8fa56f4c3f6572bf015392f7f9
1 file changed +7 -9
builtin/pull.c
+7 -9
@@ -947,7 +947,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
947 struct oid_array merge_heads = OID_ARRAY_INIT;
948 struct object_id orig_head, curr_head;
949 struct object_id rebase_fork_point;
950 - int autostash;
950 int rebase_unspecified = 0;
951 int can_ff;
952
@@ -982,8 +981,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
981 if (get_oid("HEAD", &orig_head))
982 oidclr(&orig_head);
983
985 - autostash = config_autostash;
984 if (opt_rebase) {
985 + int autostash = config_autostash;
986 if (opt_autostash != -1)
987 autostash = opt_autostash;
988
@@ -1065,13 +1064,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1064 recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) &&
1065 submodule_touches_in_range(the_repository, &upstream, &curr_head))
1066 die(_("cannot rebase with locally recorded submodule modifications"));
1068 - if (!autostash) {
1069 - if (can_ff) {
1070 - /* we can fast-forward this without invoking rebase */
1071 - opt_ff = "--ff-only";
1072 - ran_ff = 1;
1073 - ret = run_merge();
1074 - }
1067 +
1068 + if (can_ff) {
1069 + /* we can fast-forward this without invoking rebase */
1070 + opt_ff = "--ff-only";
1071 + ran_ff = 1;
1072 + ret = run_merge();
1073 }
1074 if (!ran_ff)
1075 ret = run_rebase(&newbase, &upstream);