summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-05-09 03:17:42 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-05-09 03:17:42 (GMT)
commit9b669787fc6ebc527df9ad058c4bcaf46bacc267 (patch)
treeede7e61c87fb7766abe95cf348e75a9ac60f0de6
parent4fa66c85f11bc5a541462ca5ae3246aa0ce02e74 (diff)
parent4d9bc37fbe9902fc033573cf7375b528fc6a434e (diff)
downloadgit-9b669787fc6ebc527df9ad058c4bcaf46bacc267.zip
git-9b669787fc6ebc527df9ad058c4bcaf46bacc267.tar.gz
git-9b669787fc6ebc527df9ad058c4bcaf46bacc267.tar.bz2
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
-rwxr-xr-xt/t1450-fsck.sh34
1 files changed, 26 insertions, 8 deletions
diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
index 677e15a..adf0bc8 100755
--- a/t/t1450-fsck.sh
+++ b/t/t1450-fsck.sh
@@ -689,17 +689,35 @@ test_expect_success 'bogus head does not fallback to all heads' '
! 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' '
cp .git/index .git/index.backup &&
test_when_finished "mv .git/index.backup .git/index" &&
- echo zzzzzzzz >zzzzzzzz &&
- git add zzzzzzzz &&
- sed -e "s/zzzzzzzz/yyyyyyyy/" .git/index >.git/index.yyy &&
- 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
+ corrupt_index_checksum &&
+ test_must_fail git fsck --cache 2>errors &&
+ grep "bad index file" errors
'
test_done