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
17 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=master
18 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
26 rm -fr "$repo_name" &&
31 git config receive.denyCurrentBranch warn
&&
32 mv .git
/hooks .git
/hooks-disabled
40 mk_empty
"$repo_name" &&
44 git push
"$repo_name" $the_first_commit:refs
/$ref ||
50 echo "$the_first_commit" >expect
&&
51 git show-ref
-s --verify refs
/$ref >actual
&&
52 test_cmp expect actual ||
59 mk_test_with_hooks
() {
67 cat >pre-receive
<<-'EOF' &&
69 cat - >>pre-receive.actual
72 cat >update
<<-'EOF' &&
74 printf "%s %s %s\n" "$@" >>update.actual
77 cat >post-receive
<<-'EOF' &&
79 cat - >>post-receive.actual
82 cat >post-update
<<-'EOF' &&
86 printf "%s\n" "$ref" >>post-update.actual
90 chmod +x pre-receive update post-receive post-update
99 check_push_result
() {
101 BUG
"check_push_result requires at least 3 parameters"
112 git show-ref
-s --verify refs
/$ref >actual
&&
113 test_cmp expect actual ||
120 test_expect_success setup
'
125 git commit -a -m repo &&
126 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
131 git commit -a -m second &&
132 the_commit=$(git show-ref -s --verify refs/heads/master)
136 test_expect_success
'fetch without wildcard' '
140 git fetch .. refs/heads/master:refs/remotes/origin/master &&
142 echo "$the_commit commit refs/remotes/origin/master" >expect &&
143 git for-each-ref refs/remotes/origin >actual &&
144 test_cmp expect actual
148 test_expect_success
'fetch with wildcard' '
152 git config remote.up.url .. &&
153 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
156 echo "$the_commit commit refs/remotes/origin/master" >expect &&
157 git for-each-ref refs/remotes/origin >actual &&
158 test_cmp expect actual
162 test_expect_success
'fetch with insteadOf' '
167 git config "url.$TRASH.insteadOf" trash/ &&
168 git config remote.up.url trash/. &&
169 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
172 echo "$the_commit commit refs/remotes/origin/master" >expect &&
173 git for-each-ref refs/remotes/origin >actual &&
174 test_cmp expect actual
178 test_expect_success
'fetch with pushInsteadOf (should not rewrite)' '
183 git config "url.trash/.pushInsteadOf" "$TRASH" &&
184 git config remote.up.url "$TRASH." &&
185 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
188 echo "$the_commit commit refs/remotes/origin/master" >expect &&
189 git for-each-ref refs/remotes/origin >actual &&
190 test_cmp expect actual
194 test_expect_success
'push without wildcard' '
197 git push testrepo refs/heads/master:refs/remotes/origin/master &&
200 echo "$the_commit commit refs/remotes/origin/master" >expect &&
201 git for-each-ref refs/remotes/origin >actual &&
202 test_cmp expect actual
206 test_expect_success
'push with wildcard' '
209 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
212 echo "$the_commit commit refs/remotes/origin/master" >expect &&
213 git for-each-ref refs/remotes/origin >actual &&
214 test_cmp expect actual
218 test_expect_success
'push with insteadOf' '
221 test_config "url.$TRASH.insteadOf" trash/ &&
222 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
225 echo "$the_commit commit refs/remotes/origin/master" >expect &&
226 git for-each-ref refs/remotes/origin >actual &&
227 test_cmp expect actual
231 test_expect_success
'push with pushInsteadOf' '
234 test_config "url.$TRASH.pushInsteadOf" trash/ &&
235 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
238 echo "$the_commit commit refs/remotes/origin/master" >expect &&
239 git for-each-ref refs/remotes/origin >actual &&
240 test_cmp expect actual
244 test_expect_success
'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
246 test_config "url.trash2/.pushInsteadOf" testrepo/ &&
247 test_config "url.trash3/.pushInsteadOf" trash/wrong &&
248 test_config remote.r.url trash/wrong &&
249 test_config remote.r.pushurl "testrepo/" &&
250 git push r refs/heads/master:refs/remotes/origin/master &&
253 echo "$the_commit commit refs/remotes/origin/master" >expect &&
254 git for-each-ref refs/remotes/origin >actual &&
255 test_cmp expect actual
259 test_expect_success
'push with matching heads' '
261 mk_test testrepo heads/master &&
262 git push testrepo : &&
263 check_push_result testrepo $the_commit heads/master
267 test_expect_success
'push with matching heads on the command line' '
269 mk_test testrepo heads/master &&
270 git push testrepo : &&
271 check_push_result testrepo $the_commit heads/master
275 test_expect_success
'failed (non-fast-forward) push with matching heads' '
277 mk_test testrepo heads/master &&
278 git push testrepo : &&
279 git commit --amend -massaged &&
280 test_must_fail git push testrepo &&
281 check_push_result testrepo $the_commit heads/master &&
282 git reset --hard $the_commit
286 test_expect_success
'push --force with matching heads' '
288 mk_test testrepo heads/master &&
289 git push testrepo : &&
290 git commit --amend -massaged &&
291 git push --force testrepo : &&
292 ! check_push_result testrepo $the_commit heads/master &&
293 git reset --hard $the_commit
297 test_expect_success
'push with matching heads and forced update' '
299 mk_test testrepo heads/master &&
300 git push testrepo : &&
301 git commit --amend -massaged &&
302 git push testrepo +: &&
303 ! check_push_result testrepo $the_commit heads/master &&
304 git reset --hard $the_commit
308 test_expect_success
'push with no ambiguity (1)' '
310 mk_test testrepo heads/master &&
311 git push testrepo master:master &&
312 check_push_result testrepo $the_commit heads/master
316 test_expect_success
'push with no ambiguity (2)' '
318 mk_test testrepo remotes/origin/master &&
319 git push testrepo master:origin/master &&
320 check_push_result testrepo $the_commit remotes/origin/master
324 test_expect_success
'push with colon-less refspec, no ambiguity' '
326 mk_test testrepo heads/master heads/t/master &&
327 git branch -f t/master master &&
328 git push testrepo master &&
329 check_push_result testrepo $the_commit heads/master &&
330 check_push_result testrepo $the_first_commit heads/t/master
334 test_expect_success
'push with weak ambiguity (1)' '
336 mk_test testrepo heads/master remotes/origin/master &&
337 git push testrepo master:master &&
338 check_push_result testrepo $the_commit heads/master &&
339 check_push_result testrepo $the_first_commit remotes/origin/master
343 test_expect_success
'push with weak ambiguity (2)' '
345 mk_test testrepo heads/master remotes/origin/master remotes/another/master &&
346 git push testrepo master:master &&
347 check_push_result testrepo $the_commit heads/master &&
348 check_push_result testrepo $the_first_commit remotes/origin/master remotes/another/master
352 test_expect_success
'push with ambiguity' '
354 mk_test testrepo heads/frotz tags/frotz &&
355 test_must_fail git push testrepo master:frotz &&
356 check_push_result testrepo $the_first_commit heads/frotz tags/frotz
360 test_expect_success
'push with colon-less refspec (1)' '
362 mk_test testrepo heads/frotz tags/frotz &&
363 git branch -f frotz master &&
364 git push testrepo frotz &&
365 check_push_result testrepo $the_commit heads/frotz &&
366 check_push_result testrepo $the_first_commit tags/frotz
370 test_expect_success
'push with colon-less refspec (2)' '
372 mk_test testrepo heads/frotz tags/frotz &&
373 if git show-ref --verify -q refs/heads/frotz
378 git push -f testrepo frotz &&
379 check_push_result testrepo $the_commit tags/frotz &&
380 check_push_result testrepo $the_first_commit heads/frotz
384 test_expect_success
'push with colon-less refspec (3)' '
387 if git show-ref --verify -q refs/tags/frotz
391 git branch -f frotz master &&
392 git push testrepo frotz &&
393 check_push_result testrepo $the_commit heads/frotz &&
394 test 1 = $( cd testrepo && git show-ref | wc -l )
397 test_expect_success
'push with colon-less refspec (4)' '
400 if git show-ref --verify -q refs/heads/frotz
405 git push testrepo frotz &&
406 check_push_result testrepo $the_commit tags/frotz &&
407 test 1 = $( cd testrepo && git show-ref | wc -l )
411 test_expect_success
'push head with non-existent, incomplete dest' '
414 git push testrepo master:branch &&
415 check_push_result testrepo $the_commit heads/branch
419 test_expect_success
'push tag with non-existent, incomplete dest' '
423 git push testrepo v1.0:tag &&
424 check_push_result testrepo $the_commit tags/tag
428 test_expect_success
'push sha1 with non-existent, incomplete dest' '
431 test_must_fail git push testrepo $(git rev-parse master):foo
435 test_expect_success
'push ref expression with non-existent, incomplete dest' '
438 test_must_fail git push testrepo master^:branch
442 test_expect_success
'push with HEAD' '
444 mk_test testrepo heads/master &&
445 git checkout master &&
446 git push testrepo HEAD &&
447 check_push_result testrepo $the_commit heads/master
451 test_expect_success
'push with HEAD nonexisting at remote' '
453 mk_test testrepo heads/master &&
454 git checkout -b local master &&
455 git push testrepo HEAD &&
456 check_push_result testrepo $the_commit heads/local
459 test_expect_success
'push with +HEAD' '
461 mk_test testrepo heads/master &&
462 git checkout master &&
463 git branch -D local &&
464 git checkout -b local &&
465 git push testrepo master local &&
466 check_push_result testrepo $the_commit heads/master &&
467 check_push_result testrepo $the_commit heads/local &&
469 # Without force rewinding should fail
470 git reset --hard HEAD^ &&
471 test_must_fail git push testrepo HEAD &&
472 check_push_result testrepo $the_commit heads/local &&
474 # With force rewinding should succeed
475 git push testrepo +HEAD &&
476 check_push_result testrepo $the_first_commit heads/local
480 test_expect_success
'push HEAD with non-existent, incomplete dest' '
483 git checkout master &&
484 git push testrepo HEAD:branch &&
485 check_push_result testrepo $the_commit heads/branch
489 test_expect_success
'push with config remote.*.push = HEAD' '
491 mk_test testrepo heads/local &&
492 git checkout master &&
493 git branch -f local $the_commit &&
496 git checkout local &&
497 git reset --hard $the_first_commit
499 test_config remote.there.url testrepo &&
500 test_config remote.there.push HEAD &&
501 test_config branch.master.remote there &&
503 check_push_result testrepo $the_commit heads/master &&
504 check_push_result testrepo $the_first_commit heads/local
507 test_expect_success
'push with remote.pushdefault' '
508 mk_test up_repo heads/master &&
509 mk_test down_repo heads/master &&
510 test_config remote.up.url up_repo &&
511 test_config remote.down.url down_repo &&
512 test_config branch.master.remote up &&
513 test_config remote.pushdefault down &&
514 test_config push.default matching &&
516 check_push_result up_repo $the_first_commit heads/master &&
517 check_push_result down_repo $the_commit heads/master
520 test_expect_success
'push with config remote.*.pushurl' '
522 mk_test testrepo heads/master &&
523 git checkout master &&
524 test_config remote.there.url test2repo &&
525 test_config remote.there.pushurl testrepo &&
527 check_push_result testrepo $the_commit heads/master
530 test_expect_success
'push with config branch.*.pushremote' '
531 mk_test up_repo heads/master &&
532 mk_test side_repo heads/master &&
533 mk_test down_repo heads/master &&
534 test_config remote.up.url up_repo &&
535 test_config remote.pushdefault side_repo &&
536 test_config remote.down.url down_repo &&
537 test_config branch.master.remote up &&
538 test_config branch.master.pushremote down &&
539 test_config push.default matching &&
541 check_push_result up_repo $the_first_commit heads/master &&
542 check_push_result side_repo $the_first_commit heads/master &&
543 check_push_result down_repo $the_commit heads/master
546 test_expect_success
'branch.*.pushremote config order is irrelevant' '
547 mk_test one_repo heads/master &&
548 mk_test two_repo heads/master &&
549 test_config remote.one.url one_repo &&
550 test_config remote.two.url two_repo &&
551 test_config branch.master.pushremote two_repo &&
552 test_config remote.pushdefault one_repo &&
553 test_config push.default matching &&
555 check_push_result one_repo $the_first_commit heads/master &&
556 check_push_result two_repo $the_commit heads/master
559 test_expect_success
'push with dry-run' '
561 mk_test testrepo heads/master &&
562 old_commit=$(git -C testrepo show-ref -s --verify refs/heads/master) &&
563 git push --dry-run testrepo : &&
564 check_push_result testrepo $old_commit heads/master
567 test_expect_success
'push updates local refs' '
569 mk_test testrepo heads/master &&
570 mk_child testrepo child &&
573 git pull .. master &&
575 test $(git rev-parse master) = \
576 $(git rev-parse remotes/origin/master)
581 test_expect_success
'push updates up-to-date local refs' '
583 mk_test testrepo heads/master &&
584 mk_child testrepo child1 &&
585 mk_child testrepo child2 &&
586 (cd child1 && git pull .. master && git push) &&
589 git pull ../child1 master &&
591 test $(git rev-parse master) = \
592 $(git rev-parse remotes/origin/master)
597 test_expect_success
'push preserves up-to-date packed refs' '
599 mk_test testrepo heads/master &&
600 mk_child testrepo child &&
604 ! test -f .git/refs/remotes/origin/master
609 test_expect_success
'push does not update local refs on failure' '
611 mk_test testrepo heads/master &&
612 mk_child testrepo child &&
613 mkdir testrepo/.git/hooks &&
614 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
615 chmod +x testrepo/.git/hooks/pre-receive &&
618 git pull .. master &&
619 test_must_fail git push &&
620 test $(git rev-parse master) != \
621 $(git rev-parse remotes/origin/master)
626 test_expect_success
'allow deleting an invalid remote ref' '
628 mk_test testrepo heads/master &&
629 rm -f testrepo/.git/objects/??/* &&
630 git push testrepo :refs/heads/master &&
631 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
635 test_expect_success
'pushing valid refs triggers post-receive and post-update hooks' '
636 mk_test_with_hooks testrepo heads/master heads/next &&
637 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
638 newmaster=$(git show-ref -s --verify refs/heads/master) &&
639 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
641 git push testrepo refs/heads/master:refs/heads/master :refs/heads/next &&
644 cat >pre-receive.expect <<-EOF &&
645 $orgmaster $newmaster refs/heads/master
646 $orgnext $newnext refs/heads/next
649 cat >update.expect <<-EOF &&
650 refs/heads/master $orgmaster $newmaster
651 refs/heads/next $orgnext $newnext
654 cat >post-receive.expect <<-EOF &&
655 $orgmaster $newmaster refs/heads/master
656 $orgnext $newnext refs/heads/next
659 cat >post-update.expect <<-EOF &&
664 test_cmp pre-receive.expect pre-receive.actual &&
665 test_cmp update.expect update.actual &&
666 test_cmp post-receive.expect post-receive.actual &&
667 test_cmp post-update.expect post-update.actual
671 test_expect_success
'deleting dangling ref triggers hooks with correct args' '
672 mk_test_with_hooks testrepo heads/master &&
673 rm -f testrepo/.git/objects/??/* &&
674 git push testrepo :refs/heads/master &&
677 cat >pre-receive.expect <<-EOF &&
678 $ZERO_OID $ZERO_OID refs/heads/master
681 cat >update.expect <<-EOF &&
682 refs/heads/master $ZERO_OID $ZERO_OID
685 cat >post-receive.expect <<-EOF &&
686 $ZERO_OID $ZERO_OID refs/heads/master
689 cat >post-update.expect <<-EOF &&
693 test_cmp pre-receive.expect pre-receive.actual &&
694 test_cmp update.expect update.actual &&
695 test_cmp post-receive.expect post-receive.actual &&
696 test_cmp post-update.expect post-update.actual
700 test_expect_success
'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
701 mk_test_with_hooks testrepo heads/master &&
702 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
703 newmaster=$(git show-ref -s --verify refs/heads/master) &&
704 git push testrepo master :refs/heads/nonexistent &&
707 cat >pre-receive.expect <<-EOF &&
708 $orgmaster $newmaster refs/heads/master
709 $ZERO_OID $ZERO_OID refs/heads/nonexistent
712 cat >update.expect <<-EOF &&
713 refs/heads/master $orgmaster $newmaster
714 refs/heads/nonexistent $ZERO_OID $ZERO_OID
717 cat >post-receive.expect <<-EOF &&
718 $orgmaster $newmaster refs/heads/master
721 cat >post-update.expect <<-EOF &&
725 test_cmp pre-receive.expect pre-receive.actual &&
726 test_cmp update.expect update.actual &&
727 test_cmp post-receive.expect post-receive.actual &&
728 test_cmp post-update.expect post-update.actual
732 test_expect_success
'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
733 mk_test_with_hooks testrepo heads/master &&
734 git push testrepo :refs/heads/nonexistent &&
737 cat >pre-receive.expect <<-EOF &&
738 $ZERO_OID $ZERO_OID refs/heads/nonexistent
741 cat >update.expect <<-EOF &&
742 refs/heads/nonexistent $ZERO_OID $ZERO_OID
745 test_cmp pre-receive.expect pre-receive.actual &&
746 test_cmp update.expect update.actual &&
747 test_path_is_missing post-receive.actual &&
748 test_path_is_missing post-update.actual
752 test_expect_success
'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
753 mk_test_with_hooks testrepo heads/master heads/next heads/seen &&
754 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
755 newmaster=$(git show-ref -s --verify refs/heads/master) &&
756 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
758 orgseen=$(cd testrepo && git show-ref -s --verify refs/heads/seen) &&
759 newseen=$(git show-ref -s --verify refs/heads/master) &&
760 git push testrepo refs/heads/master:refs/heads/master \
761 refs/heads/master:refs/heads/seen :refs/heads/next \
762 :refs/heads/nonexistent &&
765 cat >pre-receive.expect <<-EOF &&
766 $orgmaster $newmaster refs/heads/master
767 $orgnext $newnext refs/heads/next
768 $orgseen $newseen refs/heads/seen
769 $ZERO_OID $ZERO_OID refs/heads/nonexistent
772 cat >update.expect <<-EOF &&
773 refs/heads/master $orgmaster $newmaster
774 refs/heads/next $orgnext $newnext
775 refs/heads/seen $orgseen $newseen
776 refs/heads/nonexistent $ZERO_OID $ZERO_OID
779 cat >post-receive.expect <<-EOF &&
780 $orgmaster $newmaster refs/heads/master
781 $orgnext $newnext refs/heads/next
782 $orgseen $newseen refs/heads/seen
785 cat >post-update.expect <<-EOF &&
791 test_cmp pre-receive.expect pre-receive.actual &&
792 test_cmp update.expect update.actual &&
793 test_cmp post-receive.expect post-receive.actual &&
794 test_cmp post-update.expect post-update.actual
798 test_expect_success
'allow deleting a ref using --delete' '
799 mk_test testrepo heads/master &&
800 (cd testrepo && git config receive.denyDeleteCurrent warn) &&
801 git push testrepo --delete master &&
802 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
805 test_expect_success
'allow deleting a tag using --delete' '
806 mk_test testrepo heads/master &&
807 git tag -a -m dummy_message deltag heads/master &&
808 git push testrepo --tags &&
809 (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
810 git push testrepo --delete tag deltag &&
811 (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
814 test_expect_success
'push --delete without args aborts' '
815 mk_test testrepo heads/master &&
816 test_must_fail git push testrepo --delete
819 test_expect_success
'push --delete refuses src:dest refspecs' '
820 mk_test testrepo heads/master &&
821 test_must_fail git push testrepo --delete master:foo
824 test_expect_success
'warn on push to HEAD of non-bare repository' '
825 mk_test testrepo heads/master &&
828 git checkout master &&
829 git config receive.denyCurrentBranch warn
831 git push testrepo master 2>stderr &&
832 grep "warning: updating the current branch" stderr
835 test_expect_success
'deny push to HEAD of non-bare repository' '
836 mk_test testrepo heads/master &&
839 git checkout master &&
840 git config receive.denyCurrentBranch true
842 test_must_fail git push testrepo master
845 test_expect_success
'allow push to HEAD of bare repository (bare)' '
846 mk_test testrepo heads/master &&
849 git checkout master &&
850 git config receive.denyCurrentBranch true &&
851 git config core.bare true
853 git push testrepo master 2>stderr &&
854 ! grep "warning: updating the current branch" stderr
857 test_expect_success
'allow push to HEAD of non-bare repository (config)' '
858 mk_test testrepo heads/master &&
861 git checkout master &&
862 git config receive.denyCurrentBranch false
864 git push testrepo master 2>stderr &&
865 ! grep "warning: updating the current branch" stderr
868 test_expect_success
'fetch with branches' '
870 git branch second $the_first_commit &&
871 git checkout second &&
872 echo ".." > testrepo/.git/branches/branch1 &&
876 echo "$the_commit commit refs/heads/branch1" >expect &&
877 git for-each-ref refs/heads >actual &&
878 test_cmp expect actual
883 test_expect_success
'fetch with branches containing #' '
885 echo "..#second" > testrepo/.git/branches/branch2 &&
889 echo "$the_first_commit commit refs/heads/branch2" >expect &&
890 git for-each-ref refs/heads >actual &&
891 test_cmp expect actual
896 test_expect_success
'push with branches' '
898 git checkout second &&
899 echo "testrepo" > .git/branches/branch1 &&
903 echo "$the_first_commit commit refs/heads/master" >expect &&
904 git for-each-ref refs/heads >actual &&
905 test_cmp expect actual
909 test_expect_success
'push with branches containing #' '
911 echo "testrepo#branch3" > .git/branches/branch2 &&
915 echo "$the_first_commit commit refs/heads/branch3" >expect &&
916 git for-each-ref refs/heads >actual &&
917 test_cmp expect actual
922 test_expect_success
'push into aliased refs (consistent)' '
923 mk_test testrepo heads/master &&
924 mk_child testrepo child1 &&
925 mk_child testrepo child2 &&
929 git symbolic-ref refs/heads/bar refs/heads/foo &&
930 git config receive.denyCurrentBranch false
937 git commit -a -m child2 &&
940 git push ../child1 foo bar
944 test_expect_success
'push into aliased refs (inconsistent)' '
945 mk_test testrepo heads/master &&
946 mk_child testrepo child1 &&
947 mk_child testrepo child2 &&
951 git symbolic-ref refs/heads/bar refs/heads/foo &&
952 git config receive.denyCurrentBranch false
959 git commit -a -m child2 &&
964 git commit -a -m child2 &&
966 test_must_fail git push ../child1 foo bar 2>stderr &&
967 grep "refusing inconsistent update" stderr
971 test_force_push_tag
() {
972 tag_type_description
=$1
975 test_expect_success
"force pushing required to update $tag_type_description" "
976 mk_test testrepo heads/master &&
977 mk_child testrepo child1 &&
978 mk_child testrepo child2 &&
982 git push ../child2 testTag &&
985 git commit -m 'file1' &&
986 git tag $tag_args testTag &&
987 test_must_fail git push ../child2 testTag &&
988 git push --force ../child2 testTag &&
989 git tag $tag_args testTag HEAD~ &&
990 test_must_fail git push ../child2 testTag &&
991 git push --force ../child2 testTag &&
993 # Clobbering without + in refspec needs --force
994 git tag -f testTag &&
995 test_must_fail git push ../child2 'refs/tags/*:refs/tags/*' &&
996 git push --force ../child2 'refs/tags/*:refs/tags/*' &&
998 # Clobbering with + in refspec does not need --force
999 git tag -f testTag HEAD~ &&
1000 git push ../child2 '+refs/tags/*:refs/tags/*' &&
1002 # Clobbering with --no-force still obeys + in refspec
1003 git tag -f testTag &&
1004 git push --no-force ../child2 '+refs/tags/*:refs/tags/*' &&
1006 # Clobbering with/without --force and 'tag <name>' format
1007 git tag -f testTag HEAD~ &&
1008 test_must_fail git push ../child2 tag testTag &&
1009 git push --force ../child2 tag testTag
1014 test_force_push_tag
"lightweight tag" "-f"
1015 test_force_push_tag
"annotated tag" "-f -a -m'tag message'"
1017 test_force_fetch_tag
() {
1018 tag_type_description
=$1
1021 test_expect_success
"fetch will not clobber an existing $tag_type_description without --force" "
1022 mk_test testrepo heads/master &&
1023 mk_child testrepo child1 &&
1024 mk_child testrepo child2 &&
1028 git -C ../child1 fetch origin tag testTag &&
1031 git commit -m 'file1' &&
1032 git tag $tag_args testTag &&
1033 test_must_fail git -C ../child1 fetch origin tag testTag &&
1034 git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*'
1039 test_force_fetch_tag
"lightweight tag" "-f"
1040 test_force_fetch_tag
"annotated tag" "-f -a -m'tag message'"
1042 test_expect_success
'push --porcelain' '
1043 mk_empty testrepo &&
1044 echo >.git/foo "To testrepo" &&
1045 echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new reference]" &&
1046 echo >>.git/foo "Done" &&
1047 git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master &&
1050 echo "$the_commit commit refs/remotes/origin/master" >expect &&
1051 git for-each-ref refs/remotes/origin >actual &&
1052 test_cmp expect actual
1054 test_cmp .git/foo .git/bar
1057 test_expect_success
'push --porcelain bad url' '
1058 mk_empty testrepo &&
1059 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
1060 ! grep -q Done .git/bar
1063 test_expect_success
'push --porcelain rejected' '
1064 mk_empty testrepo &&
1065 git push testrepo refs/heads/master:refs/remotes/origin/master &&
1067 git reset --hard origin/master^ &&
1068 git config receive.denyCurrentBranch true) &&
1070 echo >.git/foo "To testrepo" &&
1071 echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" &&
1072 echo >>.git/foo "Done" &&
1074 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master &&
1075 test_cmp .git/foo .git/bar
1078 test_expect_success
'push --porcelain --dry-run rejected' '
1079 mk_empty testrepo &&
1080 git push testrepo refs/heads/master:refs/remotes/origin/master &&
1082 git reset --hard origin/master &&
1083 git config receive.denyCurrentBranch true) &&
1085 echo >.git/foo "To testrepo" &&
1086 echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" &&
1087 echo >>.git/foo "Done" &&
1089 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master &&
1090 test_cmp .git/foo .git/bar
1093 test_expect_success
'push --prune' '
1094 mk_test testrepo heads/master heads/second heads/foo heads/bar &&
1095 git push --prune testrepo : &&
1096 check_push_result testrepo $the_commit heads/master &&
1097 check_push_result testrepo $the_first_commit heads/second &&
1098 ! check_push_result testrepo $the_first_commit heads/foo heads/bar
1101 test_expect_success
'push --prune refspec' '
1102 mk_test testrepo tmp/master tmp/second tmp/foo tmp/bar &&
1103 git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
1104 check_push_result testrepo $the_commit tmp/master &&
1105 check_push_result testrepo $the_first_commit tmp/second &&
1106 ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
1109 for configsection
in transfer receive
1111 test_expect_success
"push to update a ref hidden by $configsection.hiderefs" '
1112 mk_test testrepo heads/master hidden/one hidden/two hidden/three &&
1115 git config $configsection.hiderefs refs/hidden
1118 # push to unhidden ref succeeds normally
1119 git push testrepo master:refs/heads/master &&
1120 check_push_result testrepo $the_commit heads/master &&
1122 # push to update a hidden ref should fail
1123 test_must_fail git push testrepo master:refs/hidden/one &&
1124 check_push_result testrepo $the_first_commit hidden/one &&
1126 # push to delete a hidden ref should fail
1127 test_must_fail git push testrepo :refs/hidden/two &&
1128 check_push_result testrepo $the_first_commit hidden/two &&
1130 # idempotent push to update a hidden ref should fail
1131 test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
1132 check_push_result testrepo $the_first_commit hidden/three
1136 test_expect_success
'fetch exact SHA1' '
1137 mk_test testrepo heads/master hidden/one &&
1138 git push testrepo master:refs/hidden/one &&
1141 git config transfer.hiderefs refs/hidden
1143 check_push_result testrepo $the_commit hidden/one &&
1145 mk_child testrepo child &&
1149 # make sure $the_commit does not exist here
1152 test_must_fail git cat-file -t $the_commit &&
1154 # Some protocol versions (e.g. 2) support fetching
1155 # unadvertised objects, so restrict this test to v0.
1157 # fetching the hidden object should fail by default
1158 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1159 git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err &&
1160 test_i18ngrep "Server does not allow request for unadvertised object" err &&
1161 test_must_fail git rev-parse --verify refs/heads/copy &&
1163 # the server side can allow it to succeed
1166 git config uploadpack.allowtipsha1inwant true
1169 git fetch -v ../testrepo $the_commit:refs/heads/copy master:refs/heads/extra &&
1170 cat >expect <<-EOF &&
1175 git rev-parse --verify refs/heads/copy &&
1176 git rev-parse --verify refs/heads/extra
1178 test_cmp expect actual
1182 test_expect_success
'fetch exact SHA1 in protocol v2' '
1183 mk_test testrepo heads/master hidden/one &&
1184 git push testrepo master:refs/hidden/one &&
1185 git -C testrepo config transfer.hiderefs refs/hidden &&
1186 check_push_result testrepo $the_commit hidden/one &&
1188 mk_child testrepo child &&
1189 git -C child config protocol.version 2 &&
1191 # make sure $the_commit does not exist here
1192 git -C child repack -a -d &&
1193 git -C child prune &&
1194 test_must_fail git -C child cat-file -t $the_commit &&
1196 # fetching the hidden object succeeds by default
1197 # NEEDSWORK: should this match the v0 behavior instead?
1198 git -C child fetch -v ../testrepo $the_commit:refs/heads/copy
1201 for configallowtipsha1inwant
in true false
1203 test_expect_success
"shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" '
1204 mk_empty testrepo &&
1207 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1208 git commit --allow-empty -m foo &&
1209 git commit --allow-empty -m bar
1211 SHA1=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1215 # Some protocol versions (e.g. 2) support fetching
1216 # unadvertised objects, so restrict this test to v0.
1217 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1218 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1219 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1220 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1221 git cat-file commit $SHA1
1225 test_expect_success
"deny fetch unreachable SHA1, allowtipsha1inwant=$configallowtipsha1inwant" '
1226 mk_empty testrepo &&
1229 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1230 git commit --allow-empty -m foo &&
1231 git commit --allow-empty -m bar &&
1232 git commit --allow-empty -m xyz
1234 SHA1_1=$(git --git-dir=testrepo/.git rev-parse HEAD^^) &&
1235 SHA1_2=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1236 SHA1_3=$(git --git-dir=testrepo/.git rev-parse HEAD) &&
1239 git reset --hard $SHA1_2 &&
1240 git cat-file commit $SHA1_1 &&
1241 git cat-file commit $SHA1_3
1246 # Some protocol versions (e.g. 2) support fetching
1247 # unadvertised objects, so restrict this test to v0.
1248 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1249 git fetch ../testrepo/.git $SHA1_3 &&
1250 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1251 git fetch ../testrepo/.git $SHA1_1 &&
1252 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1253 git fetch ../testrepo/.git $SHA1_1 &&
1254 git cat-file commit $SHA1_1 &&
1255 test_must_fail git cat-file commit $SHA1_2 &&
1256 git fetch ../testrepo/.git $SHA1_2 &&
1257 git cat-file commit $SHA1_2 &&
1258 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1259 git fetch ../testrepo/.git $SHA1_3 2>err &&
1260 test_i18ngrep "remote error:.*not our ref.*$SHA1_3\$" err
1265 test_expect_success
'fetch follows tags by default' '
1266 mk_test testrepo heads/master &&
1271 git pull ../testrepo master &&
1272 git tag -m "annotated" tag &&
1273 git for-each-ref >tmp1 &&
1276 sed -n "s|refs/heads/master$|refs/remotes/origin/master|p" tmp1
1278 sort -k 3 >../expect
1283 git remote add origin ../src &&
1284 git config branch.master.remote origin &&
1285 git config branch.master.merge refs/heads/master &&
1287 git for-each-ref >../actual
1289 test_cmp expect actual
1292 test_expect_success
'peeled advertisements are not considered ref tips' '
1293 mk_empty testrepo &&
1294 git -C testrepo commit --allow-empty -m one &&
1295 git -C testrepo commit --allow-empty -m two &&
1296 git -C testrepo tag -m foo mytag HEAD^ &&
1297 oid=$(git -C testrepo rev-parse mytag^{commit}) &&
1298 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1299 git fetch testrepo $oid 2>err &&
1300 test_i18ngrep "Server does not allow request for unadvertised object" err
1303 test_expect_success
'pushing a specific ref applies remote.$name.push as refmap' '
1304 mk_test testrepo heads/master &&
1307 git init --bare dst &&
1310 git pull ../testrepo master &&
1312 git config remote.dst.url ../dst &&
1313 git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" &&
1314 git push dst master &&
1315 git show-ref refs/heads/master |
1316 sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect
1320 test_must_fail git show-ref refs/heads/next &&
1321 test_must_fail git show-ref refs/heads/master &&
1322 git show-ref refs/remotes/src/master >actual
1324 test_cmp dst/expect dst/actual
1327 test_expect_success
'with no remote.$name.push, it is not used as refmap' '
1328 mk_test testrepo heads/master &&
1331 git init --bare dst &&
1334 git pull ../testrepo master &&
1336 git config remote.dst.url ../dst &&
1337 git config push.default matching &&
1338 git push dst master &&
1339 git show-ref refs/heads/master >../dst/expect
1343 test_must_fail git show-ref refs/heads/next &&
1344 git show-ref refs/heads/master >actual
1346 test_cmp dst/expect dst/actual
1349 test_expect_success
'with no remote.$name.push, upstream mapping is used' '
1350 mk_test testrepo heads/master &&
1353 git init --bare dst &&
1356 git pull ../testrepo master &&
1358 git config remote.dst.url ../dst &&
1359 git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" &&
1360 git config push.default upstream &&
1362 git config branch.master.merge refs/heads/trunk &&
1363 git config branch.master.remote dst &&
1365 git push dst master &&
1366 git show-ref refs/heads/master |
1367 sed -e "s|refs/heads/master|refs/heads/trunk|" >../dst/expect
1371 test_must_fail git show-ref refs/heads/master &&
1372 test_must_fail git show-ref refs/heads/next &&
1373 git show-ref refs/heads/trunk >actual
1375 test_cmp dst/expect dst/actual
1378 test_expect_success
'push does not follow tags by default' '
1379 mk_test testrepo heads/master &&
1382 git init --bare dst &&
1385 git pull ../testrepo master &&
1386 git tag -m "annotated" tag &&
1387 git checkout -b another &&
1388 git commit --allow-empty -m "future commit" &&
1389 git tag -m "future" future &&
1390 git checkout master &&
1391 git for-each-ref refs/heads/master >../expect &&
1392 git push ../dst master
1396 git for-each-ref >../actual
1398 test_cmp expect actual
1401 test_expect_success
'push --follow-tags only pushes relevant tags' '
1402 mk_test testrepo heads/master &&
1405 git init --bare dst &&
1408 git pull ../testrepo master &&
1409 git tag -m "annotated" tag &&
1410 git checkout -b another &&
1411 git commit --allow-empty -m "future commit" &&
1412 git tag -m "future" future &&
1413 git checkout master &&
1414 git for-each-ref refs/heads/master refs/tags/tag >../expect &&
1415 git push --follow-tags ../dst master
1419 git for-each-ref >../actual
1421 test_cmp expect actual
1424 test_expect_success
'push --no-thin must produce non-thin pack' '
1425 cat >>path1 <<\EOF &&
1426 keep base version of path1 big enough, compared to the new changes
1427 later, in order to pass size heuristics in
1428 builtin/pack-objects.c:try_delta()
1430 git commit -am initial &&
1432 git --git-dir=no-thin/.git config receive.unpacklimit 0 &&
1433 git push no-thin/.git refs/heads/master:refs/heads/foo &&
1434 echo modified >> path1 &&
1435 git commit -am modified &&
1437 rcvpck="git receive-pack --reject-thin-pack-for-testing" &&
1438 git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/master:refs/heads/foo
1441 test_expect_success
'pushing a tag pushes the tagged object' '
1443 blob=$(echo unreferenced | git hash-object -w --stdin) &&
1444 git tag -m foo tag-of-blob $blob &&
1445 git init --bare dst.git &&
1446 git push dst.git tag-of-blob &&
1447 # the receiving index-pack should have noticed
1448 # any problems, but we double check
1449 echo unreferenced >expect &&
1450 git --git-dir=dst.git cat-file blob tag-of-blob >actual &&
1451 test_cmp expect actual
1454 test_expect_success
'push into bare respects core.logallrefupdates' '
1456 git init --bare dst.git &&
1457 git -C dst.git config core.logallrefupdates true &&
1459 # double push to test both with and without
1460 # the actual pack transfer
1461 git push dst.git master:one &&
1462 echo "one@{0} push" >expect &&
1463 git -C dst.git log -g --format="%gd %gs" one >actual &&
1464 test_cmp expect actual &&
1466 git push dst.git master:two &&
1467 echo "two@{0} push" >expect &&
1468 git -C dst.git log -g --format="%gd %gs" two >actual &&
1469 test_cmp expect actual
1472 test_expect_success
'fetch into bare respects core.logallrefupdates' '
1474 git init --bare dst.git &&
1477 git config core.logallrefupdates true &&
1479 # as above, we double-fetch to test both
1480 # with and without pack transfer
1481 git fetch .. master:one &&
1482 echo "one@{0} fetch .. master:one: storing head" >expect &&
1483 git log -g --format="%gd %gs" one >actual &&
1484 test_cmp expect actual &&
1486 git fetch .. master:two &&
1487 echo "two@{0} fetch .. master:two: storing head" >expect &&
1488 git log -g --format="%gd %gs" two >actual &&
1489 test_cmp expect actual
1493 test_expect_success
'receive.denyCurrentBranch = updateInstead' '
1494 git push testrepo master &&
1498 git config receive.denyCurrentBranch updateInstead
1500 test_commit third path2 &&
1502 # Try pushing into a repository with pristine working tree
1503 git push testrepo master &&
1506 git update-index -q --refresh &&
1507 git diff-files --quiet -- &&
1508 git diff-index --quiet --cached HEAD -- &&
1509 test third = "$(cat path2)" &&
1510 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1513 # Try pushing into a repository with working tree needing a refresh
1516 git reset --hard HEAD^ &&
1517 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1518 test-tool chmtime +100 path1
1520 git push testrepo master &&
1523 git update-index -q --refresh &&
1524 git diff-files --quiet -- &&
1525 git diff-index --quiet --cached HEAD -- &&
1526 test_cmp ../path1 path1 &&
1527 test third = "$(cat path2)" &&
1528 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1531 # Update what is to be pushed
1532 test_commit fourth path2 &&
1534 # Try pushing into a repository with a dirty working tree
1535 # (1) the working tree updated
1540 test_must_fail git push testrepo master &&
1543 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1544 git diff --quiet --cached &&
1545 test changed = "$(cat path1)"
1548 # (2) the index updated
1551 echo changed >path1 &&
1554 test_must_fail git push testrepo master &&
1557 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1559 test changed = "$(cat path1)"
1562 # Introduce a new file in the update
1563 test_commit fifth path3 &&
1565 # (3) the working tree has an untracked file that would interfere
1571 test_must_fail git push testrepo master &&
1574 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1576 git diff --quiet --cached &&
1577 test changed = "$(cat path3)"
1580 # (4) the target changes to what gets pushed but it still is a change
1584 echo fifth >path3 &&
1587 test_must_fail git push testrepo master &&
1590 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1592 test fifth = "$(cat path3)"
1595 # (5) push into void
1600 git config receive.denyCurrentBranch updateInstead
1602 git push void master &&
1605 test $(git -C .. rev-parse master) = $(git rev-parse HEAD) &&
1607 git diff --cached --quiet
1610 # (6) updateInstead intervened by fast-forward check
1611 test_must_fail git push void master^:master &&
1612 test $(git -C void rev-parse HEAD) = $(git rev-parse master) &&
1613 git -C void diff --quiet &&
1614 git -C void diff --cached --quiet
1617 test_expect_success
'updateInstead with push-to-checkout hook' '
1619 git init testrepo &&
1622 git pull .. master &&
1623 git reset --hard HEAD^^ &&
1625 git config receive.denyCurrentBranch updateInstead &&
1626 write_script .git/hooks/push-to-checkout <<-\EOF
1627 echo >&2 updating from $(git rev-parse HEAD)
1628 echo >&2 updating to "$1"
1630 git update-index -q --refresh &&
1631 git read-tree -u -m HEAD "$1" || {
1633 echo >&2 read-tree failed
1639 # Try pushing into a pristine
1640 git push testrepo master &&
1644 git diff HEAD --quiet &&
1645 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1648 # Try pushing into a repository with conflicting change
1651 git reset --hard initial &&
1652 echo conflicting >path2
1654 test_must_fail git push testrepo master &&
1657 test $(git rev-parse initial) = $(git rev-parse HEAD) &&
1658 test conflicting = "$(cat path2)" &&
1659 git diff-index --quiet --cached HEAD
1662 # Try pushing into a repository with unrelated change
1665 git reset --hard initial &&
1666 echo unrelated >path1 &&
1667 echo irrelevant >path5 &&
1670 git push testrepo master &&
1673 test "$(cat path1)" = unrelated &&
1674 test "$(cat path5)" = irrelevant &&
1675 test "$(git diff --name-only --cached HEAD)" = path5 &&
1676 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1684 git config receive.denyCurrentBranch updateInstead &&
1685 write_script .git/hooks/push-to-checkout <<-\EOF
1686 if git rev-parse --quiet --verify HEAD
1689 echo >&2 updating from $(git rev-parse HEAD)
1692 echo >&2 pushing into void
1694 echo >&2 updating to "$1"
1696 git update-index -q --refresh &&
1699 git read-tree -u -m HEAD "$1" ;;
1701 git read-tree -u -m "$1" ;;
1704 echo >&2 read-tree failed
1710 git push void master &&
1714 git diff --cached --quiet &&
1715 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1719 test_expect_success
'denyCurrentBranch and worktrees' '
1720 git worktree add new-wt &&
1721 git clone . cloned &&
1722 test_commit -C cloned first &&
1723 test_config receive.denyCurrentBranch refuse &&
1724 test_must_fail git -C cloned push origin HEAD:new-wt &&
1725 test_config receive.denyCurrentBranch updateInstead &&
1726 git -C cloned push origin HEAD:new-wt &&
1727 test_must_fail git -C cloned push --delete origin new-wt