Skip to content

Commit a2a0942

Browse files
committed
Merge branch 'js/rebase-autosquash-double-fixup-fix'
"rebase -i" segfaulted when rearranging a sequence that has a fix-up that applies another fix-up (which may or may not be a fix-up of yet another step). * js/rebase-autosquash-double-fixup-fix: rebase --autosquash: fix a potential segfault
2 parents 73d9f96 + 02471e7 commit a2a0942

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

sequencer.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5385,10 +5385,13 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
53855385
todo_list->items[i].command =
53865386
starts_with(subject, "fixup!") ?
53875387
TODO_FIXUP : TODO_SQUASH;
5388-
if (next[i2] < 0)
5388+
if (tail[i2] < 0) {
5389+
next[i] = next[i2];
53895390
next[i2] = i;
5390-
else
5391+
} else {
5392+
next[i] = next[tail[i2]];
53915393
next[tail[i2]] = i;
5394+
}
53925395
tail[i2] = i;
53935396
} else if (!hashmap_get_from_hash(&subject2item,
53945397
strhash(subject), subject)) {

t/t3415-rebase-autosquash.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,4 +424,20 @@ test_expect_success 'abort last squash' '
424424
! grep first actual
425425
'
426426

427+
test_expect_success 'fixup a fixup' '
428+
echo 0to-fixup >file0 &&
429+
test_tick &&
430+
git commit -m "to-fixup" file0 &&
431+
test_tick &&
432+
git commit --squash HEAD -m X --allow-empty &&
433+
test_tick &&
434+
git commit --squash HEAD^ -m Y --allow-empty &&
435+
test_tick &&
436+
git commit -m "squash! $(git rev-parse HEAD^)" -m Z --allow-empty &&
437+
test_tick &&
438+
git commit -m "squash! $(git rev-parse HEAD^^)" -m W --allow-empty &&
439+
git rebase -ki --autosquash HEAD~5 &&
440+
test XZWY = $(git show | tr -cd W-Z)
441+
'
442+
427443
test_done

0 commit comments

Comments
 (0)