Skip to content

Commit 10d2f35

Browse files
dschogitster
authored andcommitted
rebase -i: be careful to wrap up fixup/squash chains
When an interactive rebase was stopped at the end of a fixup/squash chain, the user might have edited the commit manually before continuing (with either `git rebase --skip` or `git rebase --continue`, it does not really matter which). We need to be very careful to wrap up the fixup/squash chain also in this scenario: otherwise the next fixup/squash chain would try to pick up where the previous one was left. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 2f3eb68 commit 10d2f35

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

sequencer.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3438,9 +3438,20 @@ static int commit_staged_changes(struct replay_opts *opts,
34383438
* the commit message and if there was a squash, let the user
34393439
* edit it.
34403440
*/
3441-
if (is_clean && !oidcmp(&head, &to_amend) &&
3442-
opts->current_fixup_count > 0 &&
3443-
file_exists(rebase_path_stopped_sha())) {
3441+
if (!is_clean || !opts->current_fixup_count)
3442+
; /* this is not the final fixup */
3443+
else if (oidcmp(&head, &to_amend) ||
3444+
!file_exists(rebase_path_stopped_sha())) {
3445+
/* was a final fixup or squash done manually? */
3446+
if (!is_fixup(peek_command(todo_list, 0))) {
3447+
unlink(rebase_path_fixup_msg());
3448+
unlink(rebase_path_squash_msg());
3449+
unlink(rebase_path_current_fixups());
3450+
strbuf_reset(&opts->current_fixups);
3451+
opts->current_fixup_count = 0;
3452+
}
3453+
} else {
3454+
/* we are in a fixup/squash chain */
34443455
const char *p = opts->current_fixups.buf;
34453456
int len = opts->current_fixups.len;
34463457

t/t3415-rebase-autosquash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ test_expect_success 'wrapped original subject' '
330330
test $base = $parent
331331
'
332332

333-
test_expect_failure 'abort last squash' '
333+
test_expect_success 'abort last squash' '
334334
test_when_finished "test_might_fail git rebase --abort" &&
335335
test_when_finished "git checkout master" &&
336336

0 commit comments

Comments
 (0)