]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5504-fetch-receive-strict.sh
fsck: document and test commented & empty line skipList input
[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)
67EOF
68
b10a5358
JH
69test_expect_success 'push without strict' '
70 rm -rf dst &&
71 git init dst &&
72 (
73 cd dst &&
74 git config fetch.fsckobjects false &&
75 git config transfer.fsckobjects false
76 ) &&
ef7e93d9
CB
77 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
78 test_cmp exp act
b10a5358
JH
79'
80
81test_expect_success 'push with !receive.fsckobjects' '
82 rm -rf dst &&
83 git init dst &&
84 (
85 cd dst &&
86 git config receive.fsckobjects false &&
87 git config transfer.fsckobjects true
88 ) &&
ef7e93d9
CB
89 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
90 test_cmp exp act
b10a5358
JH
91'
92
ef7e93d9
CB
93cat >exp <<EOF
94To dst
74eb32d3 95! refs/heads/master:refs/heads/test [remote rejected] (unpacker error)
ef7e93d9
CB
96EOF
97
b10a5358
JH
98test_expect_success 'push with receive.fsckobjects' '
99 rm -rf dst &&
100 git init dst &&
101 (
102 cd dst &&
103 git config receive.fsckobjects true &&
104 git config transfer.fsckobjects false
105 ) &&
c4b27511
JK
106 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
107 test_cmp exp act
b10a5358
JH
108'
109
110test_expect_success 'push with transfer.fsckobjects' '
111 rm -rf dst &&
112 git init dst &&
113 (
114 cd dst &&
115 git config transfer.fsckobjects true
116 ) &&
c4b27511
JK
117 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
118 test_cmp exp act
b10a5358
JH
119'
120
8b55b9db
ÆAB
121test_expect_success 'repair the "corrupt or missing" object' '
122 mv -f .git/objects/$(cat S) .git/objects/$(cat X) &&
123 mv .git/objects/$(cat S).back .git/objects/$(cat S) &&
124 rm -rf .git/objects/$(cat X) &&
125 git fsck
126'
127
f9e7d9f8
NTND
128cat >bogus-commit <<EOF
129tree $EMPTY_TREE
70a4ae73
JS
130author Bugs Bunny 1234567890 +0000
131committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
132
133This commit object intentionally broken
134EOF
135
134b7327
ÆAB
136test_expect_success 'setup bogus commit' '
137 commit="$(git hash-object -t commit -w --stdin <bogus-commit)"
138'
139
536a9ce8
ÆAB
140test_expect_success 'fsck with no skipList input' '
141 test_must_fail git fsck 2>err &&
142 test_i18ngrep "missingEmail" err
143'
144
58dc440b
ÆAB
145test_expect_success 'setup sorted and unsorted skipLists' '
146 cat >SKIP.unsorted <<-EOF &&
147 0000000000000000000000000000000000000004
148 0000000000000000000000000000000000000002
149 $commit
150 0000000000000000000000000000000000000001
151 0000000000000000000000000000000000000003
152 EOF
153 sort SKIP.unsorted >SKIP.sorted
154'
155
156test_expect_success 'fsck with sorted skipList' '
157 git -c fsck.skipList=SKIP.sorted fsck
158'
159
160test_expect_success 'fsck with unsorted skipList' '
161 git -c fsck.skipList=SKIP.unsorted fsck
162'
163
65a836fa
ÆAB
164test_expect_success 'fsck with invalid or bogus skipList input' '
165 git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck &&
166 test_must_fail git -c fsck.skipList=does-not-exist -c fsck.missingEmail=ignore fsck 2>err &&
167 test_i18ngrep "Could not open skip list: does-not-exist" err &&
168 test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err &&
169 test_i18ngrep "Invalid SHA-1: \[core\]" err
170'
171
f706c42b
ÆAB
172test_expect_success 'fsck with invalid or bogus skipList input (comments & empty lines)' '
173 cat >SKIP.with-comment <<-EOF &&
174 # Some bad commit
175 0000000000000000000000000000000000000001
176 EOF
177 test_must_fail git -c fsck.skipList=SKIP.with-comment fsck 2>err-with-comment &&
178 test_i18ngrep "^fatal: Invalid SHA-1: # Some bad commit$" err-with-comment &&
179 cat >SKIP.with-empty-line <<-EOF &&
180 0000000000000000000000000000000000000001
181
182 0000000000000000000000000000000000000002
183 EOF
184 test_must_fail git -c fsck.skipList=SKIP.with-empty-line fsck 2>err-with-empty-line &&
185 test_i18ngrep "^fatal: Invalid SHA-1: " err-with-empty-line
186'
187
188test_expect_failure 'fsck no garbage output from comments & empty lines errors' '
189 test_line_count = 1 err-with-comment &&
190 test_line_count = 1 err-with-empty-line
191'
192
cd94c6f9 193test_expect_success 'push with receive.fsck.skipList' '
cd94c6f9
JS
194 git push . $commit:refs/heads/bogus &&
195 rm -rf dst &&
196 git init dst &&
197 git --git-dir=dst/.git config receive.fsckObjects true &&
198 test_must_fail git push --porcelain dst bogus &&
cd94c6f9 199 echo $commit >dst/.git/SKIP &&
d786da1c
ÆAB
200
201 # receive.fsck.* does not fall back on fsck.*
202 git --git-dir=dst/.git config fsck.skipList SKIP &&
203 test_must_fail git push --porcelain dst bogus &&
204
65a836fa
ÆAB
205 # Invalid and/or bogus skipList input
206 git --git-dir=dst/.git config receive.fsck.skipList /dev/null &&
207 test_must_fail git push --porcelain dst bogus &&
208 git --git-dir=dst/.git config receive.fsck.skipList does-not-exist &&
209 test_must_fail git push --porcelain dst bogus 2>err &&
210 test_i18ngrep "Could not open skip list: does-not-exist" err &&
211 git --git-dir=dst/.git config receive.fsck.skipList config &&
212 test_must_fail git push --porcelain dst bogus 2>err &&
213 test_i18ngrep "Invalid SHA-1: \[core\]" err &&
214
d786da1c 215 git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
cd94c6f9
JS
216 git push --porcelain dst bogus
217'
218
1362df0d 219test_expect_success 'fetch with fetch.fsck.skipList' '
1362df0d
ÆAB
220 refspec=refs/heads/bogus:refs/heads/bogus &&
221 git push . $commit:refs/heads/bogus &&
222 rm -rf dst &&
223 git init dst &&
224 git --git-dir=dst/.git config fetch.fsckObjects true &&
225 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
d786da1c
ÆAB
226 git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
227 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
1362df0d 228 echo $commit >dst/.git/SKIP &&
d786da1c
ÆAB
229
230 # fetch.fsck.* does not fall back on fsck.*
231 git --git-dir=dst/.git config fsck.skipList dst/.git/SKIP &&
232 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
233
65a836fa
ÆAB
234 # Invalid and/or bogus skipList input
235 git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
236 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
237 git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist &&
238 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
239 test_i18ngrep "Could not open skip list: does-not-exist" err &&
240 git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/config &&
241 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
242 test_i18ngrep "Invalid SHA-1: \[core\]" err &&
243
d786da1c 244 git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP &&
1362df0d
ÆAB
245 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec
246'
247
8a6d0525
ÆAB
248test_expect_success 'fsck.<unknownmsg-id> dies' '
249 test_must_fail git -c fsck.whatEver=ignore fsck 2>err &&
250 test_i18ngrep "Unhandled message id: whatever" err
251'
1362df0d 252
70a4ae73 253test_expect_success 'push with receive.fsck.missingEmail=warn' '
70a4ae73
JS
254 git push . $commit:refs/heads/bogus &&
255 rm -rf dst &&
256 git init dst &&
257 git --git-dir=dst/.git config receive.fsckobjects true &&
258 test_must_fail git push --porcelain dst bogus &&
d786da1c
ÆAB
259
260 # receive.fsck.<msg-id> does not fall back on fsck.<msg-id>
261 git --git-dir=dst/.git config fsck.missingEmail warn &&
262 test_must_fail git push --porcelain dst bogus &&
263
8a6d0525
ÆAB
264 # receive.fsck.<unknownmsg-id> warns
265 git --git-dir=dst/.git config \
266 receive.fsck.whatEver error &&
267
70a4ae73
JS
268 git --git-dir=dst/.git config \
269 receive.fsck.missingEmail warn &&
270 git push --porcelain dst bogus >act 2>&1 &&
efaba7cc 271 grep "missingEmail" act &&
8a6d0525 272 test_i18ngrep "Skipping unknown msg id.*whatever" act &&
efaba7cc
JS
273 git --git-dir=dst/.git branch -D bogus &&
274 git --git-dir=dst/.git config --add \
275 receive.fsck.missingEmail ignore &&
efaba7cc 276 git push --porcelain dst bogus >act 2>&1 &&
c7cf9566 277 ! grep "missingEmail" act
70a4ae73
JS
278'
279
1362df0d 280test_expect_success 'fetch with fetch.fsck.missingEmail=warn' '
1362df0d
ÆAB
281 refspec=refs/heads/bogus:refs/heads/bogus &&
282 git push . $commit:refs/heads/bogus &&
283 rm -rf dst &&
284 git init dst &&
285 git --git-dir=dst/.git config fetch.fsckobjects true &&
286 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
d786da1c
ÆAB
287
288 # fetch.fsck.<msg-id> does not fall back on fsck.<msg-id>
289 git --git-dir=dst/.git config fsck.missingEmail warn &&
290 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
291
8a6d0525
ÆAB
292 # receive.fsck.<unknownmsg-id> warns
293 git --git-dir=dst/.git config \
294 fetch.fsck.whatEver error &&
295
1362df0d
ÆAB
296 git --git-dir=dst/.git config \
297 fetch.fsck.missingEmail warn &&
298 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 &&
299 grep "missingEmail" act &&
8a6d0525 300 test_i18ngrep "Skipping unknown msg id.*whatever" act &&
1362df0d
ÆAB
301 rm -rf dst &&
302 git init dst &&
303 git --git-dir=dst/.git config fetch.fsckobjects true &&
304 git --git-dir=dst/.git config \
305 fetch.fsck.missingEmail ignore &&
306 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 &&
307 ! grep "missingEmail" act
308'
309
f50c4407
JS
310test_expect_success \
311 'receive.fsck.unterminatedHeader=warn triggers error' '
312 rm -rf dst &&
313 git init dst &&
314 git --git-dir=dst/.git config receive.fsckobjects true &&
315 git --git-dir=dst/.git config \
316 receive.fsck.unterminatedheader warn &&
317 test_must_fail git push --porcelain dst HEAD >act 2>&1 &&
318 grep "Cannot demote unterminatedheader" act
319'
320
1362df0d
ÆAB
321test_expect_success \
322 'fetch.fsck.unterminatedHeader=warn triggers error' '
323 rm -rf dst &&
324 git init dst &&
325 git --git-dir=dst/.git config fetch.fsckobjects true &&
326 git --git-dir=dst/.git config \
327 fetch.fsck.unterminatedheader warn &&
328 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" HEAD &&
329 grep "Cannot demote unterminatedheader" act
330'
331
b10a5358 332test_done