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 'fsck with invalid or bogus skipList input' '
137 git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck &&
138 test_must_fail git -c fsck.skipList=does-not-exist -c fsck.missingEmail=ignore fsck 2>err &&
139 test_i18ngrep "Could not open skip list: does-not-exist" err &&
140 test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err &&
141 test_i18ngrep "Invalid SHA-1: \[core\]" err
144 test_expect_success 'push with receive.fsck.skipList' '
145 commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
146 git push . $commit:refs/heads/bogus &&
149 git --git-dir=dst/.git config receive.fsckObjects true &&
150 test_must_fail git push --porcelain dst bogus &&
151 echo $commit >dst/.git/SKIP &&
153 # receive.fsck.* does not fall back on fsck.*
154 git --git-dir=dst/.git config fsck.skipList SKIP &&
155 test_must_fail git push --porcelain dst bogus &&
157 # Invalid and/or bogus skipList input
158 git --git-dir=dst/.git config receive.fsck.skipList /dev/null &&
159 test_must_fail git push --porcelain dst bogus &&
160 git --git-dir=dst/.git config receive.fsck.skipList does-not-exist &&
161 test_must_fail git push --porcelain dst bogus 2>err &&
162 test_i18ngrep "Could not open skip list: does-not-exist" err &&
163 git --git-dir=dst/.git config receive.fsck.skipList config &&
164 test_must_fail git push --porcelain dst bogus 2>err &&
165 test_i18ngrep "Invalid SHA-1: \[core\]" err &&
167 git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
168 git push --porcelain dst bogus
171 test_expect_success 'fetch with fetch.fsck.skipList' '
172 commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
173 refspec=refs/heads/bogus:refs/heads/bogus &&
174 git push . $commit:refs/heads/bogus &&
177 git --git-dir=dst/.git config fetch.fsckObjects true &&
178 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
179 git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
180 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
181 echo $commit >dst/.git/SKIP &&
183 # fetch.fsck.* does not fall back on fsck.*
184 git --git-dir=dst/.git config fsck.skipList dst/.git/SKIP &&
185 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
187 # Invalid and/or bogus skipList input
188 git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
189 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
190 git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist &&
191 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
192 test_i18ngrep "Could not open skip list: does-not-exist" err &&
193 git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/config &&
194 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec 2>err &&
195 test_i18ngrep "Invalid SHA-1: \[core\]" err &&
197 git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP &&
198 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec
201 test_expect_success 'fsck.<unknownmsg-id> dies' '
202 test_must_fail git -c fsck.whatEver=ignore fsck 2>err &&
203 test_i18ngrep "Unhandled message id: whatever" err
206 test_expect_success 'push with receive.fsck.missingEmail=warn' '
207 commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
208 git push . $commit:refs/heads/bogus &&
211 git --git-dir=dst/.git config receive.fsckobjects true &&
212 test_must_fail git push --porcelain dst bogus &&
214 # receive.fsck.<msg-id> does not fall back on fsck.<msg-id>
215 git --git-dir=dst/.git config fsck.missingEmail warn &&
216 test_must_fail git push --porcelain dst bogus &&
218 # receive.fsck.<unknownmsg-id> warns
219 git --git-dir=dst/.git config \
220 receive.fsck.whatEver error &&
222 git --git-dir=dst/.git config \
223 receive.fsck.missingEmail warn &&
224 git push --porcelain dst bogus >act 2>&1 &&
225 grep "missingEmail" act &&
226 test_i18ngrep "Skipping unknown msg id.*whatever" act &&
227 git --git-dir=dst/.git branch -D bogus &&
228 git --git-dir=dst/.git config --add \
229 receive.fsck.missingEmail ignore &&
230 git push --porcelain dst bogus >act 2>&1 &&
231 ! grep "missingEmail" act
234 test_expect_success 'fetch with fetch.fsck.missingEmail=warn' '
235 commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
236 refspec=refs/heads/bogus:refs/heads/bogus &&
237 git push . $commit:refs/heads/bogus &&
240 git --git-dir=dst/.git config fetch.fsckobjects true &&
241 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
243 # fetch.fsck.<msg-id> does not fall back on fsck.<msg-id>
244 git --git-dir=dst/.git config fsck.missingEmail warn &&
245 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
247 # receive.fsck.<unknownmsg-id> warns
248 git --git-dir=dst/.git config \
249 fetch.fsck.whatEver error &&
251 git --git-dir=dst/.git config \
252 fetch.fsck.missingEmail warn &&
253 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 &&
254 grep "missingEmail" act &&
255 test_i18ngrep "Skipping unknown msg id.*whatever" act &&
258 git --git-dir=dst/.git config fetch.fsckobjects true &&
259 git --git-dir=dst/.git config \
260 fetch.fsck.missingEmail ignore &&
261 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 &&
262 ! grep "missingEmail" act
265 test_expect_success \
266 'receive.fsck.unterminatedHeader=warn triggers error' '
269 git --git-dir=dst/.git config receive.fsckobjects true &&
270 git --git-dir=dst/.git config \
271 receive.fsck.unterminatedheader warn &&
272 test_must_fail git push --porcelain dst HEAD >act 2>&1 &&
273 grep "Cannot demote unterminatedheader" act
276 test_expect_success \
277 'fetch.fsck.unterminatedHeader=warn triggers error' '
280 git --git-dir=dst/.git config fetch.fsckobjects true &&
281 git --git-dir=dst/.git config \
282 fetch.fsck.unterminatedheader warn &&
283 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" HEAD &&
284 grep "Cannot demote unterminatedheader" act