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 test_when_finished "git checkout master; git branch -D local" &&
453 git push testrepo HEAD &&
454 check_push_result testrepo $the_commit heads/local
457 test_expect_success 'push with +HEAD' '
459 mk_test testrepo heads/master &&
460 git checkout master &&
461 git checkout -b local &&
462 test_when_finished "git checkout master; git branch -D local" &&
463 git push testrepo master local &&
464 check_push_result testrepo $the_commit heads/master &&
465 check_push_result testrepo $the_commit heads/local &&
467 # Without force rewinding should fail
468 git reset --hard HEAD^ &&
469 test_must_fail git push testrepo HEAD &&
470 check_push_result testrepo $the_commit heads/local &&
472 # With force rewinding should succeed
473 git push testrepo +HEAD &&
474 check_push_result testrepo $the_first_commit heads/local
478 test_expect_success 'push HEAD with non-existent, incomplete dest' '
481 git checkout master &&
482 git push testrepo HEAD:branch &&
483 check_push_result testrepo $the_commit heads/branch
487 test_expect_success 'push with config remote.*.push = HEAD' '
489 mk_test testrepo heads/local &&
490 git checkout master &&
491 git branch -f local $the_commit &&
492 test_when_finished "git branch -D local" &&
495 git checkout local &&
496 git reset --hard $the_first_commit
498 test_config remote.there.url testrepo &&
499 test_config remote.there.push HEAD &&
500 test_config branch.master.remote there &&
502 check_push_result testrepo $the_commit heads/master &&
503 check_push_result testrepo $the_first_commit heads/local
506 test_expect_success 'push with remote.pushdefault' '
507 mk_test up_repo heads/master &&
508 mk_test down_repo heads/master &&
509 test_config remote.up.url up_repo &&
510 test_config remote.down.url down_repo &&
511 test_config branch.master.remote up &&
512 test_config remote.pushdefault down &&
513 test_config push.default matching &&
515 check_push_result up_repo $the_first_commit heads/master &&
516 check_push_result down_repo $the_commit heads/master
519 test_expect_success 'push with config remote.*.pushurl' '
521 mk_test testrepo heads/master &&
522 git checkout master &&
523 test_config remote.there.url test2repo &&
524 test_config remote.there.pushurl testrepo &&
526 check_push_result testrepo $the_commit heads/master
529 test_expect_success 'push with config branch.*.pushremote' '
530 mk_test up_repo heads/master &&
531 mk_test side_repo heads/master &&
532 mk_test down_repo heads/master &&
533 test_config remote.up.url up_repo &&
534 test_config remote.pushdefault side_repo &&
535 test_config remote.down.url down_repo &&
536 test_config branch.master.remote up &&
537 test_config branch.master.pushremote down &&
538 test_config push.default matching &&
540 check_push_result up_repo $the_first_commit heads/master &&
541 check_push_result side_repo $the_first_commit heads/master &&
542 check_push_result down_repo $the_commit heads/master
545 test_expect_success 'branch.*.pushremote config order is irrelevant' '
546 mk_test one_repo heads/master &&
547 mk_test two_repo heads/master &&
548 test_config remote.one.url one_repo &&
549 test_config remote.two.url two_repo &&
550 test_config branch.master.pushremote two_repo &&
551 test_config remote.pushdefault one_repo &&
552 test_config push.default matching &&
554 check_push_result one_repo $the_first_commit heads/master &&
555 check_push_result two_repo $the_commit heads/master
558 test_expect_success 'push with dry-run' '
560 mk_test testrepo heads/master &&
561 old_commit=$(git -C testrepo show-ref -s --verify refs/heads/master) &&
562 git push --dry-run testrepo : &&
563 check_push_result testrepo $old_commit heads/master
566 test_expect_success 'push updates local refs' '
568 mk_test testrepo heads/master &&
569 mk_child testrepo child &&
572 git pull .. master &&
574 test $(git rev-parse master) = \
575 $(git rev-parse remotes/origin/master)
580 test_expect_success 'push updates up-to-date local refs' '
582 mk_test testrepo heads/master &&
583 mk_child testrepo child1 &&
584 mk_child testrepo child2 &&
585 (cd child1 && git pull .. master && git push) &&
588 git pull ../child1 master &&
590 test $(git rev-parse master) = \
591 $(git rev-parse remotes/origin/master)
596 test_expect_success 'push preserves up-to-date packed refs' '
598 mk_test testrepo heads/master &&
599 mk_child testrepo child &&
603 ! test -f .git/refs/remotes/origin/master
608 test_expect_success 'push does not update local refs on failure' '
610 mk_test testrepo heads/master &&
611 mk_child testrepo child &&
612 mkdir testrepo/.git/hooks &&
613 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
614 chmod +x testrepo/.git/hooks/pre-receive &&
617 git pull .. master &&
618 test_must_fail git push &&
619 test $(git rev-parse master) != \
620 $(git rev-parse remotes/origin/master)
625 test_expect_success 'allow deleting an invalid remote ref' '
627 mk_test testrepo heads/master &&
628 rm -f testrepo/.git/objects/??/* &&
629 git push testrepo :refs/heads/master &&
630 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
634 test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' '
635 mk_test_with_hooks testrepo heads/master heads/next &&
636 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
637 newmaster=$(git show-ref -s --verify refs/heads/master) &&
638 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
640 git push testrepo refs/heads/master:refs/heads/master :refs/heads/next &&
643 cat >pre-receive.expect <<-EOF &&
644 $orgmaster $newmaster refs/heads/master
645 $orgnext $newnext refs/heads/next
648 cat >update.expect <<-EOF &&
649 refs/heads/master $orgmaster $newmaster
650 refs/heads/next $orgnext $newnext
653 cat >post-receive.expect <<-EOF &&
654 $orgmaster $newmaster refs/heads/master
655 $orgnext $newnext refs/heads/next
658 cat >post-update.expect <<-EOF &&
663 test_cmp pre-receive.expect pre-receive.actual &&
664 test_cmp update.expect update.actual &&
665 test_cmp post-receive.expect post-receive.actual &&
666 test_cmp post-update.expect post-update.actual
670 test_expect_success 'deleting dangling ref triggers hooks with correct args' '
671 mk_test_with_hooks testrepo heads/master &&
672 rm -f testrepo/.git/objects/??/* &&
673 git push testrepo :refs/heads/master &&
676 cat >pre-receive.expect <<-EOF &&
677 $ZERO_OID $ZERO_OID refs/heads/master
680 cat >update.expect <<-EOF &&
681 refs/heads/master $ZERO_OID $ZERO_OID
684 cat >post-receive.expect <<-EOF &&
685 $ZERO_OID $ZERO_OID refs/heads/master
688 cat >post-update.expect <<-EOF &&
692 test_cmp pre-receive.expect pre-receive.actual &&
693 test_cmp update.expect update.actual &&
694 test_cmp post-receive.expect post-receive.actual &&
695 test_cmp post-update.expect post-update.actual
699 test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
700 mk_test_with_hooks testrepo heads/master &&
701 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
702 newmaster=$(git show-ref -s --verify refs/heads/master) &&
703 git push testrepo master :refs/heads/nonexistent &&
706 cat >pre-receive.expect <<-EOF &&
707 $orgmaster $newmaster refs/heads/master
708 $ZERO_OID $ZERO_OID refs/heads/nonexistent
711 cat >update.expect <<-EOF &&
712 refs/heads/master $orgmaster $newmaster
713 refs/heads/nonexistent $ZERO_OID $ZERO_OID
716 cat >post-receive.expect <<-EOF &&
717 $orgmaster $newmaster refs/heads/master
720 cat >post-update.expect <<-EOF &&
724 test_cmp pre-receive.expect pre-receive.actual &&
725 test_cmp update.expect update.actual &&
726 test_cmp post-receive.expect post-receive.actual &&
727 test_cmp post-update.expect post-update.actual
731 test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
732 mk_test_with_hooks testrepo heads/master &&
733 git push testrepo :refs/heads/nonexistent &&
736 cat >pre-receive.expect <<-EOF &&
737 $ZERO_OID $ZERO_OID refs/heads/nonexistent
740 cat >update.expect <<-EOF &&
741 refs/heads/nonexistent $ZERO_OID $ZERO_OID
744 test_cmp pre-receive.expect pre-receive.actual &&
745 test_cmp update.expect update.actual &&
746 test_path_is_missing post-receive.actual &&
747 test_path_is_missing post-update.actual
751 test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
752 mk_test_with_hooks testrepo heads/master heads/next heads/seen &&
753 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
754 newmaster=$(git show-ref -s --verify refs/heads/master) &&
755 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
757 orgseen=$(cd testrepo && git show-ref -s --verify refs/heads/seen) &&
758 newseen=$(git show-ref -s --verify refs/heads/master) &&
759 git push testrepo refs/heads/master:refs/heads/master \
760 refs/heads/master:refs/heads/seen :refs/heads/next \
761 :refs/heads/nonexistent &&
764 cat >pre-receive.expect <<-EOF &&
765 $orgmaster $newmaster refs/heads/master
766 $orgnext $newnext refs/heads/next
767 $orgseen $newseen refs/heads/seen
768 $ZERO_OID $ZERO_OID refs/heads/nonexistent
771 cat >update.expect <<-EOF &&
772 refs/heads/master $orgmaster $newmaster
773 refs/heads/next $orgnext $newnext
774 refs/heads/seen $orgseen $newseen
775 refs/heads/nonexistent $ZERO_OID $ZERO_OID
778 cat >post-receive.expect <<-EOF &&
779 $orgmaster $newmaster refs/heads/master
780 $orgnext $newnext refs/heads/next
781 $orgseen $newseen refs/heads/seen
784 cat >post-update.expect <<-EOF &&
790 test_cmp pre-receive.expect pre-receive.actual &&
791 test_cmp update.expect update.actual &&
792 test_cmp post-receive.expect post-receive.actual &&
793 test_cmp post-update.expect post-update.actual
797 test_expect_success 'allow deleting a ref using --delete' '
798 mk_test testrepo heads/master &&
799 (cd testrepo && git config receive.denyDeleteCurrent warn) &&
800 git push testrepo --delete master &&
801 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
804 test_expect_success 'allow deleting a tag using --delete' '
805 mk_test testrepo heads/master &&
806 git tag -a -m dummy_message deltag heads/master &&
807 git push testrepo --tags &&
808 (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
809 git push testrepo --delete tag deltag &&
810 (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
813 test_expect_success 'push --delete without args aborts' '
814 mk_test testrepo heads/master &&
815 test_must_fail git push testrepo --delete
818 test_expect_success 'push --delete refuses src:dest refspecs' '
819 mk_test testrepo heads/master &&
820 test_must_fail git push testrepo --delete master:foo
823 test_expect_success 'warn on push to HEAD of non-bare repository' '
824 mk_test testrepo heads/master &&
827 git checkout master &&
828 git config receive.denyCurrentBranch warn
830 git push testrepo master 2>stderr &&
831 grep "warning: updating the current branch" stderr
834 test_expect_success 'deny push to HEAD of non-bare repository' '
835 mk_test testrepo heads/master &&
838 git checkout master &&
839 git config receive.denyCurrentBranch true
841 test_must_fail git push testrepo master
844 test_expect_success 'allow push to HEAD of bare repository (bare)' '
845 mk_test testrepo heads/master &&
848 git checkout master &&
849 git config receive.denyCurrentBranch true &&
850 git config core.bare true
852 git push testrepo master 2>stderr &&
853 ! grep "warning: updating the current branch" stderr
856 test_expect_success 'allow push to HEAD of non-bare repository (config)' '
857 mk_test testrepo heads/master &&
860 git checkout master &&
861 git config receive.denyCurrentBranch false
863 git push testrepo master 2>stderr &&
864 ! grep "warning: updating the current branch" stderr
867 test_expect_success 'fetch with branches' '
869 git branch second $the_first_commit &&
870 git checkout second &&
871 echo ".." > testrepo/.git/branches/branch1 &&
875 echo "$the_commit commit refs/heads/branch1" >expect &&
876 git for-each-ref refs/heads >actual &&
877 test_cmp expect actual
882 test_expect_success 'fetch with branches containing #' '
884 echo "..#second" > testrepo/.git/branches/branch2 &&
888 echo "$the_first_commit commit refs/heads/branch2" >expect &&
889 git for-each-ref refs/heads >actual &&
890 test_cmp expect actual
895 test_expect_success 'push with branches' '
897 git checkout second &&
898 echo "testrepo" > .git/branches/branch1 &&
902 echo "$the_first_commit commit refs/heads/master" >expect &&
903 git for-each-ref refs/heads >actual &&
904 test_cmp expect actual
908 test_expect_success 'push with branches containing #' '
910 echo "testrepo#branch3" > .git/branches/branch2 &&
914 echo "$the_first_commit commit refs/heads/branch3" >expect &&
915 git for-each-ref refs/heads >actual &&
916 test_cmp expect actual
921 test_expect_success 'push into aliased refs (consistent)' '
922 mk_test testrepo heads/master &&
923 mk_child testrepo child1 &&
924 mk_child testrepo child2 &&
928 git symbolic-ref refs/heads/bar refs/heads/foo &&
929 git config receive.denyCurrentBranch false
936 git commit -a -m child2 &&
939 git push ../child1 foo bar
943 test_expect_success 'push into aliased refs (inconsistent)' '
944 mk_test testrepo heads/master &&
945 mk_child testrepo child1 &&
946 mk_child testrepo child2 &&
950 git symbolic-ref refs/heads/bar refs/heads/foo &&
951 git config receive.denyCurrentBranch false
958 git commit -a -m child2 &&
963 git commit -a -m child2 &&
965 test_must_fail git push ../child1 foo bar 2>stderr &&
966 grep "refusing inconsistent update" stderr
970 test_force_push_tag () {
971 tag_type_description=$1
974 test_expect_success "force pushing required to update $tag_type_description" "
975 mk_test testrepo heads/master &&
976 mk_child testrepo child1 &&
977 mk_child testrepo child2 &&
981 git push ../child2 testTag &&
984 git commit -m 'file1' &&
985 git tag $tag_args testTag &&
986 test_must_fail git push ../child2 testTag &&
987 git push --force ../child2 testTag &&
988 git tag $tag_args testTag HEAD~ &&
989 test_must_fail git push ../child2 testTag &&
990 git push --force ../child2 testTag &&
992 # Clobbering without + in refspec needs --force
993 git tag -f testTag &&
994 test_must_fail git push ../child2 'refs/tags/*:refs/tags/*' &&
995 git push --force ../child2 'refs/tags/*:refs/tags/*' &&
997 # Clobbering with + in refspec does not need --force
998 git tag -f testTag HEAD~ &&
999 git push ../child2 '+refs/tags/*:refs/tags/*' &&
1001 # Clobbering with --no-force still obeys + in refspec
1002 git tag -f testTag &&
1003 git push --no-force ../child2 '+refs/tags/*:refs/tags/*' &&
1005 # Clobbering with/without --force and 'tag <name>' format
1006 git tag -f testTag HEAD~ &&
1007 test_must_fail git push ../child2 tag testTag &&
1008 git push --force ../child2 tag testTag
1013 test_force_push_tag "lightweight tag" "-f"
1014 test_force_push_tag "annotated tag" "-f -a -m'tag message'"
1016 test_force_fetch_tag () {
1017 tag_type_description=$1
1020 test_expect_success "fetch will not clobber an existing $tag_type_description without --force" "
1021 mk_test testrepo heads/master &&
1022 mk_child testrepo child1 &&
1023 mk_child testrepo child2 &&
1027 git -C ../child1 fetch origin tag testTag &&
1030 git commit -m 'file1' &&
1031 git tag $tag_args testTag &&
1032 test_must_fail git -C ../child1 fetch origin tag testTag &&
1033 git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*'
1038 test_force_fetch_tag "lightweight tag" "-f"
1039 test_force_fetch_tag "annotated tag" "-f -a -m'tag message'"
1041 test_expect_success 'push --porcelain' '
1042 mk_empty testrepo &&
1043 echo >.git/foo "To testrepo" &&
1044 echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new reference]" &&
1045 echo >>.git/foo "Done" &&
1046 git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master &&
1049 echo "$the_commit commit refs/remotes/origin/master" >expect &&
1050 git for-each-ref refs/remotes/origin >actual &&
1051 test_cmp expect actual
1053 test_cmp .git/foo .git/bar
1056 test_expect_success 'push --porcelain bad url' '
1057 mk_empty testrepo &&
1058 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
1059 ! grep -q Done .git/bar
1062 test_expect_success 'push --porcelain rejected' '
1063 mk_empty testrepo &&
1064 git push testrepo refs/heads/master:refs/remotes/origin/master &&
1066 git reset --hard origin/master^ &&
1067 git config receive.denyCurrentBranch true) &&
1069 echo >.git/foo "To testrepo" &&
1070 echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" &&
1071 echo >>.git/foo "Done" &&
1073 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master &&
1074 test_cmp .git/foo .git/bar
1077 test_expect_success 'push --porcelain --dry-run rejected' '
1078 mk_empty testrepo &&
1079 git push testrepo refs/heads/master:refs/remotes/origin/master &&
1081 git reset --hard origin/master &&
1082 git config receive.denyCurrentBranch true) &&
1084 echo >.git/foo "To testrepo" &&
1085 echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" &&
1086 echo >>.git/foo "Done" &&
1088 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master &&
1089 test_cmp .git/foo .git/bar
1092 test_expect_success 'push --prune' '
1093 mk_test testrepo heads/master heads/second heads/foo heads/bar &&
1094 git push --prune testrepo : &&
1095 check_push_result testrepo $the_commit heads/master &&
1096 check_push_result testrepo $the_first_commit heads/second &&
1097 ! check_push_result testrepo $the_first_commit heads/foo heads/bar
1100 test_expect_success 'push --prune refspec' '
1101 mk_test testrepo tmp/master tmp/second tmp/foo tmp/bar &&
1102 git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
1103 check_push_result testrepo $the_commit tmp/master &&
1104 check_push_result testrepo $the_first_commit tmp/second &&
1105 ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
1108 for configsection in transfer receive
1110 test_expect_success "push to update a ref hidden by $configsection.hiderefs" '
1111 mk_test testrepo heads/master hidden/one hidden/two hidden/three &&
1114 git config $configsection.hiderefs refs/hidden
1117 # push to unhidden ref succeeds normally
1118 git push testrepo master:refs/heads/master &&
1119 check_push_result testrepo $the_commit heads/master &&
1121 # push to update a hidden ref should fail
1122 test_must_fail git push testrepo master:refs/hidden/one &&
1123 check_push_result testrepo $the_first_commit hidden/one &&
1125 # push to delete a hidden ref should fail
1126 test_must_fail git push testrepo :refs/hidden/two &&
1127 check_push_result testrepo $the_first_commit hidden/two &&
1129 # idempotent push to update a hidden ref should fail
1130 test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
1131 check_push_result testrepo $the_first_commit hidden/three
1135 test_expect_success 'fetch exact SHA1' '
1136 mk_test testrepo heads/master hidden/one &&
1137 git push testrepo master:refs/hidden/one &&
1140 git config transfer.hiderefs refs/hidden
1142 check_push_result testrepo $the_commit hidden/one &&
1144 mk_child testrepo child &&
1148 # make sure $the_commit does not exist here
1151 test_must_fail git cat-file -t $the_commit &&
1153 # Some protocol versions (e.g. 2) support fetching
1154 # unadvertised objects, so restrict this test to v0.
1156 # fetching the hidden object should fail by default
1157 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1158 git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err &&
1159 test_i18ngrep "Server does not allow request for unadvertised object" err &&
1160 test_must_fail git rev-parse --verify refs/heads/copy &&
1162 # the server side can allow it to succeed
1165 git config uploadpack.allowtipsha1inwant true
1168 git fetch -v ../testrepo $the_commit:refs/heads/copy master:refs/heads/extra &&
1169 cat >expect <<-EOF &&
1174 git rev-parse --verify refs/heads/copy &&
1175 git rev-parse --verify refs/heads/extra
1177 test_cmp expect actual
1181 test_expect_success 'fetch exact SHA1 in protocol v2' '
1182 mk_test testrepo heads/master hidden/one &&
1183 git push testrepo master:refs/hidden/one &&
1184 git -C testrepo config transfer.hiderefs refs/hidden &&
1185 check_push_result testrepo $the_commit hidden/one &&
1187 mk_child testrepo child &&
1188 git -C child config protocol.version 2 &&
1190 # make sure $the_commit does not exist here
1191 git -C child repack -a -d &&
1192 git -C child prune &&
1193 test_must_fail git -C child cat-file -t $the_commit &&
1195 # fetching the hidden object succeeds by default
1196 # NEEDSWORK: should this match the v0 behavior instead?
1197 git -C child fetch -v ../testrepo $the_commit:refs/heads/copy
1200 for configallowtipsha1inwant in true false
1202 test_expect_success "shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" '
1203 mk_empty testrepo &&
1206 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1207 git commit --allow-empty -m foo &&
1208 git commit --allow-empty -m bar
1210 SHA1=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1214 # Some protocol versions (e.g. 2) support fetching
1215 # unadvertised objects, so restrict this test to v0.
1216 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1217 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1218 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1219 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1220 git cat-file commit $SHA1
1224 test_expect_success "deny fetch unreachable SHA1, allowtipsha1inwant=$configallowtipsha1inwant" '
1225 mk_empty testrepo &&
1228 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1229 git commit --allow-empty -m foo &&
1230 git commit --allow-empty -m bar &&
1231 git commit --allow-empty -m xyz
1233 SHA1_1=$(git --git-dir=testrepo/.git rev-parse HEAD^^) &&
1234 SHA1_2=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1235 SHA1_3=$(git --git-dir=testrepo/.git rev-parse HEAD) &&
1238 git reset --hard $SHA1_2 &&
1239 git cat-file commit $SHA1_1 &&
1240 git cat-file commit $SHA1_3
1245 # Some protocol versions (e.g. 2) support fetching
1246 # unadvertised objects, so restrict this test to v0.
1247 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1248 git fetch ../testrepo/.git $SHA1_3 &&
1249 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1250 git fetch ../testrepo/.git $SHA1_1 &&
1251 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1252 git fetch ../testrepo/.git $SHA1_1 &&
1253 git cat-file commit $SHA1_1 &&
1254 test_must_fail git cat-file commit $SHA1_2 &&
1255 git fetch ../testrepo/.git $SHA1_2 &&
1256 git cat-file commit $SHA1_2 &&
1257 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1258 git fetch ../testrepo/.git $SHA1_3 2>err &&
1259 test_i18ngrep "remote error:.*not our ref.*$SHA1_3\$" err
1264 test_expect_success 'fetch follows tags by default' '
1265 mk_test testrepo heads/master &&
1270 git pull ../testrepo master &&
1271 git tag -m "annotated" tag &&
1272 git for-each-ref >tmp1 &&
1275 sed -n "s|refs/heads/master$|refs/remotes/origin/master|p" tmp1
1277 sort -k 3 >../expect
1282 git remote add origin ../src &&
1283 git config branch.master.remote origin &&
1284 git config branch.master.merge refs/heads/master &&
1286 git for-each-ref >../actual
1288 test_cmp expect actual
1291 test_expect_success 'peeled advertisements are not considered ref tips' '
1292 mk_empty testrepo &&
1293 git -C testrepo commit --allow-empty -m one &&
1294 git -C testrepo commit --allow-empty -m two &&
1295 git -C testrepo tag -m foo mytag HEAD^ &&
1296 oid=$(git -C testrepo rev-parse mytag^{commit}) &&
1297 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1298 git fetch testrepo $oid 2>err &&
1299 test_i18ngrep "Server does not allow request for unadvertised object" err
1302 test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' '
1303 mk_test testrepo heads/master &&
1306 git init --bare dst &&
1309 git pull ../testrepo master &&
1311 git config remote.dst.url ../dst &&
1312 git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" &&
1313 git push dst master &&
1314 git show-ref refs/heads/master |
1315 sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect
1319 test_must_fail git show-ref refs/heads/next &&
1320 test_must_fail git show-ref refs/heads/master &&
1321 git show-ref refs/remotes/src/master >actual
1323 test_cmp dst/expect dst/actual
1326 test_expect_success 'with no remote.$name.push, it is not used as refmap' '
1327 mk_test testrepo heads/master &&
1330 git init --bare dst &&
1333 git pull ../testrepo master &&
1335 git config remote.dst.url ../dst &&
1336 git config push.default matching &&
1337 git push dst master &&
1338 git show-ref refs/heads/master >../dst/expect
1342 test_must_fail git show-ref refs/heads/next &&
1343 git show-ref refs/heads/master >actual
1345 test_cmp dst/expect dst/actual
1348 test_expect_success 'with no remote.$name.push, upstream mapping is used' '
1349 mk_test testrepo heads/master &&
1352 git init --bare dst &&
1355 git pull ../testrepo master &&
1357 git config remote.dst.url ../dst &&
1358 git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" &&
1359 git config push.default upstream &&
1361 git config branch.master.merge refs/heads/trunk &&
1362 git config branch.master.remote dst &&
1364 git push dst master &&
1365 git show-ref refs/heads/master |
1366 sed -e "s|refs/heads/master|refs/heads/trunk|" >../dst/expect
1370 test_must_fail git show-ref refs/heads/master &&
1371 test_must_fail git show-ref refs/heads/next &&
1372 git show-ref refs/heads/trunk >actual
1374 test_cmp dst/expect dst/actual
1377 test_expect_success 'push does not follow tags by default' '
1378 mk_test testrepo heads/master &&
1381 git init --bare dst &&
1384 git pull ../testrepo master &&
1385 git tag -m "annotated" tag &&
1386 git checkout -b another &&
1387 git commit --allow-empty -m "future commit" &&
1388 git tag -m "future" future &&
1389 git checkout master &&
1390 git for-each-ref refs/heads/master >../expect &&
1391 git push ../dst master
1395 git for-each-ref >../actual
1397 test_cmp expect actual
1400 test_expect_success 'push --follow-tags only pushes relevant tags' '
1401 mk_test testrepo heads/master &&
1404 git init --bare dst &&
1407 git pull ../testrepo master &&
1408 git tag -m "annotated" tag &&
1409 git checkout -b another &&
1410 git commit --allow-empty -m "future commit" &&
1411 git tag -m "future" future &&
1412 git checkout master &&
1413 git for-each-ref refs/heads/master refs/tags/tag >../expect &&
1414 git push --follow-tags ../dst master
1418 git for-each-ref >../actual
1420 test_cmp expect actual
1423 test_expect_success 'push --no-thin must produce non-thin pack' '
1424 cat >>path1 <<\EOF &&
1425 keep base version of path1 big enough, compared to the new changes
1426 later, in order to pass size heuristics in
1427 builtin/pack-objects.c:try_delta()
1429 git commit -am initial &&
1431 git --git-dir=no-thin/.git config receive.unpacklimit 0 &&
1432 git push no-thin/.git refs/heads/master:refs/heads/foo &&
1433 echo modified >> path1 &&
1434 git commit -am modified &&
1436 rcvpck="git receive-pack --reject-thin-pack-for-testing" &&
1437 git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/master:refs/heads/foo
1440 test_expect_success 'pushing a tag pushes the tagged object' '
1442 blob=$(echo unreferenced | git hash-object -w --stdin) &&
1443 git tag -m foo tag-of-blob $blob &&
1444 git init --bare dst.git &&
1445 git push dst.git tag-of-blob &&
1446 # the receiving index-pack should have noticed
1447 # any problems, but we double check
1448 echo unreferenced >expect &&
1449 git --git-dir=dst.git cat-file blob tag-of-blob >actual &&
1450 test_cmp expect actual
1453 test_expect_success 'push into bare respects core.logallrefupdates' '
1455 git init --bare dst.git &&
1456 git -C dst.git config core.logallrefupdates true &&
1458 # double push to test both with and without
1459 # the actual pack transfer
1460 git push dst.git master:one &&
1461 echo "one@{0} push" >expect &&
1462 git -C dst.git log -g --format="%gd %gs" one >actual &&
1463 test_cmp expect actual &&
1465 git push dst.git master:two &&
1466 echo "two@{0} push" >expect &&
1467 git -C dst.git log -g --format="%gd %gs" two >actual &&
1468 test_cmp expect actual
1471 test_expect_success 'fetch into bare respects core.logallrefupdates' '
1473 git init --bare dst.git &&
1476 git config core.logallrefupdates true &&
1478 # as above, we double-fetch to test both
1479 # with and without pack transfer
1480 git fetch .. master:one &&
1481 echo "one@{0} fetch .. master:one: storing head" >expect &&
1482 git log -g --format="%gd %gs" one >actual &&
1483 test_cmp expect actual &&
1485 git fetch .. master:two &&
1486 echo "two@{0} fetch .. master:two: storing head" >expect &&
1487 git log -g --format="%gd %gs" two >actual &&
1488 test_cmp expect actual
1492 test_expect_success 'receive.denyCurrentBranch = updateInstead' '
1493 git push testrepo master &&
1497 git config receive.denyCurrentBranch updateInstead
1499 test_commit third path2 &&
1501 # Try pushing into a repository with pristine working tree
1502 git push testrepo master &&
1505 git update-index -q --refresh &&
1506 git diff-files --quiet -- &&
1507 git diff-index --quiet --cached HEAD -- &&
1508 test third = "$(cat path2)" &&
1509 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1512 # Try pushing into a repository with working tree needing a refresh
1515 git reset --hard HEAD^ &&
1516 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1517 test-tool chmtime +100 path1
1519 git push testrepo master &&
1522 git update-index -q --refresh &&
1523 git diff-files --quiet -- &&
1524 git diff-index --quiet --cached HEAD -- &&
1525 test_cmp ../path1 path1 &&
1526 test third = "$(cat path2)" &&
1527 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1530 # Update what is to be pushed
1531 test_commit fourth path2 &&
1533 # Try pushing into a repository with a dirty working tree
1534 # (1) the working tree updated
1539 test_must_fail git push testrepo master &&
1542 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1543 git diff --quiet --cached &&
1544 test changed = "$(cat path1)"
1547 # (2) the index updated
1550 echo changed >path1 &&
1553 test_must_fail git push testrepo master &&
1556 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1558 test changed = "$(cat path1)"
1561 # Introduce a new file in the update
1562 test_commit fifth path3 &&
1564 # (3) the working tree has an untracked file that would interfere
1570 test_must_fail git push testrepo master &&
1573 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1575 git diff --quiet --cached &&
1576 test changed = "$(cat path3)"
1579 # (4) the target changes to what gets pushed but it still is a change
1583 echo fifth >path3 &&
1586 test_must_fail git push testrepo master &&
1589 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1591 test fifth = "$(cat path3)"
1594 # (5) push into void
1599 git config receive.denyCurrentBranch updateInstead
1601 git push void master &&
1604 test $(git -C .. rev-parse master) = $(git rev-parse HEAD) &&
1606 git diff --cached --quiet
1609 # (6) updateInstead intervened by fast-forward check
1610 test_must_fail git push void master^:master &&
1611 test $(git -C void rev-parse HEAD) = $(git rev-parse master) &&
1612 git -C void diff --quiet &&
1613 git -C void diff --cached --quiet
1616 test_expect_success 'updateInstead with push-to-checkout hook' '
1618 git init testrepo &&
1621 git pull .. master &&
1622 git reset --hard HEAD^^ &&
1624 git config receive.denyCurrentBranch updateInstead &&
1625 write_script .git/hooks/push-to-checkout <<-\EOF
1626 echo >&2 updating from $(git rev-parse HEAD)
1627 echo >&2 updating to "$1"
1629 git update-index -q --refresh &&
1630 git read-tree -u -m HEAD "$1" || {
1632 echo >&2 read-tree failed
1638 # Try pushing into a pristine
1639 git push testrepo master &&
1643 git diff HEAD --quiet &&
1644 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1647 # Try pushing into a repository with conflicting change
1650 git reset --hard initial &&
1651 echo conflicting >path2
1653 test_must_fail git push testrepo master &&
1656 test $(git rev-parse initial) = $(git rev-parse HEAD) &&
1657 test conflicting = "$(cat path2)" &&
1658 git diff-index --quiet --cached HEAD
1661 # Try pushing into a repository with unrelated change
1664 git reset --hard initial &&
1665 echo unrelated >path1 &&
1666 echo irrelevant >path5 &&
1669 git push testrepo master &&
1672 test "$(cat path1)" = unrelated &&
1673 test "$(cat path5)" = irrelevant &&
1674 test "$(git diff --name-only --cached HEAD)" = path5 &&
1675 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1683 git config receive.denyCurrentBranch updateInstead &&
1684 write_script .git/hooks/push-to-checkout <<-\EOF
1685 if git rev-parse --quiet --verify HEAD
1688 echo >&2 updating from $(git rev-parse HEAD)
1691 echo >&2 pushing into void
1693 echo >&2 updating to "$1"
1695 git update-index -q --refresh &&
1698 git read-tree -u -m HEAD "$1" ;;
1700 git read-tree -u -m "$1" ;;
1703 echo >&2 read-tree failed
1709 git push void master &&
1713 git diff --cached --quiet &&
1714 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1718 test_expect_success 'denyCurrentBranch and worktrees' '
1719 git worktree add new-wt &&
1720 git clone . cloned &&
1721 test_commit -C cloned first &&
1722 test_config receive.denyCurrentBranch refuse &&
1723 test_must_fail git -C cloned push origin HEAD:new-wt &&
1724 test_config receive.denyCurrentBranch updateInstead &&
1725 git -C cloned push origin HEAD:new-wt &&
1726 test_must_fail git -C cloned push --delete origin new-wt