git-describe: Die early if there are no possible descriptions
[alt-git.git] / t / t5516-fetch-push.sh
blob2d2633f3f8784565faf5db84c6efe12d9c405013
1 #!/bin/sh
3 test_description='fetching and pushing, with or without wildcard'
5 . ./test-lib.sh
7 D=`pwd`
9 mk_empty () {
10 rm -fr testrepo &&
11 mkdir testrepo &&
13 cd testrepo &&
14 git init &&
15 mv .git/hooks .git/hooks-disabled
19 mk_test () {
20 mk_empty &&
22 for ref in "$@"
24 git push testrepo $the_first_commit:refs/$ref || {
25 echo "Oops, push refs/$ref failure"
26 exit 1
28 done &&
29 cd testrepo &&
30 for ref in "$@"
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
37 done &&
38 git fsck --full
42 mk_child() {
43 rm -rf "$1" &&
44 git clone testrepo "$1"
47 check_push_result () {
49 cd testrepo &&
50 it="$1" &&
51 shift
52 for ref in "$@"
54 r=$(git show-ref -s --verify refs/$ref) &&
55 test "z$r" = "z$it" || {
56 echo "Oops, refs/$ref is wrong"
57 exit 1
59 done &&
60 git fsck --full
64 test_expect_success setup '
66 : >path1 &&
67 git add path1 &&
68 test_tick &&
69 git commit -a -m repo &&
70 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
72 : >path2 &&
73 git add path2 &&
74 test_tick &&
75 git commit -a -m second &&
76 the_commit=$(git show-ref -s --verify refs/heads/master)
80 test_expect_success 'fetch without wildcard' '
81 mk_empty &&
83 cd testrepo &&
84 git fetch .. refs/heads/master:refs/remotes/origin/master &&
86 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
87 test "z$r" = "z$the_commit" &&
89 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
93 test_expect_success 'fetch with wildcard' '
94 mk_empty &&
96 cd testrepo &&
97 git config remote.up.url .. &&
98 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
99 git fetch up &&
101 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
102 test "z$r" = "z$the_commit" &&
104 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
108 test_expect_success 'fetch with insteadOf' '
109 mk_empty &&
111 TRASH=$(pwd)/ &&
112 cd testrepo &&
113 git config "url.$TRASH.insteadOf" trash/ &&
114 git config remote.up.url trash/. &&
115 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
116 git fetch up &&
118 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
119 test "z$r" = "z$the_commit" &&
121 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
125 test_expect_success 'push without wildcard' '
126 mk_empty &&
128 git push testrepo refs/heads/master:refs/remotes/origin/master &&
130 cd testrepo &&
131 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
132 test "z$r" = "z$the_commit" &&
134 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
138 test_expect_success 'push with wildcard' '
139 mk_empty &&
141 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
143 cd testrepo &&
144 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
145 test "z$r" = "z$the_commit" &&
147 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
151 test_expect_success 'push with insteadOf' '
152 mk_empty &&
153 TRASH="$(pwd)/" &&
154 git config "url.$TRASH.insteadOf" trash/ &&
155 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
157 cd testrepo &&
158 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
159 test "z$r" = "z$the_commit" &&
161 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
165 test_expect_success 'push with matching heads' '
167 mk_test heads/master &&
168 git push testrepo &&
169 check_push_result $the_commit heads/master
173 test_expect_success 'push with matching heads on the command line' '
175 mk_test heads/master &&
176 git push testrepo : &&
177 check_push_result $the_commit heads/master
181 test_expect_success 'failed (non-fast-forward) push with matching heads' '
183 mk_test heads/master &&
184 git push testrepo : &&
185 git commit --amend -massaged &&
186 test_must_fail git push testrepo &&
187 check_push_result $the_commit heads/master &&
188 git reset --hard $the_commit
192 test_expect_success 'push --force with matching heads' '
194 mk_test heads/master &&
195 git push testrepo : &&
196 git commit --amend -massaged &&
197 git push --force testrepo &&
198 ! check_push_result $the_commit heads/master &&
199 git reset --hard $the_commit
203 test_expect_success 'push with matching heads and forced update' '
205 mk_test heads/master &&
206 git push testrepo : &&
207 git commit --amend -massaged &&
208 git push testrepo +: &&
209 ! check_push_result $the_commit heads/master &&
210 git reset --hard $the_commit
214 test_expect_success 'push with no ambiguity (1)' '
216 mk_test heads/master &&
217 git push testrepo master:master &&
218 check_push_result $the_commit heads/master
222 test_expect_success 'push with no ambiguity (2)' '
224 mk_test remotes/origin/master &&
225 git push testrepo master:origin/master &&
226 check_push_result $the_commit remotes/origin/master
230 test_expect_success 'push with colon-less refspec, no ambiguity' '
232 mk_test heads/master heads/t/master &&
233 git branch -f t/master master &&
234 git push testrepo master &&
235 check_push_result $the_commit heads/master &&
236 check_push_result $the_first_commit heads/t/master
240 test_expect_success 'push with weak ambiguity (1)' '
242 mk_test heads/master remotes/origin/master &&
243 git push testrepo master:master &&
244 check_push_result $the_commit heads/master &&
245 check_push_result $the_first_commit remotes/origin/master
249 test_expect_success 'push with weak ambiguity (2)' '
251 mk_test heads/master remotes/origin/master remotes/another/master &&
252 git push testrepo master:master &&
253 check_push_result $the_commit heads/master &&
254 check_push_result $the_first_commit remotes/origin/master remotes/another/master
258 test_expect_success 'push with ambiguity' '
260 mk_test heads/frotz tags/frotz &&
261 if git push testrepo master:frotz
262 then
263 echo "Oops, should have failed"
264 false
265 else
266 check_push_result $the_first_commit heads/frotz tags/frotz
271 test_expect_success 'push with colon-less refspec (1)' '
273 mk_test heads/frotz tags/frotz &&
274 git branch -f frotz master &&
275 git push testrepo frotz &&
276 check_push_result $the_commit heads/frotz &&
277 check_push_result $the_first_commit tags/frotz
281 test_expect_success 'push with colon-less refspec (2)' '
283 mk_test heads/frotz tags/frotz &&
284 if git show-ref --verify -q refs/heads/frotz
285 then
286 git branch -D frotz
287 fi &&
288 git tag -f frotz &&
289 git push testrepo frotz &&
290 check_push_result $the_commit tags/frotz &&
291 check_push_result $the_first_commit heads/frotz
295 test_expect_success 'push with colon-less refspec (3)' '
297 mk_test &&
298 if git show-ref --verify -q refs/tags/frotz
299 then
300 git tag -d frotz
301 fi &&
302 git branch -f frotz master &&
303 git push testrepo frotz &&
304 check_push_result $the_commit heads/frotz &&
305 test 1 = $( cd testrepo && git show-ref | wc -l )
308 test_expect_success 'push with colon-less refspec (4)' '
310 mk_test &&
311 if git show-ref --verify -q refs/heads/frotz
312 then
313 git branch -D frotz
314 fi &&
315 git tag -f frotz &&
316 git push testrepo frotz &&
317 check_push_result $the_commit tags/frotz &&
318 test 1 = $( cd testrepo && git show-ref | wc -l )
322 test_expect_success 'push head with non-existant, incomplete dest' '
324 mk_test &&
325 git push testrepo master:branch &&
326 check_push_result $the_commit heads/branch
330 test_expect_success 'push tag with non-existant, incomplete dest' '
332 mk_test &&
333 git tag -f v1.0 &&
334 git push testrepo v1.0:tag &&
335 check_push_result $the_commit tags/tag
339 test_expect_success 'push sha1 with non-existant, incomplete dest' '
341 mk_test &&
342 test_must_fail git push testrepo `git rev-parse master`:foo
346 test_expect_success 'push ref expression with non-existant, incomplete dest' '
348 mk_test &&
349 test_must_fail git push testrepo master^:branch
353 test_expect_success 'push with HEAD' '
355 mk_test heads/master &&
356 git checkout master &&
357 git push testrepo HEAD &&
358 check_push_result $the_commit heads/master
362 test_expect_success 'push with HEAD nonexisting at remote' '
364 mk_test heads/master &&
365 git checkout -b local master &&
366 git push testrepo HEAD &&
367 check_push_result $the_commit heads/local
370 test_expect_success 'push with +HEAD' '
372 mk_test heads/master &&
373 git checkout master &&
374 git branch -D local &&
375 git checkout -b local &&
376 git push testrepo master local &&
377 check_push_result $the_commit heads/master &&
378 check_push_result $the_commit heads/local &&
380 # Without force rewinding should fail
381 git reset --hard HEAD^ &&
382 test_must_fail git push testrepo HEAD &&
383 check_push_result $the_commit heads/local &&
385 # With force rewinding should succeed
386 git push testrepo +HEAD &&
387 check_push_result $the_first_commit heads/local
391 test_expect_success 'push HEAD with non-existant, incomplete dest' '
393 mk_test &&
394 git checkout master &&
395 git push testrepo HEAD:branch &&
396 check_push_result $the_commit heads/branch
400 test_expect_success 'push with config remote.*.push = HEAD' '
402 mk_test heads/local &&
403 git checkout master &&
404 git branch -f local $the_commit &&
406 cd testrepo &&
407 git checkout local &&
408 git reset --hard $the_first_commit
409 ) &&
410 git config remote.there.url testrepo &&
411 git config remote.there.push HEAD &&
412 git config branch.master.remote there &&
413 git push &&
414 check_push_result $the_commit heads/master &&
415 check_push_result $the_first_commit heads/local
418 # clean up the cruft left with the previous one
419 git config --remove-section remote.there
420 git config --remove-section branch.master
422 test_expect_success 'push with config remote.*.pushurl' '
424 mk_test heads/master &&
425 git checkout master &&
426 git config remote.there.url test2repo &&
427 git config remote.there.pushurl testrepo &&
428 git push there &&
429 check_push_result $the_commit heads/master
432 # clean up the cruft left with the previous one
433 git config --remove-section remote.there
435 test_expect_success 'push with dry-run' '
437 mk_test heads/master &&
438 (cd testrepo &&
439 old_commit=$(git show-ref -s --verify refs/heads/master)) &&
440 git push --dry-run testrepo &&
441 check_push_result $old_commit heads/master
444 test_expect_success 'push updates local refs' '
446 mk_test heads/master &&
447 mk_child child &&
448 (cd child &&
449 git pull .. master &&
450 git push &&
451 test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
455 test_expect_success 'push updates up-to-date local refs' '
457 mk_test heads/master &&
458 mk_child child1 &&
459 mk_child child2 &&
460 (cd child1 && git pull .. master && git push) &&
461 (cd child2 &&
462 git pull ../child1 master &&
463 git push &&
464 test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
468 test_expect_success 'push preserves up-to-date packed refs' '
470 mk_test heads/master &&
471 mk_child child &&
472 (cd child &&
473 git push &&
474 ! test -f .git/refs/remotes/origin/master)
478 test_expect_success 'push does not update local refs on failure' '
480 mk_test heads/master &&
481 mk_child child &&
482 mkdir testrepo/.git/hooks &&
483 echo exit 1 >testrepo/.git/hooks/pre-receive &&
484 chmod +x testrepo/.git/hooks/pre-receive &&
485 (cd child &&
486 git pull .. master
487 test_must_fail git push &&
488 test $(git rev-parse master) != \
489 $(git rev-parse remotes/origin/master))
493 test_expect_success 'allow deleting an invalid remote ref' '
495 mk_test heads/master &&
496 rm -f testrepo/.git/objects/??/* &&
497 git push testrepo :refs/heads/master &&
498 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
502 test_expect_success 'warn on push to HEAD of non-bare repository' '
503 mk_test heads/master
504 (cd testrepo &&
505 git checkout master &&
506 git config receive.denyCurrentBranch warn) &&
507 git push testrepo master 2>stderr &&
508 grep "warning: updating the current branch" stderr
511 test_expect_success 'deny push to HEAD of non-bare repository' '
512 mk_test heads/master
513 (cd testrepo &&
514 git checkout master &&
515 git config receive.denyCurrentBranch true) &&
516 test_must_fail git push testrepo master
519 test_expect_success 'allow push to HEAD of bare repository (bare)' '
520 mk_test heads/master
521 (cd testrepo &&
522 git checkout master &&
523 git config receive.denyCurrentBranch true &&
524 git config core.bare true) &&
525 git push testrepo master 2>stderr &&
526 ! grep "warning: updating the current branch" stderr
529 test_expect_success 'allow push to HEAD of non-bare repository (config)' '
530 mk_test heads/master
531 (cd testrepo &&
532 git checkout master &&
533 git config receive.denyCurrentBranch false
534 ) &&
535 git push testrepo master 2>stderr &&
536 ! grep "warning: updating the current branch" stderr
539 test_expect_success 'fetch with branches' '
540 mk_empty &&
541 git branch second $the_first_commit &&
542 git checkout second &&
543 echo ".." > testrepo/.git/branches/branch1 &&
544 (cd testrepo &&
545 git fetch branch1 &&
546 r=$(git show-ref -s --verify refs/heads/branch1) &&
547 test "z$r" = "z$the_commit" &&
548 test 1 = $(git for-each-ref refs/heads | wc -l)
549 ) &&
550 git checkout master
553 test_expect_success 'fetch with branches containing #' '
554 mk_empty &&
555 echo "..#second" > testrepo/.git/branches/branch2 &&
556 (cd testrepo &&
557 git fetch branch2 &&
558 r=$(git show-ref -s --verify refs/heads/branch2) &&
559 test "z$r" = "z$the_first_commit" &&
560 test 1 = $(git for-each-ref refs/heads | wc -l)
561 ) &&
562 git checkout master
565 test_expect_success 'push with branches' '
566 mk_empty &&
567 git checkout second &&
568 echo "testrepo" > .git/branches/branch1 &&
569 git push branch1 &&
570 (cd testrepo &&
571 r=$(git show-ref -s --verify refs/heads/master) &&
572 test "z$r" = "z$the_first_commit" &&
573 test 1 = $(git for-each-ref refs/heads | wc -l)
577 test_expect_success 'push with branches containing #' '
578 mk_empty &&
579 echo "testrepo#branch3" > .git/branches/branch2 &&
580 git push branch2 &&
581 (cd testrepo &&
582 r=$(git show-ref -s --verify refs/heads/branch3) &&
583 test "z$r" = "z$the_first_commit" &&
584 test 1 = $(git for-each-ref refs/heads | wc -l)
585 ) &&
586 git checkout master
589 test_done