mirror of
https://github.com/git/git
synced 2024-08-28 12:09:19 +00:00
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
This commit is contained in:
commit
9b669787fc
|
@ -689,17 +689,35 @@ test_expect_success 'bogus head does not fallback to all heads' '
|
||||||
! grep $blob out
|
! grep $blob out
|
||||||
'
|
'
|
||||||
|
|
||||||
|
# Corrupt the checksum on the index.
|
||||||
|
# Add 1 to the last byte in the SHA.
|
||||||
|
corrupt_index_checksum () {
|
||||||
|
perl -w -e '
|
||||||
|
use Fcntl ":seek";
|
||||||
|
open my $fh, "+<", ".git/index" or die "open: $!";
|
||||||
|
binmode $fh;
|
||||||
|
seek $fh, -1, SEEK_END or die "seek: $!";
|
||||||
|
read $fh, my $in_byte, 1 or die "read: $!";
|
||||||
|
|
||||||
|
$in_value = unpack("C", $in_byte);
|
||||||
|
$out_value = ($in_value + 1) & 255;
|
||||||
|
|
||||||
|
$out_byte = pack("C", $out_value);
|
||||||
|
|
||||||
|
seek $fh, -1, SEEK_END or die "seek: $!";
|
||||||
|
print $fh $out_byte;
|
||||||
|
close $fh or die "close: $!";
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Corrupt the checksum on the index and then
|
||||||
|
# verify that only fsck notices.
|
||||||
test_expect_success 'detect corrupt index file in fsck' '
|
test_expect_success 'detect corrupt index file in fsck' '
|
||||||
cp .git/index .git/index.backup &&
|
cp .git/index .git/index.backup &&
|
||||||
test_when_finished "mv .git/index.backup .git/index" &&
|
test_when_finished "mv .git/index.backup .git/index" &&
|
||||||
echo zzzzzzzz >zzzzzzzz &&
|
corrupt_index_checksum &&
|
||||||
git add zzzzzzzz &&
|
test_must_fail git fsck --cache 2>errors &&
|
||||||
sed -e "s/zzzzzzzz/yyyyyyyy/" .git/index >.git/index.yyy &&
|
grep "bad index file" errors
|
||||||
mv .git/index.yyy .git/index &&
|
|
||||||
# Confirm that fsck detects invalid checksum
|
|
||||||
test_must_fail git fsck --cache &&
|
|
||||||
# Confirm that status no longer complains about invalid checksum
|
|
||||||
git status
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in a new issue