Win32: Unicode arguments (outgoing)
[git/dscho.git] / t / t5516-fetch-push.sh
blob2482796454a41cab63e28a45ebe58f0e7f7d700a
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_test_with_hooks() {
44 mk_test "$@" &&
46 cd testrepo &&
47 mkdir .git/hooks &&
48 cd .git/hooks &&
50 cat >pre-receive <<-'EOF' &&
51 #!/bin/sh
52 cat - >>pre-receive.actual
53 EOF
55 cat >update <<-'EOF' &&
56 #!/bin/sh
57 printf "%s %s %s\n" "$@" >>update.actual
58 EOF
60 cat >post-receive <<-'EOF' &&
61 #!/bin/sh
62 cat - >>post-receive.actual
63 EOF
65 cat >post-update <<-'EOF' &&
66 #!/bin/sh
67 for ref in "$@"
69 printf "%s\n" "$ref" >>post-update.actual
70 done
71 EOF
73 chmod +x pre-receive update post-receive post-update
77 mk_child() {
78 rm -rf "$1" &&
79 git clone testrepo "$1"
82 check_push_result () {
84 cd testrepo &&
85 it="$1" &&
86 shift
87 for ref in "$@"
89 r=$(git show-ref -s --verify refs/$ref) &&
90 test "z$r" = "z$it" || {
91 echo "Oops, refs/$ref is wrong"
92 exit 1
94 done &&
95 git fsck --full
99 test_expect_success setup '
101 >path1 &&
102 git add path1 &&
103 test_tick &&
104 git commit -a -m repo &&
105 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
107 >path2 &&
108 git add path2 &&
109 test_tick &&
110 git commit -a -m second &&
111 the_commit=$(git show-ref -s --verify refs/heads/master)
115 test_expect_success 'fetch without wildcard' '
116 mk_empty &&
118 cd testrepo &&
119 git fetch .. refs/heads/master:refs/remotes/origin/master &&
121 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
122 test "z$r" = "z$the_commit" &&
124 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
128 test_expect_success 'fetch with wildcard' '
129 mk_empty &&
131 cd testrepo &&
132 git config remote.up.url .. &&
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 'fetch with insteadOf' '
144 mk_empty &&
146 TRASH=$(pwd)/ &&
147 cd testrepo &&
148 git config "url.$TRASH.insteadOf" trash/ &&
149 git config remote.up.url trash/. &&
150 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
151 git fetch up &&
153 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
154 test "z$r" = "z$the_commit" &&
156 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
160 test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
161 mk_empty &&
163 TRASH=$(pwd)/ &&
164 cd testrepo &&
165 git config "url.trash/.pushInsteadOf" "$TRASH" &&
166 git config remote.up.url "$TRASH." &&
167 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
168 git fetch up &&
170 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
171 test "z$r" = "z$the_commit" &&
173 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
177 test_expect_success 'push without wildcard' '
178 mk_empty &&
180 git push testrepo refs/heads/master:refs/remotes/origin/master &&
182 cd testrepo &&
183 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
184 test "z$r" = "z$the_commit" &&
186 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
190 test_expect_success 'push with wildcard' '
191 mk_empty &&
193 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
195 cd testrepo &&
196 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
197 test "z$r" = "z$the_commit" &&
199 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
203 test_expect_success 'push with insteadOf' '
204 mk_empty &&
205 TRASH="$(pwd)/" &&
206 git config "url.$TRASH.insteadOf" trash/ &&
207 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
209 cd testrepo &&
210 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
211 test "z$r" = "z$the_commit" &&
213 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
217 test_expect_success 'push with pushInsteadOf' '
218 mk_empty &&
219 TRASH="$(pwd)/" &&
220 git config "url.$TRASH.pushInsteadOf" trash/ &&
221 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
223 cd testrepo &&
224 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
225 test "z$r" = "z$the_commit" &&
227 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
231 test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
232 mk_empty &&
233 TRASH="$(pwd)/" &&
234 git config "url.trash2/.pushInsteadOf" trash/ &&
235 git config remote.r.url trash/wrong &&
236 git config remote.r.pushurl "$TRASH/testrepo" &&
237 git push r refs/heads/master:refs/remotes/origin/master &&
239 cd testrepo &&
240 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
241 test "z$r" = "z$the_commit" &&
243 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
247 test_expect_success 'push with matching heads' '
249 mk_test heads/master &&
250 git push testrepo &&
251 check_push_result $the_commit heads/master
255 test_expect_success 'push with matching heads on the command line' '
257 mk_test heads/master &&
258 git push testrepo : &&
259 check_push_result $the_commit heads/master
263 test_expect_success 'failed (non-fast-forward) push with matching heads' '
265 mk_test heads/master &&
266 git push testrepo : &&
267 git commit --amend -massaged &&
268 test_must_fail git push testrepo &&
269 check_push_result $the_commit heads/master &&
270 git reset --hard $the_commit
274 test_expect_success 'push --force with matching heads' '
276 mk_test heads/master &&
277 git push testrepo : &&
278 git commit --amend -massaged &&
279 git push --force testrepo &&
280 ! check_push_result $the_commit heads/master &&
281 git reset --hard $the_commit
285 test_expect_success 'push with matching heads and forced update' '
287 mk_test heads/master &&
288 git push testrepo : &&
289 git commit --amend -massaged &&
290 git push testrepo +: &&
291 ! check_push_result $the_commit heads/master &&
292 git reset --hard $the_commit
296 test_expect_success 'push with no ambiguity (1)' '
298 mk_test heads/master &&
299 git push testrepo master:master &&
300 check_push_result $the_commit heads/master
304 test_expect_success 'push with no ambiguity (2)' '
306 mk_test remotes/origin/master &&
307 git push testrepo master:origin/master &&
308 check_push_result $the_commit remotes/origin/master
312 test_expect_success 'push with colon-less refspec, no ambiguity' '
314 mk_test heads/master heads/t/master &&
315 git branch -f t/master master &&
316 git push testrepo master &&
317 check_push_result $the_commit heads/master &&
318 check_push_result $the_first_commit heads/t/master
322 test_expect_success 'push with weak ambiguity (1)' '
324 mk_test heads/master remotes/origin/master &&
325 git push testrepo master:master &&
326 check_push_result $the_commit heads/master &&
327 check_push_result $the_first_commit remotes/origin/master
331 test_expect_success 'push with weak ambiguity (2)' '
333 mk_test heads/master remotes/origin/master remotes/another/master &&
334 git push testrepo master:master &&
335 check_push_result $the_commit heads/master &&
336 check_push_result $the_first_commit remotes/origin/master remotes/another/master
340 test_expect_success 'push with ambiguity' '
342 mk_test heads/frotz tags/frotz &&
343 if git push testrepo master:frotz
344 then
345 echo "Oops, should have failed"
346 false
347 else
348 check_push_result $the_first_commit heads/frotz tags/frotz
353 test_expect_success 'push with colon-less refspec (1)' '
355 mk_test heads/frotz tags/frotz &&
356 git branch -f frotz master &&
357 git push testrepo frotz &&
358 check_push_result $the_commit heads/frotz &&
359 check_push_result $the_first_commit tags/frotz
363 test_expect_success 'push with colon-less refspec (2)' '
365 mk_test heads/frotz tags/frotz &&
366 if git show-ref --verify -q refs/heads/frotz
367 then
368 git branch -D frotz
369 fi &&
370 git tag -f frotz &&
371 git push testrepo frotz &&
372 check_push_result $the_commit tags/frotz &&
373 check_push_result $the_first_commit heads/frotz
377 test_expect_success 'push with colon-less refspec (3)' '
379 mk_test &&
380 if git show-ref --verify -q refs/tags/frotz
381 then
382 git tag -d frotz
383 fi &&
384 git branch -f frotz master &&
385 git push testrepo frotz &&
386 check_push_result $the_commit heads/frotz &&
387 test 1 = $( cd testrepo && git show-ref | wc -l )
390 test_expect_success 'push with colon-less refspec (4)' '
392 mk_test &&
393 if git show-ref --verify -q refs/heads/frotz
394 then
395 git branch -D frotz
396 fi &&
397 git tag -f frotz &&
398 git push testrepo frotz &&
399 check_push_result $the_commit tags/frotz &&
400 test 1 = $( cd testrepo && git show-ref | wc -l )
404 test_expect_success 'push head with non-existent, incomplete dest' '
406 mk_test &&
407 git push testrepo master:branch &&
408 check_push_result $the_commit heads/branch
412 test_expect_success 'push tag with non-existent, incomplete dest' '
414 mk_test &&
415 git tag -f v1.0 &&
416 git push testrepo v1.0:tag &&
417 check_push_result $the_commit tags/tag
421 test_expect_success 'push sha1 with non-existent, incomplete dest' '
423 mk_test &&
424 test_must_fail git push testrepo `git rev-parse master`:foo
428 test_expect_success 'push ref expression with non-existent, incomplete dest' '
430 mk_test &&
431 test_must_fail git push testrepo master^:branch
435 test_expect_success 'push with HEAD' '
437 mk_test heads/master &&
438 git checkout master &&
439 git push testrepo HEAD &&
440 check_push_result $the_commit heads/master
444 test_expect_success 'push with HEAD nonexisting at remote' '
446 mk_test heads/master &&
447 git checkout -b local master &&
448 git push testrepo HEAD &&
449 check_push_result $the_commit heads/local
452 test_expect_success 'push with +HEAD' '
454 mk_test heads/master &&
455 git checkout master &&
456 git branch -D local &&
457 git checkout -b local &&
458 git push testrepo master local &&
459 check_push_result $the_commit heads/master &&
460 check_push_result $the_commit heads/local &&
462 # Without force rewinding should fail
463 git reset --hard HEAD^ &&
464 test_must_fail git push testrepo HEAD &&
465 check_push_result $the_commit heads/local &&
467 # With force rewinding should succeed
468 git push testrepo +HEAD &&
469 check_push_result $the_first_commit heads/local
473 test_expect_success 'push HEAD with non-existent, incomplete dest' '
475 mk_test &&
476 git checkout master &&
477 git push testrepo HEAD:branch &&
478 check_push_result $the_commit heads/branch
482 test_expect_success 'push with config remote.*.push = HEAD' '
484 mk_test heads/local &&
485 git checkout master &&
486 git branch -f local $the_commit &&
488 cd testrepo &&
489 git checkout local &&
490 git reset --hard $the_first_commit
491 ) &&
492 git config remote.there.url testrepo &&
493 git config remote.there.push HEAD &&
494 git config branch.master.remote there &&
495 git push &&
496 check_push_result $the_commit heads/master &&
497 check_push_result $the_first_commit heads/local
500 # clean up the cruft left with the previous one
501 git config --remove-section remote.there
502 git config --remove-section branch.master
504 test_expect_success 'push with config remote.*.pushurl' '
506 mk_test heads/master &&
507 git checkout master &&
508 git config remote.there.url test2repo &&
509 git config remote.there.pushurl testrepo &&
510 git push there &&
511 check_push_result $the_commit heads/master
514 # clean up the cruft left with the previous one
515 git config --remove-section remote.there
517 test_expect_success 'push with dry-run' '
519 mk_test heads/master &&
521 cd testrepo &&
522 old_commit=$(git show-ref -s --verify refs/heads/master)
523 ) &&
524 git push --dry-run testrepo &&
525 check_push_result $old_commit heads/master
528 test_expect_success 'push updates local refs' '
530 mk_test heads/master &&
531 mk_child child &&
533 cd child &&
534 git pull .. master &&
535 git push &&
536 test $(git rev-parse master) = \
537 $(git rev-parse remotes/origin/master)
542 test_expect_success 'push updates up-to-date local refs' '
544 mk_test heads/master &&
545 mk_child child1 &&
546 mk_child child2 &&
547 (cd child1 && git pull .. master && git push) &&
549 cd child2 &&
550 git pull ../child1 master &&
551 git push &&
552 test $(git rev-parse master) = \
553 $(git rev-parse remotes/origin/master)
558 test_expect_success 'push preserves up-to-date packed refs' '
560 mk_test heads/master &&
561 mk_child child &&
563 cd child &&
564 git push &&
565 ! test -f .git/refs/remotes/origin/master
570 test_expect_success 'push does not update local refs on failure' '
572 mk_test heads/master &&
573 mk_child child &&
574 mkdir testrepo/.git/hooks &&
575 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
576 chmod +x testrepo/.git/hooks/pre-receive &&
578 cd child &&
579 git pull .. master
580 test_must_fail git push &&
581 test $(git rev-parse master) != \
582 $(git rev-parse remotes/origin/master)
587 test_expect_success 'allow deleting an invalid remote ref' '
589 mk_test heads/master &&
590 rm -f testrepo/.git/objects/??/* &&
591 git push testrepo :refs/heads/master &&
592 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
596 test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' '
597 mk_test_with_hooks heads/master heads/next &&
598 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
599 newmaster=$(git show-ref -s --verify refs/heads/master) &&
600 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
601 newnext=$_z40 &&
602 git push testrepo refs/heads/master:refs/heads/master :refs/heads/next &&
604 cd testrepo/.git &&
605 cat >pre-receive.expect <<-EOF &&
606 $orgmaster $newmaster refs/heads/master
607 $orgnext $newnext refs/heads/next
610 cat >update.expect <<-EOF &&
611 refs/heads/master $orgmaster $newmaster
612 refs/heads/next $orgnext $newnext
615 cat >post-receive.expect <<-EOF &&
616 $orgmaster $newmaster refs/heads/master
617 $orgnext $newnext refs/heads/next
620 cat >post-update.expect <<-EOF &&
621 refs/heads/master
622 refs/heads/next
625 test_cmp pre-receive.expect pre-receive.actual &&
626 test_cmp update.expect update.actual &&
627 test_cmp post-receive.expect post-receive.actual &&
628 test_cmp post-update.expect post-update.actual
632 test_expect_success 'deleting dangling ref triggers hooks with correct args' '
633 mk_test_with_hooks heads/master &&
634 rm -f testrepo/.git/objects/??/* &&
635 git push testrepo :refs/heads/master &&
637 cd testrepo/.git &&
638 cat >pre-receive.expect <<-EOF &&
639 $_z40 $_z40 refs/heads/master
642 cat >update.expect <<-EOF &&
643 refs/heads/master $_z40 $_z40
646 cat >post-receive.expect <<-EOF &&
647 $_z40 $_z40 refs/heads/master
650 cat >post-update.expect <<-EOF &&
651 refs/heads/master
654 test_cmp pre-receive.expect pre-receive.actual &&
655 test_cmp update.expect update.actual &&
656 test_cmp post-receive.expect post-receive.actual &&
657 test_cmp post-update.expect post-update.actual
661 test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
662 mk_test_with_hooks heads/master &&
663 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
664 newmaster=$(git show-ref -s --verify refs/heads/master) &&
665 git push testrepo master :refs/heads/nonexistent &&
667 cd testrepo/.git &&
668 cat >pre-receive.expect <<-EOF &&
669 $orgmaster $newmaster refs/heads/master
670 $_z40 $_z40 refs/heads/nonexistent
673 cat >update.expect <<-EOF &&
674 refs/heads/master $orgmaster $newmaster
675 refs/heads/nonexistent $_z40 $_z40
678 cat >post-receive.expect <<-EOF &&
679 $orgmaster $newmaster refs/heads/master
682 cat >post-update.expect <<-EOF &&
683 refs/heads/master
686 test_cmp pre-receive.expect pre-receive.actual &&
687 test_cmp update.expect update.actual &&
688 test_cmp post-receive.expect post-receive.actual &&
689 test_cmp post-update.expect post-update.actual
693 test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
694 mk_test_with_hooks heads/master &&
695 git push testrepo :refs/heads/nonexistent &&
697 cd testrepo/.git &&
698 cat >pre-receive.expect <<-EOF &&
699 $_z40 $_z40 refs/heads/nonexistent
702 cat >update.expect <<-EOF &&
703 refs/heads/nonexistent $_z40 $_z40
706 test_cmp pre-receive.expect pre-receive.actual &&
707 test_cmp update.expect update.actual &&
708 test_path_is_missing post-receive.actual &&
709 test_path_is_missing post-update.actual
713 test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
714 mk_test_with_hooks heads/master heads/next heads/pu &&
715 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
716 newmaster=$(git show-ref -s --verify refs/heads/master) &&
717 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
718 newnext=$_z40 &&
719 orgpu=$(cd testrepo && git show-ref -s --verify refs/heads/pu) &&
720 newpu=$(git show-ref -s --verify refs/heads/master) &&
721 git push testrepo refs/heads/master:refs/heads/master \
722 refs/heads/master:refs/heads/pu :refs/heads/next \
723 :refs/heads/nonexistent &&
725 cd testrepo/.git &&
726 cat >pre-receive.expect <<-EOF &&
727 $orgmaster $newmaster refs/heads/master
728 $orgnext $newnext refs/heads/next
729 $orgpu $newpu refs/heads/pu
730 $_z40 $_z40 refs/heads/nonexistent
733 cat >update.expect <<-EOF &&
734 refs/heads/master $orgmaster $newmaster
735 refs/heads/next $orgnext $newnext
736 refs/heads/pu $orgpu $newpu
737 refs/heads/nonexistent $_z40 $_z40
740 cat >post-receive.expect <<-EOF &&
741 $orgmaster $newmaster refs/heads/master
742 $orgnext $newnext refs/heads/next
743 $orgpu $newpu refs/heads/pu
746 cat >post-update.expect <<-EOF &&
747 refs/heads/master
748 refs/heads/next
749 refs/heads/pu
752 test_cmp pre-receive.expect pre-receive.actual &&
753 test_cmp update.expect update.actual &&
754 test_cmp post-receive.expect post-receive.actual &&
755 test_cmp post-update.expect post-update.actual
759 test_expect_success 'allow deleting a ref using --delete' '
760 mk_test heads/master &&
761 (cd testrepo && git config receive.denyDeleteCurrent warn) &&
762 git push testrepo --delete master &&
763 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
766 test_expect_success 'allow deleting a tag using --delete' '
767 mk_test heads/master &&
768 git tag -a -m dummy_message deltag heads/master &&
769 git push testrepo --tags &&
770 (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
771 git push testrepo --delete tag deltag &&
772 (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
775 test_expect_success 'push --delete without args aborts' '
776 mk_test heads/master &&
777 test_must_fail git push testrepo --delete
780 test_expect_success 'push --delete refuses src:dest refspecs' '
781 mk_test heads/master &&
782 test_must_fail git push testrepo --delete master:foo
785 test_expect_success 'warn on push to HEAD of non-bare repository' '
786 mk_test heads/master &&
788 cd testrepo &&
789 git checkout master &&
790 git config receive.denyCurrentBranch warn
791 ) &&
792 git push testrepo master 2>stderr &&
793 grep "warning: updating the current branch" stderr
796 test_expect_success 'deny push to HEAD of non-bare repository' '
797 mk_test heads/master &&
799 cd testrepo &&
800 git checkout master &&
801 git config receive.denyCurrentBranch true
802 ) &&
803 test_must_fail git push testrepo master
806 test_expect_success 'allow push to HEAD of bare repository (bare)' '
807 mk_test heads/master &&
809 cd testrepo &&
810 git checkout master &&
811 git config receive.denyCurrentBranch true &&
812 git config core.bare true
813 ) &&
814 git push testrepo master 2>stderr &&
815 ! grep "warning: updating the current branch" stderr
818 test_expect_success 'allow push to HEAD of non-bare repository (config)' '
819 mk_test heads/master &&
821 cd testrepo &&
822 git checkout master &&
823 git config receive.denyCurrentBranch false
824 ) &&
825 git push testrepo master 2>stderr &&
826 ! grep "warning: updating the current branch" stderr
829 test_expect_success 'fetch with branches' '
830 mk_empty &&
831 git branch second $the_first_commit &&
832 git checkout second &&
833 echo ".." > testrepo/.git/branches/branch1 &&
835 cd testrepo &&
836 git fetch branch1 &&
837 r=$(git show-ref -s --verify refs/heads/branch1) &&
838 test "z$r" = "z$the_commit" &&
839 test 1 = $(git for-each-ref refs/heads | wc -l)
840 ) &&
841 git checkout master
844 test_expect_success 'fetch with branches containing #' '
845 mk_empty &&
846 echo "..#second" > testrepo/.git/branches/branch2 &&
848 cd testrepo &&
849 git fetch branch2 &&
850 r=$(git show-ref -s --verify refs/heads/branch2) &&
851 test "z$r" = "z$the_first_commit" &&
852 test 1 = $(git for-each-ref refs/heads | wc -l)
853 ) &&
854 git checkout master
857 test_expect_success 'push with branches' '
858 mk_empty &&
859 git checkout second &&
860 echo "testrepo" > .git/branches/branch1 &&
861 git push branch1 &&
863 cd testrepo &&
864 r=$(git show-ref -s --verify refs/heads/master) &&
865 test "z$r" = "z$the_first_commit" &&
866 test 1 = $(git for-each-ref refs/heads | wc -l)
870 test_expect_success 'push with branches containing #' '
871 mk_empty &&
872 echo "testrepo#branch3" > .git/branches/branch2 &&
873 git push branch2 &&
875 cd testrepo &&
876 r=$(git show-ref -s --verify refs/heads/branch3) &&
877 test "z$r" = "z$the_first_commit" &&
878 test 1 = $(git for-each-ref refs/heads | wc -l)
879 ) &&
880 git checkout master
883 test_expect_success 'push into aliased refs (consistent)' '
884 mk_test heads/master &&
885 mk_child child1 &&
886 mk_child child2 &&
888 cd child1 &&
889 git branch foo &&
890 git symbolic-ref refs/heads/bar refs/heads/foo
891 git config receive.denyCurrentBranch false
892 ) &&
894 cd child2 &&
895 >path2 &&
896 git add path2 &&
897 test_tick &&
898 git commit -a -m child2 &&
899 git branch foo &&
900 git branch bar &&
901 git push ../child1 foo bar
905 test_expect_success 'push into aliased refs (inconsistent)' '
906 mk_test heads/master &&
907 mk_child child1 &&
908 mk_child child2 &&
910 cd child1 &&
911 git branch foo &&
912 git symbolic-ref refs/heads/bar refs/heads/foo
913 git config receive.denyCurrentBranch false
914 ) &&
916 cd child2 &&
917 >path2 &&
918 git add path2 &&
919 test_tick &&
920 git commit -a -m child2 &&
921 git branch foo &&
922 >path3 &&
923 git add path3 &&
924 test_tick &&
925 git commit -a -m child2 &&
926 git branch bar &&
927 test_must_fail git push ../child1 foo bar 2>stderr &&
928 grep "refusing inconsistent update" stderr
932 test_expect_success 'push --porcelain' '
933 mk_empty &&
934 echo >.git/foo "To testrepo" &&
935 echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" &&
936 echo >>.git/foo "Done" &&
937 git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master &&
939 cd testrepo &&
940 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
941 test "z$r" = "z$the_commit" &&
942 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
943 ) &&
944 test_cmp .git/foo .git/bar
947 test_expect_success 'push --porcelain bad url' '
948 mk_empty &&
949 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
950 test_must_fail grep -q Done .git/bar
953 test_expect_success 'push --porcelain rejected' '
954 mk_empty &&
955 git push testrepo refs/heads/master:refs/remotes/origin/master &&
956 (cd testrepo &&
957 git reset --hard origin/master^
958 git config receive.denyCurrentBranch true) &&
960 echo >.git/foo "To testrepo" &&
961 echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" &&
963 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master &&
964 test_cmp .git/foo .git/bar
967 test_expect_success 'push --porcelain --dry-run rejected' '
968 mk_empty &&
969 git push testrepo refs/heads/master:refs/remotes/origin/master &&
970 (cd testrepo &&
971 git reset --hard origin/master
972 git config receive.denyCurrentBranch true) &&
974 echo >.git/foo "To testrepo" &&
975 echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" &&
976 echo >>.git/foo "Done" &&
978 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master &&
979 test_cmp .git/foo .git/bar
982 test_expect_success 'push --prune' '
983 mk_test heads/master heads/second heads/foo heads/bar &&
984 git push --prune testrepo &&
985 check_push_result $the_commit heads/master &&
986 check_push_result $the_first_commit heads/second &&
987 ! check_push_result $the_first_commit heads/foo heads/bar
990 test_expect_success 'push --prune refspec' '
991 mk_test tmp/master tmp/second tmp/foo tmp/bar &&
992 git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
993 check_push_result $the_commit tmp/master &&
994 check_push_result $the_first_commit tmp/second &&
995 ! check_push_result $the_first_commit tmp/foo tmp/bar
998 test_expect_success 'receive.denyCurrentBranch = updateInstead' '
999 git push testrepo master &&
1000 (cd testrepo &&
1001 git reset --hard &&
1002 git config receive.denyCurrentBranch updateInstead
1003 ) &&
1004 test_commit third path2 &&
1005 git push testrepo master &&
1006 test $(git rev-parse HEAD) = $(cd testrepo && git rev-parse HEAD) &&
1007 test third = "$(cat testrepo/path2)" &&
1008 (cd testrepo &&
1009 git update-index --refresh &&
1010 git diff-files --quiet &&
1011 git diff-index --cached HEAD --
1015 test_expect_success 'receive.denyCurrentBranch = detachInstead' '
1016 (cd testrepo &&
1017 git reset --hard &&
1018 git config receive.denyCurrentBranch detachInstead
1019 ) &&
1020 OLDHEAD=$(cd testrepo && git rev-parse HEAD) &&
1021 test_commit fourth path2 &&
1022 test fourth = "$(cat path2)" &&
1023 git push testrepo master &&
1024 test $OLDHEAD = $(cd testrepo && git rev-parse HEAD) &&
1025 test fourth != "$(cat testrepo/path2)" &&
1026 (cd testrepo &&
1027 test_must_fail git symbolic-ref HEAD &&
1028 git update-index --refresh &&
1029 git diff-files --quiet &&
1030 git diff-index --cached HEAD --
1034 test_done