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
This commit is contained in:
Junio C Hamano 2024-04-23 11:52:41 -07:00
Родитель fb9f603f3c 167395bb47
Коммит 7b66f5dd8b
2 изменённых файлов: 68 добавлений и 0 удалений

Просмотреть файл

@ -219,6 +219,11 @@ static void read_rr(struct repository *r, struct string_list *rr)
buf.buf[hexsz] = '\0';
id = new_rerere_id_hex(buf.buf);
id->variant = variant;
/*
* make sure id->collection->status has enough space
* for the variant we are interested in
*/
fit_variant(id->collection, variant);
string_list_insert(rr, path)->util = id;
}
strbuf_release(&buf);

Просмотреть файл

@ -671,4 +671,67 @@ test_expect_success 'test simple stage 1 handling' '
)
'
test_expect_success 'rerere does not crash with missing preimage' '
git config rerere.enabled true &&
echo bar >test &&
git add test &&
git commit -m "one" &&
git branch rerere_no_crash &&
echo foo >>test &&
git add test &&
git commit -m "two" &&
git checkout rerere_no_crash &&
echo "bar" >>test &&
git add test &&
git commit -m "three" &&
test_must_fail git rebase main &&
rm .git/rr-cache/*/preimage &&
git rebase --abort
'
test_expect_success 'rerere does not crash with unmatched conflict marker' '
git config rerere.enabled true &&
echo bar >test &&
git add test &&
git commit -m "one" &&
git branch rerere_no_preimage &&
cat >test <<-EOF &&
test
bar
foobar
EOF
git add test &&
git commit -m "two" &&
git checkout rerere_no_preimage &&
echo "bar" >>test &&
git add test &&
git commit -m "three" &&
cat >test <<-EOF &&
foobar
bar
bar
EOF
git add test &&
git commit -m "four" &&
test_must_fail git rebase main &&
cat >test <<-EOF &&
test
bar
<<<<<<< HEAD
foobar
bar
EOF
git add test &&
test_must_fail git rebase --continue
'
test_done