3 test_description='fetch/receive strict mode'
6 test_expect_success 'setup and inject "corrupt or missing" object' '
8 echo hello >greetings &&
10 git commit -m greetings &&
12 S=$(git rev-parse :greetings | sed -e "s|^..|&/|") &&
13 X=$(echo bye | git hash-object -w --stdin | sed -e "s|^..|&/|") &&
16 cp .git/objects/$S .git/objects/$S.back &&
17 mv -f .git/objects/$X .git/objects/$S &&
19 test_must_fail git fsck
22 test_expect_success 'fetch without strict' '
27 git config fetch.fsckobjects false &&
28 git config transfer.fsckobjects false &&
29 test_must_fail git fetch ../.git master
33 test_expect_success 'fetch with !fetch.fsckobjects' '
38 git config fetch.fsckobjects false &&
39 git config transfer.fsckobjects true &&
40 test_must_fail git fetch ../.git master
44 test_expect_success 'fetch with fetch.fsckobjects' '
49 git config fetch.fsckobjects true &&
50 git config transfer.fsckobjects false &&
51 test_must_fail git fetch ../.git master
55 test_expect_success 'fetch with transfer.fsckobjects' '
60 git config transfer.fsckobjects true &&
61 test_must_fail git fetch ../.git master
67 ! refs/heads/master:refs/heads/test [remote rejected] (missing necessary objects)
71 test_expect_success 'push without strict' '
76 git config fetch.fsckobjects false &&
77 git config transfer.fsckobjects false
79 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
83 test_expect_success 'push with !receive.fsckobjects' '
88 git config receive.fsckobjects false &&
89 git config transfer.fsckobjects true
91 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
97 ! refs/heads/master:refs/heads/test [remote rejected] (unpacker error)
100 test_expect_success 'push with receive.fsckobjects' '
105 git config receive.fsckobjects true &&
106 git config transfer.fsckobjects false
108 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
112 test_expect_success 'push with transfer.fsckobjects' '
117 git config transfer.fsckobjects true
119 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
123 test_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) &&
130 cat >bogus-commit <<EOF
132 author Bugs Bunny 1234567890 +0000
133 committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
135 This commit object intentionally broken
138 test_expect_success 'setup bogus commit' '
139 commit="$(git hash-object -t commit -w --stdin <bogus-commit)"
142 test_expect_success 'fsck with no skipList input' '
143 test_must_fail git fsck 2>err &&
144 test_i18ngrep "missingEmail" err
147 test_expect_success 'setup sorted and unsorted skipLists' '
148 cat >SKIP.unsorted <<-EOF &&
155 sort SKIP.unsorted >SKIP.sorted
158 test_expect_success 'fsck with sorted skipList' '
159 git -c fsck.skipList=SKIP.sorted fsck
162 test_expect_success 'fsck with unsorted skipList' '
163 git -c fsck.skipList=SKIP.unsorted fsck
166 test_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 &&
169 test_i18ngrep "could not open.*: does-not-exist" err &&
170 test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err &&
171 test_i18ngrep "invalid object name: \[core\]" err
174 test_expect_success 'fsck with other accepted skipList input (comments & empty lines)' '
175 cat >SKIP.with-comment <<-EOF &&
179 test_must_fail git -c fsck.skipList=SKIP.with-comment fsck 2>err-with-comment &&
180 test_i18ngrep "missingEmail" err-with-comment &&
181 cat >SKIP.with-empty-line <<-EOF &&
186 test_must_fail git -c fsck.skipList=SKIP.with-empty-line fsck 2>err-with-empty-line &&
187 test_i18ngrep "missingEmail" err-with-empty-line
190 test_expect_success 'fsck no garbage output from comments & empty lines errors' '
191 test_line_count = 1 err-with-comment &&
192 test_line_count = 1 err-with-empty-line
195 test_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 &&
198 test_i18ngrep "^fatal: invalid object name: " err-abbreviated
201 test_expect_success 'fsck with exhaustive accepted skipList input (various types of comments etc.)' '
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 &&
209 echo " $(test_oid 001)" >>SKIP.exhaustive &&
210 git -c fsck.skipList=SKIP.exhaustive fsck 2>err &&
211 test_must_be_empty err
214 test_expect_success 'push with receive.fsck.skipList' '
215 git push . $commit:refs/heads/bogus &&
218 git --git-dir=dst/.git config receive.fsckObjects true &&
219 test_must_fail git push --porcelain dst bogus &&
220 echo $commit >dst/.git/SKIP &&
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 &&
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 &&
231 test_i18ngrep "could not open.*: does-not-exist" err &&
232 git --git-dir=dst/.git config receive.fsck.skipList config &&
233 test_must_fail git push --porcelain dst bogus 2>err &&
234 test_i18ngrep "invalid object name: \[core\]" err &&
236 git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
237 git push --porcelain dst bogus
240 test_expect_success 'fetch with fetch.fsck.skipList' '
241 refspec=refs/heads/bogus:refs/heads/bogus &&
242 git push . $commit:refs/heads/bogus &&
245 git --git-dir=dst/.git config fetch.fsckObjects true &&
246 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
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 &&
249 echo $commit >dst/.git/SKIP &&
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 &&
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 &&
260 test_i18ngrep "could not open.*: does-not-exist" err &&
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 &&
263 test_i18ngrep "invalid object name: \[core\]" err &&
265 git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP &&
266 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec
269 test_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
274 test_expect_success 'push with receive.fsck.missingEmail=warn' '
275 git push . $commit:refs/heads/bogus &&
278 git --git-dir=dst/.git config receive.fsckobjects true &&
279 test_must_fail git push --porcelain dst bogus &&
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 &&
285 # receive.fsck.<unknownmsg-id> warns
286 git --git-dir=dst/.git config \
287 receive.fsck.whatEver error &&
289 git --git-dir=dst/.git config \
290 receive.fsck.missingEmail warn &&
291 git push --porcelain dst bogus >act 2>&1 &&
292 grep "missingEmail" act &&
293 test_i18ngrep "Skipping unknown msg id.*whatever" act &&
294 git --git-dir=dst/.git branch -D bogus &&
295 git --git-dir=dst/.git config --add \
296 receive.fsck.missingEmail ignore &&
297 git push --porcelain dst bogus >act 2>&1 &&
298 ! grep "missingEmail" act
301 test_expect_success 'fetch with fetch.fsck.missingEmail=warn' '
302 refspec=refs/heads/bogus:refs/heads/bogus &&
303 git push . $commit:refs/heads/bogus &&
306 git --git-dir=dst/.git config fetch.fsckobjects true &&
307 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
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 &&
313 # receive.fsck.<unknownmsg-id> warns
314 git --git-dir=dst/.git config \
315 fetch.fsck.whatEver error &&
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 &&
321 test_i18ngrep "Skipping unknown msg id.*whatever" act &&
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
331 test_expect_success \
332 'receive.fsck.unterminatedHeader=warn triggers error' '
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
342 test_expect_success \
343 'fetch.fsck.unterminatedHeader=warn triggers error' '
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