]> granicus.if.org Git - git/commitdiff
rebase -i: restore autostash on abort
authorPatrick Steinhardt <ps@pks.im>
Wed, 29 Jun 2016 06:21:27 +0000 (08:21 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 29 Jun 2016 16:51:00 +0000 (09:51 -0700)
When we abort an interactive rebase we do so by calling
`die_abort`, which cleans up after us by removing the rebase
state directory. If the user has requested to use the autostash
feature, though, the state directory may also contain a reference
to the autostash, which will now be deleted.

Fix the issue by trying to re-apply the autostash in `die_abort`.
This will also handle the case where the autostash does not apply
cleanly anymore by recording it in a user-visible stash.

Reported-by: Daniel Hahler <git@thequod.de>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-rebase--interactive.sh
t/t3420-rebase-autostash.sh

index b938a6d4aa86b5f1e75312188c71cc4b0cdaab23..8fe7a7015b3d6385be43d02199ca945ccf962802 100644 (file)
@@ -216,6 +216,7 @@ exit_with_patch () {
 }
 
 die_abort () {
+       apply_autostash
        rm -rf "$state_dir"
        die "$1"
 }
index 944154b2e0ad7da5ddacdde5c22847babf1909c9..532ff5cbd1cbbce8bdbc83660d3084b938886c60 100755 (executable)
@@ -192,4 +192,35 @@ test_expect_success 'abort rebase -i with --autostash' '
        test_cmp expected file0
 '
 
+test_expect_success 'restore autostash on editor failure' '
+       test_when_finished "git reset --hard" &&
+       echo uncommitted-content >file0 &&
+       (
+               test_set_editor "false" &&
+               test_must_fail git rebase -i --autostash HEAD^
+       ) &&
+       echo uncommitted-content >expected &&
+       test_cmp expected file0
+'
+
+test_expect_success 'autostash is saved on editor failure with conflict' '
+       test_when_finished "git reset --hard" &&
+       echo uncommitted-content >file0 &&
+       (
+               write_script abort-editor.sh <<-\EOF &&
+                       echo conflicting-content >file0
+                       exit 1
+               EOF
+               test_set_editor "$(pwd)/abort-editor.sh" &&
+               test_must_fail git rebase -i --autostash HEAD^ &&
+               rm -f abort-editor.sh
+       ) &&
+       echo conflicting-content >expected &&
+       test_cmp expected file0 &&
+       git checkout file0 &&
+       git stash pop &&
+       echo uncommitted-content >expected &&
+       test_cmp expected file0
+'
+
 test_done