tests: ensure fsck fails on corrupt packfiles

t1450-fsck.sh does not have a test that checks fsck's behavior when a packfile is invalid. It does have a test for when an object in a packfile is invalid, but in that test, the packfile itself is valid. Add such a test. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Jul 28, 2017 at 13:08 UTC a7c28a21617130ebaa709957bd038dab8ee9abdf
1 file changed +16
t/t1450-fsck.sh
+16
@@ -608,6 +608,22 @@ test_expect_success 'fsck errors in packed objects' '
608 ! grep corrupt out
609 '
610
611 +test_expect_success 'fsck fails on corrupt packfile' '
612 + hsh=$(git commit-tree -m mycommit HEAD^{tree}) &&
613 + pack=$(echo $hsh | git pack-objects .git/objects/pack/pack) &&
614 +
615 + # Corrupt the first byte of the first object. (It contains 3 type bits,
616 + # at least one of which is not zero, so setting the first byte to 0 is
617 + # sufficient.)
618 + chmod a+w .git/objects/pack/pack-$pack.pack &&
619 + printf '\0' | dd of=.git/objects/pack/pack-$pack.pack bs=1 conv=notrunc seek=12 &&
620 +
621 + test_when_finished "rm -f .git/objects/pack/pack-$pack.*" &&
622 + remove_object $hsh &&
623 + test_must_fail git fsck 2>out &&
624 + test_i18ngrep "checksum mismatch" out
625 +'
626 +
627 test_expect_success 'fsck finds problems in duplicate loose objects' '
628 rm -rf broken-duplicate &&
629 git init broken-duplicate &&