rebase learned to stash changes when it encounters a dirty work tree, but
git pull --rebase does not.

Only verify if the working tree is dirty when rebase.autostash is not
enabled.

Signed-off-by: Kevin Daudt <m...@ikke.info>
Helped-by: Paul Tan <pyoka...@gmail.com>
---
Changes to v2:
 - Dropped the change of the existing --rebase test
 - Improvements to the test.

Verified that the test fails before the change, and succeeds after the change.

 git-pull.sh     |  5 ++++-
 t/t5520-pull.sh | 11 +++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/git-pull.sh b/git-pull.sh
index 0917d0d..f0a3b6e 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -239,7 +239,10 @@ test true = "$rebase" && {
                        die "$(gettext "updating an unborn branch with changes 
added to the index")"
                fi
        else
-               require_clean_work_tree "pull with rebase" "Please commit or 
stash them."
+               if [ $(git config --bool --get rebase.autostash || echo false) 
= false ]
+               then
+                       require_clean_work_tree "pull with rebase" "Please 
commit or stash them."
+               fi
        fi
        oldremoteref= &&
        test -n "$curr_branch" &&
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index af31f04..aa247ec 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -233,6 +233,17 @@ test_expect_success '--rebase fails with multiple 
branches' '
        test modified = "$(git show HEAD:file)"
 '
 
+test_expect_success 'pull --rebase succeeds with dirty working directory and 
rebase.autostash set' '
+       test_config rebase.autostash true &&
+       git reset --hard before-rebase &&
+       echo dirty >new_file &&
+       git add new_file &&
+       git pull --rebase . copy &&
+       test_cmp_rev HEAD^ copy &&
+       test "$(cat new_file)" = dirty &&
+       test "$(cat file)" = "modified again"
+'
+
 test_expect_success 'pull.rebase' '
        git reset --hard before-rebase &&
        test_config pull.rebase true &&
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to