]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1060-object-corruption.sh
Start the 2.46 cycle
[thirdparty/git.git] / t / t1060-object-corruption.sh
CommitLineData
7b6257b0
JK
1#!/bin/sh
2
3test_description='see how we handle various forms of corruption'
7a98d9ab 4
e75d2f7f 5TEST_PASSES_SANITIZE_LEAK=true
7b6257b0
JK
6. ./test-lib.sh
7
8# convert "1234abcd" to ".git/objects/12/34abcd"
9obj_to_file() {
10 echo "$(git rev-parse --git-dir)/objects/$(git rev-parse "$1" | sed 's,..,&/,')"
11}
12
13# Convert byte at offset "$2" of object "$1" into '\0'
14corrupt_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
18}
19
20test_expect_success 'setup corrupt repo' '
21 git init bit-error &&
22 (
23 cd bit-error &&
24 test_commit content &&
25 corrupt_byte HEAD:content.t 10
51054177
JK
26 ) &&
27 git init no-bit-error &&
28 (
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
7b6257b0
JK
34 )
35'
36
d9c31e14
JK
37test_expect_success 'setup repo with missing object' '
38 git init missing &&
39 (
40 cd missing &&
41 test_commit content &&
42 rm -f "$(obj_to_file HEAD:content.t)"
43 )
44'
45
0e15ad9b
JK
46test_expect_success 'setup repo with misnamed object' '
47 git init misnamed &&
48 (
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"
56 )
57'
58
7b6257b0
JK
59test_expect_success 'streaming a corrupt blob fails' '
60 (
61 cd bit-error &&
62 test_must_fail git cat-file blob HEAD:content.t
63 )
64'
65
93cff9a9
JK
66test_expect_success 'getting type of a corrupt blob fails' '
67 (
68 cd bit-error &&
69 test_must_fail git cat-file -s HEAD:content.t
70 )
71'
72
d9c31e14
JK
73test_expect_success 'read-tree -u detects bit-errors in blobs' '
74 (
75 cd bit-error &&
76 rm -f content.t &&
77 test_must_fail git read-tree --reset -u HEAD
78 )
79'
80
81test_expect_success 'read-tree -u detects missing objects' '
82 (
83 cd missing &&
84 rm -f content.t &&
85 test_must_fail git read-tree --reset -u HEAD
86 )
87'
88
0e15ad9b
JK
89# We use --bare to make sure that the transport detects it, not the checkout
90# phase.
91test_expect_success 'clone --no-local --bare detects corruption' '
92 test_must_fail git clone --no-local --bare bit-error corrupt-transport
93'
94
95test_expect_success 'clone --no-local --bare detects missing object' '
96 test_must_fail git clone --no-local --bare missing missing-transport
97'
98
0433ad12 99test_expect_success 'clone --no-local --bare detects misnamed object' '
0e15ad9b
JK
100 test_must_fail git clone --no-local --bare misnamed misnamed-transport
101'
102
103# We do not expect --local to detect corruption at the transport layer,
104# so we are really checking the checkout() code path.
105test_expect_success 'clone --local detects corruption' '
106 test_must_fail git clone --local bit-error corrupt-checkout
107'
108
d3b34622
JK
109test_expect_success 'error detected during checkout leaves repo intact' '
110 test_path_is_dir corrupt-checkout/.git
111'
112
0aac7bb2 113test_expect_success 'clone --local detects missing objects' '
0e15ad9b
JK
114 test_must_fail git clone --local missing missing-checkout
115'
116
117test_expect_failure 'clone --local detects misnamed objects' '
118 test_must_fail git clone --local misnamed misnamed-checkout
119'
120
51054177 121test_expect_success 'fetch into corrupted repo with index-pack' '
aa984dbe
ÆAB
122 cp -R bit-error bit-error-cp &&
123 test_when_finished "rm -rf bit-error-cp" &&
51054177 124 (
aa984dbe 125 cd bit-error-cp &&
51054177
JK
126 test_must_fail git -c transfer.unpackLimit=1 \
127 fetch ../no-bit-error 2>stderr &&
6789275d 128 test_grep ! -i collision stderr
51054177
JK
129 )
130'
131
f06ab027
JK
132test_expect_success 'internal tree objects are not "missing"' '
133 git init missing-empty &&
134 (
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
139 )
140'
141
945ed009
JK
142test_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
147'
148
7b6257b0 149test_done