Skip to contentSkip to conversation

builtin/pull.c: teach run_merge() to honor rebase.autostash config

PATCH Superseded John Cai 1 participant 1 message Jan 6, 2022

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

John Cai

author
#0 lore raw

PATCH v2 1/1 builtin/pull.c: teach run_merge() to honor rebase.autostash config

On a git pull --rebase, if fast forward is possible we run merge. However, merge will not honor rebase.autostash if it is configured. This has the unfortunate result of

$ git config rebase.autostash true
$ git pull --rebase

to ignore the rebase.autostash value.

Allow run_merge() to honor rebase.autostash by passing in config_autostash if --autostash or --no-autostash flags are not explicitly set.

---

Notes:
Fix a bug that prevents git pull --rebase from honoring the rebase.autostash config value.

Changes since V1:
- used simpler fix as proposed by Junio
- removed redundant test cases

 builtin/pull.c          |  9 ++++++++-
 t/t5521-pull-options.sh | 12 ++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
builtin/pull.c +8 -1
index 100cbf9fb8..8423e420ee 100644
@@ -1133,7 +1133,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 			die(_("cannot rebase with locally recorded submodule modifications"));
 
 		if (can_ff) {
-			/* we can fast-forward this without invoking rebase */
+			/*
+			* We can fast-forward without invoking
+			* rebase, by calling run_merge().  But we
+			* have to allow rebase.autostash=true to kick
+			* in.
+			*/
+			if (opt_autostash < 0)
+				opt_autostash = config_autostash;
 			opt_ff = "--ff-only";
 			ret = run_merge();
 		} else {
t/t5521-pull-options.sh +12 -0
index 66cfcb09c5..66fac99d2b 100755
@@ -252,4 +252,16 @@ test_expect_success 'git pull --no-verify --verify passed to merge' '
 	test_must_fail git -C dst pull --no-ff --no-verify --verify
 '
 
+test_expect_success 'git pull --rebase --autostash succeeds on ff' '
+	test_when_finished "rm -fr src dst actual" &&
+	git init src &&
+	test_commit -C src "initial" file "content" &&
+	git clone src dst &&
+	test_commit -C src --printf "more_content" file "more content\ncontent\n" &&
+	echo "dirty" >>dst/file &&
+	git -C dst pull --rebase --autostash >actual 2>&1 &&
+	grep -q "Fast-forward" actual &&
+	grep -q "Applied autostash." actual
+'
+
 test_done
Signature · 1 line
2.34.1