Skip to content

Commit 7b66f5d

Browse files
committed
Merge branch 'mr/rerere-crash-fix'
When .git/rr-cache/ rerere database gets corrupted or rerere is fed to work on a file with conflicted hunks resolved incompletely, the rerere machinery got confused and segfaulted, which has been corrected. * mr/rerere-crash-fix: rerere: fix crashes due to unmatched opening conflict markers
2 parents fb9f603 + 167395b commit 7b66f5d

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

rerere.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ static void read_rr(struct repository *r, struct string_list *rr)
219219
buf.buf[hexsz] = '\0';
220220
id = new_rerere_id_hex(buf.buf);
221221
id->variant = variant;
222+
/*
223+
* make sure id->collection->status has enough space
224+
* for the variant we are interested in
225+
*/
226+
fit_variant(id->collection, variant);
222227
string_list_insert(rr, path)->util = id;
223228
}
224229
strbuf_release(&buf);

t/t4200-rerere.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,4 +671,67 @@ test_expect_success 'test simple stage 1 handling' '
671671
)
672672
'
673673

674+
test_expect_success 'rerere does not crash with missing preimage' '
675+
git config rerere.enabled true &&
676+
677+
echo bar >test &&
678+
git add test &&
679+
git commit -m "one" &&
680+
git branch rerere_no_crash &&
681+
682+
echo foo >>test &&
683+
git add test &&
684+
git commit -m "two" &&
685+
686+
git checkout rerere_no_crash &&
687+
echo "bar" >>test &&
688+
git add test &&
689+
git commit -m "three" &&
690+
691+
test_must_fail git rebase main &&
692+
rm .git/rr-cache/*/preimage &&
693+
git rebase --abort
694+
'
695+
696+
test_expect_success 'rerere does not crash with unmatched conflict marker' '
697+
git config rerere.enabled true &&
698+
699+
echo bar >test &&
700+
git add test &&
701+
git commit -m "one" &&
702+
git branch rerere_no_preimage &&
703+
704+
cat >test <<-EOF &&
705+
test
706+
bar
707+
foobar
708+
EOF
709+
git add test &&
710+
git commit -m "two" &&
711+
712+
git checkout rerere_no_preimage &&
713+
echo "bar" >>test &&
714+
git add test &&
715+
git commit -m "three" &&
716+
717+
cat >test <<-EOF &&
718+
foobar
719+
bar
720+
bar
721+
EOF
722+
git add test &&
723+
git commit -m "four" &&
724+
725+
test_must_fail git rebase main &&
726+
cat >test <<-EOF &&
727+
test
728+
bar
729+
<<<<<<< HEAD
730+
foobar
731+
bar
732+
EOF
733+
git add test &&
734+
test_must_fail git rebase --continue
735+
'
736+
674737
test_done

0 commit comments

Comments
 (0)