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@xxxxxx> 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@xxxxxx> --- 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