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)
70 test_expect_success 'push without strict' '
75 git config fetch.fsckobjects false &&
76 git config transfer.fsckobjects false
78 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
82 test_expect_success 'push with !receive.fsckobjects' '
87 git config receive.fsckobjects false &&
88 git config transfer.fsckobjects true
90 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
96 ! refs/heads/master:refs/heads/test [remote rejected] (unpacker error)
99 test_expect_success 'push with receive.fsckobjects' '
104 git config receive.fsckobjects true &&
105 git config transfer.fsckobjects false
107 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
111 test_expect_success 'push with transfer.fsckobjects' '
116 git config transfer.fsckobjects true
118 test_must_fail git push --porcelain dst master:refs/heads/test >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) &&
129 cat >bogus-commit <<EOF
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 &&
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 &&
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 &&
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.)' '
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 &&
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 &&
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 &&
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 &&
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 &&
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' '
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' '
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