git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[BUG] git pull --rebase ignores rebase.autostash config when fast-forwarding

From
Tilman Vogel <tilman.vogel@web.de>
Date
Jan 3, 2022, 18:08 UTC
Message-ID
<9749fa2c-b08d-c08b-ce43-041d13852d02@web.de>
Hi git-people,

I ran into strange behavior when having rebase.autostash enabled and doing a git pull --rebase:

> git config rebase.autostash true
> git pull --rebase
Updating cd9ff8a..f3c9840
error: Your local changes to the following files would be overwritten by
merge:
        content
Please commit your changes or stash them before you merge.
Aborting
Confusingly, this fixes the issue:
> git config merge.autostash true
> git pull --rebase
Updating cd9ff8a..f3c9840
Created autostash: c615fda
Fast-forward
 content | 1 +
 1 file changed, 1 insertion(+)
Applied autostash.
Leaving me wonder why merge config options fix rebase behavior.

So, in order to make it easier to check the problem, I added some test-cases to the git test-suite. Please see the attached patch.

Or here: https://github.com/tvogel/git/commit/bc941f9357518a34cfa11788dfb8e7fa7f711705

I did not try to find the root-cause as I am not experienced with the code-base but if there are questions, let me know.

Best regards,
Tilman
From bc941f9357518a34cfa11788dfb8e7fa7f711705 Mon Sep 17 00:00:00 2001
From: Tilman Vogel <tilman.vogel@web.de>
Date: Mon, 3 Jan 2022 18:31:59 +0100
Subject: [PATCH] t5521: Show inconsistent rebase behavior (--autostash vs.
 rebase.autostash)

When pull --rebase can be done as a fast-forward, the rebase.autostash config is neglected such that the second test-case added in this commit will fail to autostash and succeed. In fact, setting merge.autostash as a workaround would cause autostash to be done.

The other three test-cases added in this commit document that autostashing works as expected when either requested explicitly with --autostash or when pull --rebase cannot be done as a fast-forward.

Signed-off-by: Tilman Vogel <tilman.vogel@web.de>
---
 t/t5521-pull-options.sh | 52 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
diff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh
index 66cfcb09c5..4046a74cad 100755
--- a/t/t5521-pull-options.sh
+++ b/t/t5521-pull-options.sh
@@ -252,4 +252,56 @@ 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_expect_success 'git pull --rebase with 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 &&
+	test_config -C dst rebase.autostash true &&
+	git -C dst pull --rebase  >actual 2>&1 &&
+	grep -q "Fast-forward" actual &&
+	grep -q "Applied autostash." actual
+'
+
+test_expect_success 'git pull --rebase --autostash succeeds on non-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 "src_content" file "src content\ncontent\n" &&
+	test_commit -C dst --append "dst_content" file "dst content" &&
+	echo "dirty" >>dst/file &&
+	git -C dst pull --rebase --autostash >actual 2>&1 &&
+	grep -q "Successfully rebased and updated refs/heads/main." actual &&
+	grep -q "Applied autostash." actual
+'
+
+test_expect_success 'git pull --rebase with rebase.autostash succeeds on non-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 "src_content" file "src content\ncontent\n" &&
+	test_commit -C dst --append "dst_content" file "dst content" &&
+	echo "dirty" >>dst/file &&
+	test_config -C dst rebase.autostash true &&
+	git -C dst pull --rebase >actual 2>&1 &&
+	grep -q "Successfully rebased and updated refs/heads/main." actual &&
+	grep -q "Applied autostash." actual
+'
+
 test_done
-- 
2.34.1
Next: Philip Oakley
Message 1 of 6 in “[BUG] git pull --rebase ignores rebase.autostash config when fast-forwarding”
  1. Tilman VogelJan 3, 2022
  2. Philip OakleyJan 4, 2022
  3. Philippe BlainJan 4, 2022
  4. Philippe BlainJan 4, 2022
  5. Tilman VogelJan 4, 2022
  6. Philippe BlainJan 4, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.