Merge branch 'maint-1.7.0' into maint-1.7.1
[git/jnareb-git.git] / t / t5516-fetch-push.sh
blobb8f64e13865a0f5fe24d90e6864b58962e8d384c
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 git config receive.denyCurrentBranch warn &&
16 mv .git/hooks .git/hooks-disabled
20 mk_test () {
21 mk_empty &&
23 for ref in "$@"
25 git push testrepo $the_first_commit:refs/$ref || {
26 echo "Oops, push refs/$ref failure"
27 exit 1
29 done &&
30 cd testrepo &&
31 for ref in "$@"
33 r=$(git show-ref -s --verify refs/$ref) &&
34 test "z$r" = "z$the_first_commit" || {
35 echo "Oops, refs/$ref is wrong"
36 exit 1
38 done &&
39 git fsck --full
43 mk_child() {
44 rm -rf "$1" &&
45 git clone testrepo "$1"
48 check_push_result () {
50 cd testrepo &&
51 it="$1" &&
52 shift
53 for ref in "$@"
55 r=$(git show-ref -s --verify refs/$ref) &&
56 test "z$r" = "z$it" || {
57 echo "Oops, refs/$ref is wrong"
58 exit 1
60 done &&
61 git fsck --full
65 test_expect_success setup '
67 : >path1 &&
68 git add path1 &&
69 test_tick &&
70 git commit -a -m repo &&
71 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
73 : >path2 &&
74 git add path2 &&
75 test_tick &&
76 git commit -a -m second &&
77 the_commit=$(git show-ref -s --verify refs/heads/master)
81 test_expect_success 'fetch without wildcard' '
82 mk_empty &&
84 cd testrepo &&
85 git fetch .. refs/heads/master:refs/remotes/origin/master &&
87 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
88 test "z$r" = "z$the_commit" &&
90 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
94 test_expect_success 'fetch with wildcard' '
95 mk_empty &&
97 cd testrepo &&
98 git config remote.up.url .. &&
99 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
100 git fetch up &&
102 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
103 test "z$r" = "z$the_commit" &&
105 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
109 test_expect_success 'fetch with insteadOf' '
110 mk_empty &&
112 TRASH=$(pwd)/ &&
113 cd testrepo &&
114 git config "url.$TRASH.insteadOf" trash/ &&
115 git config remote.up.url trash/. &&
116 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
117 git fetch up &&
119 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
120 test "z$r" = "z$the_commit" &&
122 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
126 test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
127 mk_empty &&
129 TRASH=$(pwd)/ &&
130 cd testrepo &&
131 git config "url.trash/.pushInsteadOf" "$TRASH" &&
132 git config remote.up.url "$TRASH." &&
133 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
134 git fetch up &&
136 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
137 test "z$r" = "z$the_commit" &&
139 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
143 test_expect_success 'push without wildcard' '
144 mk_empty &&
146 git push testrepo refs/heads/master:refs/remotes/origin/master &&
148 cd testrepo &&
149 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
150 test "z$r" = "z$the_commit" &&
152 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
156 test_expect_success 'push with wildcard' '
157 mk_empty &&
159 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
161 cd testrepo &&
162 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
163 test "z$r" = "z$the_commit" &&
165 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
169 test_expect_success 'push with insteadOf' '
170 mk_empty &&
171 TRASH="$(pwd)/" &&
172 git config "url.$TRASH.insteadOf" trash/ &&
173 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
175 cd testrepo &&
176 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
177 test "z$r" = "z$the_commit" &&
179 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
183 test_expect_success 'push with pushInsteadOf' '
184 mk_empty &&
185 TRASH="$(pwd)/" &&
186 git config "url.$TRASH.pushInsteadOf" trash/ &&
187 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
189 cd testrepo &&
190 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
191 test "z$r" = "z$the_commit" &&
193 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
197 test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
198 mk_empty &&
199 TRASH="$(pwd)/" &&
200 git config "url.trash2/.pushInsteadOf" trash/ &&
201 git config remote.r.url trash/wrong &&
202 git config remote.r.pushurl "$TRASH/testrepo" &&
203 git push r refs/heads/master:refs/remotes/origin/master &&
205 cd testrepo &&
206 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
207 test "z$r" = "z$the_commit" &&
209 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
213 test_expect_success 'push with matching heads' '
215 mk_test heads/master &&
216 git push testrepo &&
217 check_push_result $the_commit heads/master
221 test_expect_success 'push with matching heads on the command line' '
223 mk_test heads/master &&
224 git push testrepo : &&
225 check_push_result $the_commit heads/master
229 test_expect_success 'failed (non-fast-forward) push with matching heads' '
231 mk_test heads/master &&
232 git push testrepo : &&
233 git commit --amend -massaged &&
234 test_must_fail git push testrepo &&
235 check_push_result $the_commit heads/master &&
236 git reset --hard $the_commit
240 test_expect_success 'push --force with matching heads' '
242 mk_test heads/master &&
243 git push testrepo : &&
244 git commit --amend -massaged &&
245 git push --force testrepo &&
246 ! check_push_result $the_commit heads/master &&
247 git reset --hard $the_commit
251 test_expect_success 'push with matching heads and forced update' '
253 mk_test heads/master &&
254 git push testrepo : &&
255 git commit --amend -massaged &&
256 git push testrepo +: &&
257 ! check_push_result $the_commit heads/master &&
258 git reset --hard $the_commit
262 test_expect_success 'push with no ambiguity (1)' '
264 mk_test heads/master &&
265 git push testrepo master:master &&
266 check_push_result $the_commit heads/master
270 test_expect_success 'push with no ambiguity (2)' '
272 mk_test remotes/origin/master &&
273 git push testrepo master:origin/master &&
274 check_push_result $the_commit remotes/origin/master
278 test_expect_success 'push with colon-less refspec, no ambiguity' '
280 mk_test heads/master heads/t/master &&
281 git branch -f t/master master &&
282 git push testrepo master &&
283 check_push_result $the_commit heads/master &&
284 check_push_result $the_first_commit heads/t/master
288 test_expect_success 'push with weak ambiguity (1)' '
290 mk_test heads/master remotes/origin/master &&
291 git push testrepo master:master &&
292 check_push_result $the_commit heads/master &&
293 check_push_result $the_first_commit remotes/origin/master
297 test_expect_success 'push with weak ambiguity (2)' '
299 mk_test heads/master remotes/origin/master remotes/another/master &&
300 git push testrepo master:master &&
301 check_push_result $the_commit heads/master &&
302 check_push_result $the_first_commit remotes/origin/master remotes/another/master
306 test_expect_success 'push with ambiguity' '
308 mk_test heads/frotz tags/frotz &&
309 if git push testrepo master:frotz
310 then
311 echo "Oops, should have failed"
312 false
313 else
314 check_push_result $the_first_commit heads/frotz tags/frotz
319 test_expect_success 'push with colon-less refspec (1)' '
321 mk_test heads/frotz tags/frotz &&
322 git branch -f frotz master &&
323 git push testrepo frotz &&
324 check_push_result $the_commit heads/frotz &&
325 check_push_result $the_first_commit tags/frotz
329 test_expect_success 'push with colon-less refspec (2)' '
331 mk_test heads/frotz tags/frotz &&
332 if git show-ref --verify -q refs/heads/frotz
333 then
334 git branch -D frotz
335 fi &&
336 git tag -f frotz &&
337 git push testrepo frotz &&
338 check_push_result $the_commit tags/frotz &&
339 check_push_result $the_first_commit heads/frotz
343 test_expect_success 'push with colon-less refspec (3)' '
345 mk_test &&
346 if git show-ref --verify -q refs/tags/frotz
347 then
348 git tag -d frotz
349 fi &&
350 git branch -f frotz master &&
351 git push testrepo frotz &&
352 check_push_result $the_commit heads/frotz &&
353 test 1 = $( cd testrepo && git show-ref | wc -l )
356 test_expect_success 'push with colon-less refspec (4)' '
358 mk_test &&
359 if git show-ref --verify -q refs/heads/frotz
360 then
361 git branch -D frotz
362 fi &&
363 git tag -f frotz &&
364 git push testrepo frotz &&
365 check_push_result $the_commit tags/frotz &&
366 test 1 = $( cd testrepo && git show-ref | wc -l )
370 test_expect_success 'push head with non-existant, incomplete dest' '
372 mk_test &&
373 git push testrepo master:branch &&
374 check_push_result $the_commit heads/branch
378 test_expect_success 'push tag with non-existant, incomplete dest' '
380 mk_test &&
381 git tag -f v1.0 &&
382 git push testrepo v1.0:tag &&
383 check_push_result $the_commit tags/tag
387 test_expect_success 'push sha1 with non-existant, incomplete dest' '
389 mk_test &&
390 test_must_fail git push testrepo `git rev-parse master`:foo
394 test_expect_success 'push ref expression with non-existant, incomplete dest' '
396 mk_test &&
397 test_must_fail git push testrepo master^:branch
401 test_expect_success 'push with HEAD' '
403 mk_test heads/master &&
404 git checkout master &&
405 git push testrepo HEAD &&
406 check_push_result $the_commit heads/master
410 test_expect_success 'push with HEAD nonexisting at remote' '
412 mk_test heads/master &&
413 git checkout -b local master &&
414 git push testrepo HEAD &&
415 check_push_result $the_commit heads/local
418 test_expect_success 'push with +HEAD' '
420 mk_test heads/master &&
421 git checkout master &&
422 git branch -D local &&
423 git checkout -b local &&
424 git push testrepo master local &&
425 check_push_result $the_commit heads/master &&
426 check_push_result $the_commit heads/local &&
428 # Without force rewinding should fail
429 git reset --hard HEAD^ &&
430 test_must_fail git push testrepo HEAD &&
431 check_push_result $the_commit heads/local &&
433 # With force rewinding should succeed
434 git push testrepo +HEAD &&
435 check_push_result $the_first_commit heads/local
439 test_expect_success 'push HEAD with non-existant, incomplete dest' '
441 mk_test &&
442 git checkout master &&
443 git push testrepo HEAD:branch &&
444 check_push_result $the_commit heads/branch
448 test_expect_success 'push with config remote.*.push = HEAD' '
450 mk_test heads/local &&
451 git checkout master &&
452 git branch -f local $the_commit &&
454 cd testrepo &&
455 git checkout local &&
456 git reset --hard $the_first_commit
457 ) &&
458 git config remote.there.url testrepo &&
459 git config remote.there.push HEAD &&
460 git config branch.master.remote there &&
461 git push &&
462 check_push_result $the_commit heads/master &&
463 check_push_result $the_first_commit heads/local
466 # clean up the cruft left with the previous one
467 git config --remove-section remote.there
468 git config --remove-section branch.master
470 test_expect_success 'push with config remote.*.pushurl' '
472 mk_test heads/master &&
473 git checkout master &&
474 git config remote.there.url test2repo &&
475 git config remote.there.pushurl testrepo &&
476 git push there &&
477 check_push_result $the_commit heads/master
480 # clean up the cruft left with the previous one
481 git config --remove-section remote.there
483 test_expect_success 'push with dry-run' '
485 mk_test heads/master &&
486 (cd testrepo &&
487 old_commit=$(git show-ref -s --verify refs/heads/master)) &&
488 git push --dry-run testrepo &&
489 check_push_result $old_commit heads/master
492 test_expect_success 'push updates local refs' '
494 mk_test heads/master &&
495 mk_child child &&
496 (cd child &&
497 git pull .. master &&
498 git push &&
499 test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
503 test_expect_success 'push updates up-to-date local refs' '
505 mk_test heads/master &&
506 mk_child child1 &&
507 mk_child child2 &&
508 (cd child1 && git pull .. master && git push) &&
509 (cd child2 &&
510 git pull ../child1 master &&
511 git push &&
512 test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
516 test_expect_success 'push preserves up-to-date packed refs' '
518 mk_test heads/master &&
519 mk_child child &&
520 (cd child &&
521 git push &&
522 ! test -f .git/refs/remotes/origin/master)
526 test_expect_success 'push does not update local refs on failure' '
528 mk_test heads/master &&
529 mk_child child &&
530 mkdir testrepo/.git/hooks &&
531 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
532 chmod +x testrepo/.git/hooks/pre-receive &&
533 (cd child &&
534 git pull .. master
535 test_must_fail git push &&
536 test $(git rev-parse master) != \
537 $(git rev-parse remotes/origin/master))
541 test_expect_success 'allow deleting an invalid remote ref' '
543 mk_test heads/master &&
544 rm -f testrepo/.git/objects/??/* &&
545 git push testrepo :refs/heads/master &&
546 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
550 test_expect_success 'allow deleting a ref using --delete' '
551 mk_test heads/master &&
552 (cd testrepo && git config receive.denyDeleteCurrent warn) &&
553 git push testrepo --delete master &&
554 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
557 test_expect_success 'allow deleting a tag using --delete' '
558 mk_test heads/master &&
559 git tag -a -m dummy_message deltag heads/master &&
560 git push testrepo --tags &&
561 (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
562 git push testrepo --delete tag deltag &&
563 (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
566 test_expect_success 'push --delete without args aborts' '
567 mk_test heads/master &&
568 test_must_fail git push testrepo --delete
571 test_expect_success 'push --delete refuses src:dest refspecs' '
572 mk_test heads/master &&
573 test_must_fail git push testrepo --delete master:foo
576 test_expect_success 'warn on push to HEAD of non-bare repository' '
577 mk_test heads/master
578 (cd testrepo &&
579 git checkout master &&
580 git config receive.denyCurrentBranch warn) &&
581 git push testrepo master 2>stderr &&
582 grep "warning: updating the current branch" stderr
585 test_expect_success 'deny push to HEAD of non-bare repository' '
586 mk_test heads/master
587 (cd testrepo &&
588 git checkout master &&
589 git config receive.denyCurrentBranch true) &&
590 test_must_fail git push testrepo master
593 test_expect_success 'allow push to HEAD of bare repository (bare)' '
594 mk_test heads/master
595 (cd testrepo &&
596 git checkout master &&
597 git config receive.denyCurrentBranch true &&
598 git config core.bare true) &&
599 git push testrepo master 2>stderr &&
600 ! grep "warning: updating the current branch" stderr
603 test_expect_success 'allow push to HEAD of non-bare repository (config)' '
604 mk_test heads/master
605 (cd testrepo &&
606 git checkout master &&
607 git config receive.denyCurrentBranch false
608 ) &&
609 git push testrepo master 2>stderr &&
610 ! grep "warning: updating the current branch" stderr
613 test_expect_success 'fetch with branches' '
614 mk_empty &&
615 git branch second $the_first_commit &&
616 git checkout second &&
617 echo ".." > testrepo/.git/branches/branch1 &&
618 (cd testrepo &&
619 git fetch branch1 &&
620 r=$(git show-ref -s --verify refs/heads/branch1) &&
621 test "z$r" = "z$the_commit" &&
622 test 1 = $(git for-each-ref refs/heads | wc -l)
623 ) &&
624 git checkout master
627 test_expect_success 'fetch with branches containing #' '
628 mk_empty &&
629 echo "..#second" > testrepo/.git/branches/branch2 &&
630 (cd testrepo &&
631 git fetch branch2 &&
632 r=$(git show-ref -s --verify refs/heads/branch2) &&
633 test "z$r" = "z$the_first_commit" &&
634 test 1 = $(git for-each-ref refs/heads | wc -l)
635 ) &&
636 git checkout master
639 test_expect_success 'push with branches' '
640 mk_empty &&
641 git checkout second &&
642 echo "testrepo" > .git/branches/branch1 &&
643 git push branch1 &&
644 (cd testrepo &&
645 r=$(git show-ref -s --verify refs/heads/master) &&
646 test "z$r" = "z$the_first_commit" &&
647 test 1 = $(git for-each-ref refs/heads | wc -l)
651 test_expect_success 'push with branches containing #' '
652 mk_empty &&
653 echo "testrepo#branch3" > .git/branches/branch2 &&
654 git push branch2 &&
655 (cd testrepo &&
656 r=$(git show-ref -s --verify refs/heads/branch3) &&
657 test "z$r" = "z$the_first_commit" &&
658 test 1 = $(git for-each-ref refs/heads | wc -l)
659 ) &&
660 git checkout master
663 test_expect_success 'push into aliased refs (consistent)' '
664 mk_test heads/master &&
665 mk_child child1 &&
666 mk_child child2 &&
668 cd child1 &&
669 git branch foo &&
670 git symbolic-ref refs/heads/bar refs/heads/foo
671 git config receive.denyCurrentBranch false
672 ) &&
674 cd child2 &&
675 >path2 &&
676 git add path2 &&
677 test_tick &&
678 git commit -a -m child2 &&
679 git branch foo &&
680 git branch bar &&
681 git push ../child1 foo bar
685 test_expect_success 'push into aliased refs (inconsistent)' '
686 mk_test heads/master &&
687 mk_child child1 &&
688 mk_child child2 &&
690 cd child1 &&
691 git branch foo &&
692 git symbolic-ref refs/heads/bar refs/heads/foo
693 git config receive.denyCurrentBranch false
694 ) &&
696 cd child2 &&
697 >path2 &&
698 git add path2 &&
699 test_tick &&
700 git commit -a -m child2 &&
701 git branch foo &&
702 >path3 &&
703 git add path3 &&
704 test_tick &&
705 git commit -a -m child2 &&
706 git branch bar &&
707 test_must_fail git push ../child1 foo bar 2>stderr &&
708 grep "refusing inconsistent update" stderr
712 test_expect_success 'push --porcelain' '
713 mk_empty &&
714 echo >.git/foo "To testrepo" &&
715 echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" &&
716 echo >>.git/foo "Done" &&
717 git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master &&
719 cd testrepo &&
720 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
721 test "z$r" = "z$the_commit" &&
722 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
723 ) &&
724 test_cmp .git/foo .git/bar
727 test_expect_success 'push --porcelain bad url' '
728 mk_empty &&
729 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
730 test_must_fail grep -q Done .git/bar
733 test_expect_success 'push --porcelain rejected' '
734 mk_empty &&
735 git push testrepo refs/heads/master:refs/remotes/origin/master &&
736 (cd testrepo &&
737 git reset --hard origin/master^
738 git config receive.denyCurrentBranch true) &&
740 echo >.git/foo "To testrepo" &&
741 echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" &&
743 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master &&
744 test_cmp .git/foo .git/bar
747 test_expect_success 'push --porcelain --dry-run rejected' '
748 mk_empty &&
749 git push testrepo refs/heads/master:refs/remotes/origin/master &&
750 (cd testrepo &&
751 git reset --hard origin/master
752 git config receive.denyCurrentBranch true) &&
754 echo >.git/foo "To testrepo" &&
755 echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" &&
756 echo >>.git/foo "Done" &&
758 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master &&
759 test_cmp .git/foo .git/bar
762 test_done