3 test_description
='Basic fetch/push functionality.
5 This test checks the following functionality:
9 * fast-forward detection, and overriding it
12 * --porcelain output format
22 rm -fr "$repo_name" &&
27 git config receive.denyCurrentBranch warn
&&
28 mv .git
/hooks .git
/hooks-disabled
36 mk_empty
"$repo_name" &&
40 git push
"$repo_name" $the_first_commit:refs
/$ref ||
46 echo "$the_first_commit" >expect
&&
47 git show-ref
-s --verify refs
/$ref >actual
&&
48 test_cmp expect actual ||
55 mk_test_with_hooks
() {
63 cat >pre-receive
<<-'EOF' &&
65 cat - >>pre-receive.actual
68 cat >update
<<-'EOF' &&
70 printf "%s %s %s\n" "$@" >>update.actual
73 cat >post-receive
<<-'EOF' &&
75 cat - >>post-receive.actual
78 cat >post-update
<<-'EOF' &&
82 printf "%s\n" "$ref" >>post-update.actual
86 chmod +x pre-receive update post-receive post-update
95 check_push_result
() {
105 git show-ref
-s --verify refs
/$ref >actual
&&
106 test_cmp expect actual ||
113 test_expect_success setup
'
118 git commit -a -m repo &&
119 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
124 git commit -a -m second &&
125 the_commit=$(git show-ref -s --verify refs/heads/master)
129 test_expect_success
'fetch without wildcard' '
133 git fetch .. refs/heads/master:refs/remotes/origin/master &&
135 echo "$the_commit commit refs/remotes/origin/master" >expect &&
136 git for-each-ref refs/remotes/origin >actual &&
137 test_cmp expect actual
141 test_expect_success
'fetch with wildcard' '
145 git config remote.up.url .. &&
146 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
149 echo "$the_commit commit refs/remotes/origin/master" >expect &&
150 git for-each-ref refs/remotes/origin >actual &&
151 test_cmp expect actual
155 test_expect_success
'fetch with insteadOf' '
160 git config "url.$TRASH.insteadOf" trash/ &&
161 git config remote.up.url trash/. &&
162 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
165 echo "$the_commit commit refs/remotes/origin/master" >expect &&
166 git for-each-ref refs/remotes/origin >actual &&
167 test_cmp expect actual
171 test_expect_success
'fetch with pushInsteadOf (should not rewrite)' '
176 git config "url.trash/.pushInsteadOf" "$TRASH" &&
177 git config remote.up.url "$TRASH." &&
178 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
181 echo "$the_commit commit refs/remotes/origin/master" >expect &&
182 git for-each-ref refs/remotes/origin >actual &&
183 test_cmp expect actual
187 test_expect_success
'push without wildcard' '
190 git push testrepo refs/heads/master:refs/remotes/origin/master &&
193 echo "$the_commit commit refs/remotes/origin/master" >expect &&
194 git for-each-ref refs/remotes/origin >actual &&
195 test_cmp expect actual
199 test_expect_success
'push with wildcard' '
202 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
205 echo "$the_commit commit refs/remotes/origin/master" >expect &&
206 git for-each-ref refs/remotes/origin >actual &&
207 test_cmp expect actual
211 test_expect_success
'push with insteadOf' '
214 test_config "url.$TRASH.insteadOf" trash/ &&
215 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
218 echo "$the_commit commit refs/remotes/origin/master" >expect &&
219 git for-each-ref refs/remotes/origin >actual &&
220 test_cmp expect actual
224 test_expect_success
'push with pushInsteadOf' '
227 test_config "url.$TRASH.pushInsteadOf" trash/ &&
228 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
231 echo "$the_commit commit refs/remotes/origin/master" >expect &&
232 git for-each-ref refs/remotes/origin >actual &&
233 test_cmp expect actual
237 test_expect_success
'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
239 test_config "url.trash2/.pushInsteadOf" testrepo/ &&
240 test_config "url.trash3/.pusnInsteadOf" trash/wrong &&
241 test_config remote.r.url trash/wrong &&
242 test_config remote.r.pushurl "testrepo/" &&
243 git push r refs/heads/master:refs/remotes/origin/master &&
246 echo "$the_commit commit refs/remotes/origin/master" >expect &&
247 git for-each-ref refs/remotes/origin >actual &&
248 test_cmp expect actual
252 test_expect_success
'push with matching heads' '
254 mk_test testrepo heads/master &&
255 git push testrepo : &&
256 check_push_result testrepo $the_commit heads/master
260 test_expect_success
'push with matching heads on the command line' '
262 mk_test testrepo heads/master &&
263 git push testrepo : &&
264 check_push_result testrepo $the_commit heads/master
268 test_expect_success
'failed (non-fast-forward) push with matching heads' '
270 mk_test testrepo heads/master &&
271 git push testrepo : &&
272 git commit --amend -massaged &&
273 test_must_fail git push testrepo &&
274 check_push_result testrepo $the_commit heads/master &&
275 git reset --hard $the_commit
279 test_expect_success
'push --force with matching heads' '
281 mk_test testrepo heads/master &&
282 git push testrepo : &&
283 git commit --amend -massaged &&
284 git push --force testrepo : &&
285 ! check_push_result testrepo $the_commit heads/master &&
286 git reset --hard $the_commit
290 test_expect_success
'push with matching heads and forced update' '
292 mk_test testrepo heads/master &&
293 git push testrepo : &&
294 git commit --amend -massaged &&
295 git push testrepo +: &&
296 ! check_push_result testrepo $the_commit heads/master &&
297 git reset --hard $the_commit
301 test_expect_success
'push with no ambiguity (1)' '
303 mk_test testrepo heads/master &&
304 git push testrepo master:master &&
305 check_push_result testrepo $the_commit heads/master
309 test_expect_success
'push with no ambiguity (2)' '
311 mk_test testrepo remotes/origin/master &&
312 git push testrepo master:origin/master &&
313 check_push_result testrepo $the_commit remotes/origin/master
317 test_expect_success
'push with colon-less refspec, no ambiguity' '
319 mk_test testrepo heads/master heads/t/master &&
320 git branch -f t/master master &&
321 git push testrepo master &&
322 check_push_result testrepo $the_commit heads/master &&
323 check_push_result testrepo $the_first_commit heads/t/master
327 test_expect_success
'push with weak ambiguity (1)' '
329 mk_test testrepo heads/master remotes/origin/master &&
330 git push testrepo master:master &&
331 check_push_result testrepo $the_commit heads/master &&
332 check_push_result testrepo $the_first_commit remotes/origin/master
336 test_expect_success
'push with weak ambiguity (2)' '
338 mk_test testrepo heads/master remotes/origin/master remotes/another/master &&
339 git push testrepo master:master &&
340 check_push_result testrepo $the_commit heads/master &&
341 check_push_result testrepo $the_first_commit remotes/origin/master remotes/another/master
345 test_expect_success
'push with ambiguity' '
347 mk_test testrepo heads/frotz tags/frotz &&
348 test_must_fail git push testrepo master:frotz &&
349 check_push_result testrepo $the_first_commit heads/frotz tags/frotz
353 test_expect_success
'push with colon-less refspec (1)' '
355 mk_test testrepo heads/frotz tags/frotz &&
356 git branch -f frotz master &&
357 git push testrepo frotz &&
358 check_push_result testrepo $the_commit heads/frotz &&
359 check_push_result testrepo $the_first_commit tags/frotz
363 test_expect_success
'push with colon-less refspec (2)' '
365 mk_test testrepo heads/frotz tags/frotz &&
366 if git show-ref --verify -q refs/heads/frotz
371 git push -f testrepo frotz &&
372 check_push_result testrepo $the_commit tags/frotz &&
373 check_push_result testrepo $the_first_commit heads/frotz
377 test_expect_success
'push with colon-less refspec (3)' '
380 if git show-ref --verify -q refs/tags/frotz
384 git branch -f frotz master &&
385 git push testrepo frotz &&
386 check_push_result testrepo $the_commit heads/frotz &&
387 test 1 = $( cd testrepo && git show-ref | wc -l )
390 test_expect_success
'push with colon-less refspec (4)' '
393 if git show-ref --verify -q refs/heads/frotz
398 git push testrepo frotz &&
399 check_push_result testrepo $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' '
407 git push testrepo master:branch &&
408 check_push_result testrepo $the_commit heads/branch
412 test_expect_success
'push tag with non-existent, incomplete dest' '
416 git push testrepo v1.0:tag &&
417 check_push_result testrepo $the_commit tags/tag
421 test_expect_success
'push sha1 with non-existent, incomplete dest' '
424 test_must_fail git push testrepo `git rev-parse master`:foo
428 test_expect_success
'push ref expression with non-existent, incomplete dest' '
431 test_must_fail git push testrepo master^:branch
435 test_expect_success
'push with HEAD' '
437 mk_test testrepo heads/master &&
438 git checkout master &&
439 git push testrepo HEAD &&
440 check_push_result testrepo $the_commit heads/master
444 test_expect_success
'push with HEAD nonexisting at remote' '
446 mk_test testrepo heads/master &&
447 git checkout -b local master &&
448 git push testrepo HEAD &&
449 check_push_result testrepo $the_commit heads/local
452 test_expect_success
'push with +HEAD' '
454 mk_test testrepo 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 testrepo $the_commit heads/master &&
460 check_push_result testrepo $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 testrepo $the_commit heads/local &&
467 # With force rewinding should succeed
468 git push testrepo +HEAD &&
469 check_push_result testrepo $the_first_commit heads/local
473 test_expect_success
'push HEAD with non-existent, incomplete dest' '
476 git checkout master &&
477 git push testrepo HEAD:branch &&
478 check_push_result testrepo $the_commit heads/branch
482 test_expect_success
'push with config remote.*.push = HEAD' '
484 mk_test testrepo heads/local &&
485 git checkout master &&
486 git branch -f local $the_commit &&
489 git checkout local &&
490 git reset --hard $the_first_commit
492 test_config remote.there.url testrepo &&
493 test_config remote.there.push HEAD &&
494 test_config branch.master.remote there &&
496 check_push_result testrepo $the_commit heads/master &&
497 check_push_result testrepo $the_first_commit heads/local
500 test_expect_success
'push with remote.pushdefault' '
501 mk_test up_repo heads/master &&
502 mk_test down_repo heads/master &&
503 test_config remote.up.url up_repo &&
504 test_config remote.down.url down_repo &&
505 test_config branch.master.remote up &&
506 test_config remote.pushdefault down &&
507 test_config push.default matching &&
509 check_push_result up_repo $the_first_commit heads/master &&
510 check_push_result down_repo $the_commit heads/master
513 test_expect_success
'push with config remote.*.pushurl' '
515 mk_test testrepo heads/master &&
516 git checkout master &&
517 test_config remote.there.url test2repo &&
518 test_config remote.there.pushurl testrepo &&
520 check_push_result testrepo $the_commit heads/master
523 test_expect_success
'push with config branch.*.pushremote' '
524 mk_test up_repo heads/master &&
525 mk_test side_repo heads/master &&
526 mk_test down_repo heads/master &&
527 test_config remote.up.url up_repo &&
528 test_config remote.pushdefault side_repo &&
529 test_config remote.down.url down_repo &&
530 test_config branch.master.remote up &&
531 test_config branch.master.pushremote down &&
532 test_config push.default matching &&
534 check_push_result up_repo $the_first_commit heads/master &&
535 check_push_result side_repo $the_first_commit heads/master &&
536 check_push_result down_repo $the_commit heads/master
539 test_expect_success
'branch.*.pushremote config order is irrelevant' '
540 mk_test one_repo heads/master &&
541 mk_test two_repo heads/master &&
542 test_config remote.one.url one_repo &&
543 test_config remote.two.url two_repo &&
544 test_config branch.master.pushremote two_repo &&
545 test_config remote.pushdefault one_repo &&
546 test_config push.default matching &&
548 check_push_result one_repo $the_first_commit heads/master &&
549 check_push_result two_repo $the_commit heads/master
552 test_expect_success
'push with dry-run' '
554 mk_test testrepo heads/master &&
557 old_commit=$(git show-ref -s --verify refs/heads/master)
559 git push --dry-run testrepo : &&
560 check_push_result testrepo $old_commit heads/master
563 test_expect_success
'push updates local refs' '
565 mk_test testrepo heads/master &&
566 mk_child testrepo child &&
569 git pull .. master &&
571 test $(git rev-parse master) = \
572 $(git rev-parse remotes/origin/master)
577 test_expect_success
'push updates up-to-date local refs' '
579 mk_test testrepo heads/master &&
580 mk_child testrepo child1 &&
581 mk_child testrepo child2 &&
582 (cd child1 && git pull .. master && git push) &&
585 git pull ../child1 master &&
587 test $(git rev-parse master) = \
588 $(git rev-parse remotes/origin/master)
593 test_expect_success
'push preserves up-to-date packed refs' '
595 mk_test testrepo heads/master &&
596 mk_child testrepo child &&
600 ! test -f .git/refs/remotes/origin/master
605 test_expect_success
'push does not update local refs on failure' '
607 mk_test testrepo heads/master &&
608 mk_child testrepo child &&
609 mkdir testrepo/.git/hooks &&
610 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
611 chmod +x testrepo/.git/hooks/pre-receive &&
615 test_must_fail git push &&
616 test $(git rev-parse master) != \
617 $(git rev-parse remotes/origin/master)
622 test_expect_success
'allow deleting an invalid remote ref' '
624 mk_test testrepo heads/master &&
625 rm -f testrepo/.git/objects/??/* &&
626 git push testrepo :refs/heads/master &&
627 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
631 test_expect_success
'pushing valid refs triggers post-receive and post-update hooks' '
632 mk_test_with_hooks testrepo heads/master heads/next &&
633 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
634 newmaster=$(git show-ref -s --verify refs/heads/master) &&
635 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
637 git push testrepo refs/heads/master:refs/heads/master :refs/heads/next &&
640 cat >pre-receive.expect <<-EOF &&
641 $orgmaster $newmaster refs/heads/master
642 $orgnext $newnext refs/heads/next
645 cat >update.expect <<-EOF &&
646 refs/heads/master $orgmaster $newmaster
647 refs/heads/next $orgnext $newnext
650 cat >post-receive.expect <<-EOF &&
651 $orgmaster $newmaster refs/heads/master
652 $orgnext $newnext refs/heads/next
655 cat >post-update.expect <<-EOF &&
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
'deleting dangling ref triggers hooks with correct args' '
668 mk_test_with_hooks testrepo heads/master &&
669 rm -f testrepo/.git/objects/??/* &&
670 git push testrepo :refs/heads/master &&
673 cat >pre-receive.expect <<-EOF &&
674 $_z40 $_z40 refs/heads/master
677 cat >update.expect <<-EOF &&
678 refs/heads/master $_z40 $_z40
681 cat >post-receive.expect <<-EOF &&
682 $_z40 $_z40 refs/heads/master
685 cat >post-update.expect <<-EOF &&
689 test_cmp pre-receive.expect pre-receive.actual &&
690 test_cmp update.expect update.actual &&
691 test_cmp post-receive.expect post-receive.actual &&
692 test_cmp post-update.expect post-update.actual
696 test_expect_success
'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
697 mk_test_with_hooks testrepo heads/master &&
698 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
699 newmaster=$(git show-ref -s --verify refs/heads/master) &&
700 git push testrepo master :refs/heads/nonexistent &&
703 cat >pre-receive.expect <<-EOF &&
704 $orgmaster $newmaster refs/heads/master
705 $_z40 $_z40 refs/heads/nonexistent
708 cat >update.expect <<-EOF &&
709 refs/heads/master $orgmaster $newmaster
710 refs/heads/nonexistent $_z40 $_z40
713 cat >post-receive.expect <<-EOF &&
714 $orgmaster $newmaster refs/heads/master
717 cat >post-update.expect <<-EOF &&
721 test_cmp pre-receive.expect pre-receive.actual &&
722 test_cmp update.expect update.actual &&
723 test_cmp post-receive.expect post-receive.actual &&
724 test_cmp post-update.expect post-update.actual
728 test_expect_success
'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
729 mk_test_with_hooks testrepo heads/master &&
730 git push testrepo :refs/heads/nonexistent &&
733 cat >pre-receive.expect <<-EOF &&
734 $_z40 $_z40 refs/heads/nonexistent
737 cat >update.expect <<-EOF &&
738 refs/heads/nonexistent $_z40 $_z40
741 test_cmp pre-receive.expect pre-receive.actual &&
742 test_cmp update.expect update.actual &&
743 test_path_is_missing post-receive.actual &&
744 test_path_is_missing post-update.actual
748 test_expect_success
'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
749 mk_test_with_hooks testrepo heads/master heads/next heads/pu &&
750 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
751 newmaster=$(git show-ref -s --verify refs/heads/master) &&
752 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
754 orgpu=$(cd testrepo && git show-ref -s --verify refs/heads/pu) &&
755 newpu=$(git show-ref -s --verify refs/heads/master) &&
756 git push testrepo refs/heads/master:refs/heads/master \
757 refs/heads/master:refs/heads/pu :refs/heads/next \
758 :refs/heads/nonexistent &&
761 cat >pre-receive.expect <<-EOF &&
762 $orgmaster $newmaster refs/heads/master
763 $orgnext $newnext refs/heads/next
764 $orgpu $newpu refs/heads/pu
765 $_z40 $_z40 refs/heads/nonexistent
768 cat >update.expect <<-EOF &&
769 refs/heads/master $orgmaster $newmaster
770 refs/heads/next $orgnext $newnext
771 refs/heads/pu $orgpu $newpu
772 refs/heads/nonexistent $_z40 $_z40
775 cat >post-receive.expect <<-EOF &&
776 $orgmaster $newmaster refs/heads/master
777 $orgnext $newnext refs/heads/next
778 $orgpu $newpu refs/heads/pu
781 cat >post-update.expect <<-EOF &&
787 test_cmp pre-receive.expect pre-receive.actual &&
788 test_cmp update.expect update.actual &&
789 test_cmp post-receive.expect post-receive.actual &&
790 test_cmp post-update.expect post-update.actual
794 test_expect_success
'allow deleting a ref using --delete' '
795 mk_test testrepo heads/master &&
796 (cd testrepo && git config receive.denyDeleteCurrent warn) &&
797 git push testrepo --delete master &&
798 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
801 test_expect_success
'allow deleting a tag using --delete' '
802 mk_test testrepo heads/master &&
803 git tag -a -m dummy_message deltag heads/master &&
804 git push testrepo --tags &&
805 (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
806 git push testrepo --delete tag deltag &&
807 (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
810 test_expect_success
'push --delete without args aborts' '
811 mk_test testrepo heads/master &&
812 test_must_fail git push testrepo --delete
815 test_expect_success
'push --delete refuses src:dest refspecs' '
816 mk_test testrepo heads/master &&
817 test_must_fail git push testrepo --delete master:foo
820 test_expect_success
'warn on push to HEAD of non-bare repository' '
821 mk_test testrepo heads/master &&
824 git checkout master &&
825 git config receive.denyCurrentBranch warn
827 git push testrepo master 2>stderr &&
828 grep "warning: updating the current branch" stderr
831 test_expect_success
'deny push to HEAD of non-bare repository' '
832 mk_test testrepo heads/master &&
835 git checkout master &&
836 git config receive.denyCurrentBranch true
838 test_must_fail git push testrepo master
841 test_expect_success
'allow push to HEAD of bare repository (bare)' '
842 mk_test testrepo heads/master &&
845 git checkout master &&
846 git config receive.denyCurrentBranch true &&
847 git config core.bare true
849 git push testrepo master 2>stderr &&
850 ! grep "warning: updating the current branch" stderr
853 test_expect_success
'allow push to HEAD of non-bare repository (config)' '
854 mk_test testrepo heads/master &&
857 git checkout master &&
858 git config receive.denyCurrentBranch false
860 git push testrepo master 2>stderr &&
861 ! grep "warning: updating the current branch" stderr
864 test_expect_success
'fetch with branches' '
866 git branch second $the_first_commit &&
867 git checkout second &&
868 echo ".." > testrepo/.git/branches/branch1 &&
872 echo "$the_commit commit refs/heads/branch1" >expect &&
873 git for-each-ref refs/heads >actual &&
874 test_cmp expect actual
879 test_expect_success
'fetch with branches containing #' '
881 echo "..#second" > testrepo/.git/branches/branch2 &&
885 echo "$the_first_commit commit refs/heads/branch2" >expect &&
886 git for-each-ref refs/heads >actual &&
887 test_cmp expect actual
892 test_expect_success
'push with branches' '
894 git checkout second &&
895 echo "testrepo" > .git/branches/branch1 &&
899 echo "$the_first_commit commit refs/heads/master" >expect &&
900 git for-each-ref refs/heads >actual &&
901 test_cmp expect actual
905 test_expect_success
'push with branches containing #' '
907 echo "testrepo#branch3" > .git/branches/branch2 &&
911 echo "$the_first_commit commit refs/heads/branch3" >expect &&
912 git for-each-ref refs/heads >actual &&
913 test_cmp expect actual
918 test_expect_success
'push into aliased refs (consistent)' '
919 mk_test testrepo heads/master &&
920 mk_child testrepo child1 &&
921 mk_child testrepo child2 &&
925 git symbolic-ref refs/heads/bar refs/heads/foo
926 git config receive.denyCurrentBranch false
933 git commit -a -m child2 &&
936 git push ../child1 foo bar
940 test_expect_success
'push into aliased refs (inconsistent)' '
941 mk_test testrepo heads/master &&
942 mk_child testrepo child1 &&
943 mk_child testrepo child2 &&
947 git symbolic-ref refs/heads/bar refs/heads/foo
948 git config receive.denyCurrentBranch false
955 git commit -a -m child2 &&
960 git commit -a -m child2 &&
962 test_must_fail git push ../child1 foo bar 2>stderr &&
963 grep "refusing inconsistent update" stderr
967 test_expect_success
'push requires --force to update lightweight tag' '
968 mk_test testrepo heads/master &&
969 mk_child testrepo child1 &&
970 mk_child testrepo child2 &&
974 git push ../child2 Tag &&
975 git push ../child2 Tag &&
978 git commit -m "file1" &&
980 test_must_fail git push ../child2 Tag &&
981 git push --force ../child2 Tag &&
983 test_must_fail git push ../child2 Tag HEAD~ &&
984 git push --force ../child2 Tag
988 test_expect_success
'push --porcelain' '
990 echo >.git/foo "To testrepo" &&
991 echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" &&
992 echo >>.git/foo "Done" &&
993 git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master &&
996 echo "$the_commit commit refs/remotes/origin/master" >expect &&
997 git for-each-ref refs/remotes/origin >actual &&
998 test_cmp expect actual
1000 test_cmp .git/foo .git/bar
1003 test_expect_success
'push --porcelain bad url' '
1004 mk_empty testrepo &&
1005 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
1006 test_must_fail grep -q Done .git/bar
1009 test_expect_success
'push --porcelain rejected' '
1010 mk_empty testrepo &&
1011 git push testrepo refs/heads/master:refs/remotes/origin/master &&
1013 git reset --hard origin/master^
1014 git config receive.denyCurrentBranch true) &&
1016 echo >.git/foo "To testrepo" &&
1017 echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" &&
1019 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master &&
1020 test_cmp .git/foo .git/bar
1023 test_expect_success
'push --porcelain --dry-run rejected' '
1024 mk_empty testrepo &&
1025 git push testrepo refs/heads/master:refs/remotes/origin/master &&
1027 git reset --hard origin/master
1028 git config receive.denyCurrentBranch true) &&
1030 echo >.git/foo "To testrepo" &&
1031 echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" &&
1032 echo >>.git/foo "Done" &&
1034 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master &&
1035 test_cmp .git/foo .git/bar
1038 test_expect_success
'push --prune' '
1039 mk_test testrepo heads/master heads/second heads/foo heads/bar &&
1040 git push --prune testrepo : &&
1041 check_push_result testrepo $the_commit heads/master &&
1042 check_push_result testrepo $the_first_commit heads/second &&
1043 ! check_push_result testrepo $the_first_commit heads/foo heads/bar
1046 test_expect_success
'push --prune refspec' '
1047 mk_test testrepo tmp/master tmp/second tmp/foo tmp/bar &&
1048 git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
1049 check_push_result testrepo $the_commit tmp/master &&
1050 check_push_result testrepo $the_first_commit tmp/second &&
1051 ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
1054 for configsection
in transfer receive
1056 test_expect_success
"push to update a ref hidden by $configsection.hiderefs" '
1057 mk_test testrepo heads/master hidden/one hidden/two hidden/three &&
1060 git config $configsection.hiderefs refs/hidden
1063 # push to unhidden ref succeeds normally
1064 git push testrepo master:refs/heads/master &&
1065 check_push_result testrepo $the_commit heads/master &&
1067 # push to update a hidden ref should fail
1068 test_must_fail git push testrepo master:refs/hidden/one &&
1069 check_push_result testrepo $the_first_commit hidden/one &&
1071 # push to delete a hidden ref should fail
1072 test_must_fail git push testrepo :refs/hidden/two &&
1073 check_push_result testrepo $the_first_commit hidden/two &&
1075 # idempotent push to update a hidden ref should fail
1076 test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
1077 check_push_result testrepo $the_first_commit hidden/three
1081 test_expect_success
'fetch exact SHA1' '
1082 mk_test testrepo heads/master hidden/one &&
1083 git push testrepo master:refs/hidden/one &&
1086 git config transfer.hiderefs refs/hidden
1088 check_push_result testrepo $the_commit hidden/one &&
1090 mk_child testrepo child &&
1094 # make sure $the_commit does not exist here
1097 test_must_fail git cat-file -t $the_commit &&
1099 # fetching the hidden object should fail by default
1100 test_must_fail git fetch -v ../testrepo $the_commit:refs/heads/copy &&
1101 test_must_fail git rev-parse --verify refs/heads/copy &&
1103 # the server side can allow it to succeed
1106 git config uploadpack.allowtipsha1inwant true
1109 git fetch -v ../testrepo $the_commit:refs/heads/copy &&
1110 result=$(git rev-parse --verify refs/heads/copy) &&
1111 test "$the_commit" = "$result"
1115 test_expect_success
'fetch follows tags by default' '
1116 mk_test testrepo heads/master &&
1121 git pull ../testrepo master &&
1122 git tag -m "annotated" tag &&
1123 git for-each-ref >tmp1 &&
1126 sed -n "s|refs/heads/master$|refs/remotes/origin/master|p" tmp1
1128 sort -k 3 >../expect
1133 git remote add origin ../src &&
1134 git config branch.master.remote origin &&
1135 git config branch.master.merge refs/heads/master &&
1137 git for-each-ref >../actual
1139 test_cmp expect actual
1142 test_expect_success
'pushing a specific ref applies remote.$name.push as refmap' '
1143 mk_test testrepo heads/master &&
1146 git init --bare dst &&
1149 git pull ../testrepo master &&
1151 git config remote.dst.url ../dst &&
1152 git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" &&
1153 git push dst master &&
1154 git show-ref refs/heads/master |
1155 sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect
1159 test_must_fail git show-ref refs/heads/next &&
1160 test_must_fail git show-ref refs/heads/master &&
1161 git show-ref refs/remotes/src/master >actual
1163 test_cmp dst/expect dst/actual
1166 test_expect_success
'with no remote.$name.push, it is not used as refmap' '
1167 mk_test testrepo heads/master &&
1170 git init --bare dst &&
1173 git pull ../testrepo master &&
1175 git config remote.dst.url ../dst &&
1176 git config push.default matching &&
1177 git push dst master &&
1178 git show-ref refs/heads/master >../dst/expect
1182 test_must_fail git show-ref refs/heads/next &&
1183 git show-ref refs/heads/master >actual
1185 test_cmp dst/expect dst/actual
1188 test_expect_success
'with no remote.$name.push, upstream mapping is used' '
1189 mk_test testrepo heads/master &&
1192 git init --bare dst &&
1195 git pull ../testrepo master &&
1197 git config remote.dst.url ../dst &&
1198 git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" &&
1199 git config push.default upstream &&
1201 git config branch.master.merge refs/heads/trunk &&
1202 git config branch.master.remote dst &&
1204 git push dst master &&
1205 git show-ref refs/heads/master |
1206 sed -e "s|refs/heads/master|refs/heads/trunk|" >../dst/expect
1210 test_must_fail git show-ref refs/heads/master &&
1211 test_must_fail git show-ref refs/heads/next &&
1212 git show-ref refs/heads/trunk >actual
1214 test_cmp dst/expect dst/actual
1217 test_expect_success
'push does not follow tags by default' '
1218 mk_test testrepo heads/master &&
1221 git init --bare dst &&
1224 git pull ../testrepo master &&
1225 git tag -m "annotated" tag &&
1226 git checkout -b another &&
1227 git commit --allow-empty -m "future commit" &&
1228 git tag -m "future" future &&
1229 git checkout master &&
1230 git for-each-ref refs/heads/master >../expect &&
1231 git push ../dst master
1235 git for-each-ref >../actual
1237 test_cmp expect actual
1240 test_expect_success
'push --follow-tag only pushes relevant tags' '
1241 mk_test testrepo heads/master &&
1244 git init --bare dst &&
1247 git pull ../testrepo master &&
1248 git tag -m "annotated" tag &&
1249 git checkout -b another &&
1250 git commit --allow-empty -m "future commit" &&
1251 git tag -m "future" future &&
1252 git checkout master &&
1253 git for-each-ref refs/heads/master refs/tags/tag >../expect
1254 git push --follow-tag ../dst master
1258 git for-each-ref >../actual
1260 test_cmp expect actual
1263 test_expect_success
'push --no-thin must produce non-thin pack' '
1264 cat >>path1 <<\EOF &&
1265 keep base version of path1 big enough, compared to the new changes
1266 later, in order to pass size heuristics in
1267 builtin/pack-objects.c:try_delta()
1269 git commit -am initial &&
1271 git --git-dir=no-thin/.git config receive.unpacklimit 0 &&
1272 git push no-thin/.git refs/heads/master:refs/heads/foo &&
1273 echo modified >> path1 &&
1274 git commit -am modified &&
1276 rcvpck="git receive-pack --reject-thin-pack-for-testing" &&
1277 git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/master:refs/heads/foo
1280 test_expect_success
'receive.denyCurrentBranch = updateInstead' '
1281 git push testrepo master &&
1284 git config receive.denyCurrentBranch updateInstead
1286 test_commit third path2 &&
1287 git push testrepo master &&
1288 test $(git rev-parse HEAD) = $(cd testrepo && git rev-parse HEAD) &&
1289 test third = "$(cat testrepo/path2)" &&
1291 git update-index --refresh &&
1292 git diff-files --quiet &&
1293 git diff-index --cached HEAD --
1297 test_expect_success
'receive.denyCurrentBranch = detachInstead' '
1300 git config receive.denyCurrentBranch detachInstead
1302 OLDHEAD=$(cd testrepo && git rev-parse HEAD) &&
1303 test_commit fourth path2 &&
1304 test fourth = "$(cat path2)" &&
1305 git push testrepo master &&
1306 test $OLDHEAD = $(cd testrepo && git rev-parse HEAD) &&
1307 test fourth != "$(cat testrepo/path2)" &&
1309 test_must_fail git symbolic-ref HEAD &&
1310 git update-index --refresh &&
1311 git diff-files --quiet &&
1312 git diff-index --cached HEAD --