Skip to content

Commit 118e6ce

Browse files
peffgitster
authored andcommitted
t1450: test fsck of packed objects
The code paths in fsck for packed and loose objects are quite different, and it is not immediately obvious that the packed case behaves well. In particular: 1. The fsck_loose() function always returns "0" to tell the iterator to keep checking more objects. Whereas fsck_obj_buffer() (which handles packed objects) returns -1. This is OK, because the callback machinery for verify_pack() does not stop when it sees a non-zero return. 2. The fsck_loose() function sets the ERROR_OBJECT bit when fsck_obj() fails, whereas fsck_obj_buffer() sets it only when it sees a corrupt object. This turns out not to matter. We don't actually do anything with this bit except exit the program with a non-zero code, and that is handled already by the non-zero return from the function. So there are no bugs here, but it was certainly confusing to me. And we do not test either of the properties in t1450 (neither that a non-corruption error will caused a non-zero exit for a packed object, nor that we keep going after seeing the first error). Let's test both of those conditions, so that we'll notice if any of those assumptions becomes invalid. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 771e7d5 commit 118e6ce

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

t/t1450-fsck.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,4 +560,25 @@ test_expect_success 'alternate objects are correctly blamed' '
560560
grep alt.git out
561561
'
562562

563+
test_expect_success 'fsck errors in packed objects' '
564+
git cat-file commit HEAD >basis &&
565+
sed "s/</one/" basis >one &&
566+
sed "s/</foo/" basis >two &&
567+
one=$(git hash-object -t commit -w one) &&
568+
two=$(git hash-object -t commit -w two) &&
569+
pack=$(
570+
{
571+
echo $one &&
572+
echo $two
573+
} | git pack-objects .git/objects/pack/pack
574+
) &&
575+
test_when_finished "rm -f .git/objects/pack/pack-$pack.*" &&
576+
remove_object $one &&
577+
remove_object $two &&
578+
test_must_fail git fsck 2>out &&
579+
grep "error in commit $one.* - bad name" out &&
580+
grep "error in commit $two.* - bad name" out &&
581+
! grep corrupt out
582+
'
583+
563584
test_done

0 commit comments

Comments
 (0)