]>
Commit | Line | Data |
---|---|---|
b10a5358 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='fetch/receive strict mode' | |
3275f4e8 | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
6 | ||
c65d18cb | 7 | TEST_PASSES_SANITIZE_LEAK=true |
b10a5358 JH |
8 | . ./test-lib.sh |
9 | ||
8b55b9db | 10 | test_expect_success 'setup and inject "corrupt or missing" object' ' |
b10a5358 JH |
11 | echo hello >greetings && |
12 | git add greetings && | |
13 | git commit -m greetings && | |
14 | ||
15 | S=$(git rev-parse :greetings | sed -e "s|^..|&/|") && | |
16 | X=$(echo bye | git hash-object -w --stdin | sed -e "s|^..|&/|") && | |
8b55b9db ÆAB |
17 | echo $S >S && |
18 | echo $X >X && | |
19 | cp .git/objects/$S .git/objects/$S.back && | |
b10a5358 JH |
20 | mv -f .git/objects/$X .git/objects/$S && |
21 | ||
22 | test_must_fail git fsck | |
23 | ' | |
24 | ||
25 | test_expect_success 'fetch without strict' ' | |
26 | rm -rf dst && | |
27 | git init dst && | |
28 | ( | |
29 | cd dst && | |
30 | git config fetch.fsckobjects false && | |
31 | git config transfer.fsckobjects false && | |
3275f4e8 | 32 | test_must_fail git fetch ../.git main |
b10a5358 JH |
33 | ) |
34 | ' | |
35 | ||
36 | test_expect_success 'fetch with !fetch.fsckobjects' ' | |
37 | rm -rf dst && | |
38 | git init dst && | |
39 | ( | |
40 | cd dst && | |
41 | git config fetch.fsckobjects false && | |
42 | git config transfer.fsckobjects true && | |
3275f4e8 | 43 | test_must_fail git fetch ../.git main |
b10a5358 JH |
44 | ) |
45 | ' | |
46 | ||
47 | test_expect_success 'fetch with fetch.fsckobjects' ' | |
48 | rm -rf dst && | |
49 | git init dst && | |
50 | ( | |
51 | cd dst && | |
52 | git config fetch.fsckobjects true && | |
53 | git config transfer.fsckobjects false && | |
3275f4e8 | 54 | test_must_fail git fetch ../.git main |
b10a5358 JH |
55 | ) |
56 | ' | |
57 | ||
58 | test_expect_success 'fetch with transfer.fsckobjects' ' | |
59 | rm -rf dst && | |
60 | git init dst && | |
61 | ( | |
62 | cd dst && | |
63 | git config transfer.fsckobjects true && | |
3275f4e8 | 64 | test_must_fail git fetch ../.git main |
b10a5358 JH |
65 | ) |
66 | ' | |
67 | ||
ef7e93d9 CB |
68 | cat >exp <<EOF |
69 | To dst | |
3275f4e8 | 70 | ! refs/heads/main:refs/heads/test [remote rejected] (missing necessary objects) |
7dcbeaa0 | 71 | Done |
ef7e93d9 CB |
72 | EOF |
73 | ||
b10a5358 JH |
74 | test_expect_success 'push without strict' ' |
75 | rm -rf dst && | |
76 | git init dst && | |
77 | ( | |
78 | cd dst && | |
79 | git config fetch.fsckobjects false && | |
80 | git config transfer.fsckobjects false | |
81 | ) && | |
3275f4e8 | 82 | test_must_fail git push --porcelain dst main:refs/heads/test >act && |
ef7e93d9 | 83 | test_cmp exp act |
b10a5358 JH |
84 | ' |
85 | ||
86 | test_expect_success 'push with !receive.fsckobjects' ' | |
87 | rm -rf dst && | |
88 | git init dst && | |
89 | ( | |
90 | cd dst && | |
91 | git config receive.fsckobjects false && | |
92 | git config transfer.fsckobjects true | |
93 | ) && | |
3275f4e8 | 94 | test_must_fail git push --porcelain dst main:refs/heads/test >act && |
ef7e93d9 | 95 | test_cmp exp act |
b10a5358 JH |
96 | ' |
97 | ||
ef7e93d9 CB |
98 | cat >exp <<EOF |
99 | To dst | |
3275f4e8 | 100 | ! refs/heads/main:refs/heads/test [remote rejected] (unpacker error) |
ef7e93d9 CB |
101 | EOF |
102 | ||
b10a5358 JH |
103 | test_expect_success 'push with receive.fsckobjects' ' |
104 | rm -rf dst && | |
105 | git init dst && | |
106 | ( | |
107 | cd dst && | |
108 | git config receive.fsckobjects true && | |
109 | git config transfer.fsckobjects false | |
110 | ) && | |
3275f4e8 | 111 | test_must_fail git push --porcelain dst main:refs/heads/test >act && |
c4b27511 | 112 | test_cmp exp act |
b10a5358 JH |
113 | ' |
114 | ||
115 | test_expect_success 'push with transfer.fsckobjects' ' | |
116 | rm -rf dst && | |
117 | git init dst && | |
118 | ( | |
119 | cd dst && | |
120 | git config transfer.fsckobjects true | |
121 | ) && | |
3275f4e8 | 122 | test_must_fail git push --porcelain dst main:refs/heads/test >act && |
c4b27511 | 123 | test_cmp exp act |
b10a5358 JH |
124 | ' |
125 | ||
8b55b9db ÆAB |
126 | test_expect_success 'repair the "corrupt or missing" object' ' |
127 | mv -f .git/objects/$(cat S) .git/objects/$(cat X) && | |
128 | mv .git/objects/$(cat S).back .git/objects/$(cat S) && | |
129 | rm -rf .git/objects/$(cat X) && | |
130 | git fsck | |
131 | ' | |
132 | ||
f9e7d9f8 NTND |
133 | cat >bogus-commit <<EOF |
134 | tree $EMPTY_TREE | |
70a4ae73 JS |
135 | author Bugs Bunny 1234567890 +0000 |
136 | committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000 | |
137 | ||
138 | This commit object intentionally broken | |
139 | EOF | |
140 | ||
134b7327 | 141 | test_expect_success 'setup bogus commit' ' |
34959d80 | 142 | commit="$(git hash-object --literally -t commit -w --stdin <bogus-commit)" |
134b7327 ÆAB |
143 | ' |
144 | ||
536a9ce8 ÆAB |
145 | test_expect_success 'fsck with no skipList input' ' |
146 | test_must_fail git fsck 2>err && | |
6789275d | 147 | test_grep "missingEmail" err |
536a9ce8 ÆAB |
148 | ' |
149 | ||
58dc440b ÆAB |
150 | test_expect_success 'setup sorted and unsorted skipLists' ' |
151 | cat >SKIP.unsorted <<-EOF && | |
cba472d3 | 152 | $(test_oid 004) |
153 | $(test_oid 002) | |
58dc440b | 154 | $commit |
cba472d3 | 155 | $(test_oid 001) |
156 | $(test_oid 003) | |
58dc440b ÆAB |
157 | EOF |
158 | sort SKIP.unsorted >SKIP.sorted | |
159 | ' | |
160 | ||
161 | test_expect_success 'fsck with sorted skipList' ' | |
162 | git -c fsck.skipList=SKIP.sorted fsck | |
163 | ' | |
164 | ||
165 | test_expect_success 'fsck with unsorted skipList' ' | |
166 | git -c fsck.skipList=SKIP.unsorted fsck | |
167 | ' | |
168 | ||
65a836fa ÆAB |
169 | test_expect_success 'fsck with invalid or bogus skipList input' ' |
170 | git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck && | |
171 | test_must_fail git -c fsck.skipList=does-not-exist -c fsck.missingEmail=ignore fsck 2>err && | |
6789275d | 172 | test_grep "could not open.*: does-not-exist" err && |
65a836fa | 173 | test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err && |
6789275d | 174 | test_grep "invalid object name: \[core\]" err |
65a836fa ÆAB |
175 | ' |
176 | ||
371a6550 | 177 | test_expect_success 'fsck with other accepted skipList input (comments & empty lines)' ' |
f706c42b ÆAB |
178 | cat >SKIP.with-comment <<-EOF && |
179 | # Some bad commit | |
cba472d3 | 180 | $(test_oid 001) |
f706c42b ÆAB |
181 | EOF |
182 | test_must_fail git -c fsck.skipList=SKIP.with-comment fsck 2>err-with-comment && | |
6789275d | 183 | test_grep "missingEmail" err-with-comment && |
f706c42b | 184 | cat >SKIP.with-empty-line <<-EOF && |
cba472d3 | 185 | $(test_oid 001) |
f706c42b | 186 | |
cba472d3 | 187 | $(test_oid 002) |
f706c42b ÆAB |
188 | EOF |
189 | test_must_fail git -c fsck.skipList=SKIP.with-empty-line fsck 2>err-with-empty-line && | |
6789275d | 190 | test_grep "missingEmail" err-with-empty-line |
f706c42b ÆAB |
191 | ' |
192 | ||
fb895207 | 193 | test_expect_success 'fsck no garbage output from comments & empty lines errors' ' |
f706c42b ÆAB |
194 | test_line_count = 1 err-with-comment && |
195 | test_line_count = 1 err-with-empty-line | |
196 | ' | |
197 | ||
12b1c50a ÆAB |
198 | test_expect_success 'fsck with invalid abbreviated skipList input' ' |
199 | echo $commit | test_copy_bytes 20 >SKIP.abbreviated && | |
200 | test_must_fail git -c fsck.skipList=SKIP.abbreviated fsck 2>err-abbreviated && | |
6789275d | 201 | test_grep "^fatal: invalid object name: " err-abbreviated |
12b1c50a ÆAB |
202 | ' |
203 | ||
371a6550 ÆAB |
204 | test_expect_success 'fsck with exhaustive accepted skipList input (various types of comments etc.)' ' |
205 | >SKIP.exhaustive && | |
206 | echo "# A commented line" >>SKIP.exhaustive && | |
207 | echo "" >>SKIP.exhaustive && | |
208 | echo " " >>SKIP.exhaustive && | |
209 | echo " # Comment after whitespace" >>SKIP.exhaustive && | |
210 | echo "$commit # Our bad commit (with leading whitespace and trailing comment)" >>SKIP.exhaustive && | |
211 | echo "# Some bad commit (leading whitespace)" >>SKIP.exhaustive && | |
cba472d3 | 212 | echo " $(test_oid 001)" >>SKIP.exhaustive && |
371a6550 ÆAB |
213 | git -c fsck.skipList=SKIP.exhaustive fsck 2>err && |
214 | test_must_be_empty err | |
215 | ' | |
216 | ||
cd94c6f9 | 217 | test_expect_success 'push with receive.fsck.skipList' ' |
cd94c6f9 JS |
218 | git push . $commit:refs/heads/bogus && |
219 | rm -rf dst && | |
220 | git init dst && | |
221 | git --git-dir=dst/.git config receive.fsckObjects true && | |
222 | test_must_fail git push --porcelain dst bogus && | |
cd94c6f9 | 223 | echo $commit >dst/.git/SKIP && |
d786da1c ÆAB |
224 | |
225 | # receive.fsck.* does not fall back on fsck.* | |
226 | git --git-dir=dst/.git config fsck.skipList SKIP && | |
227 | test_must_fail git push --porcelain dst bogus && | |
228 | ||
65a836fa ÆAB |
229 | # Invalid and/or bogus skipList input |
230 | git --git-dir=dst/.git config receive.fsck.skipList /dev/null && | |
231 | test_must_fail git push --porcelain dst bogus && | |
232 | git --git-dir=dst/.git config receive.fsck.skipList does-not-exist && | |
233 | test_must_fail git push --porcelain dst bogus 2>err && | |
6789275d | 234 | test_grep "could not open.*: does-not-exist" err && |
65a836fa ÆAB |
235 | git --git-dir=dst/.git config receive.fsck.skipList config && |
236 | test_must_fail git push --porcelain dst bogus 2>err && | |
6789275d | 237 | test_grep "invalid object name: \[core\]" err && |
65a836fa | 238 | |
d786da1c | 239 | git --git-dir=dst/.git config receive.fsck.skipList SKIP && |
cd94c6f9 JS |
240 | git push --porcelain dst bogus |
241 | ' | |
242 | ||
1362df0d | 243 | test_expect_success 'fetch with fetch.fsck.skipList' ' |
1362df0d ÆAB |
244 | refspec=refs/heads/bogus:refs/heads/bogus && |
245 | git push . $commit:refs/heads/bogus && | |
246 | rm -rf dst && | |
247 | git init dst && | |
248 | git --git-dir=dst/.git config fetch.fsckObjects true && | |
249 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec && | |
d786da1c ÆAB |
250 | git --git-dir=dst/.git config fetch.fsck.skipList /dev/null && |
251 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec && | |
1362df0d | 252 | echo $commit >dst/.git/SKIP && |
d786da1c ÆAB |
253 | |
254 | # fetch.fsck.* does not fall back on fsck.* | |
255 | git --git-dir=dst/.git config fsck.skipList dst/.git/SKIP && | |
256 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec && | |
257 | ||
65a836fa ÆAB |
258 | # Invalid and/or bogus skipList input |
259 | git --git-dir=dst/.git config fetch.fsck.skipList /dev/null && | |
260 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec && | |
261 | git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist && | |
262 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err && | |
6789275d | 263 | test_grep "could not open.*: does-not-exist" err && |
65a836fa ÆAB |
264 | git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/config && |
265 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err && | |
6789275d | 266 | test_grep "invalid object name: \[core\]" err && |
65a836fa | 267 | |
d786da1c | 268 | git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP && |
1362df0d ÆAB |
269 | git --git-dir=dst/.git fetch "file://$(pwd)" $refspec |
270 | ' | |
271 | ||
8a6d0525 ÆAB |
272 | test_expect_success 'fsck.<unknownmsg-id> dies' ' |
273 | test_must_fail git -c fsck.whatEver=ignore fsck 2>err && | |
6789275d | 274 | test_grep "Unhandled message id: whatever" err |
8a6d0525 | 275 | ' |
1362df0d | 276 | |
70a4ae73 | 277 | test_expect_success 'push with receive.fsck.missingEmail=warn' ' |
70a4ae73 JS |
278 | git push . $commit:refs/heads/bogus && |
279 | rm -rf dst && | |
280 | git init dst && | |
281 | git --git-dir=dst/.git config receive.fsckobjects true && | |
282 | test_must_fail git push --porcelain dst bogus && | |
d786da1c ÆAB |
283 | |
284 | # receive.fsck.<msg-id> does not fall back on fsck.<msg-id> | |
285 | git --git-dir=dst/.git config fsck.missingEmail warn && | |
286 | test_must_fail git push --porcelain dst bogus && | |
287 | ||
8a6d0525 ÆAB |
288 | # receive.fsck.<unknownmsg-id> warns |
289 | git --git-dir=dst/.git config \ | |
290 | receive.fsck.whatEver error && | |
291 | ||
70a4ae73 JS |
292 | git --git-dir=dst/.git config \ |
293 | receive.fsck.missingEmail warn && | |
294 | git push --porcelain dst bogus >act 2>&1 && | |
efaba7cc | 295 | grep "missingEmail" act && |
6789275d | 296 | test_grep "skipping unknown msg id.*whatever" act && |
efaba7cc JS |
297 | git --git-dir=dst/.git branch -D bogus && |
298 | git --git-dir=dst/.git config --add \ | |
299 | receive.fsck.missingEmail ignore && | |
efaba7cc | 300 | git push --porcelain dst bogus >act 2>&1 && |
c7cf9566 | 301 | ! grep "missingEmail" act |
70a4ae73 JS |
302 | ' |
303 | ||
1362df0d | 304 | test_expect_success 'fetch with fetch.fsck.missingEmail=warn' ' |
1362df0d ÆAB |
305 | refspec=refs/heads/bogus:refs/heads/bogus && |
306 | git push . $commit:refs/heads/bogus && | |
307 | rm -rf dst && | |
308 | git init dst && | |
309 | git --git-dir=dst/.git config fetch.fsckobjects true && | |
310 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec && | |
d786da1c ÆAB |
311 | |
312 | # fetch.fsck.<msg-id> does not fall back on fsck.<msg-id> | |
313 | git --git-dir=dst/.git config fsck.missingEmail warn && | |
314 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec && | |
315 | ||
8a6d0525 ÆAB |
316 | # receive.fsck.<unknownmsg-id> warns |
317 | git --git-dir=dst/.git config \ | |
318 | fetch.fsck.whatEver error && | |
319 | ||
1362df0d ÆAB |
320 | git --git-dir=dst/.git config \ |
321 | fetch.fsck.missingEmail warn && | |
322 | git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 && | |
323 | grep "missingEmail" act && | |
6789275d | 324 | test_grep "Skipping unknown msg id.*whatever" act && |
1362df0d ÆAB |
325 | rm -rf dst && |
326 | git init dst && | |
327 | git --git-dir=dst/.git config fetch.fsckobjects true && | |
328 | git --git-dir=dst/.git config \ | |
329 | fetch.fsck.missingEmail ignore && | |
330 | git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 && | |
331 | ! grep "missingEmail" act | |
332 | ' | |
333 | ||
f50c4407 JS |
334 | test_expect_success \ |
335 | 'receive.fsck.unterminatedHeader=warn triggers error' ' | |
336 | rm -rf dst && | |
337 | git init dst && | |
338 | git --git-dir=dst/.git config receive.fsckobjects true && | |
339 | git --git-dir=dst/.git config \ | |
340 | receive.fsck.unterminatedheader warn && | |
341 | test_must_fail git push --porcelain dst HEAD >act 2>&1 && | |
342 | grep "Cannot demote unterminatedheader" act | |
343 | ' | |
344 | ||
1362df0d ÆAB |
345 | test_expect_success \ |
346 | 'fetch.fsck.unterminatedHeader=warn triggers error' ' | |
347 | rm -rf dst && | |
348 | git init dst && | |
349 | git --git-dir=dst/.git config fetch.fsckobjects true && | |
350 | git --git-dir=dst/.git config \ | |
351 | fetch.fsck.unterminatedheader warn && | |
352 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" HEAD && | |
353 | grep "Cannot demote unterminatedheader" act | |
354 | ' | |
355 | ||
4dd3b045 JK |
356 | test_expect_success 'badFilemode is not a strict error' ' |
357 | git init --bare badmode.git && | |
358 | tree=$( | |
359 | cd badmode.git && | |
360 | blob=$(echo blob | git hash-object -w --stdin | hex2oct) && | |
361 | printf "123456 foo\0${blob}" | | |
362 | git hash-object -t tree --stdin -w --literally | |
363 | ) && | |
364 | ||
365 | rm -rf dst.git && | |
366 | git init --bare dst.git && | |
367 | git -C dst.git config transfer.fsckObjects true && | |
368 | ||
369 | git -C badmode.git push ../dst.git $tree:refs/tags/tree 2>err && | |
370 | grep "$tree: badFilemode" err | |
371 | ' | |
372 | ||
b10a5358 | 373 | test_done |