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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jan 13, 2017 at 12:55 UTC 118e6cead47fafa17db12fdec9b997535f4f0fc6
1 file changed +21
t/t1450-fsck.sh
+21
@@ -560,4 +560,25 @@ test_expect_success 'alternate objects are correctly blamed' '
560 grep alt.git out
561 '
562
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 +
584 test_done