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
23 rm -fr "$repo_name" &&
28 git config receive.denyCurrentBranch warn &&
29 mv .git/hooks .git/hooks-disabled
37 mk_empty "$repo_name" &&
41 git push "$repo_name" $the_first_commit:refs/$ref ||
47 echo "$the_first_commit" >expect &&
48 git show-ref -s --verify refs/$ref >actual &&
49 test_cmp expect actual ||
56 mk_test_with_hooks() {
64 cat >pre-receive <<-'EOF' &&
66 cat - >>pre-receive.actual
69 cat >update <<-'EOF' &&
71 printf "%s %s %s\n" "$@" >>update.actual
74 cat >post-receive <<-'EOF' &&
76 cat - >>post-receive.actual
79 cat >post-update <<-'EOF' &&
83 printf "%s\n" "$ref" >>post-update.actual
87 chmod +x pre-receive update post-receive post-update
96 check_push_result () {
98 BUG "check_push_result requires at least 3 parameters"
109 git show-ref -s --verify refs/$ref >actual &&
110 test_cmp expect actual ||
117 test_expect_success setup '
122 git commit -a -m repo &&
123 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
128 git commit -a -m second &&
129 the_commit=$(git show-ref -s --verify refs/heads/master)
133 test_expect_success 'fetch without wildcard' '
137 git fetch .. refs/heads/master:refs/remotes/origin/master &&
139 echo "$the_commit commit refs/remotes/origin/master" >expect &&
140 git for-each-ref refs/remotes/origin >actual &&
141 test_cmp expect actual
145 test_expect_success 'fetch with wildcard' '
149 git config remote.up.url .. &&
150 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
153 echo "$the_commit commit refs/remotes/origin/master" >expect &&
154 git for-each-ref refs/remotes/origin >actual &&
155 test_cmp expect actual
159 test_expect_success 'fetch with insteadOf' '
164 git config "url.$TRASH.insteadOf" trash/ &&
165 git config remote.up.url trash/. &&
166 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
169 echo "$the_commit commit refs/remotes/origin/master" >expect &&
170 git for-each-ref refs/remotes/origin >actual &&
171 test_cmp expect actual
175 test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
180 git config "url.trash/.pushInsteadOf" "$TRASH" &&
181 git config remote.up.url "$TRASH." &&
182 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
185 echo "$the_commit commit refs/remotes/origin/master" >expect &&
186 git for-each-ref refs/remotes/origin >actual &&
187 test_cmp expect actual
191 test_expect_success 'push without wildcard' '
194 git push testrepo refs/heads/master:refs/remotes/origin/master &&
197 echo "$the_commit commit refs/remotes/origin/master" >expect &&
198 git for-each-ref refs/remotes/origin >actual &&
199 test_cmp expect actual
203 test_expect_success 'push with wildcard' '
206 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
209 echo "$the_commit commit refs/remotes/origin/master" >expect &&
210 git for-each-ref refs/remotes/origin >actual &&
211 test_cmp expect actual
215 test_expect_success 'push with insteadOf' '
218 test_config "url.$TRASH.insteadOf" trash/ &&
219 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
222 echo "$the_commit commit refs/remotes/origin/master" >expect &&
223 git for-each-ref refs/remotes/origin >actual &&
224 test_cmp expect actual
228 test_expect_success 'push with pushInsteadOf' '
231 test_config "url.$TRASH.pushInsteadOf" trash/ &&
232 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
235 echo "$the_commit commit refs/remotes/origin/master" >expect &&
236 git for-each-ref refs/remotes/origin >actual &&
237 test_cmp expect actual
241 test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
243 test_config "url.trash2/.pushInsteadOf" testrepo/ &&
244 test_config "url.trash3/.pushInsteadOf" trash/wrong &&
245 test_config remote.r.url trash/wrong &&
246 test_config remote.r.pushurl "testrepo/" &&
247 git push r refs/heads/master:refs/remotes/origin/master &&
250 echo "$the_commit commit refs/remotes/origin/master" >expect &&
251 git for-each-ref refs/remotes/origin >actual &&
252 test_cmp expect actual
256 test_expect_success 'push with matching heads' '
258 mk_test testrepo heads/master &&
259 git push testrepo : &&
260 check_push_result testrepo $the_commit heads/master
264 test_expect_success 'push with matching heads on the command line' '
266 mk_test testrepo heads/master &&
267 git push testrepo : &&
268 check_push_result testrepo $the_commit heads/master
272 test_expect_success 'failed (non-fast-forward) push with matching heads' '
274 mk_test testrepo heads/master &&
275 git push testrepo : &&
276 git commit --amend -massaged &&
277 test_must_fail git push testrepo &&
278 check_push_result testrepo $the_commit heads/master &&
279 git reset --hard $the_commit
283 test_expect_success 'push --force with matching heads' '
285 mk_test testrepo heads/master &&
286 git push testrepo : &&
287 git commit --amend -massaged &&
288 git push --force testrepo : &&
289 ! check_push_result testrepo $the_commit heads/master &&
290 git reset --hard $the_commit
294 test_expect_success 'push with matching heads and forced update' '
296 mk_test testrepo heads/master &&
297 git push testrepo : &&
298 git commit --amend -massaged &&
299 git push testrepo +: &&
300 ! check_push_result testrepo $the_commit heads/master &&
301 git reset --hard $the_commit
305 test_expect_success 'push with no ambiguity (1)' '
307 mk_test testrepo heads/master &&
308 git push testrepo master:master &&
309 check_push_result testrepo $the_commit heads/master
313 test_expect_success 'push with no ambiguity (2)' '
315 mk_test testrepo remotes/origin/master &&
316 git push testrepo master:origin/master &&
317 check_push_result testrepo $the_commit remotes/origin/master
321 test_expect_success 'push with colon-less refspec, no ambiguity' '
323 mk_test testrepo heads/master heads/t/master &&
324 git branch -f t/master master &&
325 git push testrepo master &&
326 check_push_result testrepo $the_commit heads/master &&
327 check_push_result testrepo $the_first_commit heads/t/master
331 test_expect_success 'push with weak ambiguity (1)' '
333 mk_test testrepo heads/master remotes/origin/master &&
334 git push testrepo master:master &&
335 check_push_result testrepo $the_commit heads/master &&
336 check_push_result testrepo $the_first_commit remotes/origin/master
340 test_expect_success 'push with weak ambiguity (2)' '
342 mk_test testrepo heads/master remotes/origin/master remotes/another/master &&
343 git push testrepo master:master &&
344 check_push_result testrepo $the_commit heads/master &&
345 check_push_result testrepo $the_first_commit remotes/origin/master remotes/another/master
349 test_expect_success 'push with ambiguity' '
351 mk_test testrepo heads/frotz tags/frotz &&
352 test_must_fail git push testrepo master:frotz &&
353 check_push_result testrepo $the_first_commit heads/frotz tags/frotz
357 test_expect_success 'push with colon-less refspec (1)' '
359 mk_test testrepo heads/frotz tags/frotz &&
360 git branch -f frotz master &&
361 git push testrepo frotz &&
362 check_push_result testrepo $the_commit heads/frotz &&
363 check_push_result testrepo $the_first_commit tags/frotz
367 test_expect_success 'push with colon-less refspec (2)' '
369 mk_test testrepo heads/frotz tags/frotz &&
370 if git show-ref --verify -q refs/heads/frotz
375 git push -f testrepo frotz &&
376 check_push_result testrepo $the_commit tags/frotz &&
377 check_push_result testrepo $the_first_commit heads/frotz
381 test_expect_success 'push with colon-less refspec (3)' '
384 if git show-ref --verify -q refs/tags/frotz
388 git branch -f frotz master &&
389 git push testrepo frotz &&
390 check_push_result testrepo $the_commit heads/frotz &&
391 test 1 = $( cd testrepo && git show-ref | wc -l )
394 test_expect_success 'push with colon-less refspec (4)' '
397 if git show-ref --verify -q refs/heads/frotz
402 git push testrepo frotz &&
403 check_push_result testrepo $the_commit tags/frotz &&
404 test 1 = $( cd testrepo && git show-ref | wc -l )
408 test_expect_success 'push head with non-existent, incomplete dest' '
411 git push testrepo master:branch &&
412 check_push_result testrepo $the_commit heads/branch
416 test_expect_success 'push tag with non-existent, incomplete dest' '
420 git push testrepo v1.0:tag &&
421 check_push_result testrepo $the_commit tags/tag
425 test_expect_success 'push sha1 with non-existent, incomplete dest' '
428 test_must_fail git push testrepo $(git rev-parse master):foo
432 test_expect_success 'push ref expression with non-existent, incomplete dest' '
435 test_must_fail git push testrepo master^:branch
439 test_expect_success 'push with HEAD' '
441 mk_test testrepo heads/master &&
442 git checkout master &&
443 git push testrepo HEAD &&
444 check_push_result testrepo $the_commit heads/master
448 test_expect_success 'push with HEAD nonexisting at remote' '
450 mk_test testrepo heads/master &&
451 git checkout -b local master &&
452 git push testrepo HEAD &&
453 check_push_result testrepo $the_commit heads/local
456 test_expect_success 'push with +HEAD' '
458 mk_test testrepo heads/master &&
459 git checkout master &&
460 git branch -D local &&
461 git checkout -b local &&
462 git push testrepo master local &&
463 check_push_result testrepo $the_commit heads/master &&
464 check_push_result testrepo $the_commit heads/local &&
466 # Without force rewinding should fail
467 git reset --hard HEAD^ &&
468 test_must_fail git push testrepo HEAD &&
469 check_push_result testrepo $the_commit heads/local &&
471 # With force rewinding should succeed
472 git push testrepo +HEAD &&
473 check_push_result testrepo $the_first_commit heads/local
477 test_expect_success 'push HEAD with non-existent, incomplete dest' '
480 git checkout master &&
481 git push testrepo HEAD:branch &&
482 check_push_result testrepo $the_commit heads/branch
486 test_expect_success 'push with config remote.*.push = HEAD' '
488 mk_test testrepo heads/local &&
489 git checkout master &&
490 git branch -f local $the_commit &&
493 git checkout local &&
494 git reset --hard $the_first_commit
496 test_config remote.there.url testrepo &&
497 test_config remote.there.push HEAD &&
498 test_config branch.master.remote there &&
500 check_push_result testrepo $the_commit heads/master &&
501 check_push_result testrepo $the_first_commit heads/local
504 test_expect_success 'push with remote.pushdefault' '
505 mk_test up_repo heads/master &&
506 mk_test down_repo heads/master &&
507 test_config remote.up.url up_repo &&
508 test_config remote.down.url down_repo &&
509 test_config branch.master.remote up &&
510 test_config remote.pushdefault down &&
511 test_config push.default matching &&
513 check_push_result up_repo $the_first_commit heads/master &&
514 check_push_result down_repo $the_commit heads/master
517 test_expect_success 'push with config remote.*.pushurl' '
519 mk_test testrepo heads/master &&
520 git checkout master &&
521 test_config remote.there.url test2repo &&
522 test_config remote.there.pushurl testrepo &&
524 check_push_result testrepo $the_commit heads/master
527 test_expect_success 'push with config branch.*.pushremote' '
528 mk_test up_repo heads/master &&
529 mk_test side_repo heads/master &&
530 mk_test down_repo heads/master &&
531 test_config remote.up.url up_repo &&
532 test_config remote.pushdefault side_repo &&
533 test_config remote.down.url down_repo &&
534 test_config branch.master.remote up &&
535 test_config branch.master.pushremote down &&
536 test_config push.default matching &&
538 check_push_result up_repo $the_first_commit heads/master &&
539 check_push_result side_repo $the_first_commit heads/master &&
540 check_push_result down_repo $the_commit heads/master
543 test_expect_success 'branch.*.pushremote config order is irrelevant' '
544 mk_test one_repo heads/master &&
545 mk_test two_repo heads/master &&
546 test_config remote.one.url one_repo &&
547 test_config remote.two.url two_repo &&
548 test_config branch.master.pushremote two_repo &&
549 test_config remote.pushdefault one_repo &&
550 test_config push.default matching &&
552 check_push_result one_repo $the_first_commit heads/master &&
553 check_push_result two_repo $the_commit heads/master
556 test_expect_success 'push with dry-run' '
558 mk_test testrepo heads/master &&
559 old_commit=$(git -C testrepo show-ref -s --verify refs/heads/master) &&
560 git push --dry-run testrepo : &&
561 check_push_result testrepo $old_commit heads/master
564 test_expect_success 'push updates local refs' '
566 mk_test testrepo heads/master &&
567 mk_child testrepo child &&
570 git pull .. master &&
572 test $(git rev-parse master) = \
573 $(git rev-parse remotes/origin/master)
578 test_expect_success 'push updates up-to-date local refs' '
580 mk_test testrepo heads/master &&
581 mk_child testrepo child1 &&
582 mk_child testrepo child2 &&
583 (cd child1 && git pull .. master && git push) &&
586 git pull ../child1 master &&
588 test $(git rev-parse master) = \
589 $(git rev-parse remotes/origin/master)
594 test_expect_success 'push preserves up-to-date packed refs' '
596 mk_test testrepo heads/master &&
597 mk_child testrepo child &&
601 ! test -f .git/refs/remotes/origin/master
606 test_expect_success 'push does not update local refs on failure' '
608 mk_test testrepo heads/master &&
609 mk_child testrepo child &&
610 mkdir testrepo/.git/hooks &&
611 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
612 chmod +x testrepo/.git/hooks/pre-receive &&
615 git pull .. master &&
616 test_must_fail git push &&
617 test $(git rev-parse master) != \
618 $(git rev-parse remotes/origin/master)
623 test_expect_success 'allow deleting an invalid remote ref' '
625 mk_test testrepo heads/master &&
626 rm -f testrepo/.git/objects/??/* &&
627 git push testrepo :refs/heads/master &&
628 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
632 test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' '
633 mk_test_with_hooks testrepo heads/master heads/next &&
634 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
635 newmaster=$(git show-ref -s --verify refs/heads/master) &&
636 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
638 git push testrepo refs/heads/master:refs/heads/master :refs/heads/next &&
641 cat >pre-receive.expect <<-EOF &&
642 $orgmaster $newmaster refs/heads/master
643 $orgnext $newnext refs/heads/next
646 cat >update.expect <<-EOF &&
647 refs/heads/master $orgmaster $newmaster
648 refs/heads/next $orgnext $newnext
651 cat >post-receive.expect <<-EOF &&
652 $orgmaster $newmaster refs/heads/master
653 $orgnext $newnext refs/heads/next
656 cat >post-update.expect <<-EOF &&
661 test_cmp pre-receive.expect pre-receive.actual &&
662 test_cmp update.expect update.actual &&
663 test_cmp post-receive.expect post-receive.actual &&
664 test_cmp post-update.expect post-update.actual
668 test_expect_success 'deleting dangling ref triggers hooks with correct args' '
669 mk_test_with_hooks testrepo heads/master &&
670 rm -f testrepo/.git/objects/??/* &&
671 git push testrepo :refs/heads/master &&
674 cat >pre-receive.expect <<-EOF &&
675 $ZERO_OID $ZERO_OID refs/heads/master
678 cat >update.expect <<-EOF &&
679 refs/heads/master $ZERO_OID $ZERO_OID
682 cat >post-receive.expect <<-EOF &&
683 $ZERO_OID $ZERO_OID refs/heads/master
686 cat >post-update.expect <<-EOF &&
690 test_cmp pre-receive.expect pre-receive.actual &&
691 test_cmp update.expect update.actual &&
692 test_cmp post-receive.expect post-receive.actual &&
693 test_cmp post-update.expect post-update.actual
697 test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
698 mk_test_with_hooks testrepo heads/master &&
699 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
700 newmaster=$(git show-ref -s --verify refs/heads/master) &&
701 git push testrepo master :refs/heads/nonexistent &&
704 cat >pre-receive.expect <<-EOF &&
705 $orgmaster $newmaster refs/heads/master
706 $ZERO_OID $ZERO_OID refs/heads/nonexistent
709 cat >update.expect <<-EOF &&
710 refs/heads/master $orgmaster $newmaster
711 refs/heads/nonexistent $ZERO_OID $ZERO_OID
714 cat >post-receive.expect <<-EOF &&
715 $orgmaster $newmaster refs/heads/master
718 cat >post-update.expect <<-EOF &&
722 test_cmp pre-receive.expect pre-receive.actual &&
723 test_cmp update.expect update.actual &&
724 test_cmp post-receive.expect post-receive.actual &&
725 test_cmp post-update.expect post-update.actual
729 test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
730 mk_test_with_hooks testrepo heads/master &&
731 git push testrepo :refs/heads/nonexistent &&
734 cat >pre-receive.expect <<-EOF &&
735 $ZERO_OID $ZERO_OID refs/heads/nonexistent
738 cat >update.expect <<-EOF &&
739 refs/heads/nonexistent $ZERO_OID $ZERO_OID
742 test_cmp pre-receive.expect pre-receive.actual &&
743 test_cmp update.expect update.actual &&
744 test_path_is_missing post-receive.actual &&
745 test_path_is_missing post-update.actual
749 test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
750 mk_test_with_hooks testrepo heads/master heads/next heads/seen &&
751 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
752 newmaster=$(git show-ref -s --verify refs/heads/master) &&
753 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
755 orgseen=$(cd testrepo && git show-ref -s --verify refs/heads/seen) &&
756 newseen=$(git show-ref -s --verify refs/heads/master) &&
757 git push testrepo refs/heads/master:refs/heads/master \
758 refs/heads/master:refs/heads/seen :refs/heads/next \
759 :refs/heads/nonexistent &&
762 cat >pre-receive.expect <<-EOF &&
763 $orgmaster $newmaster refs/heads/master
764 $orgnext $newnext refs/heads/next
765 $orgseen $newseen refs/heads/seen
766 $ZERO_OID $ZERO_OID refs/heads/nonexistent
769 cat >update.expect <<-EOF &&
770 refs/heads/master $orgmaster $newmaster
771 refs/heads/next $orgnext $newnext
772 refs/heads/seen $orgseen $newseen
773 refs/heads/nonexistent $ZERO_OID $ZERO_OID
776 cat >post-receive.expect <<-EOF &&
777 $orgmaster $newmaster refs/heads/master
778 $orgnext $newnext refs/heads/next
779 $orgseen $newseen refs/heads/seen
782 cat >post-update.expect <<-EOF &&
788 test_cmp pre-receive.expect pre-receive.actual &&
789 test_cmp update.expect update.actual &&
790 test_cmp post-receive.expect post-receive.actual &&
791 test_cmp post-update.expect post-update.actual
795 test_expect_success 'allow deleting a ref using --delete' '
796 mk_test testrepo heads/master &&
797 (cd testrepo && git config receive.denyDeleteCurrent warn) &&
798 git push testrepo --delete master &&
799 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
802 test_expect_success 'allow deleting a tag using --delete' '
803 mk_test testrepo heads/master &&
804 git tag -a -m dummy_message deltag heads/master &&
805 git push testrepo --tags &&
806 (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
807 git push testrepo --delete tag deltag &&
808 (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
811 test_expect_success 'push --delete without args aborts' '
812 mk_test testrepo heads/master &&
813 test_must_fail git push testrepo --delete
816 test_expect_success 'push --delete refuses src:dest refspecs' '
817 mk_test testrepo heads/master &&
818 test_must_fail git push testrepo --delete master:foo
821 test_expect_success 'warn on push to HEAD of non-bare repository' '
822 mk_test testrepo heads/master &&
825 git checkout master &&
826 git config receive.denyCurrentBranch warn
828 git push testrepo master 2>stderr &&
829 grep "warning: updating the current branch" stderr
832 test_expect_success 'deny push to HEAD of non-bare repository' '
833 mk_test testrepo heads/master &&
836 git checkout master &&
837 git config receive.denyCurrentBranch true
839 test_must_fail git push testrepo master
842 test_expect_success 'allow push to HEAD of bare repository (bare)' '
843 mk_test testrepo heads/master &&
846 git checkout master &&
847 git config receive.denyCurrentBranch true &&
848 git config core.bare true
850 git push testrepo master 2>stderr &&
851 ! grep "warning: updating the current branch" stderr
854 test_expect_success 'allow push to HEAD of non-bare repository (config)' '
855 mk_test testrepo heads/master &&
858 git checkout master &&
859 git config receive.denyCurrentBranch false
861 git push testrepo master 2>stderr &&
862 ! grep "warning: updating the current branch" stderr
865 test_expect_success 'fetch with branches' '
867 git branch second $the_first_commit &&
868 git checkout second &&
869 echo ".." > testrepo/.git/branches/branch1 &&
873 echo "$the_commit commit refs/heads/branch1" >expect &&
874 git for-each-ref refs/heads >actual &&
875 test_cmp expect actual
880 test_expect_success 'fetch with branches containing #' '
882 echo "..#second" > testrepo/.git/branches/branch2 &&
886 echo "$the_first_commit commit refs/heads/branch2" >expect &&
887 git for-each-ref refs/heads >actual &&
888 test_cmp expect actual
893 test_expect_success 'push with branches' '
895 git checkout second &&
896 echo "testrepo" > .git/branches/branch1 &&
900 echo "$the_first_commit commit refs/heads/master" >expect &&
901 git for-each-ref refs/heads >actual &&
902 test_cmp expect actual
906 test_expect_success 'push with branches containing #' '
908 echo "testrepo#branch3" > .git/branches/branch2 &&
912 echo "$the_first_commit commit refs/heads/branch3" >expect &&
913 git for-each-ref refs/heads >actual &&
914 test_cmp expect actual
919 test_expect_success 'push into aliased refs (consistent)' '
920 mk_test testrepo heads/master &&
921 mk_child testrepo child1 &&
922 mk_child testrepo child2 &&
926 git symbolic-ref refs/heads/bar refs/heads/foo &&
927 git config receive.denyCurrentBranch false
934 git commit -a -m child2 &&
937 git push ../child1 foo bar
941 test_expect_success 'push into aliased refs (inconsistent)' '
942 mk_test testrepo heads/master &&
943 mk_child testrepo child1 &&
944 mk_child testrepo child2 &&
948 git symbolic-ref refs/heads/bar refs/heads/foo &&
949 git config receive.denyCurrentBranch false
956 git commit -a -m child2 &&
961 git commit -a -m child2 &&
963 test_must_fail git push ../child1 foo bar 2>stderr &&
964 grep "refusing inconsistent update" stderr
968 test_force_push_tag () {
969 tag_type_description=$1
972 test_expect_success "force pushing required to update $tag_type_description" "
973 mk_test testrepo heads/master &&
974 mk_child testrepo child1 &&
975 mk_child testrepo child2 &&
979 git push ../child2 testTag &&
982 git commit -m 'file1' &&
983 git tag $tag_args testTag &&
984 test_must_fail git push ../child2 testTag &&
985 git push --force ../child2 testTag &&
986 git tag $tag_args testTag HEAD~ &&
987 test_must_fail git push ../child2 testTag &&
988 git push --force ../child2 testTag &&
990 # Clobbering without + in refspec needs --force
991 git tag -f testTag &&
992 test_must_fail git push ../child2 'refs/tags/*:refs/tags/*' &&
993 git push --force ../child2 'refs/tags/*:refs/tags/*' &&
995 # Clobbering with + in refspec does not need --force
996 git tag -f testTag HEAD~ &&
997 git push ../child2 '+refs/tags/*:refs/tags/*' &&
999 # Clobbering with --no-force still obeys + in refspec
1000 git tag -f testTag &&
1001 git push --no-force ../child2 '+refs/tags/*:refs/tags/*' &&
1003 # Clobbering with/without --force and 'tag <name>' format
1004 git tag -f testTag HEAD~ &&
1005 test_must_fail git push ../child2 tag testTag &&
1006 git push --force ../child2 tag testTag
1011 test_force_push_tag "lightweight tag" "-f"
1012 test_force_push_tag "annotated tag" "-f -a -m'tag message'"
1014 test_force_fetch_tag () {
1015 tag_type_description=$1
1018 test_expect_success "fetch will not clobber an existing $tag_type_description without --force" "
1019 mk_test testrepo heads/master &&
1020 mk_child testrepo child1 &&
1021 mk_child testrepo child2 &&
1025 git -C ../child1 fetch origin tag testTag &&
1028 git commit -m 'file1' &&
1029 git tag $tag_args testTag &&
1030 test_must_fail git -C ../child1 fetch origin tag testTag &&
1031 git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*'
1036 test_force_fetch_tag "lightweight tag" "-f"
1037 test_force_fetch_tag "annotated tag" "-f -a -m'tag message'"
1039 test_expect_success 'push --porcelain' '
1040 mk_empty testrepo &&
1041 echo >.git/foo "To testrepo" &&
1042 echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" &&
1043 echo >>.git/foo "Done" &&
1044 git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master &&
1047 echo "$the_commit commit refs/remotes/origin/master" >expect &&
1048 git for-each-ref refs/remotes/origin >actual &&
1049 test_cmp expect actual
1051 test_cmp .git/foo .git/bar
1054 test_expect_success 'push --porcelain bad url' '
1055 mk_empty testrepo &&
1056 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
1057 ! grep -q Done .git/bar
1060 test_expect_success 'push --porcelain rejected' '
1061 mk_empty testrepo &&
1062 git push testrepo refs/heads/master:refs/remotes/origin/master &&
1064 git reset --hard origin/master^ &&
1065 git config receive.denyCurrentBranch true) &&
1067 echo >.git/foo "To testrepo" &&
1068 echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" &&
1069 echo >>.git/foo "Done" &&
1071 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master &&
1072 test_cmp .git/foo .git/bar
1075 test_expect_success 'push --porcelain --dry-run rejected' '
1076 mk_empty testrepo &&
1077 git push testrepo refs/heads/master:refs/remotes/origin/master &&
1079 git reset --hard origin/master &&
1080 git config receive.denyCurrentBranch true) &&
1082 echo >.git/foo "To testrepo" &&
1083 echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" &&
1084 echo >>.git/foo "Done" &&
1086 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master &&
1087 test_cmp .git/foo .git/bar
1090 test_expect_success 'push --prune' '
1091 mk_test testrepo heads/master heads/second heads/foo heads/bar &&
1092 git push --prune testrepo : &&
1093 check_push_result testrepo $the_commit heads/master &&
1094 check_push_result testrepo $the_first_commit heads/second &&
1095 ! check_push_result testrepo $the_first_commit heads/foo heads/bar
1098 test_expect_success 'push --prune refspec' '
1099 mk_test testrepo tmp/master tmp/second tmp/foo tmp/bar &&
1100 git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
1101 check_push_result testrepo $the_commit tmp/master &&
1102 check_push_result testrepo $the_first_commit tmp/second &&
1103 ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
1106 for configsection in transfer receive
1108 test_expect_success "push to update a ref hidden by $configsection.hiderefs" '
1109 mk_test testrepo heads/master hidden/one hidden/two hidden/three &&
1112 git config $configsection.hiderefs refs/hidden
1115 # push to unhidden ref succeeds normally
1116 git push testrepo master:refs/heads/master &&
1117 check_push_result testrepo $the_commit heads/master &&
1119 # push to update a hidden ref should fail
1120 test_must_fail git push testrepo master:refs/hidden/one &&
1121 check_push_result testrepo $the_first_commit hidden/one &&
1123 # push to delete a hidden ref should fail
1124 test_must_fail git push testrepo :refs/hidden/two &&
1125 check_push_result testrepo $the_first_commit hidden/two &&
1127 # idempotent push to update a hidden ref should fail
1128 test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
1129 check_push_result testrepo $the_first_commit hidden/three
1133 test_expect_success 'fetch exact SHA1' '
1134 mk_test testrepo heads/master hidden/one &&
1135 git push testrepo master:refs/hidden/one &&
1138 git config transfer.hiderefs refs/hidden
1140 check_push_result testrepo $the_commit hidden/one &&
1142 mk_child testrepo child &&
1146 # make sure $the_commit does not exist here
1149 test_must_fail git cat-file -t $the_commit &&
1151 # Some protocol versions (e.g. 2) support fetching
1152 # unadvertised objects, so restrict this test to v0.
1154 # fetching the hidden object should fail by default
1155 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1156 git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err &&
1157 test_i18ngrep "Server does not allow request for unadvertised object" err &&
1158 test_must_fail git rev-parse --verify refs/heads/copy &&
1160 # the server side can allow it to succeed
1163 git config uploadpack.allowtipsha1inwant true
1166 git fetch -v ../testrepo $the_commit:refs/heads/copy master:refs/heads/extra &&
1167 cat >expect <<-EOF &&
1172 git rev-parse --verify refs/heads/copy &&
1173 git rev-parse --verify refs/heads/extra
1175 test_cmp expect actual
1179 test_expect_success 'fetch exact SHA1 in protocol v2' '
1180 mk_test testrepo heads/master hidden/one &&
1181 git push testrepo master:refs/hidden/one &&
1182 git -C testrepo config transfer.hiderefs refs/hidden &&
1183 check_push_result testrepo $the_commit hidden/one &&
1185 mk_child testrepo child &&
1186 git -C child config protocol.version 2 &&
1188 # make sure $the_commit does not exist here
1189 git -C child repack -a -d &&
1190 git -C child prune &&
1191 test_must_fail git -C child cat-file -t $the_commit &&
1193 # fetching the hidden object succeeds by default
1194 # NEEDSWORK: should this match the v0 behavior instead?
1195 git -C child fetch -v ../testrepo $the_commit:refs/heads/copy
1198 for configallowtipsha1inwant in true false
1200 test_expect_success "shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" '
1201 mk_empty testrepo &&
1204 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1205 git commit --allow-empty -m foo &&
1206 git commit --allow-empty -m bar
1208 SHA1=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1212 # Some protocol versions (e.g. 2) support fetching
1213 # unadvertised objects, so restrict this test to v0.
1214 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1215 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1216 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1217 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1218 git cat-file commit $SHA1
1222 test_expect_success "deny fetch unreachable SHA1, allowtipsha1inwant=$configallowtipsha1inwant" '
1223 mk_empty testrepo &&
1226 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1227 git commit --allow-empty -m foo &&
1228 git commit --allow-empty -m bar &&
1229 git commit --allow-empty -m xyz
1231 SHA1_1=$(git --git-dir=testrepo/.git rev-parse HEAD^^) &&
1232 SHA1_2=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1233 SHA1_3=$(git --git-dir=testrepo/.git rev-parse HEAD) &&
1236 git reset --hard $SHA1_2 &&
1237 git cat-file commit $SHA1_1 &&
1238 git cat-file commit $SHA1_3
1243 # Some protocol versions (e.g. 2) support fetching
1244 # unadvertised objects, so restrict this test to v0.
1245 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1246 git fetch ../testrepo/.git $SHA1_3 &&
1247 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1248 git fetch ../testrepo/.git $SHA1_1 &&
1249 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1250 git fetch ../testrepo/.git $SHA1_1 &&
1251 git cat-file commit $SHA1_1 &&
1252 test_must_fail git cat-file commit $SHA1_2 &&
1253 git fetch ../testrepo/.git $SHA1_2 &&
1254 git cat-file commit $SHA1_2 &&
1255 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1256 git fetch ../testrepo/.git $SHA1_3 2>err &&
1257 test_i18ngrep "remote error:.*not our ref.*$SHA1_3\$" err
1262 test_expect_success 'fetch follows tags by default' '
1263 mk_test testrepo heads/master &&
1268 git pull ../testrepo master &&
1269 git tag -m "annotated" tag &&
1270 git for-each-ref >tmp1 &&
1273 sed -n "s|refs/heads/master$|refs/remotes/origin/master|p" tmp1
1275 sort -k 3 >../expect
1280 git remote add origin ../src &&
1281 git config branch.master.remote origin &&
1282 git config branch.master.merge refs/heads/master &&
1284 git for-each-ref >../actual
1286 test_cmp expect actual
1289 test_expect_success 'peeled advertisements are not considered ref tips' '
1290 mk_empty testrepo &&
1291 git -C testrepo commit --allow-empty -m one &&
1292 git -C testrepo commit --allow-empty -m two &&
1293 git -C testrepo tag -m foo mytag HEAD^ &&
1294 oid=$(git -C testrepo rev-parse mytag^{commit}) &&
1295 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1296 git fetch testrepo $oid 2>err &&
1297 test_i18ngrep "Server does not allow request for unadvertised object" err
1300 test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' '
1301 mk_test testrepo heads/master &&
1304 git init --bare dst &&
1307 git pull ../testrepo master &&
1309 git config remote.dst.url ../dst &&
1310 git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" &&
1311 git push dst master &&
1312 git show-ref refs/heads/master |
1313 sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect
1317 test_must_fail git show-ref refs/heads/next &&
1318 test_must_fail git show-ref refs/heads/master &&
1319 git show-ref refs/remotes/src/master >actual
1321 test_cmp dst/expect dst/actual
1324 test_expect_success 'with no remote.$name.push, it is not used as refmap' '
1325 mk_test testrepo heads/master &&
1328 git init --bare dst &&
1331 git pull ../testrepo master &&
1333 git config remote.dst.url ../dst &&
1334 git config push.default matching &&
1335 git push dst master &&
1336 git show-ref refs/heads/master >../dst/expect
1340 test_must_fail git show-ref refs/heads/next &&
1341 git show-ref refs/heads/master >actual
1343 test_cmp dst/expect dst/actual
1346 test_expect_success 'with no remote.$name.push, upstream mapping is used' '
1347 mk_test testrepo heads/master &&
1350 git init --bare dst &&
1353 git pull ../testrepo master &&
1355 git config remote.dst.url ../dst &&
1356 git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" &&
1357 git config push.default upstream &&
1359 git config branch.master.merge refs/heads/trunk &&
1360 git config branch.master.remote dst &&
1362 git push dst master &&
1363 git show-ref refs/heads/master |
1364 sed -e "s|refs/heads/master|refs/heads/trunk|" >../dst/expect
1368 test_must_fail git show-ref refs/heads/master &&
1369 test_must_fail git show-ref refs/heads/next &&
1370 git show-ref refs/heads/trunk >actual
1372 test_cmp dst/expect dst/actual
1375 test_expect_success 'push does not follow tags by default' '
1376 mk_test testrepo heads/master &&
1379 git init --bare dst &&
1382 git pull ../testrepo master &&
1383 git tag -m "annotated" tag &&
1384 git checkout -b another &&
1385 git commit --allow-empty -m "future commit" &&
1386 git tag -m "future" future &&
1387 git checkout master &&
1388 git for-each-ref refs/heads/master >../expect &&
1389 git push ../dst master
1393 git for-each-ref >../actual
1395 test_cmp expect actual
1398 test_expect_success 'push --follow-tags only pushes relevant tags' '
1399 mk_test testrepo heads/master &&
1402 git init --bare dst &&
1405 git pull ../testrepo master &&
1406 git tag -m "annotated" tag &&
1407 git checkout -b another &&
1408 git commit --allow-empty -m "future commit" &&
1409 git tag -m "future" future &&
1410 git checkout master &&
1411 git for-each-ref refs/heads/master refs/tags/tag >../expect &&
1412 git push --follow-tags ../dst master
1416 git for-each-ref >../actual
1418 test_cmp expect actual
1421 test_expect_success 'push --no-thin must produce non-thin pack' '
1422 cat >>path1 <<\EOF &&
1423 keep base version of path1 big enough, compared to the new changes
1424 later, in order to pass size heuristics in
1425 builtin/pack-objects.c:try_delta()
1427 git commit -am initial &&
1429 git --git-dir=no-thin/.git config receive.unpacklimit 0 &&
1430 git push no-thin/.git refs/heads/master:refs/heads/foo &&
1431 echo modified >> path1 &&
1432 git commit -am modified &&
1434 rcvpck="git receive-pack --reject-thin-pack-for-testing" &&
1435 git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/master:refs/heads/foo
1438 test_expect_success 'pushing a tag pushes the tagged object' '
1440 blob=$(echo unreferenced | git hash-object -w --stdin) &&
1441 git tag -m foo tag-of-blob $blob &&
1442 git init --bare dst.git &&
1443 git push dst.git tag-of-blob &&
1444 # the receiving index-pack should have noticed
1445 # any problems, but we double check
1446 echo unreferenced >expect &&
1447 git --git-dir=dst.git cat-file blob tag-of-blob >actual &&
1448 test_cmp expect actual
1451 test_expect_success 'push into bare respects core.logallrefupdates' '
1453 git init --bare dst.git &&
1454 git -C dst.git config core.logallrefupdates true &&
1456 # double push to test both with and without
1457 # the actual pack transfer
1458 git push dst.git master:one &&
1459 echo "one@{0} push" >expect &&
1460 git -C dst.git log -g --format="%gd %gs" one >actual &&
1461 test_cmp expect actual &&
1463 git push dst.git master:two &&
1464 echo "two@{0} push" >expect &&
1465 git -C dst.git log -g --format="%gd %gs" two >actual &&
1466 test_cmp expect actual
1469 test_expect_success 'fetch into bare respects core.logallrefupdates' '
1471 git init --bare dst.git &&
1474 git config core.logallrefupdates true &&
1476 # as above, we double-fetch to test both
1477 # with and without pack transfer
1478 git fetch .. master:one &&
1479 echo "one@{0} fetch .. master:one: storing head" >expect &&
1480 git log -g --format="%gd %gs" one >actual &&
1481 test_cmp expect actual &&
1483 git fetch .. master:two &&
1484 echo "two@{0} fetch .. master:two: storing head" >expect &&
1485 git log -g --format="%gd %gs" two >actual &&
1486 test_cmp expect actual
1490 test_expect_success 'receive.denyCurrentBranch = updateInstead' '
1491 git push testrepo master &&
1495 git config receive.denyCurrentBranch updateInstead
1497 test_commit third path2 &&
1499 # Try pushing into a repository with pristine working tree
1500 git push testrepo master &&
1503 git update-index -q --refresh &&
1504 git diff-files --quiet -- &&
1505 git diff-index --quiet --cached HEAD -- &&
1506 test third = "$(cat path2)" &&
1507 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1510 # Try pushing into a repository with working tree needing a refresh
1513 git reset --hard HEAD^ &&
1514 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1515 test-tool chmtime +100 path1
1517 git push testrepo master &&
1520 git update-index -q --refresh &&
1521 git diff-files --quiet -- &&
1522 git diff-index --quiet --cached HEAD -- &&
1523 test_cmp ../path1 path1 &&
1524 test third = "$(cat path2)" &&
1525 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1528 # Update what is to be pushed
1529 test_commit fourth path2 &&
1531 # Try pushing into a repository with a dirty working tree
1532 # (1) the working tree updated
1537 test_must_fail git push testrepo master &&
1540 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1541 git diff --quiet --cached &&
1542 test changed = "$(cat path1)"
1545 # (2) the index updated
1548 echo changed >path1 &&
1551 test_must_fail git push testrepo master &&
1554 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1556 test changed = "$(cat path1)"
1559 # Introduce a new file in the update
1560 test_commit fifth path3 &&
1562 # (3) the working tree has an untracked file that would interfere
1568 test_must_fail git push testrepo master &&
1571 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1573 git diff --quiet --cached &&
1574 test changed = "$(cat path3)"
1577 # (4) the target changes to what gets pushed but it still is a change
1581 echo fifth >path3 &&
1584 test_must_fail git push testrepo master &&
1587 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1589 test fifth = "$(cat path3)"
1592 # (5) push into void
1597 git config receive.denyCurrentBranch updateInstead
1599 git push void master &&
1602 test $(git -C .. rev-parse master) = $(git rev-parse HEAD) &&
1604 git diff --cached --quiet
1607 # (6) updateInstead intervened by fast-forward check
1608 test_must_fail git push void master^:master &&
1609 test $(git -C void rev-parse HEAD) = $(git rev-parse master) &&
1610 git -C void diff --quiet &&
1611 git -C void diff --cached --quiet
1614 test_expect_success 'updateInstead with push-to-checkout hook' '
1616 git init testrepo &&
1619 git pull .. master &&
1620 git reset --hard HEAD^^ &&
1622 git config receive.denyCurrentBranch updateInstead &&
1623 write_script .git/hooks/push-to-checkout <<-\EOF
1624 echo >&2 updating from $(git rev-parse HEAD)
1625 echo >&2 updating to "$1"
1627 git update-index -q --refresh &&
1628 git read-tree -u -m HEAD "$1" || {
1630 echo >&2 read-tree failed
1636 # Try pushing into a pristine
1637 git push testrepo master &&
1641 git diff HEAD --quiet &&
1642 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1645 # Try pushing into a repository with conflicting change
1648 git reset --hard initial &&
1649 echo conflicting >path2
1651 test_must_fail git push testrepo master &&
1654 test $(git rev-parse initial) = $(git rev-parse HEAD) &&
1655 test conflicting = "$(cat path2)" &&
1656 git diff-index --quiet --cached HEAD
1659 # Try pushing into a repository with unrelated change
1662 git reset --hard initial &&
1663 echo unrelated >path1 &&
1664 echo irrelevant >path5 &&
1667 git push testrepo master &&
1670 test "$(cat path1)" = unrelated &&
1671 test "$(cat path5)" = irrelevant &&
1672 test "$(git diff --name-only --cached HEAD)" = path5 &&
1673 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1681 git config receive.denyCurrentBranch updateInstead &&
1682 write_script .git/hooks/push-to-checkout <<-\EOF
1683 if git rev-parse --quiet --verify HEAD
1686 echo >&2 updating from $(git rev-parse HEAD)
1689 echo >&2 pushing into void
1691 echo >&2 updating to "$1"
1693 git update-index -q --refresh &&
1696 git read-tree -u -m HEAD "$1" ;;
1698 git read-tree -u -m "$1" ;;
1701 echo >&2 read-tree failed
1707 git push void master &&
1711 git diff --cached --quiet &&
1712 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1716 test_expect_success 'denyCurrentBranch and worktrees' '
1717 git worktree add new-wt &&
1718 git clone . cloned &&
1719 test_commit -C cloned first &&
1720 test_config receive.denyCurrentBranch refuse &&
1721 test_must_fail git -C cloned push origin HEAD:new-wt &&
1722 test_config receive.denyCurrentBranch updateInstead &&
1723 git -C cloned push origin HEAD:new-wt &&
1724 test_must_fail git -C cloned push --delete origin new-wt