3 test_description
='see how we handle various forms of corruption'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 # convert "1234abcd" to ".git/objects/12/34abcd"
10 echo "$(git rev-parse --git-dir)/objects/$(git rev-parse "$1" | sed 's,..,&/,')"
13 # Convert byte at offset "$2" of object "$1" into '\0'
15 obj_file
=$
(obj_to_file
"$1") &&
16 chmod +w
"$obj_file" &&
17 printf '\0' |
dd of
="$obj_file" bs
=1 seek
="$2" conv
=notrunc
20 test_expect_success
'setup corrupt repo' '
24 test_commit content &&
25 corrupt_byte HEAD:content.t 10
27 git init no-bit-error &&
29 # distinct commit from bit-error, but containing a
30 # non-corrupted version of the same blob
37 test_expect_success
'setup repo with missing object' '
41 test_commit content &&
42 rm -f "$(obj_to_file HEAD:content.t)"
46 test_expect_success
'setup repo with misnamed object' '
50 test_commit content &&
51 good=$(obj_to_file HEAD:content.t) &&
52 blob=$(echo corrupt | git hash-object -w --stdin) &&
53 bad=$(obj_to_file $blob) &&
59 test_expect_success
'streaming a corrupt blob fails' '
62 test_must_fail git cat-file blob HEAD:content.t
66 test_expect_success
'getting type of a corrupt blob fails' '
69 test_must_fail git cat-file -s HEAD:content.t
73 test_expect_success
'read-tree -u detects bit-errors in blobs' '
77 test_must_fail git read-tree --reset -u HEAD
81 test_expect_success
'read-tree -u detects missing objects' '
85 test_must_fail git read-tree --reset -u HEAD
89 # We use --bare to make sure that the transport detects it, not the checkout
91 test_expect_success
'clone --no-local --bare detects corruption' '
92 test_must_fail git clone --no-local --bare bit-error corrupt-transport
95 test_expect_success
'clone --no-local --bare detects missing object' '
96 test_must_fail git clone --no-local --bare missing missing-transport
99 test_expect_success
'clone --no-local --bare detects misnamed object' '
100 test_must_fail git clone --no-local --bare misnamed misnamed-transport
103 # We do not expect --local to detect corruption at the transport layer,
104 # so we are really checking the checkout() code path.
105 test_expect_success
'clone --local detects corruption' '
106 test_must_fail git clone --local bit-error corrupt-checkout
109 test_expect_success
'error detected during checkout leaves repo intact' '
110 test_path_is_dir corrupt-checkout/.git
113 test_expect_success
'clone --local detects missing objects' '
114 test_must_fail git clone --local missing missing-checkout
117 test_expect_failure
'clone --local detects misnamed objects' '
118 test_must_fail git clone --local misnamed misnamed-checkout
121 test_expect_success
'fetch into corrupted repo with index-pack' '
122 cp -R bit-error bit-error-cp &&
123 test_when_finished "rm -rf bit-error-cp" &&
126 test_must_fail git -c transfer.unpackLimit=1 \
127 fetch ../no-bit-error 2>stderr &&
128 test_grep ! -i collision stderr
132 test_expect_success
'internal tree objects are not "missing"' '
133 git init missing-empty &&
136 empty_tree=$(git hash-object -t tree /dev/null) &&
137 commit=$(echo foo | git commit-tree $empty_tree) &&
138 git rev-list --objects $commit
142 test_expect_success
'partial clone of corrupted repository' '
143 test_config -C misnamed uploadpack.allowFilter true &&
144 git clone --no-local --no-checkout --filter=blob:none \
145 misnamed corrupt-partial && \
146 test_must_fail git -C corrupt-partial checkout --force