Skip to content

Commit 87ae8a1

Browse files
committed
Merge branch 'js/rebase-i-autosquash-fix'
"git rebase -i" did not clear the state files correctly when a run of "squash/fixup" is aborted and then the user manually amended the commit instead, which has been corrected. * js/rebase-i-autosquash-fix: rebase -i: be careful to wrap up fixup/squash chains rebase -i --autosquash: demonstrate a problem skipping the last squash
2 parents 150f307 + 10d2f35 commit 87ae8a1

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

sequencer.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,9 +3611,20 @@ static int commit_staged_changes(struct replay_opts *opts,
36113611
* the commit message and if there was a squash, let the user
36123612
* edit it.
36133613
*/
3614-
if (is_clean && oideq(&head, &to_amend) &&
3615-
opts->current_fixup_count > 0 &&
3616-
file_exists(rebase_path_stopped_sha())) {
3614+
if (!is_clean || !opts->current_fixup_count)
3615+
; /* this is not the final fixup */
3616+
else if (!oideq(&head, &to_amend) ||
3617+
!file_exists(rebase_path_stopped_sha())) {
3618+
/* was a final fixup or squash done manually? */
3619+
if (!is_fixup(peek_command(todo_list, 0))) {
3620+
unlink(rebase_path_fixup_msg());
3621+
unlink(rebase_path_squash_msg());
3622+
unlink(rebase_path_current_fixups());
3623+
strbuf_reset(&opts->current_fixups);
3624+
opts->current_fixup_count = 0;
3625+
}
3626+
} else {
3627+
/* we are in a fixup/squash chain */
36173628
const char *p = opts->current_fixups.buf;
36183629
int len = opts->current_fixups.len;
36193630

t/t3415-rebase-autosquash.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,23 @@ test_expect_success 'wrapped original subject' '
330330
test $base = $parent
331331
'
332332

333+
test_expect_success 'abort last squash' '
334+
test_when_finished "test_might_fail git rebase --abort" &&
335+
test_when_finished "git checkout master" &&
336+
337+
git checkout -b some-squashes &&
338+
git commit --allow-empty -m first &&
339+
git commit --allow-empty --squash HEAD &&
340+
git commit --allow-empty -m second &&
341+
git commit --allow-empty --squash HEAD &&
342+
343+
test_must_fail git -c core.editor="grep -q ^pick" \
344+
rebase -ki --autosquash HEAD~4 &&
345+
: do not finish the squash, but resolve it manually &&
346+
git commit --allow-empty --amend -m edited-first &&
347+
git rebase --skip &&
348+
git show >actual &&
349+
! grep first actual
350+
'
351+
333352
test_done

0 commit comments

Comments
 (0)