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 () {
106 git show-ref -s --verify refs/$ref >actual &&
107 test_cmp expect actual ||
114 test_expect_success setup '
119 git commit -a -m repo &&
120 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
125 git commit -a -m second &&
126 the_commit=$(git show-ref -s --verify refs/heads/master)
130 test_expect_success 'fetch without wildcard' '
134 git fetch .. refs/heads/master:refs/remotes/origin/master &&
136 echo "$the_commit commit refs/remotes/origin/master" >expect &&
137 git for-each-ref refs/remotes/origin >actual &&
138 test_cmp expect actual
142 test_expect_success 'fetch with wildcard' '
146 git config remote.up.url .. &&
147 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
150 echo "$the_commit commit refs/remotes/origin/master" >expect &&
151 git for-each-ref refs/remotes/origin >actual &&
152 test_cmp expect actual
156 test_expect_success 'fetch with insteadOf' '
161 git config "url.$TRASH.insteadOf" trash/ &&
162 git config remote.up.url trash/. &&
163 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
166 echo "$the_commit commit refs/remotes/origin/master" >expect &&
167 git for-each-ref refs/remotes/origin >actual &&
168 test_cmp expect actual
172 test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
177 git config "url.trash/.pushInsteadOf" "$TRASH" &&
178 git config remote.up.url "$TRASH." &&
179 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
182 echo "$the_commit commit refs/remotes/origin/master" >expect &&
183 git for-each-ref refs/remotes/origin >actual &&
184 test_cmp expect actual
188 test_expect_success 'push without wildcard' '
191 git push testrepo refs/heads/master:refs/remotes/origin/master &&
194 echo "$the_commit commit refs/remotes/origin/master" >expect &&
195 git for-each-ref refs/remotes/origin >actual &&
196 test_cmp expect actual
200 test_expect_success 'push with wildcard' '
203 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
206 echo "$the_commit commit refs/remotes/origin/master" >expect &&
207 git for-each-ref refs/remotes/origin >actual &&
208 test_cmp expect actual
212 test_expect_success 'push with insteadOf' '
215 test_config "url.$TRASH.insteadOf" trash/ &&
216 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
219 echo "$the_commit commit refs/remotes/origin/master" >expect &&
220 git for-each-ref refs/remotes/origin >actual &&
221 test_cmp expect actual
225 test_expect_success 'push with pushInsteadOf' '
228 test_config "url.$TRASH.pushInsteadOf" trash/ &&
229 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
232 echo "$the_commit commit refs/remotes/origin/master" >expect &&
233 git for-each-ref refs/remotes/origin >actual &&
234 test_cmp expect actual
238 test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
240 test_config "url.trash2/.pushInsteadOf" testrepo/ &&
241 test_config "url.trash3/.pushInsteadOf" trash/wrong &&
242 test_config remote.r.url trash/wrong &&
243 test_config remote.r.pushurl "testrepo/" &&
244 git push r refs/heads/master:refs/remotes/origin/master &&
247 echo "$the_commit commit refs/remotes/origin/master" >expect &&
248 git for-each-ref refs/remotes/origin >actual &&
249 test_cmp expect actual
253 test_expect_success 'push with matching heads' '
255 mk_test testrepo heads/master &&
256 git push testrepo : &&
257 check_push_result testrepo $the_commit heads/master
261 test_expect_success 'push with matching heads on the command line' '
263 mk_test testrepo heads/master &&
264 git push testrepo : &&
265 check_push_result testrepo $the_commit heads/master
269 test_expect_success 'failed (non-fast-forward) push with matching heads' '
271 mk_test testrepo heads/master &&
272 git push testrepo : &&
273 git commit --amend -massaged &&
274 test_must_fail git push testrepo &&
275 check_push_result testrepo $the_commit heads/master &&
276 git reset --hard $the_commit
280 test_expect_success 'push --force with matching heads' '
282 mk_test testrepo heads/master &&
283 git push testrepo : &&
284 git commit --amend -massaged &&
285 git push --force testrepo : &&
286 ! check_push_result testrepo $the_commit heads/master &&
287 git reset --hard $the_commit
291 test_expect_success 'push with matching heads and forced update' '
293 mk_test testrepo heads/master &&
294 git push testrepo : &&
295 git commit --amend -massaged &&
296 git push testrepo +: &&
297 ! check_push_result testrepo $the_commit heads/master &&
298 git reset --hard $the_commit
302 test_expect_success 'push with no ambiguity (1)' '
304 mk_test testrepo heads/master &&
305 git push testrepo master:master &&
306 check_push_result testrepo $the_commit heads/master
310 test_expect_success 'push with no ambiguity (2)' '
312 mk_test testrepo remotes/origin/master &&
313 git push testrepo master:origin/master &&
314 check_push_result testrepo $the_commit remotes/origin/master
318 test_expect_success 'push with colon-less refspec, no ambiguity' '
320 mk_test testrepo heads/master heads/t/master &&
321 git branch -f t/master master &&
322 git push testrepo master &&
323 check_push_result testrepo $the_commit heads/master &&
324 check_push_result testrepo $the_first_commit heads/t/master
328 test_expect_success 'push with weak ambiguity (1)' '
330 mk_test testrepo heads/master remotes/origin/master &&
331 git push testrepo master:master &&
332 check_push_result testrepo $the_commit heads/master &&
333 check_push_result testrepo $the_first_commit remotes/origin/master
337 test_expect_success 'push with weak ambiguity (2)' '
339 mk_test testrepo heads/master remotes/origin/master remotes/another/master &&
340 git push testrepo master:master &&
341 check_push_result testrepo $the_commit heads/master &&
342 check_push_result testrepo $the_first_commit remotes/origin/master remotes/another/master
346 test_expect_success 'push with ambiguity' '
348 mk_test testrepo heads/frotz tags/frotz &&
349 test_must_fail git push testrepo master:frotz &&
350 check_push_result testrepo $the_first_commit heads/frotz tags/frotz
354 test_expect_success 'push with colon-less refspec (1)' '
356 mk_test testrepo heads/frotz tags/frotz &&
357 git branch -f frotz master &&
358 git push testrepo frotz &&
359 check_push_result testrepo $the_commit heads/frotz &&
360 check_push_result testrepo $the_first_commit tags/frotz
364 test_expect_success 'push with colon-less refspec (2)' '
366 mk_test testrepo heads/frotz tags/frotz &&
367 if git show-ref --verify -q refs/heads/frotz
372 git push -f testrepo frotz &&
373 check_push_result testrepo $the_commit tags/frotz &&
374 check_push_result testrepo $the_first_commit heads/frotz
378 test_expect_success 'push with colon-less refspec (3)' '
381 if git show-ref --verify -q refs/tags/frotz
385 git branch -f frotz master &&
386 git push testrepo frotz &&
387 check_push_result testrepo $the_commit heads/frotz &&
388 test 1 = $( cd testrepo && git show-ref | wc -l )
391 test_expect_success 'push with colon-less refspec (4)' '
394 if git show-ref --verify -q refs/heads/frotz
399 git push testrepo frotz &&
400 check_push_result testrepo $the_commit tags/frotz &&
401 test 1 = $( cd testrepo && git show-ref | wc -l )
405 test_expect_success 'push head with non-existent, incomplete dest' '
408 git push testrepo master:branch &&
409 check_push_result testrepo $the_commit heads/branch
413 test_expect_success 'push tag with non-existent, incomplete dest' '
417 git push testrepo v1.0:tag &&
418 check_push_result testrepo $the_commit tags/tag
422 test_expect_success 'push sha1 with non-existent, incomplete dest' '
425 test_must_fail git push testrepo $(git rev-parse master):foo
429 test_expect_success 'push ref expression with non-existent, incomplete dest' '
432 test_must_fail git push testrepo master^:branch
436 test_expect_success 'push with HEAD' '
438 mk_test testrepo heads/master &&
439 git checkout master &&
440 git push testrepo HEAD &&
441 check_push_result testrepo $the_commit heads/master
445 test_expect_success 'push with HEAD nonexisting at remote' '
447 mk_test testrepo heads/master &&
448 git checkout -b local master &&
449 git push testrepo HEAD &&
450 check_push_result testrepo $the_commit heads/local
453 test_expect_success 'push with +HEAD' '
455 mk_test testrepo heads/master &&
456 git checkout master &&
457 git branch -D local &&
458 git checkout -b local &&
459 git push testrepo master local &&
460 check_push_result testrepo $the_commit heads/master &&
461 check_push_result testrepo $the_commit heads/local &&
463 # Without force rewinding should fail
464 git reset --hard HEAD^ &&
465 test_must_fail git push testrepo HEAD &&
466 check_push_result testrepo $the_commit heads/local &&
468 # With force rewinding should succeed
469 git push testrepo +HEAD &&
470 check_push_result testrepo $the_first_commit heads/local
474 test_expect_success 'push HEAD with non-existent, incomplete dest' '
477 git checkout master &&
478 git push testrepo HEAD:branch &&
479 check_push_result testrepo $the_commit heads/branch
483 test_expect_success 'push with config remote.*.push = HEAD' '
485 mk_test testrepo heads/local &&
486 git checkout master &&
487 git branch -f local $the_commit &&
490 git checkout local &&
491 git reset --hard $the_first_commit
493 test_config remote.there.url testrepo &&
494 test_config remote.there.push HEAD &&
495 test_config branch.master.remote there &&
497 check_push_result testrepo $the_commit heads/master &&
498 check_push_result testrepo $the_first_commit heads/local
501 test_expect_success 'push with remote.pushdefault' '
502 mk_test up_repo heads/master &&
503 mk_test down_repo heads/master &&
504 test_config remote.up.url up_repo &&
505 test_config remote.down.url down_repo &&
506 test_config branch.master.remote up &&
507 test_config remote.pushdefault down &&
508 test_config push.default matching &&
510 check_push_result up_repo $the_first_commit heads/master &&
511 check_push_result down_repo $the_commit heads/master
514 test_expect_success 'push with config remote.*.pushurl' '
516 mk_test testrepo heads/master &&
517 git checkout master &&
518 test_config remote.there.url test2repo &&
519 test_config remote.there.pushurl testrepo &&
521 check_push_result testrepo $the_commit heads/master
524 test_expect_success 'push with config branch.*.pushremote' '
525 mk_test up_repo heads/master &&
526 mk_test side_repo heads/master &&
527 mk_test down_repo heads/master &&
528 test_config remote.up.url up_repo &&
529 test_config remote.pushdefault side_repo &&
530 test_config remote.down.url down_repo &&
531 test_config branch.master.remote up &&
532 test_config branch.master.pushremote down &&
533 test_config push.default matching &&
535 check_push_result up_repo $the_first_commit heads/master &&
536 check_push_result side_repo $the_first_commit heads/master &&
537 check_push_result down_repo $the_commit heads/master
540 test_expect_success 'branch.*.pushremote config order is irrelevant' '
541 mk_test one_repo heads/master &&
542 mk_test two_repo heads/master &&
543 test_config remote.one.url one_repo &&
544 test_config remote.two.url two_repo &&
545 test_config branch.master.pushremote two_repo &&
546 test_config remote.pushdefault one_repo &&
547 test_config push.default matching &&
549 check_push_result one_repo $the_first_commit heads/master &&
550 check_push_result two_repo $the_commit heads/master
553 test_expect_success 'push with dry-run' '
555 mk_test testrepo heads/master &&
558 old_commit=$(git 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 &&
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 $_z40 $_z40 refs/heads/master
678 cat >update.expect <<-EOF &&
679 refs/heads/master $_z40 $_z40
682 cat >post-receive.expect <<-EOF &&
683 $_z40 $_z40 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 $_z40 $_z40 refs/heads/nonexistent
709 cat >update.expect <<-EOF &&
710 refs/heads/master $orgmaster $newmaster
711 refs/heads/nonexistent $_z40 $_z40
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 $_z40 $_z40 refs/heads/nonexistent
738 cat >update.expect <<-EOF &&
739 refs/heads/nonexistent $_z40 $_z40
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/pu &&
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 orgpu=$(cd testrepo && git show-ref -s --verify refs/heads/pu) &&
756 newpu=$(git show-ref -s --verify refs/heads/master) &&
757 git push testrepo refs/heads/master:refs/heads/master \
758 refs/heads/master:refs/heads/pu :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 $orgpu $newpu refs/heads/pu
766 $_z40 $_z40 refs/heads/nonexistent
769 cat >update.expect <<-EOF &&
770 refs/heads/master $orgmaster $newmaster
771 refs/heads/next $orgnext $newnext
772 refs/heads/pu $orgpu $newpu
773 refs/heads/nonexistent $_z40 $_z40
776 cat >post-receive.expect <<-EOF &&
777 $orgmaster $newmaster refs/heads/master
778 $orgnext $newnext refs/heads/next
779 $orgpu $newpu refs/heads/pu
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_expect_success 'push requires --force to update lightweight tag' '
969 mk_test testrepo heads/master &&
970 mk_child testrepo child1 &&
971 mk_child testrepo child2 &&
975 git push ../child2 Tag &&
976 git push ../child2 Tag &&
979 git commit -m "file1" &&
981 test_must_fail git push ../child2 Tag &&
982 git push --force ../child2 Tag &&
984 test_must_fail git push ../child2 Tag HEAD~ &&
985 git push --force ../child2 Tag
989 test_expect_success 'push --porcelain' '
991 echo >.git/foo "To testrepo" &&
992 echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" &&
993 echo >>.git/foo "Done" &&
994 git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master &&
997 echo "$the_commit commit refs/remotes/origin/master" >expect &&
998 git for-each-ref refs/remotes/origin >actual &&
999 test_cmp expect actual
1001 test_cmp .git/foo .git/bar
1004 test_expect_success 'push --porcelain bad url' '
1005 mk_empty testrepo &&
1006 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
1007 ! grep -q Done .git/bar
1010 test_expect_success 'push --porcelain rejected' '
1011 mk_empty testrepo &&
1012 git push testrepo refs/heads/master:refs/remotes/origin/master &&
1014 git reset --hard origin/master^
1015 git config receive.denyCurrentBranch true) &&
1017 echo >.git/foo "To testrepo" &&
1018 echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" &&
1020 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master &&
1021 test_cmp .git/foo .git/bar
1024 test_expect_success 'push --porcelain --dry-run rejected' '
1025 mk_empty testrepo &&
1026 git push testrepo refs/heads/master:refs/remotes/origin/master &&
1028 git reset --hard origin/master
1029 git config receive.denyCurrentBranch true) &&
1031 echo >.git/foo "To testrepo" &&
1032 echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" &&
1033 echo >>.git/foo "Done" &&
1035 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master &&
1036 test_cmp .git/foo .git/bar
1039 test_expect_success 'push --prune' '
1040 mk_test testrepo heads/master heads/second heads/foo heads/bar &&
1041 git push --prune testrepo : &&
1042 check_push_result testrepo $the_commit heads/master &&
1043 check_push_result testrepo $the_first_commit heads/second &&
1044 ! check_push_result testrepo $the_first_commit heads/foo heads/bar
1047 test_expect_success 'push --prune refspec' '
1048 mk_test testrepo tmp/master tmp/second tmp/foo tmp/bar &&
1049 git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
1050 check_push_result testrepo $the_commit tmp/master &&
1051 check_push_result testrepo $the_first_commit tmp/second &&
1052 ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
1055 for configsection in transfer receive
1057 test_expect_success "push to update a ref hidden by $configsection.hiderefs" '
1058 mk_test testrepo heads/master hidden/one hidden/two hidden/three &&
1061 git config $configsection.hiderefs refs/hidden
1064 # push to unhidden ref succeeds normally
1065 git push testrepo master:refs/heads/master &&
1066 check_push_result testrepo $the_commit heads/master &&
1068 # push to update a hidden ref should fail
1069 test_must_fail git push testrepo master:refs/hidden/one &&
1070 check_push_result testrepo $the_first_commit hidden/one &&
1072 # push to delete a hidden ref should fail
1073 test_must_fail git push testrepo :refs/hidden/two &&
1074 check_push_result testrepo $the_first_commit hidden/two &&
1076 # idempotent push to update a hidden ref should fail
1077 test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
1078 check_push_result testrepo $the_first_commit hidden/three
1082 test_expect_success 'fetch exact SHA1' '
1083 mk_test testrepo heads/master hidden/one &&
1084 git push testrepo master:refs/hidden/one &&
1087 git config transfer.hiderefs refs/hidden
1089 check_push_result testrepo $the_commit hidden/one &&
1091 mk_child testrepo child &&
1095 # make sure $the_commit does not exist here
1098 test_must_fail git cat-file -t $the_commit &&
1100 # fetching the hidden object should fail by default
1101 test_must_fail git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err &&
1102 test_i18ngrep "Server does not allow request for unadvertised object" err &&
1103 test_must_fail git rev-parse --verify refs/heads/copy &&
1105 # the server side can allow it to succeed
1108 git config uploadpack.allowtipsha1inwant true
1111 git fetch -v ../testrepo $the_commit:refs/heads/copy master:refs/heads/extra &&
1112 cat >expect <<-EOF &&
1117 git rev-parse --verify refs/heads/copy &&
1118 git rev-parse --verify refs/heads/extra
1120 test_cmp expect actual
1124 for configallowtipsha1inwant in true false
1126 test_expect_success "shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" '
1127 mk_empty testrepo &&
1130 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1131 git commit --allow-empty -m foo &&
1132 git commit --allow-empty -m bar
1134 SHA1=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1138 test_must_fail git fetch --depth=1 ../testrepo/.git $SHA1 &&
1139 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1140 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1141 git cat-file commit $SHA1
1145 test_expect_success "deny fetch unreachable SHA1, allowtipsha1inwant=$configallowtipsha1inwant" '
1146 mk_empty testrepo &&
1149 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1150 git commit --allow-empty -m foo &&
1151 git commit --allow-empty -m bar &&
1152 git commit --allow-empty -m xyz
1154 SHA1_1=$(git --git-dir=testrepo/.git rev-parse HEAD^^) &&
1155 SHA1_2=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1156 SHA1_3=$(git --git-dir=testrepo/.git rev-parse HEAD) &&
1159 git reset --hard $SHA1_2 &&
1160 git cat-file commit $SHA1_1 &&
1161 git cat-file commit $SHA1_3
1166 test_must_fail ok=sigpipe git fetch ../testrepo/.git $SHA1_3 &&
1167 test_must_fail ok=sigpipe git fetch ../testrepo/.git $SHA1_1 &&
1168 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1169 git fetch ../testrepo/.git $SHA1_1 &&
1170 git cat-file commit $SHA1_1 &&
1171 test_must_fail git cat-file commit $SHA1_2 &&
1172 git fetch ../testrepo/.git $SHA1_2 &&
1173 git cat-file commit $SHA1_2 &&
1174 test_must_fail ok=sigpipe git fetch ../testrepo/.git $SHA1_3
1179 test_expect_success 'fetch follows tags by default' '
1180 mk_test testrepo heads/master &&
1185 git pull ../testrepo master &&
1186 git tag -m "annotated" tag &&
1187 git for-each-ref >tmp1 &&
1190 sed -n "s|refs/heads/master$|refs/remotes/origin/master|p" tmp1
1192 sort -k 3 >../expect
1197 git remote add origin ../src &&
1198 git config branch.master.remote origin &&
1199 git config branch.master.merge refs/heads/master &&
1201 git for-each-ref >../actual
1203 test_cmp expect actual
1206 test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' '
1207 mk_test testrepo heads/master &&
1210 git init --bare dst &&
1213 git pull ../testrepo master &&
1215 git config remote.dst.url ../dst &&
1216 git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" &&
1217 git push dst master &&
1218 git show-ref refs/heads/master |
1219 sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect
1223 test_must_fail git show-ref refs/heads/next &&
1224 test_must_fail git show-ref refs/heads/master &&
1225 git show-ref refs/remotes/src/master >actual
1227 test_cmp dst/expect dst/actual
1230 test_expect_success 'with no remote.$name.push, it is not used as refmap' '
1231 mk_test testrepo heads/master &&
1234 git init --bare dst &&
1237 git pull ../testrepo master &&
1239 git config remote.dst.url ../dst &&
1240 git config push.default matching &&
1241 git push dst master &&
1242 git show-ref refs/heads/master >../dst/expect
1246 test_must_fail git show-ref refs/heads/next &&
1247 git show-ref refs/heads/master >actual
1249 test_cmp dst/expect dst/actual
1252 test_expect_success 'with no remote.$name.push, upstream mapping is used' '
1253 mk_test testrepo heads/master &&
1256 git init --bare dst &&
1259 git pull ../testrepo master &&
1261 git config remote.dst.url ../dst &&
1262 git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" &&
1263 git config push.default upstream &&
1265 git config branch.master.merge refs/heads/trunk &&
1266 git config branch.master.remote dst &&
1268 git push dst master &&
1269 git show-ref refs/heads/master |
1270 sed -e "s|refs/heads/master|refs/heads/trunk|" >../dst/expect
1274 test_must_fail git show-ref refs/heads/master &&
1275 test_must_fail git show-ref refs/heads/next &&
1276 git show-ref refs/heads/trunk >actual
1278 test_cmp dst/expect dst/actual
1281 test_expect_success 'push does not follow tags by default' '
1282 mk_test testrepo heads/master &&
1285 git init --bare dst &&
1288 git pull ../testrepo master &&
1289 git tag -m "annotated" tag &&
1290 git checkout -b another &&
1291 git commit --allow-empty -m "future commit" &&
1292 git tag -m "future" future &&
1293 git checkout master &&
1294 git for-each-ref refs/heads/master >../expect &&
1295 git push ../dst master
1299 git for-each-ref >../actual
1301 test_cmp expect actual
1304 test_expect_success 'push --follow-tag only pushes relevant tags' '
1305 mk_test testrepo heads/master &&
1308 git init --bare dst &&
1311 git pull ../testrepo master &&
1312 git tag -m "annotated" tag &&
1313 git checkout -b another &&
1314 git commit --allow-empty -m "future commit" &&
1315 git tag -m "future" future &&
1316 git checkout master &&
1317 git for-each-ref refs/heads/master refs/tags/tag >../expect
1318 git push --follow-tag ../dst master
1322 git for-each-ref >../actual
1324 test_cmp expect actual
1327 test_expect_success 'push --no-thin must produce non-thin pack' '
1328 cat >>path1 <<\EOF &&
1329 keep base version of path1 big enough, compared to the new changes
1330 later, in order to pass size heuristics in
1331 builtin/pack-objects.c:try_delta()
1333 git commit -am initial &&
1335 git --git-dir=no-thin/.git config receive.unpacklimit 0 &&
1336 git push no-thin/.git refs/heads/master:refs/heads/foo &&
1337 echo modified >> path1 &&
1338 git commit -am modified &&
1340 rcvpck="git receive-pack --reject-thin-pack-for-testing" &&
1341 git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/master:refs/heads/foo
1344 test_expect_success 'pushing a tag pushes the tagged object' '
1346 blob=$(echo unreferenced | git hash-object -w --stdin) &&
1347 git tag -m foo tag-of-blob $blob &&
1348 git init --bare dst.git &&
1349 git push dst.git tag-of-blob &&
1350 # the receiving index-pack should have noticed
1351 # any problems, but we double check
1352 echo unreferenced >expect &&
1353 git --git-dir=dst.git cat-file blob tag-of-blob >actual &&
1354 test_cmp expect actual
1357 test_expect_success 'push into bare respects core.logallrefupdates' '
1359 git init --bare dst.git &&
1360 git -C dst.git config core.logallrefupdates true &&
1362 # double push to test both with and without
1363 # the actual pack transfer
1364 git push dst.git master:one &&
1365 echo "one@{0} push" >expect &&
1366 git -C dst.git log -g --format="%gd %gs" one >actual &&
1367 test_cmp expect actual &&
1369 git push dst.git master:two &&
1370 echo "two@{0} push" >expect &&
1371 git -C dst.git log -g --format="%gd %gs" two >actual &&
1372 test_cmp expect actual
1375 test_expect_success 'fetch into bare respects core.logallrefupdates' '
1377 git init --bare dst.git &&
1380 git config core.logallrefupdates true &&
1382 # as above, we double-fetch to test both
1383 # with and without pack transfer
1384 git fetch .. master:one &&
1385 echo "one@{0} fetch .. master:one: storing head" >expect &&
1386 git log -g --format="%gd %gs" one >actual &&
1387 test_cmp expect actual &&
1389 git fetch .. master:two &&
1390 echo "two@{0} fetch .. master:two: storing head" >expect &&
1391 git log -g --format="%gd %gs" two >actual &&
1392 test_cmp expect actual
1396 test_expect_success 'receive.denyCurrentBranch = updateInstead' '
1397 git push testrepo master &&
1401 git config receive.denyCurrentBranch updateInstead
1403 test_commit third path2 &&
1405 # Try pushing into a repository with pristine working tree
1406 git push testrepo master &&
1409 git update-index -q --refresh &&
1410 git diff-files --quiet -- &&
1411 git diff-index --quiet --cached HEAD -- &&
1412 test third = "$(cat path2)" &&
1413 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1416 # Try pushing into a repository with working tree needing a refresh
1419 git reset --hard HEAD^ &&
1420 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1421 test-chmtime +100 path1
1423 git push testrepo master &&
1426 git update-index -q --refresh &&
1427 git diff-files --quiet -- &&
1428 git diff-index --quiet --cached HEAD -- &&
1429 test_cmp ../path1 path1 &&
1430 test third = "$(cat path2)" &&
1431 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1434 # Update what is to be pushed
1435 test_commit fourth path2 &&
1437 # Try pushing into a repository with a dirty working tree
1438 # (1) the working tree updated
1443 test_must_fail git push testrepo master &&
1446 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1447 git diff --quiet --cached &&
1448 test changed = "$(cat path1)"
1451 # (2) the index updated
1454 echo changed >path1 &&
1457 test_must_fail git push testrepo master &&
1460 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1462 test changed = "$(cat path1)"
1465 # Introduce a new file in the update
1466 test_commit fifth path3 &&
1468 # (3) the working tree has an untracked file that would interfere
1474 test_must_fail git push testrepo master &&
1477 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1479 git diff --quiet --cached &&
1480 test changed = "$(cat path3)"
1483 # (4) the target changes to what gets pushed but it still is a change
1487 echo fifth >path3 &&
1490 test_must_fail git push testrepo master &&
1493 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1495 test fifth = "$(cat path3)"
1498 # (5) push into void
1503 git config receive.denyCurrentBranch updateInstead
1505 git push void master &&
1508 test $(git -C .. rev-parse master) = $(git rev-parse HEAD) &&
1510 git diff --cached --quiet
1514 test_expect_success 'updateInstead with push-to-checkout hook' '
1516 git init testrepo &&
1519 git pull .. master &&
1520 git reset --hard HEAD^^ &&
1522 git config receive.denyCurrentBranch updateInstead &&
1523 write_script .git/hooks/push-to-checkout <<-\EOF
1524 echo >&2 updating from $(git rev-parse HEAD)
1525 echo >&2 updating to "$1"
1527 git update-index -q --refresh &&
1528 git read-tree -u -m HEAD "$1" || {
1530 echo >&2 read-tree failed
1536 # Try pushing into a pristine
1537 git push testrepo master &&
1541 git diff HEAD --quiet &&
1542 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1545 # Try pushing into a repository with conflicting change
1548 git reset --hard initial &&
1549 echo conflicting >path2
1551 test_must_fail git push testrepo master &&
1554 test $(git rev-parse initial) = $(git rev-parse HEAD) &&
1555 test conflicting = "$(cat path2)" &&
1556 git diff-index --quiet --cached HEAD
1559 # Try pushing into a repository with unrelated change
1562 git reset --hard initial &&
1563 echo unrelated >path1 &&
1564 echo irrelevant >path5 &&
1567 git push testrepo master &&
1570 test "$(cat path1)" = unrelated &&
1571 test "$(cat path5)" = irrelevant &&
1572 test "$(git diff --name-only --cached HEAD)" = path5 &&
1573 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1581 git config receive.denyCurrentBranch updateInstead &&
1582 write_script .git/hooks/push-to-checkout <<-\EOF
1583 if git rev-parse --quiet --verify HEAD
1586 echo >&2 updating from $(git rev-parse HEAD)
1589 echo >&2 pushing into void
1591 echo >&2 updating to "$1"
1593 git update-index -q --refresh &&
1596 git read-tree -u -m HEAD "$1" ;;
1598 git read-tree -u -m "$1" ;;
1601 echo >&2 read-tree failed
1607 git push void master &&
1611 git diff --cached --quiet &&
1612 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)