Skip to content

Commit d9036cd

Browse files
committed
Merge branch 'rr/rebase-autostash-fix' into maint
The autostash mode of "git rebase -i" did not restore the dirty working tree state if the user aborted the interactive rebase by emptying the insn sheet. * rr/rebase-autostash-fix: rebase -i: test "Nothing to do" case with autostash rebase -i: handle "Nothing to do" case with autostash
2 parents 8675779 + ddb5432 commit d9036cd

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

git-rebase--interactive.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,14 +1049,14 @@ fi
10491049

10501050

10511051
has_action "$todo" ||
1052-
die_abort "Nothing to do"
1052+
return 2
10531053

10541054
cp "$todo" "$todo".backup
10551055
git_sequence_editor "$todo" ||
10561056
die_abort "Could not execute editor"
10571057

10581058
has_action "$todo" ||
1059-
die_abort "Nothing to do"
1059+
return 2
10601060

10611061
expand_todo_ids
10621062

git-rebase.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ move_to_original_branch () {
155155
esac
156156
}
157157

158-
finish_rebase () {
158+
apply_autostash () {
159159
if test -f "$state_dir/autostash"
160160
then
161161
stash_sha1=$(cat "$state_dir/autostash")
@@ -171,6 +171,10 @@ You can run "git stash pop" or "git stash drop" at any time.
171171
'
172172
fi
173173
fi
174+
}
175+
176+
finish_rebase () {
177+
apply_autostash &&
174178
git gc --auto &&
175179
rm -rf "$state_dir"
176180
}
@@ -186,6 +190,11 @@ run_specific_rebase () {
186190
if test $ret -eq 0
187191
then
188192
finish_rebase
193+
elif test $ret -eq 2 # special exit status for rebase -i
194+
then
195+
apply_autostash &&
196+
rm -rf "$state_dir" &&
197+
die "Nothing to do"
189198
fi
190199
exit $ret
191200
}

t/t3420-rebase-autostash.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,19 @@ testrebase "" .git/rebase-apply
167167
testrebase " --merge" .git/rebase-merge
168168
testrebase " --interactive" .git/rebase-merge
169169

170+
test_expect_success 'abort rebase -i with --autostash' '
171+
test_when_finished "git reset --hard" &&
172+
echo uncommited-content >file0 &&
173+
(
174+
write_script abort-editor.sh <<-\EOF &&
175+
echo >"$1"
176+
EOF
177+
test_set_editor "$(pwd)/abort-editor.sh" &&
178+
test_must_fail git rebase -i --autostash HEAD^ &&
179+
rm -f abort-editor.sh
180+
) &&
181+
echo uncommited-content >expected &&
182+
test_cmp expected file0
183+
'
184+
170185
test_done

0 commit comments

Comments
 (0)