commit-reach(paint_down_to_common): plug two memory leaks
[git.git] / t / t1060-object-corruption.sh
blob5e0f0a334f4d43dd76199a50037c5900da2cb63b
1 #!/bin/sh
3 test_description='see how we handle various forms of corruption'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 # convert "1234abcd" to ".git/objects/12/34abcd"
9 obj_to_file() {
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'
14 corrupt_byte() {
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' '
21 git init bit-error &&
23 cd bit-error &&
24 test_commit content &&
25 corrupt_byte HEAD:content.t 10
26 ) &&
27 git init no-bit-error &&
29 # distinct commit from bit-error, but containing a
30 # non-corrupted version of the same blob
31 cd no-bit-error &&
32 test_tick &&
33 test_commit content
37 test_expect_success 'setup repo with missing object' '
38 git init missing &&
40 cd missing &&
41 test_commit content &&
42 rm -f "$(obj_to_file HEAD:content.t)"
46 test_expect_success 'setup repo with misnamed object' '
47 git init misnamed &&
49 cd misnamed &&
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) &&
54 rm -f "$good" &&
55 mv "$bad" "$good"
59 test_expect_success 'streaming a corrupt blob fails' '
61 cd bit-error &&
62 test_must_fail git cat-file blob HEAD:content.t
66 test_expect_success 'getting type of a corrupt blob fails' '
68 cd bit-error &&
69 test_must_fail git cat-file -s HEAD:content.t
73 test_expect_success 'read-tree -u detects bit-errors in blobs' '
75 cd bit-error &&
76 rm -f content.t &&
77 test_must_fail git read-tree --reset -u HEAD
81 test_expect_success 'read-tree -u detects missing objects' '
83 cd missing &&
84 rm -f content.t &&
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
90 # phase.
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" &&
125 cd 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 &&
135 cd 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
149 test_done