]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5504-fetch-receive-strict.sh
Merge branch 'ea/blame-use-oideq'
[thirdparty/git.git] / t / t5504-fetch-receive-strict.sh
1 #!/bin/sh
2
3 test_description='fetch/receive strict mode'
4 . ./test-lib.sh
5
6 test_expect_success 'setup and inject "corrupt or missing" object' '
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|^..|&/|") &&
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 &&
17
18 test_must_fail git fsck
19 '
20
21 test_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 &&
28 test_must_fail git fetch ../.git master
29 )
30 '
31
32 test_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 &&
39 test_must_fail git fetch ../.git master
40 )
41 '
42
43 test_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
54 test_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
64 cat >exp <<EOF
65 To dst
66 ! refs/heads/master:refs/heads/test [remote rejected] (missing necessary objects)
67 Done
68 EOF
69
70 test_expect_success 'push without strict' '
71 rm -rf dst &&
72 git init dst &&
73 (
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
80 '
81
82 test_expect_success 'push with !receive.fsckobjects' '
83 rm -rf dst &&
84 git init dst &&
85 (
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
92 '
93
94 cat >exp <<EOF
95 To dst
96 ! refs/heads/master:refs/heads/test [remote rejected] (unpacker error)
97 EOF
98
99 test_expect_success 'push with receive.fsckobjects' '
100 rm -rf dst &&
101 git init dst &&
102 (
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
109 '
110
111 test_expect_success 'push with transfer.fsckobjects' '
112 rm -rf dst &&
113 git init dst &&
114 (
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
120 '
121
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
127 '
128
129 cat >bogus-commit <<EOF
130 tree $EMPTY_TREE
131 author Bugs Bunny 1234567890 +0000
132 committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
133
134 This commit object intentionally broken
135 EOF
136
137 test_expect_success 'setup bogus commit' '
138 commit="$(git hash-object -t commit -w --stdin <bogus-commit)"
139 '
140
141 test_expect_success 'fsck with no skipList input' '
142 test_must_fail git fsck 2>err &&
143 test_i18ngrep "missingEmail" err
144 '
145
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)
153 EOF
154 sort SKIP.unsorted >SKIP.sorted
155 '
156
157 test_expect_success 'fsck with sorted skipList' '
158 git -c fsck.skipList=SKIP.sorted fsck
159 '
160
161 test_expect_success 'fsck with unsorted skipList' '
162 git -c fsck.skipList=SKIP.unsorted fsck
163 '
164
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
171 '
172
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)
177 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 &&
181 $(test_oid 001)
182
183 $(test_oid 002)
184 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
187 '
188
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
192 '
193
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
198 '
199
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
211 '
212
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 &&
220
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 &&
224
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 &&
234
235 git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
236 git push --porcelain dst bogus
237 '
238
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 &&
249
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 &&
253
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 &&
263
264 git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP &&
265 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec
266 '
267
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
271 '
272
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 &&
279
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 &&
283
284 # receive.fsck.<unknownmsg-id> warns
285 git --git-dir=dst/.git config \
286 receive.fsck.whatEver error &&
287
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
298 '
299
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 &&
307
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 &&
311
312 # receive.fsck.<unknownmsg-id> warns
313 git --git-dir=dst/.git config \
314 fetch.fsck.whatEver error &&
315
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
328 '
329
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
339 '
340
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
350 '
351
352 test_done