]>
Commit | Line | Data |
---|---|---|
bcdb34f7 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='fetching and pushing, with or without wildcard' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | D=`pwd` | |
8 | ||
9 | mk_empty () { | |
10 | rm -fr testrepo && | |
11 | mkdir testrepo && | |
12 | ( | |
13 | cd testrepo && | |
586e4ce2 AR |
14 | git init && |
15 | mv .git/hooks .git/hooks-disabled | |
bcdb34f7 JH |
16 | ) |
17 | } | |
18 | ||
6125796f JH |
19 | mk_test () { |
20 | mk_empty && | |
21 | ( | |
22 | for ref in "$@" | |
23 | do | |
24 | git push testrepo $the_first_commit:refs/$ref || { | |
25 | echo "Oops, push refs/$ref failure" | |
26 | exit 1 | |
27 | } | |
28 | done && | |
29 | cd testrepo && | |
30 | for ref in "$@" | |
31 | do | |
32 | r=$(git show-ref -s --verify refs/$ref) && | |
33 | test "z$r" = "z$the_first_commit" || { | |
34 | echo "Oops, refs/$ref is wrong" | |
35 | exit 1 | |
36 | } | |
37 | done && | |
38 | git fsck --full | |
39 | ) | |
40 | } | |
41 | ||
42 | check_push_result () { | |
43 | ( | |
44 | cd testrepo && | |
45 | it="$1" && | |
46 | shift | |
47 | for ref in "$@" | |
48 | do | |
49 | r=$(git show-ref -s --verify refs/$ref) && | |
50 | test "z$r" = "z$it" || { | |
51 | echo "Oops, refs/$ref is wrong" | |
52 | exit 1 | |
53 | } | |
54 | done && | |
55 | git fsck --full | |
56 | ) | |
57 | } | |
58 | ||
bcdb34f7 JH |
59 | test_expect_success setup ' |
60 | ||
61 | : >path1 && | |
62 | git add path1 && | |
63 | test_tick && | |
64 | git commit -a -m repo && | |
6125796f JH |
65 | the_first_commit=$(git show-ref -s --verify refs/heads/master) && |
66 | ||
67 | : >path2 && | |
68 | git add path2 && | |
69 | test_tick && | |
70 | git commit -a -m second && | |
bcdb34f7 JH |
71 | the_commit=$(git show-ref -s --verify refs/heads/master) |
72 | ||
73 | ' | |
74 | ||
75 | test_expect_success 'fetch without wildcard' ' | |
76 | mk_empty && | |
77 | ( | |
78 | cd testrepo && | |
79 | git fetch .. refs/heads/master:refs/remotes/origin/master && | |
80 | ||
81 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
82 | test "z$r" = "z$the_commit" && | |
83 | ||
84 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
85 | ) | |
86 | ' | |
87 | ||
88 | test_expect_success 'fetch with wildcard' ' | |
89 | mk_empty && | |
90 | ( | |
91 | cd testrepo && | |
92 | git config remote.up.url .. && | |
93 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && | |
94 | git fetch up && | |
95 | ||
96 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
97 | test "z$r" = "z$the_commit" && | |
98 | ||
99 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
100 | ) | |
101 | ' | |
102 | ||
55029ae4 DB |
103 | test_expect_success 'fetch with insteadOf' ' |
104 | mk_empty && | |
105 | ( | |
60e3aba9 | 106 | TRASH=$(pwd)/ && |
55029ae4 | 107 | cd testrepo && |
60e3aba9 | 108 | git config url.$TRASH.insteadOf trash/ |
55029ae4 DB |
109 | git config remote.up.url trash/. && |
110 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && | |
111 | git fetch up && | |
112 | ||
113 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
114 | test "z$r" = "z$the_commit" && | |
115 | ||
116 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
117 | ) | |
118 | ' | |
119 | ||
bcdb34f7 JH |
120 | test_expect_success 'push without wildcard' ' |
121 | mk_empty && | |
122 | ||
123 | git push testrepo refs/heads/master:refs/remotes/origin/master && | |
124 | ( | |
125 | cd testrepo && | |
126 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
127 | test "z$r" = "z$the_commit" && | |
128 | ||
129 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
130 | ) | |
131 | ' | |
132 | ||
133 | test_expect_success 'push with wildcard' ' | |
134 | mk_empty && | |
135 | ||
136 | git push testrepo "refs/heads/*:refs/remotes/origin/*" && | |
137 | ( | |
138 | cd testrepo && | |
139 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
140 | test "z$r" = "z$the_commit" && | |
141 | ||
142 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
143 | ) | |
144 | ' | |
145 | ||
55029ae4 DB |
146 | test_expect_success 'push with insteadOf' ' |
147 | mk_empty && | |
60e3aba9 DB |
148 | TRASH=$(pwd)/ && |
149 | git config url.$TRASH.insteadOf trash/ && | |
55029ae4 DB |
150 | git push trash/testrepo refs/heads/master:refs/remotes/origin/master && |
151 | ( | |
152 | cd testrepo && | |
153 | r=$(git show-ref -s --verify refs/remotes/origin/master) && | |
154 | test "z$r" = "z$the_commit" && | |
155 | ||
156 | test 1 = $(git for-each-ref refs/remotes/origin | wc -l) | |
157 | ) | |
158 | ' | |
159 | ||
6125796f JH |
160 | test_expect_success 'push with matching heads' ' |
161 | ||
162 | mk_test heads/master && | |
163 | git push testrepo && | |
164 | check_push_result $the_commit heads/master | |
165 | ||
166 | ' | |
167 | ||
168 | test_expect_success 'push with no ambiguity (1)' ' | |
169 | ||
170 | mk_test heads/master && | |
171 | git push testrepo master:master && | |
172 | check_push_result $the_commit heads/master | |
173 | ||
174 | ' | |
175 | ||
176 | test_expect_success 'push with no ambiguity (2)' ' | |
177 | ||
178 | mk_test remotes/origin/master && | |
ae36bdcf | 179 | git push testrepo master:origin/master && |
6125796f JH |
180 | check_push_result $the_commit remotes/origin/master |
181 | ||
182 | ' | |
183 | ||
ae36bdcf SP |
184 | test_expect_success 'push with colon-less refspec, no ambiguity' ' |
185 | ||
186 | mk_test heads/master heads/t/master && | |
187 | git branch -f t/master master && | |
188 | git push testrepo master && | |
189 | check_push_result $the_commit heads/master && | |
190 | check_push_result $the_first_commit heads/t/master | |
191 | ||
192 | ' | |
193 | ||
6125796f JH |
194 | test_expect_success 'push with weak ambiguity (1)' ' |
195 | ||
196 | mk_test heads/master remotes/origin/master && | |
197 | git push testrepo master:master && | |
198 | check_push_result $the_commit heads/master && | |
199 | check_push_result $the_first_commit remotes/origin/master | |
200 | ||
201 | ' | |
202 | ||
203 | test_expect_success 'push with weak ambiguity (2)' ' | |
204 | ||
205 | mk_test heads/master remotes/origin/master remotes/another/master && | |
206 | git push testrepo master:master && | |
207 | check_push_result $the_commit heads/master && | |
208 | check_push_result $the_first_commit remotes/origin/master remotes/another/master | |
209 | ||
210 | ' | |
211 | ||
3ef6a1fe | 212 | test_expect_success 'push with ambiguity' ' |
6125796f JH |
213 | |
214 | mk_test heads/frotz tags/frotz && | |
215 | if git push testrepo master:frotz | |
216 | then | |
217 | echo "Oops, should have failed" | |
218 | false | |
219 | else | |
220 | check_push_result $the_first_commit heads/frotz tags/frotz | |
221 | fi | |
1ed10b88 JH |
222 | |
223 | ' | |
224 | ||
225 | test_expect_success 'push with colon-less refspec (1)' ' | |
226 | ||
227 | mk_test heads/frotz tags/frotz && | |
228 | git branch -f frotz master && | |
229 | git push testrepo frotz && | |
230 | check_push_result $the_commit heads/frotz && | |
231 | check_push_result $the_first_commit tags/frotz | |
232 | ||
233 | ' | |
234 | ||
235 | test_expect_success 'push with colon-less refspec (2)' ' | |
236 | ||
237 | mk_test heads/frotz tags/frotz && | |
238 | if git show-ref --verify -q refs/heads/frotz | |
239 | then | |
240 | git branch -D frotz | |
241 | fi && | |
242 | git tag -f frotz && | |
243 | git push testrepo frotz && | |
244 | check_push_result $the_commit tags/frotz && | |
245 | check_push_result $the_first_commit heads/frotz | |
246 | ||
247 | ' | |
248 | ||
249 | test_expect_success 'push with colon-less refspec (3)' ' | |
250 | ||
251 | mk_test && | |
252 | if git show-ref --verify -q refs/tags/frotz | |
253 | then | |
254 | git tag -d frotz | |
255 | fi && | |
256 | git branch -f frotz master && | |
257 | git push testrepo frotz && | |
258 | check_push_result $the_commit heads/frotz && | |
9a3c6f7b | 259 | test 1 = $( cd testrepo && git show-ref | wc -l ) |
1ed10b88 JH |
260 | ' |
261 | ||
262 | test_expect_success 'push with colon-less refspec (4)' ' | |
263 | ||
264 | mk_test && | |
265 | if git show-ref --verify -q refs/heads/frotz | |
266 | then | |
267 | git branch -D frotz | |
268 | fi && | |
269 | git tag -f frotz && | |
270 | git push testrepo frotz && | |
271 | check_push_result $the_commit tags/frotz && | |
9a3c6f7b | 272 | test 1 = $( cd testrepo && git show-ref | wc -l ) |
1ed10b88 | 273 | |
6125796f JH |
274 | ' |
275 | ||
f8aae120 JK |
276 | test_expect_success 'push head with non-existant, incomplete dest' ' |
277 | ||
278 | mk_test && | |
279 | git push testrepo master:branch && | |
280 | check_push_result $the_commit heads/branch | |
281 | ||
282 | ' | |
283 | ||
284 | test_expect_success 'push tag with non-existant, incomplete dest' ' | |
285 | ||
286 | mk_test && | |
287 | git tag -f v1.0 && | |
288 | git push testrepo v1.0:tag && | |
289 | check_push_result $the_commit tags/tag | |
290 | ||
291 | ' | |
292 | ||
293 | test_expect_success 'push sha1 with non-existant, incomplete dest' ' | |
294 | ||
295 | mk_test && | |
296 | test_must_fail git push testrepo `git rev-parse master`:foo | |
297 | ||
298 | ' | |
299 | ||
300 | test_expect_success 'push ref expression with non-existant, incomplete dest' ' | |
301 | ||
302 | mk_test && | |
303 | test_must_fail git push testrepo master^:branch | |
304 | ||
305 | ' | |
306 | ||
47d996a2 SP |
307 | test_expect_success 'push with HEAD' ' |
308 | ||
309 | mk_test heads/master && | |
310 | git checkout master && | |
311 | git push testrepo HEAD && | |
312 | check_push_result $the_commit heads/master | |
313 | ||
314 | ' | |
315 | ||
316 | test_expect_success 'push with HEAD nonexisting at remote' ' | |
317 | ||
318 | mk_test heads/master && | |
319 | git checkout -b local master && | |
320 | git push testrepo HEAD && | |
321 | check_push_result $the_commit heads/local | |
322 | ' | |
323 | ||
9f0ea7e8 DB |
324 | test_expect_success 'push with +HEAD' ' |
325 | ||
326 | mk_test heads/master && | |
327 | git checkout master && | |
328 | git branch -D local && | |
329 | git checkout -b local && | |
330 | git push testrepo master local && | |
331 | check_push_result $the_commit heads/master && | |
332 | check_push_result $the_commit heads/local && | |
333 | ||
334 | # Without force rewinding should fail | |
335 | git reset --hard HEAD^ && | |
336 | ! git push testrepo HEAD && | |
337 | check_push_result $the_commit heads/local && | |
338 | ||
339 | # With force rewinding should succeed | |
340 | git push testrepo +HEAD && | |
341 | check_push_result $the_first_commit heads/local | |
342 | ||
343 | ' | |
344 | ||
f8aae120 JK |
345 | test_expect_success 'push HEAD with non-existant, incomplete dest' ' |
346 | ||
347 | mk_test && | |
348 | git checkout master && | |
349 | git push testrepo HEAD:branch && | |
350 | check_push_result $the_commit heads/branch | |
351 | ||
352 | ' | |
353 | ||
9f0ea7e8 DB |
354 | test_expect_success 'push with config remote.*.push = HEAD' ' |
355 | ||
356 | mk_test heads/local && | |
357 | git checkout master && | |
358 | git branch -f local $the_commit && | |
359 | ( | |
360 | cd testrepo && | |
361 | git checkout local && | |
362 | git reset --hard $the_first_commit | |
363 | ) && | |
364 | git config remote.there.url testrepo && | |
365 | git config remote.there.push HEAD && | |
366 | git config branch.master.remote there && | |
367 | git push && | |
368 | check_push_result $the_commit heads/master && | |
369 | check_push_result $the_first_commit heads/local | |
370 | ' | |
371 | ||
372 | # clean up the cruft left with the previous one | |
373 | git config --remove-section remote.there | |
374 | git config --remove-section branch.master | |
375 | ||
11f2441f BE |
376 | test_expect_success 'push with dry-run' ' |
377 | ||
378 | mk_test heads/master && | |
28391a80 JS |
379 | (cd testrepo && |
380 | old_commit=$(git show-ref -s --verify refs/heads/master)) && | |
11f2441f BE |
381 | git push --dry-run testrepo && |
382 | check_push_result $old_commit heads/master | |
383 | ' | |
384 | ||
28391a80 JS |
385 | test_expect_success 'push updates local refs' ' |
386 | ||
387 | rm -rf parent child && | |
388 | mkdir parent && | |
389 | (cd parent && git init && | |
390 | echo one >foo && git add foo && git commit -m one) && | |
391 | git clone parent child && | |
392 | (cd child && | |
393 | echo two >foo && git commit -a -m two && | |
394 | git push && | |
395 | test $(git rev-parse master) = $(git rev-parse remotes/origin/master)) | |
396 | ||
397 | ' | |
398 | ||
399 | test_expect_success 'push does not update local refs on failure' ' | |
400 | ||
401 | rm -rf parent child && | |
402 | mkdir parent && | |
403 | (cd parent && git init && | |
404 | echo one >foo && git add foo && git commit -m one && | |
405 | echo exit 1 >.git/hooks/pre-receive && | |
406 | chmod +x .git/hooks/pre-receive) && | |
407 | git clone parent child && | |
408 | (cd child && | |
409 | echo two >foo && git commit -a -m two && | |
410 | ! git push && | |
411 | test $(git rev-parse master) != \ | |
412 | $(git rev-parse remotes/origin/master)) | |
413 | ||
414 | ' | |
415 | ||
416 | test_expect_success 'allow deleting an invalid remote ref' ' | |
417 | ||
418 | pwd && | |
419 | rm -f testrepo/.git/objects/??/* && | |
420 | git push testrepo :refs/heads/master && | |
421 | (cd testrepo && ! git rev-parse --verify refs/heads/master) | |
422 | ||
423 | ' | |
424 | ||
bcdb34f7 | 425 | test_done |