@@ -689,17 +689,35 @@ test_expect_success 'bogus head does not fallback to all heads' '
689
689
! grep $blob out
690
690
'
691
691
692
+ # Corrupt the checksum on the index.
693
+ # Add 1 to the last byte in the SHA.
694
+ corrupt_index_checksum () {
695
+ perl -w -e '
696
+ use Fcntl ":seek";
697
+ open my $fh, "+<", ".git/index" or die "open: $!";
698
+ binmode $fh;
699
+ seek $fh, -1, SEEK_END or die "seek: $!";
700
+ read $fh, my $in_byte, 1 or die "read: $!";
701
+
702
+ $in_value = unpack("C", $in_byte);
703
+ $out_value = ($in_value + 1) & 255;
704
+
705
+ $out_byte = pack("C", $out_value);
706
+
707
+ seek $fh, -1, SEEK_END or die "seek: $!";
708
+ print $fh $out_byte;
709
+ close $fh or die "close: $!";
710
+ '
711
+ }
712
+
713
+ # Corrupt the checksum on the index and then
714
+ # verify that only fsck notices.
692
715
test_expect_success ' detect corrupt index file in fsck' '
693
716
cp .git/index .git/index.backup &&
694
717
test_when_finished "mv .git/index.backup .git/index" &&
695
- echo zzzzzzzz >zzzzzzzz &&
696
- git add zzzzzzzz &&
697
- sed -e "s/zzzzzzzz/yyyyyyyy/" .git/index >.git/index.yyy &&
698
- mv .git/index.yyy .git/index &&
699
- # Confirm that fsck detects invalid checksum
700
- test_must_fail git fsck --cache &&
701
- # Confirm that status no longer complains about invalid checksum
702
- git status
718
+ corrupt_index_checksum &&
719
+ test_must_fail git fsck --cache 2>errors &&
720
+ grep "bad index file" errors
703
721
'
704
722
705
723
test_done
0 commit comments