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