Skip to content

Commit 33ba9c6

Browse files
pks-tgitster
authored andcommitted
rebase -i: restore autostash on abort
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 <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e465796 commit 33ba9c6

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

git-rebase--interactive.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ exit_with_patch () {
216216
}
217217

218218
die_abort () {
219+
apply_autostash
219220
rm -rf "$state_dir"
220221
die "$1"
221222
}

t/t3420-rebase-autostash.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,35 @@ test_expect_success 'abort rebase -i with --autostash' '
192192
test_cmp expected file0
193193
'
194194

195+
test_expect_success 'restore autostash on editor failure' '
196+
test_when_finished "git reset --hard" &&
197+
echo uncommitted-content >file0 &&
198+
(
199+
test_set_editor "false" &&
200+
test_must_fail git rebase -i --autostash HEAD^
201+
) &&
202+
echo uncommitted-content >expected &&
203+
test_cmp expected file0
204+
'
205+
206+
test_expect_success 'autostash is saved on editor failure with conflict' '
207+
test_when_finished "git reset --hard" &&
208+
echo uncommitted-content >file0 &&
209+
(
210+
write_script abort-editor.sh <<-\EOF &&
211+
echo conflicting-content >file0
212+
exit 1
213+
EOF
214+
test_set_editor "$(pwd)/abort-editor.sh" &&
215+
test_must_fail git rebase -i --autostash HEAD^ &&
216+
rm -f abort-editor.sh
217+
) &&
218+
echo conflicting-content >expected &&
219+
test_cmp expected file0 &&
220+
git checkout file0 &&
221+
git stash pop &&
222+
echo uncommitted-content >expected &&
223+
test_cmp expected file0
224+
'
225+
195226
test_done

0 commit comments

Comments
 (0)