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