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 <git@thequod.de> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jun 29, 2016 at 08:21 UTC
33ba9c648b6753a4184e53ffb89f0a924f9f7b7e
2 files changed
+32
git-rebase--interactive.sh
+1
@@ -216,6 +216,7 @@ exit_with_patch () {
216
}
217
218
die_abort () {
219
+ apply_autostash
220
rm -rf "$state_dir"
221
die "$1"
222
}
t/t3420-rebase-autostash.sh
+31
@@ -192,4 +192,35 @@ test_expect_success 'abort rebase -i with --autostash' '
192
test_cmp expected file0
193
'
194
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
+
226
test_done