fsck: test & document {fetch,receive}.fsck.* config fallback
[git.git] / t / t5504-fetch-receive-strict.sh
blob771a94b4b6c1ee3d55e8e441e053eaafe5e373aa
1 #!/bin/sh
3 test_description='fetch/receive strict mode'
4 . ./test-lib.sh
6 test_expect_success 'setup and inject "corrupt or missing" object' '
7 echo hello >greetings &&
8 git add 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|^..|&/|") &&
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 &&
18 test_must_fail git fsck
21 test_expect_success 'fetch without strict' '
22 rm -rf dst &&
23 git init dst &&
25 cd dst &&
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' '
33 rm -rf dst &&
34 git init dst &&
36 cd dst &&
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' '
44 rm -rf dst &&
45 git init dst &&
47 cd dst &&
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' '
55 rm -rf dst &&
56 git init dst &&
58 cd dst &&
59 git config transfer.fsckobjects true &&
60 test_must_fail git fetch ../.git master
64 cat >exp <<EOF
65 To dst
66 ! refs/heads/master:refs/heads/test [remote rejected] (missing necessary objects)
67 EOF
69 test_expect_success 'push without strict' '
70 rm -rf dst &&
71 git init dst &&
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
81 test_expect_success 'push with !receive.fsckobjects' '
82 rm -rf dst &&
83 git init dst &&
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
93 cat >exp <<EOF
94 To dst
95 ! refs/heads/master:refs/heads/test [remote rejected] (unpacker error)
96 EOF
98 test_expect_success 'push with receive.fsckobjects' '
99 rm -rf dst &&
100 git init dst &&
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
110 test_expect_success 'push with transfer.fsckobjects' '
111 rm -rf dst &&
112 git init dst &&
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
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) &&
125 git fsck
128 cat >bogus-commit <<EOF
129 tree $EMPTY_TREE
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 'push with receive.fsck.skipList' '
137 commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
138 git push . $commit:refs/heads/bogus &&
139 rm -rf dst &&
140 git init dst &&
141 git --git-dir=dst/.git config receive.fsckObjects true &&
142 test_must_fail git push --porcelain dst bogus &&
143 echo $commit >dst/.git/SKIP &&
145 # receive.fsck.* does not fall back on fsck.*
146 git --git-dir=dst/.git config fsck.skipList SKIP &&
147 test_must_fail git push --porcelain dst bogus &&
149 git --git-dir=dst/.git config receive.fsck.skipList SKIP &&
150 git push --porcelain dst bogus
153 test_expect_success 'fetch with fetch.fsck.skipList' '
154 commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
155 refspec=refs/heads/bogus:refs/heads/bogus &&
156 git push . $commit:refs/heads/bogus &&
157 rm -rf dst &&
158 git init dst &&
159 git --git-dir=dst/.git config fetch.fsckObjects true &&
160 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
161 git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
162 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
163 echo $commit >dst/.git/SKIP &&
165 # fetch.fsck.* does not fall back on fsck.*
166 git --git-dir=dst/.git config fsck.skipList dst/.git/SKIP &&
167 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
169 git --git-dir=dst/.git config fetch.fsck.skipList dst/.git/SKIP &&
170 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec
174 test_expect_success 'push with receive.fsck.missingEmail=warn' '
175 commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
176 git push . $commit:refs/heads/bogus &&
177 rm -rf dst &&
178 git init dst &&
179 git --git-dir=dst/.git config receive.fsckobjects true &&
180 test_must_fail git push --porcelain dst bogus &&
182 # receive.fsck.<msg-id> does not fall back on fsck.<msg-id>
183 git --git-dir=dst/.git config fsck.missingEmail warn &&
184 test_must_fail git push --porcelain dst bogus &&
186 git --git-dir=dst/.git config \
187 receive.fsck.missingEmail warn &&
188 git push --porcelain dst bogus >act 2>&1 &&
189 grep "missingEmail" act &&
190 git --git-dir=dst/.git branch -D bogus &&
191 git --git-dir=dst/.git config --add \
192 receive.fsck.missingEmail ignore &&
193 git push --porcelain dst bogus >act 2>&1 &&
194 ! grep "missingEmail" act
197 test_expect_success 'fetch with fetch.fsck.missingEmail=warn' '
198 commit="$(git hash-object -t commit -w --stdin <bogus-commit)" &&
199 refspec=refs/heads/bogus:refs/heads/bogus &&
200 git push . $commit:refs/heads/bogus &&
201 rm -rf dst &&
202 git init dst &&
203 git --git-dir=dst/.git config fetch.fsckobjects true &&
204 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
206 # fetch.fsck.<msg-id> does not fall back on fsck.<msg-id>
207 git --git-dir=dst/.git config fsck.missingEmail warn &&
208 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
210 git --git-dir=dst/.git config \
211 fetch.fsck.missingEmail warn &&
212 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 &&
213 grep "missingEmail" act &&
214 rm -rf dst &&
215 git init dst &&
216 git --git-dir=dst/.git config fetch.fsckobjects true &&
217 git --git-dir=dst/.git config \
218 fetch.fsck.missingEmail ignore &&
219 git --git-dir=dst/.git fetch "file://$(pwd)" $refspec >act 2>&1 &&
220 ! grep "missingEmail" act
223 test_expect_success \
224 'receive.fsck.unterminatedHeader=warn triggers error' '
225 rm -rf dst &&
226 git init dst &&
227 git --git-dir=dst/.git config receive.fsckobjects true &&
228 git --git-dir=dst/.git config \
229 receive.fsck.unterminatedheader warn &&
230 test_must_fail git push --porcelain dst HEAD >act 2>&1 &&
231 grep "Cannot demote unterminatedheader" act
234 test_expect_success \
235 'fetch.fsck.unterminatedHeader=warn triggers error' '
236 rm -rf dst &&
237 git init dst &&
238 git --git-dir=dst/.git config fetch.fsckobjects true &&
239 git --git-dir=dst/.git config \
240 fetch.fsck.unterminatedheader warn &&
241 test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" HEAD &&
242 grep "Cannot demote unterminatedheader" act
245 test_done