Skip to content

Commit 9b66978

Browse files
committed
Merge branch 'jh/verify-index-checksum-only-in-fsck'
* jh/verify-index-checksum-only-in-fsck: t1450: avoid use of "sed" on the index, which is a binary file
2 parents 4fa66c8 + 4d9bc37 commit 9b66978

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

t/t1450-fsck.sh

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -689,17 +689,35 @@ test_expect_success 'bogus head does not fallback to all heads' '
689689
! grep $blob out
690690
'
691691

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.
692715
test_expect_success 'detect corrupt index file in fsck' '
693716
cp .git/index .git/index.backup &&
694717
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
703721
'
704722

705723
test_done

0 commit comments

Comments
 (0)