Merge branch 'jc/t5516-pushInsteadOf-vs-pushURL'
[git/jnareb-git.git] / t / t5516-fetch-push.sh
blob32ad89107b20fc2187b416bc7e3f4d45e17474c6
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 exit
27 done &&
28 cd testrepo &&
29 for ref in "$@"
31 echo "$the_first_commit" >expect &&
32 git show-ref -s --verify refs/$ref >actual &&
33 test_cmp expect actual ||
34 exit
35 done &&
36 git fsck --full
40 mk_test_with_hooks() {
41 mk_test "$@" &&
43 cd testrepo &&
44 mkdir .git/hooks &&
45 cd .git/hooks &&
47 cat >pre-receive <<-'EOF' &&
48 #!/bin/sh
49 cat - >>pre-receive.actual
50 EOF
52 cat >update <<-'EOF' &&
53 #!/bin/sh
54 printf "%s %s %s\n" "$@" >>update.actual
55 EOF
57 cat >post-receive <<-'EOF' &&
58 #!/bin/sh
59 cat - >>post-receive.actual
60 EOF
62 cat >post-update <<-'EOF' &&
63 #!/bin/sh
64 for ref in "$@"
66 printf "%s\n" "$ref" >>post-update.actual
67 done
68 EOF
70 chmod +x pre-receive update post-receive post-update
74 mk_child() {
75 rm -rf "$1" &&
76 git clone testrepo "$1"
79 check_push_result () {
81 cd testrepo &&
82 echo "$1" >expect &&
83 shift &&
84 for ref in "$@"
86 git show-ref -s --verify refs/$ref >actual &&
87 test_cmp expect actual ||
88 exit
89 done &&
90 git fsck --full
94 test_expect_success setup '
96 >path1 &&
97 git add path1 &&
98 test_tick &&
99 git commit -a -m repo &&
100 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
102 >path2 &&
103 git add path2 &&
104 test_tick &&
105 git commit -a -m second &&
106 the_commit=$(git show-ref -s --verify refs/heads/master)
110 test_expect_success 'fetch without wildcard' '
111 mk_empty &&
113 cd testrepo &&
114 git fetch .. refs/heads/master:refs/remotes/origin/master &&
116 echo "$the_commit commit refs/remotes/origin/master" >expect &&
117 git for-each-ref refs/remotes/origin >actual &&
118 test_cmp expect actual
122 test_expect_success 'fetch with wildcard' '
123 mk_empty &&
125 cd testrepo &&
126 git config remote.up.url .. &&
127 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
128 git fetch up &&
130 echo "$the_commit commit refs/remotes/origin/master" >expect &&
131 git for-each-ref refs/remotes/origin >actual &&
132 test_cmp expect actual
136 test_expect_success 'fetch with insteadOf' '
137 mk_empty &&
139 TRASH=$(pwd)/ &&
140 cd testrepo &&
141 git config "url.$TRASH.insteadOf" trash/ &&
142 git config remote.up.url trash/. &&
143 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
144 git fetch up &&
146 echo "$the_commit commit refs/remotes/origin/master" >expect &&
147 git for-each-ref refs/remotes/origin >actual &&
148 test_cmp expect actual
152 test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
153 mk_empty &&
155 TRASH=$(pwd)/ &&
156 cd testrepo &&
157 git config "url.trash/.pushInsteadOf" "$TRASH" &&
158 git config remote.up.url "$TRASH." &&
159 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
160 git fetch up &&
162 echo "$the_commit commit refs/remotes/origin/master" >expect &&
163 git for-each-ref refs/remotes/origin >actual &&
164 test_cmp expect actual
168 test_expect_success 'push without wildcard' '
169 mk_empty &&
171 git push testrepo refs/heads/master:refs/remotes/origin/master &&
173 cd testrepo &&
174 echo "$the_commit commit refs/remotes/origin/master" >expect &&
175 git for-each-ref refs/remotes/origin >actual &&
176 test_cmp expect actual
180 test_expect_success 'push with wildcard' '
181 mk_empty &&
183 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
185 cd testrepo &&
186 echo "$the_commit commit refs/remotes/origin/master" >expect &&
187 git for-each-ref refs/remotes/origin >actual &&
188 test_cmp expect actual
192 test_expect_success 'push with insteadOf' '
193 mk_empty &&
194 TRASH="$(pwd)/" &&
195 test_config "url.$TRASH.insteadOf" trash/ &&
196 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
198 cd testrepo &&
199 echo "$the_commit commit refs/remotes/origin/master" >expect &&
200 git for-each-ref refs/remotes/origin >actual &&
201 test_cmp expect actual
205 test_expect_success 'push with pushInsteadOf' '
206 mk_empty &&
207 TRASH="$(pwd)/" &&
208 test_config "url.$TRASH.pushInsteadOf" trash/ &&
209 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
211 cd testrepo &&
212 echo "$the_commit commit refs/remotes/origin/master" >expect &&
213 git for-each-ref refs/remotes/origin >actual &&
214 test_cmp expect actual
218 test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
219 mk_empty &&
220 test_config "url.trash2/.pushInsteadOf" testrepo/ &&
221 test_config "url.trash3/.pusnInsteadOf" trash/wrong &&
222 test_config remote.r.url trash/wrong &&
223 test_config remote.r.pushurl "testrepo/" &&
224 git push r refs/heads/master:refs/remotes/origin/master &&
226 cd testrepo &&
227 echo "$the_commit commit refs/remotes/origin/master" >expect &&
228 git for-each-ref refs/remotes/origin >actual &&
229 test_cmp expect actual
233 test_expect_success 'push with matching heads' '
235 mk_test heads/master &&
236 git push testrepo &&
237 check_push_result $the_commit heads/master
241 test_expect_success 'push with matching heads on the command line' '
243 mk_test heads/master &&
244 git push testrepo : &&
245 check_push_result $the_commit heads/master
249 test_expect_success 'failed (non-fast-forward) push with matching heads' '
251 mk_test heads/master &&
252 git push testrepo : &&
253 git commit --amend -massaged &&
254 test_must_fail git push testrepo &&
255 check_push_result $the_commit heads/master &&
256 git reset --hard $the_commit
260 test_expect_success 'push --force with matching heads' '
262 mk_test heads/master &&
263 git push testrepo : &&
264 git commit --amend -massaged &&
265 git push --force testrepo &&
266 ! check_push_result $the_commit heads/master &&
267 git reset --hard $the_commit
271 test_expect_success 'push with matching heads and forced update' '
273 mk_test heads/master &&
274 git push testrepo : &&
275 git commit --amend -massaged &&
276 git push testrepo +: &&
277 ! check_push_result $the_commit heads/master &&
278 git reset --hard $the_commit
282 test_expect_success 'push with no ambiguity (1)' '
284 mk_test heads/master &&
285 git push testrepo master:master &&
286 check_push_result $the_commit heads/master
290 test_expect_success 'push with no ambiguity (2)' '
292 mk_test remotes/origin/master &&
293 git push testrepo master:origin/master &&
294 check_push_result $the_commit remotes/origin/master
298 test_expect_success 'push with colon-less refspec, no ambiguity' '
300 mk_test heads/master heads/t/master &&
301 git branch -f t/master master &&
302 git push testrepo master &&
303 check_push_result $the_commit heads/master &&
304 check_push_result $the_first_commit heads/t/master
308 test_expect_success 'push with weak ambiguity (1)' '
310 mk_test heads/master remotes/origin/master &&
311 git push testrepo master:master &&
312 check_push_result $the_commit heads/master &&
313 check_push_result $the_first_commit remotes/origin/master
317 test_expect_success 'push with weak ambiguity (2)' '
319 mk_test heads/master remotes/origin/master remotes/another/master &&
320 git push testrepo master:master &&
321 check_push_result $the_commit heads/master &&
322 check_push_result $the_first_commit remotes/origin/master remotes/another/master
326 test_expect_success 'push with ambiguity' '
328 mk_test heads/frotz tags/frotz &&
329 test_must_fail git push testrepo master:frotz &&
330 check_push_result $the_first_commit heads/frotz tags/frotz
334 test_expect_success 'push with colon-less refspec (1)' '
336 mk_test heads/frotz tags/frotz &&
337 git branch -f frotz master &&
338 git push testrepo frotz &&
339 check_push_result $the_commit heads/frotz &&
340 check_push_result $the_first_commit tags/frotz
344 test_expect_success 'push with colon-less refspec (2)' '
346 mk_test heads/frotz tags/frotz &&
347 if git show-ref --verify -q refs/heads/frotz
348 then
349 git branch -D frotz
350 fi &&
351 git tag -f frotz &&
352 git push -f testrepo frotz &&
353 check_push_result $the_commit tags/frotz &&
354 check_push_result $the_first_commit heads/frotz
358 test_expect_success 'push with colon-less refspec (3)' '
360 mk_test &&
361 if git show-ref --verify -q refs/tags/frotz
362 then
363 git tag -d frotz
364 fi &&
365 git branch -f frotz master &&
366 git push testrepo frotz &&
367 check_push_result $the_commit heads/frotz &&
368 test 1 = $( cd testrepo && git show-ref | wc -l )
371 test_expect_success 'push with colon-less refspec (4)' '
373 mk_test &&
374 if git show-ref --verify -q refs/heads/frotz
375 then
376 git branch -D frotz
377 fi &&
378 git tag -f frotz &&
379 git push testrepo frotz &&
380 check_push_result $the_commit tags/frotz &&
381 test 1 = $( cd testrepo && git show-ref | wc -l )
385 test_expect_success 'push head with non-existent, incomplete dest' '
387 mk_test &&
388 git push testrepo master:branch &&
389 check_push_result $the_commit heads/branch
393 test_expect_success 'push tag with non-existent, incomplete dest' '
395 mk_test &&
396 git tag -f v1.0 &&
397 git push testrepo v1.0:tag &&
398 check_push_result $the_commit tags/tag
402 test_expect_success 'push sha1 with non-existent, incomplete dest' '
404 mk_test &&
405 test_must_fail git push testrepo `git rev-parse master`:foo
409 test_expect_success 'push ref expression with non-existent, incomplete dest' '
411 mk_test &&
412 test_must_fail git push testrepo master^:branch
416 test_expect_success 'push with HEAD' '
418 mk_test heads/master &&
419 git checkout master &&
420 git push testrepo HEAD &&
421 check_push_result $the_commit heads/master
425 test_expect_success 'push with HEAD nonexisting at remote' '
427 mk_test heads/master &&
428 git checkout -b local master &&
429 git push testrepo HEAD &&
430 check_push_result $the_commit heads/local
433 test_expect_success 'push with +HEAD' '
435 mk_test heads/master &&
436 git checkout master &&
437 git branch -D local &&
438 git checkout -b local &&
439 git push testrepo master local &&
440 check_push_result $the_commit heads/master &&
441 check_push_result $the_commit heads/local &&
443 # Without force rewinding should fail
444 git reset --hard HEAD^ &&
445 test_must_fail git push testrepo HEAD &&
446 check_push_result $the_commit heads/local &&
448 # With force rewinding should succeed
449 git push testrepo +HEAD &&
450 check_push_result $the_first_commit heads/local
454 test_expect_success 'push HEAD with non-existent, incomplete dest' '
456 mk_test &&
457 git checkout master &&
458 git push testrepo HEAD:branch &&
459 check_push_result $the_commit heads/branch
463 test_expect_success 'push with config remote.*.push = HEAD' '
465 mk_test heads/local &&
466 git checkout master &&
467 git branch -f local $the_commit &&
469 cd testrepo &&
470 git checkout local &&
471 git reset --hard $the_first_commit
472 ) &&
473 test_config remote.there.url testrepo &&
474 test_config remote.there.push HEAD &&
475 test_config branch.master.remote there &&
476 git push &&
477 check_push_result $the_commit heads/master &&
478 check_push_result $the_first_commit heads/local
481 test_expect_success 'push with config remote.*.pushurl' '
483 mk_test heads/master &&
484 git checkout master &&
485 test_config remote.there.url test2repo &&
486 test_config remote.there.pushurl testrepo &&
487 git push there &&
488 check_push_result $the_commit heads/master
491 test_expect_success 'push with dry-run' '
493 mk_test heads/master &&
495 cd testrepo &&
496 old_commit=$(git show-ref -s --verify refs/heads/master)
497 ) &&
498 git push --dry-run testrepo &&
499 check_push_result $old_commit heads/master
502 test_expect_success 'push updates local refs' '
504 mk_test heads/master &&
505 mk_child child &&
507 cd child &&
508 git pull .. master &&
509 git push &&
510 test $(git rev-parse master) = \
511 $(git rev-parse remotes/origin/master)
516 test_expect_success 'push updates up-to-date local refs' '
518 mk_test heads/master &&
519 mk_child child1 &&
520 mk_child child2 &&
521 (cd child1 && git pull .. master && git push) &&
523 cd child2 &&
524 git pull ../child1 master &&
525 git push &&
526 test $(git rev-parse master) = \
527 $(git rev-parse remotes/origin/master)
532 test_expect_success 'push preserves up-to-date packed refs' '
534 mk_test heads/master &&
535 mk_child child &&
537 cd child &&
538 git push &&
539 ! test -f .git/refs/remotes/origin/master
544 test_expect_success 'push does not update local refs on failure' '
546 mk_test heads/master &&
547 mk_child child &&
548 mkdir testrepo/.git/hooks &&
549 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
550 chmod +x testrepo/.git/hooks/pre-receive &&
552 cd child &&
553 git pull .. master
554 test_must_fail git push &&
555 test $(git rev-parse master) != \
556 $(git rev-parse remotes/origin/master)
561 test_expect_success 'allow deleting an invalid remote ref' '
563 mk_test heads/master &&
564 rm -f testrepo/.git/objects/??/* &&
565 git push testrepo :refs/heads/master &&
566 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
570 test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' '
571 mk_test_with_hooks heads/master heads/next &&
572 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
573 newmaster=$(git show-ref -s --verify refs/heads/master) &&
574 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
575 newnext=$_z40 &&
576 git push testrepo refs/heads/master:refs/heads/master :refs/heads/next &&
578 cd testrepo/.git &&
579 cat >pre-receive.expect <<-EOF &&
580 $orgmaster $newmaster refs/heads/master
581 $orgnext $newnext refs/heads/next
584 cat >update.expect <<-EOF &&
585 refs/heads/master $orgmaster $newmaster
586 refs/heads/next $orgnext $newnext
589 cat >post-receive.expect <<-EOF &&
590 $orgmaster $newmaster refs/heads/master
591 $orgnext $newnext refs/heads/next
594 cat >post-update.expect <<-EOF &&
595 refs/heads/master
596 refs/heads/next
599 test_cmp pre-receive.expect pre-receive.actual &&
600 test_cmp update.expect update.actual &&
601 test_cmp post-receive.expect post-receive.actual &&
602 test_cmp post-update.expect post-update.actual
606 test_expect_success 'deleting dangling ref triggers hooks with correct args' '
607 mk_test_with_hooks heads/master &&
608 rm -f testrepo/.git/objects/??/* &&
609 git push testrepo :refs/heads/master &&
611 cd testrepo/.git &&
612 cat >pre-receive.expect <<-EOF &&
613 $_z40 $_z40 refs/heads/master
616 cat >update.expect <<-EOF &&
617 refs/heads/master $_z40 $_z40
620 cat >post-receive.expect <<-EOF &&
621 $_z40 $_z40 refs/heads/master
624 cat >post-update.expect <<-EOF &&
625 refs/heads/master
628 test_cmp pre-receive.expect pre-receive.actual &&
629 test_cmp update.expect update.actual &&
630 test_cmp post-receive.expect post-receive.actual &&
631 test_cmp post-update.expect post-update.actual
635 test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
636 mk_test_with_hooks heads/master &&
637 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
638 newmaster=$(git show-ref -s --verify refs/heads/master) &&
639 git push testrepo master :refs/heads/nonexistent &&
641 cd testrepo/.git &&
642 cat >pre-receive.expect <<-EOF &&
643 $orgmaster $newmaster refs/heads/master
644 $_z40 $_z40 refs/heads/nonexistent
647 cat >update.expect <<-EOF &&
648 refs/heads/master $orgmaster $newmaster
649 refs/heads/nonexistent $_z40 $_z40
652 cat >post-receive.expect <<-EOF &&
653 $orgmaster $newmaster refs/heads/master
656 cat >post-update.expect <<-EOF &&
657 refs/heads/master
660 test_cmp pre-receive.expect pre-receive.actual &&
661 test_cmp update.expect update.actual &&
662 test_cmp post-receive.expect post-receive.actual &&
663 test_cmp post-update.expect post-update.actual
667 test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
668 mk_test_with_hooks heads/master &&
669 git push testrepo :refs/heads/nonexistent &&
671 cd testrepo/.git &&
672 cat >pre-receive.expect <<-EOF &&
673 $_z40 $_z40 refs/heads/nonexistent
676 cat >update.expect <<-EOF &&
677 refs/heads/nonexistent $_z40 $_z40
680 test_cmp pre-receive.expect pre-receive.actual &&
681 test_cmp update.expect update.actual &&
682 test_path_is_missing post-receive.actual &&
683 test_path_is_missing post-update.actual
687 test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
688 mk_test_with_hooks heads/master heads/next heads/pu &&
689 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
690 newmaster=$(git show-ref -s --verify refs/heads/master) &&
691 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
692 newnext=$_z40 &&
693 orgpu=$(cd testrepo && git show-ref -s --verify refs/heads/pu) &&
694 newpu=$(git show-ref -s --verify refs/heads/master) &&
695 git push testrepo refs/heads/master:refs/heads/master \
696 refs/heads/master:refs/heads/pu :refs/heads/next \
697 :refs/heads/nonexistent &&
699 cd testrepo/.git &&
700 cat >pre-receive.expect <<-EOF &&
701 $orgmaster $newmaster refs/heads/master
702 $orgnext $newnext refs/heads/next
703 $orgpu $newpu refs/heads/pu
704 $_z40 $_z40 refs/heads/nonexistent
707 cat >update.expect <<-EOF &&
708 refs/heads/master $orgmaster $newmaster
709 refs/heads/next $orgnext $newnext
710 refs/heads/pu $orgpu $newpu
711 refs/heads/nonexistent $_z40 $_z40
714 cat >post-receive.expect <<-EOF &&
715 $orgmaster $newmaster refs/heads/master
716 $orgnext $newnext refs/heads/next
717 $orgpu $newpu refs/heads/pu
720 cat >post-update.expect <<-EOF &&
721 refs/heads/master
722 refs/heads/next
723 refs/heads/pu
726 test_cmp pre-receive.expect pre-receive.actual &&
727 test_cmp update.expect update.actual &&
728 test_cmp post-receive.expect post-receive.actual &&
729 test_cmp post-update.expect post-update.actual
733 test_expect_success 'allow deleting a ref using --delete' '
734 mk_test heads/master &&
735 (cd testrepo && git config receive.denyDeleteCurrent warn) &&
736 git push testrepo --delete master &&
737 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
740 test_expect_success 'allow deleting a tag using --delete' '
741 mk_test heads/master &&
742 git tag -a -m dummy_message deltag heads/master &&
743 git push testrepo --tags &&
744 (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
745 git push testrepo --delete tag deltag &&
746 (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
749 test_expect_success 'push --delete without args aborts' '
750 mk_test heads/master &&
751 test_must_fail git push testrepo --delete
754 test_expect_success 'push --delete refuses src:dest refspecs' '
755 mk_test heads/master &&
756 test_must_fail git push testrepo --delete master:foo
759 test_expect_success 'warn on push to HEAD of non-bare repository' '
760 mk_test heads/master &&
762 cd testrepo &&
763 git checkout master &&
764 git config receive.denyCurrentBranch warn
765 ) &&
766 git push testrepo master 2>stderr &&
767 grep "warning: updating the current branch" stderr
770 test_expect_success 'deny push to HEAD of non-bare repository' '
771 mk_test heads/master &&
773 cd testrepo &&
774 git checkout master &&
775 git config receive.denyCurrentBranch true
776 ) &&
777 test_must_fail git push testrepo master
780 test_expect_success 'allow push to HEAD of bare repository (bare)' '
781 mk_test heads/master &&
783 cd testrepo &&
784 git checkout master &&
785 git config receive.denyCurrentBranch true &&
786 git config core.bare true
787 ) &&
788 git push testrepo master 2>stderr &&
789 ! grep "warning: updating the current branch" stderr
792 test_expect_success 'allow push to HEAD of non-bare repository (config)' '
793 mk_test heads/master &&
795 cd testrepo &&
796 git checkout master &&
797 git config receive.denyCurrentBranch false
798 ) &&
799 git push testrepo master 2>stderr &&
800 ! grep "warning: updating the current branch" stderr
803 test_expect_success 'fetch with branches' '
804 mk_empty &&
805 git branch second $the_first_commit &&
806 git checkout second &&
807 echo ".." > testrepo/.git/branches/branch1 &&
809 cd testrepo &&
810 git fetch branch1 &&
811 echo "$the_commit commit refs/heads/branch1" >expect &&
812 git for-each-ref refs/heads >actual &&
813 test_cmp expect actual
814 ) &&
815 git checkout master
818 test_expect_success 'fetch with branches containing #' '
819 mk_empty &&
820 echo "..#second" > testrepo/.git/branches/branch2 &&
822 cd testrepo &&
823 git fetch branch2 &&
824 echo "$the_first_commit commit refs/heads/branch2" >expect &&
825 git for-each-ref refs/heads >actual &&
826 test_cmp expect actual
827 ) &&
828 git checkout master
831 test_expect_success 'push with branches' '
832 mk_empty &&
833 git checkout second &&
834 echo "testrepo" > .git/branches/branch1 &&
835 git push branch1 &&
837 cd testrepo &&
838 echo "$the_first_commit commit refs/heads/master" >expect &&
839 git for-each-ref refs/heads >actual &&
840 test_cmp expect actual
844 test_expect_success 'push with branches containing #' '
845 mk_empty &&
846 echo "testrepo#branch3" > .git/branches/branch2 &&
847 git push branch2 &&
849 cd testrepo &&
850 echo "$the_first_commit commit refs/heads/branch3" >expect &&
851 git for-each-ref refs/heads >actual &&
852 test_cmp expect actual
853 ) &&
854 git checkout master
857 test_expect_success 'push into aliased refs (consistent)' '
858 mk_test heads/master &&
859 mk_child child1 &&
860 mk_child child2 &&
862 cd child1 &&
863 git branch foo &&
864 git symbolic-ref refs/heads/bar refs/heads/foo
865 git config receive.denyCurrentBranch false
866 ) &&
868 cd child2 &&
869 >path2 &&
870 git add path2 &&
871 test_tick &&
872 git commit -a -m child2 &&
873 git branch foo &&
874 git branch bar &&
875 git push ../child1 foo bar
879 test_expect_success 'push into aliased refs (inconsistent)' '
880 mk_test heads/master &&
881 mk_child child1 &&
882 mk_child child2 &&
884 cd child1 &&
885 git branch foo &&
886 git symbolic-ref refs/heads/bar refs/heads/foo
887 git config receive.denyCurrentBranch false
888 ) &&
890 cd child2 &&
891 >path2 &&
892 git add path2 &&
893 test_tick &&
894 git commit -a -m child2 &&
895 git branch foo &&
896 >path3 &&
897 git add path3 &&
898 test_tick &&
899 git commit -a -m child2 &&
900 git branch bar &&
901 test_must_fail git push ../child1 foo bar 2>stderr &&
902 grep "refusing inconsistent update" stderr
906 test_expect_success 'push requires --force to update lightweight tag' '
907 mk_test heads/master &&
908 mk_child child1 &&
909 mk_child child2 &&
911 cd child1 &&
912 git tag Tag &&
913 git push ../child2 Tag &&
914 git push ../child2 Tag &&
915 >file1 &&
916 git add file1 &&
917 git commit -m "file1" &&
918 git tag -f Tag &&
919 test_must_fail git push ../child2 Tag &&
920 git push --force ../child2 Tag &&
921 git tag -f Tag &&
922 test_must_fail git push ../child2 Tag HEAD~ &&
923 git push --force ../child2 Tag
927 test_expect_success 'push --porcelain' '
928 mk_empty &&
929 echo >.git/foo "To testrepo" &&
930 echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" &&
931 echo >>.git/foo "Done" &&
932 git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master &&
934 cd testrepo &&
935 echo "$the_commit commit refs/remotes/origin/master" >expect &&
936 git for-each-ref refs/remotes/origin >actual &&
937 test_cmp expect actual
938 ) &&
939 test_cmp .git/foo .git/bar
942 test_expect_success 'push --porcelain bad url' '
943 mk_empty &&
944 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
945 test_must_fail grep -q Done .git/bar
948 test_expect_success 'push --porcelain rejected' '
949 mk_empty &&
950 git push testrepo refs/heads/master:refs/remotes/origin/master &&
951 (cd testrepo &&
952 git reset --hard origin/master^
953 git config receive.denyCurrentBranch true) &&
955 echo >.git/foo "To testrepo" &&
956 echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" &&
958 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master &&
959 test_cmp .git/foo .git/bar
962 test_expect_success 'push --porcelain --dry-run rejected' '
963 mk_empty &&
964 git push testrepo refs/heads/master:refs/remotes/origin/master &&
965 (cd testrepo &&
966 git reset --hard origin/master
967 git config receive.denyCurrentBranch true) &&
969 echo >.git/foo "To testrepo" &&
970 echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" &&
971 echo >>.git/foo "Done" &&
973 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master &&
974 test_cmp .git/foo .git/bar
977 test_expect_success 'push --prune' '
978 mk_test heads/master heads/second heads/foo heads/bar &&
979 git push --prune testrepo &&
980 check_push_result $the_commit heads/master &&
981 check_push_result $the_first_commit heads/second &&
982 ! check_push_result $the_first_commit heads/foo heads/bar
985 test_expect_success 'push --prune refspec' '
986 mk_test tmp/master tmp/second tmp/foo tmp/bar &&
987 git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
988 check_push_result $the_commit tmp/master &&
989 check_push_result $the_first_commit tmp/second &&
990 ! check_push_result $the_first_commit tmp/foo tmp/bar
993 for configsection in transfer receive
995 test_expect_success "push to update a ref hidden by $configsection.hiderefs" '
996 mk_test heads/master hidden/one hidden/two hidden/three &&
998 cd testrepo &&
999 git config $configsection.hiderefs refs/hidden
1000 ) &&
1002 # push to unhidden ref succeeds normally
1003 git push testrepo master:refs/heads/master &&
1004 check_push_result $the_commit heads/master &&
1006 # push to update a hidden ref should fail
1007 test_must_fail git push testrepo master:refs/hidden/one &&
1008 check_push_result $the_first_commit hidden/one &&
1010 # push to delete a hidden ref should fail
1011 test_must_fail git push testrepo :refs/hidden/two &&
1012 check_push_result $the_first_commit hidden/two &&
1014 # idempotent push to update a hidden ref should fail
1015 test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
1016 check_push_result $the_first_commit hidden/three
1018 done
1020 test_expect_success 'fetch exact SHA1' '
1021 mk_test heads/master hidden/one &&
1022 git push testrepo master:refs/hidden/one &&
1024 cd testrepo &&
1025 git config transfer.hiderefs refs/hidden
1026 ) &&
1027 check_push_result $the_commit hidden/one &&
1029 mk_child child &&
1031 cd child &&
1033 # make sure $the_commit does not exist here
1034 git repack -a -d &&
1035 git prune &&
1036 test_must_fail git cat-file -t $the_commit &&
1038 # fetching the hidden object should fail by default
1039 test_must_fail git fetch -v ../testrepo $the_commit:refs/heads/copy &&
1040 test_must_fail git rev-parse --verify refs/heads/copy &&
1042 # the server side can allow it to succeed
1044 cd ../testrepo &&
1045 git config uploadpack.allowtipsha1inwant true
1046 ) &&
1048 git fetch -v ../testrepo $the_commit:refs/heads/copy &&
1049 result=$(git rev-parse --verify refs/heads/copy) &&
1050 test "$the_commit" = "$result"
1054 test_expect_success 'fetch follows tags by default' '
1055 mk_test heads/master &&
1056 rm -fr src dst &&
1057 git init src &&
1059 cd src &&
1060 git pull ../testrepo master &&
1061 git tag -m "annotated" tag &&
1062 git for-each-ref >tmp1 &&
1064 cat tmp1
1065 sed -n "s|refs/heads/master$|refs/remotes/origin/master|p" tmp1
1067 sort -k 3 >../expect
1068 ) &&
1069 git init dst &&
1071 cd dst &&
1072 git remote add origin ../src &&
1073 git config branch.master.remote origin &&
1074 git config branch.master.merge refs/heads/master &&
1075 git pull &&
1076 git for-each-ref >../actual
1077 ) &&
1078 test_cmp expect actual
1081 test_expect_success 'push does not follow tags by default' '
1082 mk_test heads/master &&
1083 rm -fr src dst &&
1084 git init src &&
1085 git init --bare dst &&
1087 cd src &&
1088 git pull ../testrepo master &&
1089 git tag -m "annotated" tag &&
1090 git checkout -b another &&
1091 git commit --allow-empty -m "future commit" &&
1092 git tag -m "future" future &&
1093 git checkout master &&
1094 git for-each-ref refs/heads/master >../expect &&
1095 git push ../dst master
1096 ) &&
1098 cd dst &&
1099 git for-each-ref >../actual
1100 ) &&
1101 test_cmp expect actual
1104 test_expect_success 'push --follow-tag only pushes relevant tags' '
1105 mk_test heads/master &&
1106 rm -fr src dst &&
1107 git init src &&
1108 git init --bare dst &&
1110 cd src &&
1111 git pull ../testrepo master &&
1112 git tag -m "annotated" tag &&
1113 git checkout -b another &&
1114 git commit --allow-empty -m "future commit" &&
1115 git tag -m "future" future &&
1116 git checkout master &&
1117 git for-each-ref refs/heads/master refs/tags/tag >../expect
1118 git push --follow-tag ../dst master
1119 ) &&
1121 cd dst &&
1122 git for-each-ref >../actual
1123 ) &&
1124 test_cmp expect actual
1127 test_done