3 test_description='fetch/receive strict mode'
6 test_expect_success 'setup and inject "corrupt or missing" object' '
7 echo hello >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|^..|&/|") &&
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' '
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' '
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' '
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' '
59 git config transfer.fsckobjects true &&
60 test_must_fail git fetch ../.git master
66 ! refs/heads/master:refs/heads/test [remote rejected] (missing necessary objects)
69 test_expect_success 'push without strict' '
74 git config fetch.fsckobjects false &&
75 git config transfer.fsckobjects false
77 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
81 test_expect_success 'push with !receive.fsckobjects' '
86 git config receive.fsckobjects false &&
87 git config transfer.fsckobjects true
89 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
95 ! refs/heads/master:refs/heads/test [remote rejected] (unpacker error)
98 test_expect_success 'push with receive.fsckobjects' '
103 git config receive.fsckobjects true &&
104 git config transfer.fsckobjects false
106 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
110 test_expect_success 'push with transfer.fsckobjects' '
115 git config transfer.fsckobjects true
117 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
121 test_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) &&
128 cat >bogus-commit <<EOF
130 author Bugs Bunny 1234567890 +0000
131 committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
133 This commit object intentionally broken
136 test_expect_success 'setup bogus commit' '
137 commit="$(git hash-object -t commit -w --stdin <bogus-commit)"
140 test_expect_success 'fsck with no skipList input' '
141 test_must_fail git fsck 2>err &&
142 test_i18ngrep "missingEmail" err
145 test_expect_success 'setup sorted and unsorted skipLists' '
146 cat >SKIP.unsorted <<-EOF &&
147 0000000000000000000000000000000000000004
148 0000000000000000000000000000000000000002
150 0000000000000000000000000000000000000001
151 0000000000000000000000000000000000000003
153 sort SKIP.unsorted >SKIP.sorted
156 test_expect_success 'fsck with sorted skipList' '
157 git -c fsck.skipList=SKIP.sorted fsck
160 test_expect_success 'fsck with unsorted skipList' '
161 git -c fsck.skipList=SKIP.unsorted fsck
164 test_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
172 test_expect_success 'fsck with invalid or bogus skipList input (comments & empty lines)' '
173 cat >SKIP.with-comment <<-EOF &&
175 0000000000000000000000000000000000000001
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
182 0000000000000000000000000000000000000002
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
188 test_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
193 test_expect_success 'fsck with invalid abbreviated skipList input' '
194 echo $commit | test_copy_bytes 20 >SKIP.abbreviated &&
195 test_must_fail git -c fsck.skipList=SKIP.abbreviated fsck 2>err-abbreviated &&
196 test_i18ngrep "^fatal: Invalid SHA-1: " err-abbreviated
199 test_expect_success 'push with receive.fsck.skipList' '
200 git push . $commit:refs/heads/bogus &&
203 git --git-dir=dst/.git config receive.fsckObjects true &&
204 test_must_fail git push --porcelain dst bogus &&
205 echo $commit >dst/.git/SKIP &&
207 # receive.fsck.* does not fall back on fsck.*
208 git --git-dir=dst/.git config fsck.skipList SKIP &&
209 test_must_fail git push --porcelain dst bogus &&
211 # Invalid and/or bogus skipList input
212 git --git-dir=dst/.git config receive.fsck.skipList /dev/null &&
213 test_must_fail git push --porcelain dst bogus &&
214 git --git-dir=dst/.git config receive.fsck.skipList does-not-exist &&
215 test_must_fail git push --porcelain dst bogus 2>err &&
216 test_i18ngrep "Could not open skip list: does-not-exist" err &&
217 git --git-dir=dst/.git config receive.fsck.skipList config &&
218 test_must_fail git push --porcelain dst bogus 2>err &&
219 test_i18ngrep "Invalid SHA-1: \[core\]" err &&
221 git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
222 git push --porcelain dst bogus
225 test_expect_success 'fetch with fetch.fsck.skipList' '
226 refspec=refs/heads/bogus:refs/heads/bogus &&
227 git push . $commit:refs/heads/bogus &&
230 git --git-dir=dst/.git config fetch.fsckObjects true &&
231 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
232 git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
233 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
234 echo $commit >dst/.git/SKIP &&
236 # fetch.fsck.* does not fall back on fsck.*
237 git --git-dir=dst/.git config fsck.skipList dst/.git/SKIP &&
238 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
240 # Invalid and/or bogus skipList input
241 git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
242 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
243 git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist &&
244 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
245 test_i18ngrep "Could not open skip list: does-not-exist" err &&
246 git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/config &&
247 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
248 test_i18ngrep "Invalid SHA-1: \[core\]" err &&
250 git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP &&
251 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec
254 test_expect_success 'fsck.<unknownmsg-id> dies' '
255 test_must_fail git -c fsck.whatEver=ignore fsck 2>err &&
256 test_i18ngrep "Unhandled message id: whatever" err
259 test_expect_success 'push with receive.fsck.missingEmail=warn' '
260 git push . $commit:refs/heads/bogus &&
263 git --git-dir=dst/.git config receive.fsckobjects true &&
264 test_must_fail git push --porcelain dst bogus &&
266 # receive.fsck.<msg-id> does not fall back on fsck.<msg-id>
267 git --git-dir=dst/.git config fsck.missingEmail warn &&
268 test_must_fail git push --porcelain dst bogus &&
270 # receive.fsck.<unknownmsg-id> warns
271 git --git-dir=dst/.git config \
272 receive.fsck.whatEver error &&
274 git --git-dir=dst/.git config \
275 receive.fsck.missingEmail warn &&
276 git push --porcelain dst bogus >act 2>&1 &&
277 grep "missingEmail" act &&
278 test_i18ngrep "Skipping unknown msg id.*whatever" act &&
279 git --git-dir=dst/.git branch -D bogus &&
280 git --git-dir=dst/.git config --add \
281 receive.fsck.missingEmail ignore &&
282 git push --porcelain dst bogus >act 2>&1 &&
283 ! grep "missingEmail" act
286 test_expect_success 'fetch with fetch.fsck.missingEmail=warn' '
287 refspec=refs/heads/bogus:refs/heads/bogus &&
288 git push . $commit:refs/heads/bogus &&
291 git --git-dir=dst/.git config fetch.fsckobjects true &&
292 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
294 # fetch.fsck.<msg-id> does not fall back on fsck.<msg-id>
295 git --git-dir=dst/.git config fsck.missingEmail warn &&
296 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
298 # receive.fsck.<unknownmsg-id> warns
299 git --git-dir=dst/.git config \
300 fetch.fsck.whatEver error &&
302 git --git-dir=dst/.git config \
303 fetch.fsck.missingEmail warn &&
304 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 &&
305 grep "missingEmail" act &&
306 test_i18ngrep "Skipping unknown msg id.*whatever" act &&
309 git --git-dir=dst/.git config fetch.fsckobjects true &&
310 git --git-dir=dst/.git config \
311 fetch.fsck.missingEmail ignore &&
312 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 &&
313 ! grep "missingEmail" act
316 test_expect_success \
317 'receive.fsck.unterminatedHeader=warn triggers error' '
320 git --git-dir=dst/.git config receive.fsckobjects true &&
321 git --git-dir=dst/.git config \
322 receive.fsck.unterminatedheader warn &&
323 test_must_fail git push --porcelain dst HEAD >act 2>&1 &&
324 grep "Cannot demote unterminatedheader" act
327 test_expect_success \
328 'fetch.fsck.unterminatedHeader=warn triggers error' '
331 git --git-dir=dst/.git config fetch.fsckobjects true &&
332 git --git-dir=dst/.git config \
333 fetch.fsck.unterminatedheader warn &&
334 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" HEAD &&
335 grep "Cannot demote unterminatedheader" act