summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2013-03-25 20:21:34 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-03-27 20:47:06 (GMT)
commit7b6257b0d45f562629ac660cb1845c8a2aac7df1 (patch)
treec8a1253602a7c171916b5b1c54d174e98c675af7
parent692f0bc7ae0cb818bf3c757d509773d6f2e48c68 (diff)
downloadgit-7b6257b0d45f562629ac660cb1845c8a2aac7df1.zip
git-7b6257b0d45f562629ac660cb1845c8a2aac7df1.tar.gz
git-7b6257b0d45f562629ac660cb1845c8a2aac7df1.tar.bz2
add test for streaming corrupt blobs
We do not have many tests for handling corrupt objects. This new test at least checks that we detect a byte error in a corrupt blob object while streaming it out with cat-file. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rwxr-xr-xt/t1060-object-corruption.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/t/t1060-object-corruption.sh b/t/t1060-object-corruption.sh
new file mode 100755
index 0000000..c887dd8
--- /dev/null
+++ b/t/t1060-object-corruption.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+test_description='see how we handle various forms of corruption'
+. ./test-lib.sh
+
+# convert "1234abcd" to ".git/objects/12/34abcd"
+obj_to_file() {
+ echo "$(git rev-parse --git-dir)/objects/$(git rev-parse "$1" | sed 's,..,&/,')"
+}
+
+# Convert byte at offset "$2" of object "$1" into '\0'
+corrupt_byte() {
+ obj_file=$(obj_to_file "$1") &&
+ chmod +w "$obj_file" &&
+ printf '\0' | dd of="$obj_file" bs=1 seek="$2" conv=notrunc
+}
+
+test_expect_success 'setup corrupt repo' '
+ git init bit-error &&
+ (
+ cd bit-error &&
+ test_commit content &&
+ corrupt_byte HEAD:content.t 10
+ )
+'
+
+test_expect_success 'streaming a corrupt blob fails' '
+ (
+ cd bit-error &&
+ test_must_fail git cat-file blob HEAD:content.t
+ )
+'
+
+test_done