]>
Commit | Line | Data |
---|---|---|
b10a5358 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='fetch/receive strict mode' | |
334afbc7 JS |
4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master |
5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME | |
6 | ||
b10a5358 JH |
7 | . ./test-lib.sh |
8 | ||
8b55b9db | 9 | test_expect_success 'setup and inject "corrupt or missing" object' ' |
b10a5358 JH |
10 | echo hello >greetings && |
11 | git add greetings && | |
12 | git commit -m greetings && | |
13 | ||
14 | S=$(git rev-parse :greetings | sed -e "s|^..|&/|") && | |
15 | X=$(echo bye | git hash-object -w --stdin | sed -e "s|^..|&/|") && | |
8b55b9db ÆAB |
16 | echo $S >S && |
17 | echo $X >X && | |
18 | cp .git/objects/$S .git/objects/$S.back && | |
b10a5358 JH |
19 | mv -f .git/objects/$X .git/objects/$S && |
20 | ||
21 | test_must_fail git fsck | |
22 | ' | |
23 | ||
24 | test_expect_success 'fetch without strict' ' | |
25 | rm -rf dst && | |
26 | git init dst && | |
27 | ( | |
28 | cd dst && | |
29 | git config fetch.fsckobjects false && | |
30 | git config transfer.fsckobjects false && | |
2e2e7e9d | 31 | test_must_fail git fetch ../.git master |
b10a5358 JH |
32 | ) |
33 | ' | |
34 | ||
35 | test_expect_success 'fetch with !fetch.fsckobjects' ' | |
36 | rm -rf dst && | |
37 | git init dst && | |
38 | ( | |
39 | cd dst && | |
40 | git config fetch.fsckobjects false && | |
41 | git config transfer.fsckobjects true && | |
2e2e7e9d | 42 | test_must_fail git fetch ../.git master |
b10a5358 JH |
43 | ) |
44 | ' | |
45 | ||
46 | test_expect_success 'fetch with fetch.fsckobjects' ' | |
47 | rm -rf dst && | |
48 | git init dst && | |
49 | ( | |
50 | cd dst && | |
51 | git config fetch.fsckobjects true && | |
52 | git config transfer.fsckobjects false && | |
53 | test_must_fail git fetch ../.git master | |
54 | ) | |
55 | ' | |
56 | ||
57 | test_expect_success 'fetch with transfer.fsckobjects' ' | |
58 | rm -rf dst && | |
59 | git init dst && | |
60 | ( | |
61 | cd dst && | |
62 | git config transfer.fsckobjects true && | |
63 | test_must_fail git fetch ../.git master | |
64 | ) | |
65 | ' | |
66 | ||
ef7e93d9 CB |
67 | cat >exp <<EOF |
68 | To dst | |
69 | ! refs/heads/master:refs/heads/test [remote rejected] (missing necessary objects) | |
7dcbeaa0 | 70 | Done |
ef7e93d9 CB |
71 | EOF |
72 | ||
b10a5358 JH |
73 | test_expect_success 'push without strict' ' |
74 | rm -rf dst && | |
75 | git init dst && | |
76 | ( | |
77 | cd dst && | |
78 | git config fetch.fsckobjects false && | |
79 | git config transfer.fsckobjects false | |
80 | ) && | |
ef7e93d9 CB |
81 | test_must_fail git push --porcelain dst master:refs/heads/test >act && |
82 | test_cmp exp act | |
b10a5358 JH |
83 | ' |
84 | ||
85 | test_expect_success 'push with !receive.fsckobjects' ' | |
86 | rm -rf dst && | |
87 | git init dst && | |
88 | ( | |
89 | cd dst && | |
90 | git config receive.fsckobjects false && | |
91 | git config transfer.fsckobjects true | |
92 | ) && | |
ef7e93d9 CB |
93 | test_must_fail git push --porcelain dst master:refs/heads/test >act && |
94 | test_cmp exp act | |
b10a5358 JH |
95 | ' |
96 | ||
ef7e93d9 CB |
97 | cat >exp <<EOF |
98 | To dst | |
74eb32d3 | 99 | ! refs/heads/master:refs/heads/test [remote rejected] (unpacker error) |
ef7e93d9 CB |
100 | EOF |
101 | ||
b10a5358 JH |
102 | test_expect_success 'push with receive.fsckobjects' ' |
103 | rm -rf dst && | |
104 | git init dst && | |
105 | ( | |
106 | cd dst && | |
107 | git config receive.fsckobjects true && | |
108 | git config transfer.fsckobjects false | |
109 | ) && | |
c4b27511 JK |
110 | test_must_fail git push --porcelain dst master:refs/heads/test >act && |
111 | test_cmp exp act | |
b10a5358 JH |
112 | ' |
113 | ||
114 | test_expect_success 'push with transfer.fsckobjects' ' | |
115 | rm -rf dst && | |
116 | git init dst && | |
117 | ( | |
118 | cd dst && | |
119 | git config transfer.fsckobjects true | |
120 | ) && | |
c4b27511 JK |
121 | test_must_fail git push --porcelain dst master:refs/heads/test >act && |
122 | test_cmp exp act | |
b10a5358 JH |
123 | ' |
124 | ||
8b55b9db ÆAB |
125 | test_expect_success 'repair the "corrupt or missing" object' ' |
126 | mv -f .git/objects/$(cat S) .git/objects/$(cat X) && | |
127 | mv .git/objects/$(cat S).back .git/objects/$(cat S) && | |
128 | rm -rf .git/objects/$(cat X) && | |
129 | git fsck | |
130 | ' | |
131 | ||
f9e7d9f8 NTND |
132 | cat >bogus-commit <<EOF |
133 | tree $EMPTY_TREE | |
70a4ae73 JS |
134 | author Bugs Bunny 1234567890 +0000 |
135 | committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000 | |
136 | ||
137 | This commit object intentionally broken | |
138 | EOF | |
139 | ||
134b7327 ÆAB |
140 | test_expect_success 'setup bogus commit' ' |
141 | commit="$(git hash-object -t commit -w --stdin <bogus-commit)" | |
142 | ' | |
143 | ||
536a9ce8 ÆAB |
144 | test_expect_success 'fsck with no skipList input' ' |
145 | test_must_fail git fsck 2>err && | |
146 | test_i18ngrep "missingEmail" err | |
147 | ' | |
148 | ||
58dc440b ÆAB |
149 | test_expect_success 'setup sorted and unsorted skipLists' ' |
150 | cat >SKIP.unsorted <<-EOF && | |
cba472d3 | 151 | $(test_oid 004) |
152 | $(test_oid 002) | |
58dc440b | 153 | $commit |
cba472d3 | 154 | $(test_oid 001) |
155 | $(test_oid 003) | |
58dc440b ÆAB |
156 | EOF |
157 | sort SKIP.unsorted >SKIP.sorted | |
158 | ' | |
159 | ||
160 | test_expect_success 'fsck with sorted skipList' ' | |
161 | git -c fsck.skipList=SKIP.sorted fsck | |
162 | ' | |
163 | ||
164 | test_expect_success 'fsck with unsorted skipList' ' | |
165 | git -c fsck.skipList=SKIP.unsorted fsck | |
166 | ' | |
167 | ||
65a836fa ÆAB |
168 | test_expect_success 'fsck with invalid or bogus skipList input' ' |
169 | git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck && | |
170 | test_must_fail git -c fsck.skipList=does-not-exist -c fsck.missingEmail=ignore fsck 2>err && | |
24eb33eb | 171 | test_i18ngrep "could not open.*: does-not-exist" err && |
65a836fa | 172 | test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err && |
24eb33eb | 173 | test_i18ngrep "invalid object name: \[core\]" err |
65a836fa ÆAB |
174 | ' |
175 | ||
371a6550 | 176 | test_expect_success 'fsck with other accepted skipList input (comments & empty lines)' ' |
f706c42b ÆAB |
177 | cat >SKIP.with-comment <<-EOF && |
178 | # Some bad commit | |
cba472d3 | 179 | $(test_oid 001) |
f706c42b ÆAB |
180 | EOF |
181 | test_must_fail git -c fsck.skipList=SKIP.with-comment fsck 2>err-with-comment && | |
371a6550 | 182 | test_i18ngrep "missingEmail" err-with-comment && |
f706c42b | 183 | cat >SKIP.with-empty-line <<-EOF && |
cba472d3 | 184 | $(test_oid 001) |
f706c42b | 185 | |
cba472d3 | 186 | $(test_oid 002) |
f706c42b ÆAB |
187 | EOF |
188 | test_must_fail git -c fsck.skipList=SKIP.with-empty-line fsck 2>err-with-empty-line && | |
371a6550 | 189 | test_i18ngrep "missingEmail" err-with-empty-line |
f706c42b ÆAB |
190 | ' |
191 | ||
fb895207 | 192 | test_expect_success 'fsck no garbage output from comments & empty lines errors' ' |
f706c42b ÆAB |
193 | test_line_count = 1 err-with-comment && |
194 | test_line_count = 1 err-with-empty-line | |
195 | ' | |
196 | ||
12b1c50a ÆAB |
197 | test_expect_success 'fsck with invalid abbreviated skipList input' ' |
198 | echo $commit | test_copy_bytes 20 >SKIP.abbreviated && | |
199 | test_must_fail git -c fsck.skipList=SKIP.abbreviated fsck 2>err-abbreviated && | |
24eb33eb | 200 | test_i18ngrep "^fatal: invalid object name: " err-abbreviated |
12b1c50a ÆAB |
201 | ' |
202 | ||
371a6550 ÆAB |
203 | test_expect_success 'fsck with exhaustive accepted skipList input (various types of comments etc.)' ' |
204 | >SKIP.exhaustive && | |
205 | echo "# A commented line" >>SKIP.exhaustive && | |
206 | echo "" >>SKIP.exhaustive && | |
207 | echo " " >>SKIP.exhaustive && | |
208 | echo " # Comment after whitespace" >>SKIP.exhaustive && | |
209 | echo "$commit # Our bad commit (with leading whitespace and trailing comment)" >>SKIP.exhaustive && | |
210 | echo "# Some bad commit (leading whitespace)" >>SKIP.exhaustive && | |
cba472d3 | 211 | echo " $(test_oid 001)" >>SKIP.exhaustive && |
371a6550 ÆAB |
212 | git -c fsck.skipList=SKIP.exhaustive fsck 2>err && |
213 | test_must_be_empty err | |
214 | ' | |
215 | ||
cd94c6f9 | 216 | test_expect_success 'push with receive.fsck.skipList' ' |
cd94c6f9 JS |
217 | git push . $commit:refs/heads/bogus && |
218 | rm -rf dst && | |
219 | git init dst && | |
220 | git --git-dir=dst/.git config receive.fsckObjects true && | |
221 | test_must_fail git push --porcelain dst bogus && | |
cd94c6f9 | 222 | echo $commit >dst/.git/SKIP && |
d786da1c ÆAB |
223 | |
224 | # receive.fsck.* does not fall back on fsck.* | |
225 | git --git-dir=dst/.git config fsck.skipList SKIP && | |
226 | test_must_fail git push --porcelain dst bogus && | |
227 | ||
65a836fa ÆAB |
228 | # Invalid and/or bogus skipList input |
229 | git --git-dir=dst/.git config receive.fsck.skipList /dev/null && | |
230 | test_must_fail git push --porcelain dst bogus && | |
231 | git --git-dir=dst/.git config receive.fsck.skipList does-not-exist && | |
232 | test_must_fail git push --porcelain dst bogus 2>err && | |
24eb33eb | 233 | test_i18ngrep "could not open.*: does-not-exist" err && |
65a836fa ÆAB |
234 | git --git-dir=dst/.git config receive.fsck.skipList config && |
235 | test_must_fail git push --porcelain dst bogus 2>err && | |
24eb33eb | 236 | test_i18ngrep "invalid object name: \[core\]" err && |
65a836fa | 237 | |
d786da1c | 238 | git --git-dir=dst/.git config receive.fsck.skipList SKIP && |
cd94c6f9 JS |
239 | git push --porcelain dst bogus |
240 | ' | |
241 | ||
1362df0d | 242 | test_expect_success 'fetch with fetch.fsck.skipList' ' |
1362df0d ÆAB |
243 | refspec=refs/heads/bogus:refs/heads/bogus && |
244 | git push . $commit:refs/heads/bogus && | |
245 | rm -rf dst && | |
246 | git init dst && | |
247 | git --git-dir=dst/.git config fetch.fsckObjects true && | |
248 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec && | |
d786da1c ÆAB |
249 | git --git-dir=dst/.git config fetch.fsck.skipList /dev/null && |
250 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec && | |
1362df0d | 251 | echo $commit >dst/.git/SKIP && |
d786da1c ÆAB |
252 | |
253 | # fetch.fsck.* does not fall back on fsck.* | |
254 | git --git-dir=dst/.git config fsck.skipList dst/.git/SKIP && | |
255 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec && | |
256 | ||
65a836fa ÆAB |
257 | # Invalid and/or bogus skipList input |
258 | git --git-dir=dst/.git config fetch.fsck.skipList /dev/null && | |
259 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec && | |
260 | git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist && | |
261 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err && | |
24eb33eb | 262 | test_i18ngrep "could not open.*: does-not-exist" err && |
65a836fa ÆAB |
263 | git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/config && |
264 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err && | |
24eb33eb | 265 | test_i18ngrep "invalid object name: \[core\]" err && |
65a836fa | 266 | |
d786da1c | 267 | git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP && |
1362df0d ÆAB |
268 | git --git-dir=dst/.git fetch "file://$(pwd)" $refspec |
269 | ' | |
270 | ||
8a6d0525 ÆAB |
271 | test_expect_success 'fsck.<unknownmsg-id> dies' ' |
272 | test_must_fail git -c fsck.whatEver=ignore fsck 2>err && | |
273 | test_i18ngrep "Unhandled message id: whatever" err | |
274 | ' | |
1362df0d | 275 | |
70a4ae73 | 276 | test_expect_success 'push with receive.fsck.missingEmail=warn' ' |
70a4ae73 JS |
277 | git push . $commit:refs/heads/bogus && |
278 | rm -rf dst && | |
279 | git init dst && | |
280 | git --git-dir=dst/.git config receive.fsckobjects true && | |
281 | test_must_fail git push --porcelain dst bogus && | |
d786da1c ÆAB |
282 | |
283 | # receive.fsck.<msg-id> does not fall back on fsck.<msg-id> | |
284 | git --git-dir=dst/.git config fsck.missingEmail warn && | |
285 | test_must_fail git push --porcelain dst bogus && | |
286 | ||
8a6d0525 ÆAB |
287 | # receive.fsck.<unknownmsg-id> warns |
288 | git --git-dir=dst/.git config \ | |
289 | receive.fsck.whatEver error && | |
290 | ||
70a4ae73 JS |
291 | git --git-dir=dst/.git config \ |
292 | receive.fsck.missingEmail warn && | |
293 | git push --porcelain dst bogus >act 2>&1 && | |
efaba7cc | 294 | grep "missingEmail" act && |
8a6d0525 | 295 | test_i18ngrep "Skipping unknown msg id.*whatever" act && |
efaba7cc JS |
296 | git --git-dir=dst/.git branch -D bogus && |
297 | git --git-dir=dst/.git config --add \ | |
298 | receive.fsck.missingEmail ignore && | |
efaba7cc | 299 | git push --porcelain dst bogus >act 2>&1 && |
c7cf9566 | 300 | ! grep "missingEmail" act |
70a4ae73 JS |
301 | ' |
302 | ||
1362df0d | 303 | test_expect_success 'fetch with fetch.fsck.missingEmail=warn' ' |
1362df0d ÆAB |
304 | refspec=refs/heads/bogus:refs/heads/bogus && |
305 | git push . $commit:refs/heads/bogus && | |
306 | rm -rf dst && | |
307 | git init dst && | |
308 | git --git-dir=dst/.git config fetch.fsckobjects true && | |
309 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec && | |
d786da1c ÆAB |
310 | |
311 | # fetch.fsck.<msg-id> does not fall back on fsck.<msg-id> | |
312 | git --git-dir=dst/.git config fsck.missingEmail warn && | |
313 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec && | |
314 | ||
8a6d0525 ÆAB |
315 | # receive.fsck.<unknownmsg-id> warns |
316 | git --git-dir=dst/.git config \ | |
317 | fetch.fsck.whatEver error && | |
318 | ||
1362df0d ÆAB |
319 | git --git-dir=dst/.git config \ |
320 | fetch.fsck.missingEmail warn && | |
321 | git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 && | |
322 | grep "missingEmail" act && | |
8a6d0525 | 323 | test_i18ngrep "Skipping unknown msg id.*whatever" act && |
1362df0d ÆAB |
324 | rm -rf dst && |
325 | git init dst && | |
326 | git --git-dir=dst/.git config fetch.fsckobjects true && | |
327 | git --git-dir=dst/.git config \ | |
328 | fetch.fsck.missingEmail ignore && | |
329 | git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 && | |
330 | ! grep "missingEmail" act | |
331 | ' | |
332 | ||
f50c4407 JS |
333 | test_expect_success \ |
334 | 'receive.fsck.unterminatedHeader=warn triggers error' ' | |
335 | rm -rf dst && | |
336 | git init dst && | |
337 | git --git-dir=dst/.git config receive.fsckobjects true && | |
338 | git --git-dir=dst/.git config \ | |
339 | receive.fsck.unterminatedheader warn && | |
340 | test_must_fail git push --porcelain dst HEAD >act 2>&1 && | |
341 | grep "Cannot demote unterminatedheader" act | |
342 | ' | |
343 | ||
1362df0d ÆAB |
344 | test_expect_success \ |
345 | 'fetch.fsck.unterminatedHeader=warn triggers error' ' | |
346 | rm -rf dst && | |
347 | git init dst && | |
348 | git --git-dir=dst/.git config fetch.fsckobjects true && | |
349 | git --git-dir=dst/.git config \ | |
350 | fetch.fsck.unterminatedheader warn && | |
351 | test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" HEAD && | |
352 | grep "Cannot demote unterminatedheader" act | |
353 | ' | |
354 | ||
b10a5358 | 355 | test_done |