cbae31f3301b25e439b59b8925dcc21b9c5db1e4
1#!/bin/sh
2
3test_description='fetch/receive strict mode'
4. ./test-lib.sh
5
6test_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
21test_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
32test_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
43test_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
54test_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
64cat >exp <<EOF
65To dst
66! refs/heads/master:refs/heads/test [remote rejected] (missing necessary objects)
67EOF
68
69test_expect_success 'push without strict' '
70 rm -rf dst &&
71 git init dst &&
72 (
73 cd dst &&
74 git config fetch.fsckobjects false &&
75 git config transfer.fsckobjects false
76 ) &&
77 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
78 test_cmp exp act
79'
80
81test_expect_success 'push with !receive.fsckobjects' '
82 rm -rf dst &&
83 git init dst &&
84 (
85 cd dst &&
86 git config receive.fsckobjects false &&
87 git config transfer.fsckobjects true
88 ) &&
89 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
90 test_cmp exp act
91'
92
93cat >exp <<EOF
94To dst
95! refs/heads/master:refs/heads/test [remote rejected] (unpacker error)
96EOF
97
98test_expect_success 'push with receive.fsckobjects' '
99 rm -rf dst &&
100 git init dst &&
101 (
102 cd dst &&
103 git config receive.fsckobjects true &&
104 git config transfer.fsckobjects false
105 ) &&
106 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
107 test_cmp exp act
108'
109
110test_expect_success 'push with transfer.fsckobjects' '
111 rm -rf dst &&
112 git init dst &&
113 (
114 cd dst &&
115 git config transfer.fsckobjects true
116 ) &&
117 test_must_fail git push --porcelain dst master:refs/heads/test >act &&
118 test_cmp exp act
119'
120
121test_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) &&
125 git fsck
126'
127
128cat >bogus-commit <<EOF
129tree $EMPTY_TREE
130author Bugs Bunny 1234567890 +0000
131committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
132
133This commit object intentionally broken
134EOF
135
136test_expect_success 'setup bogus commit' '
137 commit="$(git hash-object -t commit -w --stdin <bogus-commit)"
138'
139
140test_expect_success 'fsck with no skipList input' '
141 test_must_fail git fsck 2>err &&
142 test_i18ngrep "missingEmail" err
143'
144
145test_expect_success 'fsck with invalid or bogus skipList input' '
146 git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck &&
147 test_must_fail git -c fsck.skipList=does-not-exist -c fsck.missingEmail=ignore fsck 2>err &&
148 test_i18ngrep "Could not open skip list: does-not-exist" err &&
149 test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err &&
150 test_i18ngrep "Invalid SHA-1: \[core\]" err
151'
152
153test_expect_success 'push with receive.fsck.skipList' '
154 git push . $commit:refs/heads/bogus &&
155 rm -rf dst &&
156 git init dst &&
157 git --git-dir=dst/.git config receive.fsckObjects true &&
158 test_must_fail git push --porcelain dst bogus &&
159 echo $commit >dst/.git/SKIP &&
160
161 # receive.fsck.* does not fall back on fsck.*
162 git --git-dir=dst/.git config fsck.skipList SKIP &&
163 test_must_fail git push --porcelain dst bogus &&
164
165 # Invalid and/or bogus skipList input
166 git --git-dir=dst/.git config receive.fsck.skipList /dev/null &&
167 test_must_fail git push --porcelain dst bogus &&
168 git --git-dir=dst/.git config receive.fsck.skipList does-not-exist &&
169 test_must_fail git push --porcelain dst bogus 2>err &&
170 test_i18ngrep "Could not open skip list: does-not-exist" err &&
171 git --git-dir=dst/.git config receive.fsck.skipList config &&
172 test_must_fail git push --porcelain dst bogus 2>err &&
173 test_i18ngrep "Invalid SHA-1: \[core\]" err &&
174
175 git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
176 git push --porcelain dst bogus
177'
178
179test_expect_success 'fetch with fetch.fsck.skipList' '
180 refspec=refs/heads/bogus:refs/heads/bogus &&
181 git push . $commit:refs/heads/bogus &&
182 rm -rf dst &&
183 git init dst &&
184 git --git-dir=dst/.git config fetch.fsckObjects true &&
185 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
186 git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
187 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
188 echo $commit >dst/.git/SKIP &&
189
190 # fetch.fsck.* does not fall back on fsck.*
191 git --git-dir=dst/.git config fsck.skipList dst/.git/SKIP &&
192 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
193
194 # Invalid and/or bogus skipList input
195 git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
196 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
197 git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist &&
198 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
199 test_i18ngrep "Could not open skip list: does-not-exist" err &&
200 git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/config &&
201 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
202 test_i18ngrep "Invalid SHA-1: \[core\]" err &&
203
204 git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP &&
205 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec
206'
207
208test_expect_success 'fsck.<unknownmsg-id> dies' '
209 test_must_fail git -c fsck.whatEver=ignore fsck 2>err &&
210 test_i18ngrep "Unhandled message id: whatever" err
211'
212
213test_expect_success 'push with receive.fsck.missingEmail=warn' '
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
220 # receive.fsck.<msg-id> does not fall back on fsck.<msg-id>
221 git --git-dir=dst/.git config fsck.missingEmail warn &&
222 test_must_fail git push --porcelain dst bogus &&
223
224 # receive.fsck.<unknownmsg-id> warns
225 git --git-dir=dst/.git config \
226 receive.fsck.whatEver error &&
227
228 git --git-dir=dst/.git config \
229 receive.fsck.missingEmail warn &&
230 git push --porcelain dst bogus >act 2>&1 &&
231 grep "missingEmail" act &&
232 test_i18ngrep "Skipping unknown msg id.*whatever" act &&
233 git --git-dir=dst/.git branch -D bogus &&
234 git --git-dir=dst/.git config --add \
235 receive.fsck.missingEmail ignore &&
236 git push --porcelain dst bogus >act 2>&1 &&
237 ! grep "missingEmail" act
238'
239
240test_expect_success 'fetch with fetch.fsck.missingEmail=warn' '
241 refspec=refs/heads/bogus:refs/heads/bogus &&
242 git push . $commit:refs/heads/bogus &&
243 rm -rf dst &&
244 git init dst &&
245 git --git-dir=dst/.git config fetch.fsckobjects true &&
246 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
247
248 # fetch.fsck.<msg-id> does not fall back on fsck.<msg-id>
249 git --git-dir=dst/.git config fsck.missingEmail warn &&
250 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
251
252 # receive.fsck.<unknownmsg-id> warns
253 git --git-dir=dst/.git config \
254 fetch.fsck.whatEver error &&
255
256 git --git-dir=dst/.git config \
257 fetch.fsck.missingEmail warn &&
258 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 &&
259 grep "missingEmail" act &&
260 test_i18ngrep "Skipping unknown msg id.*whatever" act &&
261 rm -rf dst &&
262 git init dst &&
263 git --git-dir=dst/.git config fetch.fsckobjects true &&
264 git --git-dir=dst/.git config \
265 fetch.fsck.missingEmail ignore &&
266 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 &&
267 ! grep "missingEmail" act
268'
269
270test_expect_success \
271 'receive.fsck.unterminatedHeader=warn triggers error' '
272 rm -rf dst &&
273 git init dst &&
274 git --git-dir=dst/.git config receive.fsckobjects true &&
275 git --git-dir=dst/.git config \
276 receive.fsck.unterminatedheader warn &&
277 test_must_fail git push --porcelain dst HEAD >act 2>&1 &&
278 grep "Cannot demote unterminatedheader" act
279'
280
281test_expect_success \
282 'fetch.fsck.unterminatedHeader=warn triggers error' '
283 rm -rf dst &&
284 git init dst &&
285 git --git-dir=dst/.git config fetch.fsckobjects true &&
286 git --git-dir=dst/.git config \
287 fetch.fsck.unterminatedheader warn &&
288 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" HEAD &&
289 grep "Cannot demote unterminatedheader" act
290'
291
292test_done