cat-file tests: add corrupt loose object test
Fix a blindspot in the tests for "cat-file" (and by proxy, the guts of object-file.c) by testing that when we can't decode a loose object with zlib we'll emit an error from zlib.c. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
59b8283d55
commit
7e7d220d9d
|
@ -426,6 +426,58 @@ test_expect_success "Size of large broken object is correct when type is large"
|
|||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'cat-file -t and -s on corrupt loose object' '
|
||||
git init --bare corrupt-loose.git &&
|
||||
(
|
||||
cd corrupt-loose.git &&
|
||||
|
||||
# Setup and create the empty blob and its path
|
||||
empty_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$EMPTY_BLOB")) &&
|
||||
git hash-object -w --stdin </dev/null &&
|
||||
|
||||
# Create another blob and its path
|
||||
echo other >other.blob &&
|
||||
other_blob=$(git hash-object -w --stdin <other.blob) &&
|
||||
other_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$other_blob")) &&
|
||||
|
||||
# Before the swap the size is 0
|
||||
cat >out.expect <<-EOF &&
|
||||
0
|
||||
EOF
|
||||
git cat-file -s "$EMPTY_BLOB" >out.actual 2>err.actual &&
|
||||
test_must_be_empty err.actual &&
|
||||
test_cmp out.expect out.actual &&
|
||||
|
||||
# Swap the two to corrupt the repository
|
||||
mv -f "$other_path" "$empty_path" &&
|
||||
test_must_fail git fsck 2>err.fsck &&
|
||||
grep "hash mismatch" err.fsck &&
|
||||
|
||||
# confirm that cat-file is reading the new swapped-in
|
||||
# blob...
|
||||
cat >out.expect <<-EOF &&
|
||||
blob
|
||||
EOF
|
||||
git cat-file -t "$EMPTY_BLOB" >out.actual 2>err.actual &&
|
||||
test_must_be_empty err.actual &&
|
||||
test_cmp out.expect out.actual &&
|
||||
|
||||
# ... since it has a different size now.
|
||||
cat >out.expect <<-EOF &&
|
||||
6
|
||||
EOF
|
||||
git cat-file -s "$EMPTY_BLOB" >out.actual 2>err.actual &&
|
||||
test_must_be_empty err.actual &&
|
||||
test_cmp out.expect out.actual &&
|
||||
|
||||
# So far "cat-file" has been happy to spew the found
|
||||
# content out as-is. Try to make it zlib-invalid.
|
||||
mv -f other.blob "$empty_path" &&
|
||||
test_must_fail git fsck 2>err.fsck &&
|
||||
grep "^error: inflate: data stream error (" err.fsck
|
||||
)
|
||||
'
|
||||
|
||||
# Tests for git cat-file --follow-symlinks
|
||||
test_expect_success 'prep for symlink tests' '
|
||||
echo_without_newline "$hello_content" >morx &&
|
||||
|
|
Loading…
Reference in New Issue