git: add `--super-prefix` to usage string
[alt-git.git] / t / t5504-fetch-receive-strict.sh
blob1a16ac4c0dba9dde67230e15151c327ba9c916ed
1 #!/bin/sh
3 test_description='fetch/receive strict mode'
4 . ./test-lib.sh
6 test_expect_success 'setup and inject "corrupt or missing" object' '
7 echo hello >greetings &&
8 git add greetings &&
9 git commit -m greetings &&
11 S=$(git rev-parse :greetings | sed -e "s|^..|&/|") &&
12 X=$(echo bye | git hash-object -w --stdin | sed -e "s|^..|&/|") &&
13 echo $S >S &&
14 echo $X >X &&
15 cp .git/objects/$S .git/objects/$S.back &&
16 mv -f .git/objects/$X .git/objects/$S &&
18 test_must_fail git fsck
21 test_expect_success 'fetch without strict' '
22 rm -rf dst &&
23 git init dst &&
25 cd dst &&
26 git config fetch.fsckobjects false &&
27 git config transfer.fsckobjects false &&
28 test_must_fail git fetch ../.git master
32 test_expect_success 'fetch with !fetch.fsckobjects' '
33 rm -rf dst &&
34 git init dst &&
36 cd dst &&
37 git config fetch.fsckobjects false &&
38 git config transfer.fsckobjects true &&
39 test_must_fail git fetch ../.git master
43 test_expect_success 'fetch with fetch.fsckobjects' '
44 rm -rf dst &&
45 git init dst &&
47 cd dst &&
48 git config fetch.fsckobjects true &&
49 git config transfer.fsckobjects false &&
50 test_must_fail git fetch ../.git master
54 test_expect_success 'fetch with transfer.fsckobjects' '
55 rm -rf dst &&
56 git init dst &&
58 cd dst &&
59 git config transfer.fsckobjects true &&
60 test_must_fail git fetch ../.git master
64 cat >exp <<EOF
65 To dst
66 ! refs/heads/master:refs/heads/test [remote rejected] (missing necessary objects)
67 Done
68 EOF
70 test_expect_success 'push without strict' '
71 rm -rf dst &&
72 git init dst &&
74 cd dst &&
75 git config fetch.fsckobjects false &&
76 git config transfer.fsckobjects false
77 ) &&
78 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
79 test_cmp exp act
82 test_expect_success 'push with !receive.fsckobjects' '
83 rm -rf dst &&
84 git init dst &&
86 cd dst &&
87 git config receive.fsckobjects false &&
88 git config transfer.fsckobjects true
89 ) &&
90 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
91 test_cmp exp act
94 cat >exp <<EOF
95 To dst
96 ! refs/heads/master:refs/heads/test [remote rejected] (unpacker error)
97 EOF
99 test_expect_success 'push with receive.fsckobjects' '
100 rm -rf dst &&
101 git init dst &&
103 cd dst &&
104 git config receive.fsckobjects true &&
105 git config transfer.fsckobjects false
106 ) &&
107 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
108 test_cmp exp act
111 test_expect_success 'push with transfer.fsckobjects' '
112 rm -rf dst &&
113 git init dst &&
115 cd dst &&
116 git config transfer.fsckobjects true
117 ) &&
118 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
119 test_cmp exp act
122 test_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
129 cat >bogus-commit <<EOF
130 tree $EMPTY_TREE
131 author Bugs Bunny 1234567890 +0000
132 committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
134 This commit object intentionally broken
137 test_expect_success 'setup bogus commit' '
138 commit="$(git hash-object -t commit -w --stdin <bogus-commit)"
141 test_expect_success 'fsck with no skipList input' '
142 test_must_fail git fsck 2>err &&
143 test_i18ngrep "missingEmail" err
146 test_expect_success 'setup sorted and unsorted skipLists' '
147 cat >SKIP.unsorted <<-EOF &&
148 $(test_oid 004)
149 $(test_oid 002)
150 $commit
151 $(test_oid 001)
152 $(test_oid 003)
154 sort SKIP.unsorted >SKIP.sorted
157 test_expect_success 'fsck with sorted skipList' '
158 git -c fsck.skipList=SKIP.sorted fsck
161 test_expect_success 'fsck with unsorted skipList' '
162 git -c fsck.skipList=SKIP.unsorted fsck
165 test_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 &&
168 test_i18ngrep "could not open.*: does-not-exist" err &&
169 test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err &&
170 test_i18ngrep "invalid object name: \[core\]" err
173 test_expect_success 'fsck with other accepted skipList input (comments & empty lines)' '
174 cat >SKIP.with-comment <<-EOF &&
175 # Some bad commit
176 $(test_oid 001)
178 test_must_fail git -c fsck.skipList=SKIP.with-comment fsck 2>err-with-comment &&
179 test_i18ngrep "missingEmail" err-with-comment &&
180 cat >SKIP.with-empty-line <<-EOF &&
181 $(test_oid 001)
183 $(test_oid 002)
185 test_must_fail git -c fsck.skipList=SKIP.with-empty-line fsck 2>err-with-empty-line &&
186 test_i18ngrep "missingEmail" err-with-empty-line
189 test_expect_success 'fsck no garbage output from comments & empty lines errors' '
190 test_line_count = 1 err-with-comment &&
191 test_line_count = 1 err-with-empty-line
194 test_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 &&
197 test_i18ngrep "^fatal: invalid object name: " err-abbreviated
200 test_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 &&
208 echo " $(test_oid 001)" >>SKIP.exhaustive &&
209 git -c fsck.skipList=SKIP.exhaustive fsck 2>err &&
210 test_must_be_empty err
213 test_expect_success 'push with receive.fsck.skipList' '
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 &&
219 echo $commit >dst/.git/SKIP &&
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 &&
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 &&
230 test_i18ngrep "could not open.*: does-not-exist" err &&
231 git --git-dir=dst/.git config receive.fsck.skipList config &&
232 test_must_fail git push --porcelain dst bogus 2>err &&
233 test_i18ngrep "invalid object name: \[core\]" err &&
235 git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
236 git push --porcelain dst bogus
239 test_expect_success 'fetch with fetch.fsck.skipList' '
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 &&
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 &&
248 echo $commit >dst/.git/SKIP &&
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 &&
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 &&
259 test_i18ngrep "could not open.*: does-not-exist" err &&
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 &&
262 test_i18ngrep "invalid object name: \[core\]" err &&
264 git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP &&
265 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec
268 test_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
273 test_expect_success 'push with receive.fsck.missingEmail=warn' '
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 &&
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 &&
284 # receive.fsck.<unknownmsg-id> warns
285 git --git-dir=dst/.git config \
286 receive.fsck.whatEver error &&
288 git --git-dir=dst/.git config \
289 receive.fsck.missingEmail warn &&
290 git push --porcelain dst bogus >act 2>&1 &&
291 grep "missingEmail" act &&
292 test_i18ngrep "Skipping unknown msg id.*whatever" act &&
293 git --git-dir=dst/.git branch -D bogus &&
294 git --git-dir=dst/.git config --add \
295 receive.fsck.missingEmail ignore &&
296 git push --porcelain dst bogus >act 2>&1 &&
297 ! grep "missingEmail" act
300 test_expect_success 'fetch with fetch.fsck.missingEmail=warn' '
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 &&
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 &&
312 # receive.fsck.<unknownmsg-id> warns
313 git --git-dir=dst/.git config \
314 fetch.fsck.whatEver error &&
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 &&
320 test_i18ngrep "Skipping unknown msg id.*whatever" act &&
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
330 test_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
341 test_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
352 test_done