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
=main
18 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
26 test_when_finished
"rm -rf \"$repo_name\"" &&
27 test_path_is_missing
"$repo_name" &&
28 git init
"$repo_name" &&
29 git
-C "$repo_name" config receive.denyCurrentBranch warn
36 mk_empty
"$repo_name" &&
40 git push
"$repo_name" $the_first_commit:refs
/$ref ||
46 echo "$the_first_commit" >expect
&&
47 git show-ref
-s --verify refs
/$ref >actual
&&
48 test_cmp expect actual ||
55 mk_test_with_hooks
() {
58 test_hook
-C "$repo_name" pre-receive
<<-'EOF' &&
59 cat - >>pre-receive.actual
62 test_hook
-C "$repo_name" update
<<-'EOF' &&
63 printf "%s %s %s\n" "$@" >>update.actual
66 test_hook
-C "$repo_name" post-receive
<<-'EOF' &&
67 cat - >>post-receive.actual
70 test_hook
-C "$repo_name" post-update
<<-'EOF'
73 printf "%s\n" "$ref" >>post-update.actual
79 test_when_finished
"rm -rf \"$2\"" &&
83 check_push_result
() {
85 BUG
"check_push_result requires at least 3 parameters"
96 git show-ref
-s --verify refs
/$ref >actual
&&
97 test_cmp expect actual ||
104 test_expect_success setup
'
109 git commit -a -m repo &&
110 the_first_commit=$(git show-ref -s --verify refs/heads/main) &&
115 git commit -a -m second &&
116 the_commit=$(git show-ref -s --verify refs/heads/main)
120 test_expect_success
'fetch without wildcard' '
124 git fetch .. refs/heads/main:refs/remotes/origin/main &&
126 echo "$the_commit commit refs/remotes/origin/main" >expect &&
127 git for-each-ref refs/remotes/origin >actual &&
128 test_cmp expect actual
132 test_expect_success
'fetch with wildcard' '
136 git config remote.up.url .. &&
137 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
140 echo "$the_commit commit refs/remotes/origin/main" >expect &&
141 git for-each-ref refs/remotes/origin >actual &&
142 test_cmp expect actual
146 test_expect_success
'fetch with insteadOf' '
151 git config "url.$TRASH.insteadOf" trash/ &&
152 git config remote.up.url trash/. &&
153 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
156 echo "$the_commit commit refs/remotes/origin/main" >expect &&
157 git for-each-ref refs/remotes/origin >actual &&
158 test_cmp expect actual
162 test_expect_success
'fetch with pushInsteadOf (should not rewrite)' '
167 git config "url.trash/.pushInsteadOf" "$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/main" >expect &&
173 git for-each-ref refs/remotes/origin >actual &&
174 test_cmp expect actual
181 grep 'write_pack_file/wrote.*"value":"'$1'"' $2
184 test_expect_success
'push without negotiation' '
186 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
187 test_commit -C testrepo unrelated_commit &&
188 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
189 test_when_finished "rm event" &&
190 GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 push testrepo refs/heads/main:refs/remotes/origin/main &&
191 grep_wrote 5 event # 2 commits, 2 trees, 1 blob
194 test_expect_success
'push with negotiation' '
196 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
197 test_commit -C testrepo unrelated_commit &&
198 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
199 test_when_finished "rm event" &&
200 GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main &&
201 grep_wrote 2 event # 1 commit, 1 tree
204 test_expect_success
'push with negotiation proceeds anyway even if negotiation fails' '
206 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
207 test_commit -C testrepo unrelated_commit &&
208 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
209 test_when_finished "rm event" &&
210 GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" \
211 git -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
212 grep_wrote 5 event && # 2 commits, 2 trees, 1 blob
213 test_i18ngrep "push negotiation failed" err
216 test_expect_success
'push with negotiation does not attempt to fetch submodules' '
217 mk_empty submodule_upstream &&
218 test_commit -C submodule_upstream submodule_commit &&
219 test_config_global protocol.file.allow always &&
220 git submodule add ./submodule_upstream submodule &&
222 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
223 test_commit -C testrepo unrelated_commit &&
224 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
225 git -c submodule.recurse=true -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
226 ! grep "Fetching submodule" err
229 test_expect_success
'push without wildcard' '
232 git push testrepo refs/heads/main:refs/remotes/origin/main &&
235 echo "$the_commit commit refs/remotes/origin/main" >expect &&
236 git for-each-ref refs/remotes/origin >actual &&
237 test_cmp expect actual
241 test_expect_success
'push with wildcard' '
244 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
247 echo "$the_commit commit refs/remotes/origin/main" >expect &&
248 git for-each-ref refs/remotes/origin >actual &&
249 test_cmp expect actual
253 test_expect_success
'push with insteadOf' '
256 test_config "url.$TRASH.insteadOf" trash/ &&
257 git push trash/testrepo refs/heads/main:refs/remotes/origin/main &&
260 echo "$the_commit commit refs/remotes/origin/main" >expect &&
261 git for-each-ref refs/remotes/origin >actual &&
262 test_cmp expect actual
266 test_expect_success
'push with pushInsteadOf' '
269 test_config "url.$TRASH.pushInsteadOf" trash/ &&
270 git push trash/testrepo refs/heads/main:refs/remotes/origin/main &&
273 echo "$the_commit commit refs/remotes/origin/main" >expect &&
274 git for-each-ref refs/remotes/origin >actual &&
275 test_cmp expect actual
279 test_expect_success
'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
281 test_config "url.trash2/.pushInsteadOf" testrepo/ &&
282 test_config "url.trash3/.pushInsteadOf" trash/wrong &&
283 test_config remote.r.url trash/wrong &&
284 test_config remote.r.pushurl "testrepo/" &&
285 git push r refs/heads/main:refs/remotes/origin/main &&
288 echo "$the_commit commit refs/remotes/origin/main" >expect &&
289 git for-each-ref refs/remotes/origin >actual &&
290 test_cmp expect actual
294 test_expect_success
'push with matching heads' '
296 mk_test testrepo heads/main &&
297 git push testrepo : &&
298 check_push_result testrepo $the_commit heads/main
302 test_expect_success
'push with matching heads on the command line' '
304 mk_test testrepo heads/main &&
305 git push testrepo : &&
306 check_push_result testrepo $the_commit heads/main
310 test_expect_success
'failed (non-fast-forward) push with matching heads' '
312 mk_test testrepo heads/main &&
313 git push testrepo : &&
314 git commit --amend -massaged &&
315 test_must_fail git push testrepo &&
316 check_push_result testrepo $the_commit heads/main &&
317 git reset --hard $the_commit
321 test_expect_success
'push --force with matching heads' '
323 mk_test testrepo heads/main &&
324 git push testrepo : &&
325 git commit --amend -massaged &&
326 git push --force testrepo : &&
327 ! check_push_result testrepo $the_commit heads/main &&
328 git reset --hard $the_commit
332 test_expect_success
'push with matching heads and forced update' '
334 mk_test testrepo heads/main &&
335 git push testrepo : &&
336 git commit --amend -massaged &&
337 git push testrepo +: &&
338 ! check_push_result testrepo $the_commit heads/main &&
339 git reset --hard $the_commit
343 test_expect_success
'push with no ambiguity (1)' '
345 mk_test testrepo heads/main &&
346 git push testrepo main:main &&
347 check_push_result testrepo $the_commit heads/main
351 test_expect_success
'push with no ambiguity (2)' '
353 mk_test testrepo remotes/origin/main &&
354 git push testrepo main:origin/main &&
355 check_push_result testrepo $the_commit remotes/origin/main
359 test_expect_success
'push with colon-less refspec, no ambiguity' '
361 mk_test testrepo heads/main heads/t/main &&
362 git branch -f t/main main &&
363 git push testrepo main &&
364 check_push_result testrepo $the_commit heads/main &&
365 check_push_result testrepo $the_first_commit heads/t/main
369 test_expect_success
'push with weak ambiguity (1)' '
371 mk_test testrepo heads/main remotes/origin/main &&
372 git push testrepo main:main &&
373 check_push_result testrepo $the_commit heads/main &&
374 check_push_result testrepo $the_first_commit remotes/origin/main
378 test_expect_success
'push with weak ambiguity (2)' '
380 mk_test testrepo heads/main remotes/origin/main remotes/another/main &&
381 git push testrepo main:main &&
382 check_push_result testrepo $the_commit heads/main &&
383 check_push_result testrepo $the_first_commit remotes/origin/main remotes/another/main
387 test_expect_success
'push with ambiguity' '
389 mk_test testrepo heads/frotz tags/frotz &&
390 test_must_fail git push testrepo main:frotz &&
391 check_push_result testrepo $the_first_commit heads/frotz tags/frotz
395 test_expect_success
'push with colon-less refspec (1)' '
397 mk_test testrepo heads/frotz tags/frotz &&
398 git branch -f frotz main &&
399 git push testrepo frotz &&
400 check_push_result testrepo $the_commit heads/frotz &&
401 check_push_result testrepo $the_first_commit tags/frotz
405 test_expect_success
'push with colon-less refspec (2)' '
407 mk_test testrepo heads/frotz tags/frotz &&
408 if git show-ref --verify -q refs/heads/frotz
413 git push -f testrepo frotz &&
414 check_push_result testrepo $the_commit tags/frotz &&
415 check_push_result testrepo $the_first_commit heads/frotz
419 test_expect_success
'push with colon-less refspec (3)' '
422 if git show-ref --verify -q refs/tags/frotz
426 git branch -f frotz main &&
427 git push testrepo frotz &&
428 check_push_result testrepo $the_commit heads/frotz &&
429 test 1 = $( cd testrepo && git show-ref | wc -l )
432 test_expect_success
'push with colon-less refspec (4)' '
435 if git show-ref --verify -q refs/heads/frotz
440 git push testrepo frotz &&
441 check_push_result testrepo $the_commit tags/frotz &&
442 test 1 = $( cd testrepo && git show-ref | wc -l )
446 test_expect_success
'push head with non-existent, incomplete dest' '
449 git push testrepo main:branch &&
450 check_push_result testrepo $the_commit heads/branch
454 test_expect_success
'push tag with non-existent, incomplete dest' '
458 git push testrepo v1.0:tag &&
459 check_push_result testrepo $the_commit tags/tag
463 test_expect_success
'push sha1 with non-existent, incomplete dest' '
466 test_must_fail git push testrepo $(git rev-parse main):foo
470 test_expect_success
'push ref expression with non-existent, incomplete dest' '
473 test_must_fail git push testrepo main^:branch
480 test_expect_success
"push with $head" '
481 mk_test testrepo heads/main &&
483 git push testrepo $head &&
484 check_push_result testrepo $the_commit heads/main
487 test_expect_success
"push with $head nonexisting at remote" '
488 mk_test testrepo heads/main &&
489 git checkout -b local main &&
490 test_when_finished "git checkout main; git branch -D local" &&
491 git push testrepo $head &&
492 check_push_result testrepo $the_commit heads/local
495 test_expect_success
"push with +$head" '
496 mk_test testrepo heads/main &&
497 git checkout -b local main &&
498 test_when_finished "git checkout main; git branch -D local" &&
499 git push testrepo main local &&
500 check_push_result testrepo $the_commit heads/main &&
501 check_push_result testrepo $the_commit heads/local &&
503 # Without force rewinding should fail
504 git reset --hard $head^ &&
505 test_must_fail git push testrepo $head &&
506 check_push_result testrepo $the_commit heads/local &&
508 # With force rewinding should succeed
509 git push testrepo +$head &&
510 check_push_result testrepo $the_first_commit heads/local
513 test_expect_success
"push $head with non-existent, incomplete dest" '
516 git push testrepo $head:branch &&
517 check_push_result testrepo $the_commit heads/branch
521 test_expect_success
"push with config remote.*.push = $head" '
522 mk_test testrepo heads/local &&
524 git branch -f local $the_commit &&
525 test_when_finished "git branch -D local" &&
528 git checkout local &&
529 git reset --hard $the_first_commit
531 test_config remote.there.url testrepo &&
532 test_config remote.there.push $head &&
533 test_config branch.main.remote there &&
535 check_push_result testrepo $the_commit heads/main &&
536 check_push_result testrepo $the_first_commit heads/local
541 test_expect_success
"push to remote with no explicit refspec and config remote.*.push = src:dest" '
542 mk_test testrepo heads/main &&
543 git checkout $the_first_commit &&
544 test_config remote.there.url testrepo &&
545 test_config remote.there.push refs/heads/main:refs/heads/main &&
547 check_push_result testrepo $the_commit heads/main
550 test_expect_success
'push with remote.pushdefault' '
551 mk_test up_repo heads/main &&
552 mk_test down_repo heads/main &&
553 test_config remote.up.url up_repo &&
554 test_config remote.down.url down_repo &&
555 test_config branch.main.remote up &&
556 test_config remote.pushdefault down &&
557 test_config push.default matching &&
559 check_push_result up_repo $the_first_commit heads/main &&
560 check_push_result down_repo $the_commit heads/main
563 test_expect_success
'push with config remote.*.pushurl' '
565 mk_test testrepo heads/main &&
567 test_config remote.there.url test2repo &&
568 test_config remote.there.pushurl testrepo &&
570 check_push_result testrepo $the_commit heads/main
573 test_expect_success
'push with config branch.*.pushremote' '
574 mk_test up_repo heads/main &&
575 mk_test side_repo heads/main &&
576 mk_test down_repo heads/main &&
577 test_config remote.up.url up_repo &&
578 test_config remote.pushdefault side_repo &&
579 test_config remote.down.url down_repo &&
580 test_config branch.main.remote up &&
581 test_config branch.main.pushremote down &&
582 test_config push.default matching &&
584 check_push_result up_repo $the_first_commit heads/main &&
585 check_push_result side_repo $the_first_commit heads/main &&
586 check_push_result down_repo $the_commit heads/main
589 test_expect_success
'branch.*.pushremote config order is irrelevant' '
590 mk_test one_repo heads/main &&
591 mk_test two_repo heads/main &&
592 test_config remote.one.url one_repo &&
593 test_config remote.two.url two_repo &&
594 test_config branch.main.pushremote two_repo &&
595 test_config remote.pushdefault one_repo &&
596 test_config push.default matching &&
598 check_push_result one_repo $the_first_commit heads/main &&
599 check_push_result two_repo $the_commit heads/main
602 test_expect_success
'push with dry-run' '
604 mk_test testrepo heads/main &&
605 old_commit=$(git -C testrepo show-ref -s --verify refs/heads/main) &&
606 git push --dry-run testrepo : &&
607 check_push_result testrepo $old_commit heads/main
610 test_expect_success
'push updates local refs' '
612 mk_test testrepo heads/main &&
613 mk_child testrepo child &&
618 test $(git rev-parse main) = \
619 $(git rev-parse remotes/origin/main)
624 test_expect_success
'push updates up-to-date local refs' '
626 mk_test testrepo heads/main &&
627 mk_child testrepo child1 &&
628 mk_child testrepo child2 &&
629 (cd child1 && git pull .. main && git push) &&
632 git pull ../child1 main &&
634 test $(git rev-parse main) = \
635 $(git rev-parse remotes/origin/main)
640 test_expect_success
'push preserves up-to-date packed refs' '
642 mk_test testrepo heads/main &&
643 mk_child testrepo child &&
647 ! test -f .git/refs/remotes/origin/main
652 test_expect_success
'push does not update local refs on failure' '
654 mk_test testrepo heads/main &&
655 mk_child testrepo child &&
656 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
657 chmod +x testrepo/.git/hooks/pre-receive &&
661 test_must_fail git push &&
662 test $(git rev-parse main) != \
663 $(git rev-parse remotes/origin/main)
668 test_expect_success
'allow deleting an invalid remote ref' '
670 mk_test testrepo heads/branch &&
671 rm -f testrepo/.git/objects/??/* &&
672 git push testrepo :refs/heads/branch &&
673 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/branch)
677 test_expect_success
'pushing valid refs triggers post-receive and post-update hooks' '
678 mk_test_with_hooks testrepo heads/main heads/next &&
679 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
680 newmain=$(git show-ref -s --verify refs/heads/main) &&
681 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
683 git push testrepo refs/heads/main:refs/heads/main :refs/heads/next &&
686 cat >pre-receive.expect <<-EOF &&
687 $orgmain $newmain refs/heads/main
688 $orgnext $newnext refs/heads/next
691 cat >update.expect <<-EOF &&
692 refs/heads/main $orgmain $newmain
693 refs/heads/next $orgnext $newnext
696 cat >post-receive.expect <<-EOF &&
697 $orgmain $newmain refs/heads/main
698 $orgnext $newnext refs/heads/next
701 cat >post-update.expect <<-EOF &&
706 test_cmp pre-receive.expect pre-receive.actual &&
707 test_cmp update.expect update.actual &&
708 test_cmp post-receive.expect post-receive.actual &&
709 test_cmp post-update.expect post-update.actual
713 test_expect_success
'deleting dangling ref triggers hooks with correct args' '
714 mk_test_with_hooks testrepo heads/branch &&
715 orig=$(git -C testrepo rev-parse refs/heads/branch) &&
716 rm -f testrepo/.git/objects/??/* &&
717 git push testrepo :refs/heads/branch &&
720 cat >pre-receive.expect <<-EOF &&
721 $orig $ZERO_OID refs/heads/branch
724 cat >update.expect <<-EOF &&
725 refs/heads/branch $orig $ZERO_OID
728 cat >post-receive.expect <<-EOF &&
729 $orig $ZERO_OID refs/heads/branch
732 cat >post-update.expect <<-EOF &&
736 test_cmp pre-receive.expect pre-receive.actual &&
737 test_cmp update.expect update.actual &&
738 test_cmp post-receive.expect post-receive.actual &&
739 test_cmp post-update.expect post-update.actual
743 test_expect_success
'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
744 mk_test_with_hooks testrepo heads/main &&
745 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
746 newmain=$(git show-ref -s --verify refs/heads/main) &&
747 git push testrepo main :refs/heads/nonexistent &&
750 cat >pre-receive.expect <<-EOF &&
751 $orgmain $newmain refs/heads/main
752 $ZERO_OID $ZERO_OID refs/heads/nonexistent
755 cat >update.expect <<-EOF &&
756 refs/heads/main $orgmain $newmain
757 refs/heads/nonexistent $ZERO_OID $ZERO_OID
760 cat >post-receive.expect <<-EOF &&
761 $orgmain $newmain refs/heads/main
764 cat >post-update.expect <<-EOF &&
768 test_cmp pre-receive.expect pre-receive.actual &&
769 test_cmp update.expect update.actual &&
770 test_cmp post-receive.expect post-receive.actual &&
771 test_cmp post-update.expect post-update.actual
775 test_expect_success
'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
776 mk_test_with_hooks testrepo heads/main &&
777 git push testrepo :refs/heads/nonexistent &&
780 cat >pre-receive.expect <<-EOF &&
781 $ZERO_OID $ZERO_OID refs/heads/nonexistent
784 cat >update.expect <<-EOF &&
785 refs/heads/nonexistent $ZERO_OID $ZERO_OID
788 test_cmp pre-receive.expect pre-receive.actual &&
789 test_cmp update.expect update.actual &&
790 test_path_is_missing post-receive.actual &&
791 test_path_is_missing post-update.actual
795 test_expect_success
'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
796 mk_test_with_hooks testrepo heads/main heads/next heads/seen &&
797 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
798 newmain=$(git show-ref -s --verify refs/heads/main) &&
799 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
801 orgseen=$(cd testrepo && git show-ref -s --verify refs/heads/seen) &&
802 newseen=$(git show-ref -s --verify refs/heads/main) &&
803 git push testrepo refs/heads/main:refs/heads/main \
804 refs/heads/main:refs/heads/seen :refs/heads/next \
805 :refs/heads/nonexistent &&
808 cat >pre-receive.expect <<-EOF &&
809 $orgmain $newmain refs/heads/main
810 $orgnext $newnext refs/heads/next
811 $orgseen $newseen refs/heads/seen
812 $ZERO_OID $ZERO_OID refs/heads/nonexistent
815 cat >update.expect <<-EOF &&
816 refs/heads/main $orgmain $newmain
817 refs/heads/next $orgnext $newnext
818 refs/heads/seen $orgseen $newseen
819 refs/heads/nonexistent $ZERO_OID $ZERO_OID
822 cat >post-receive.expect <<-EOF &&
823 $orgmain $newmain refs/heads/main
824 $orgnext $newnext refs/heads/next
825 $orgseen $newseen refs/heads/seen
828 cat >post-update.expect <<-EOF &&
834 test_cmp pre-receive.expect pre-receive.actual &&
835 test_cmp update.expect update.actual &&
836 test_cmp post-receive.expect post-receive.actual &&
837 test_cmp post-update.expect post-update.actual
841 test_expect_success
'allow deleting a ref using --delete' '
842 mk_test testrepo heads/main &&
843 (cd testrepo && git config receive.denyDeleteCurrent warn) &&
844 git push testrepo --delete main &&
845 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/main)
848 test_expect_success
'allow deleting a tag using --delete' '
849 mk_test testrepo heads/main &&
850 git tag -a -m dummy_message deltag heads/main &&
851 git push testrepo --tags &&
852 (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
853 git push testrepo --delete tag deltag &&
854 (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
857 test_expect_success
'push --delete without args aborts' '
858 mk_test testrepo heads/main &&
859 test_must_fail git push testrepo --delete
862 test_expect_success
'push --delete refuses src:dest refspecs' '
863 mk_test testrepo heads/main &&
864 test_must_fail git push testrepo --delete main:foo
867 test_expect_success
'push --delete refuses empty string' '
868 mk_test testrepo heads/master &&
869 test_must_fail git push testrepo --delete ""
872 test_expect_success
'warn on push to HEAD of non-bare repository' '
873 mk_test testrepo heads/main &&
877 git config receive.denyCurrentBranch warn
879 git push testrepo main 2>stderr &&
880 grep "warning: updating the current branch" stderr
883 test_expect_success
'deny push to HEAD of non-bare repository' '
884 mk_test testrepo heads/main &&
888 git config receive.denyCurrentBranch true
890 test_must_fail git push testrepo main
893 test_expect_success
'allow push to HEAD of bare repository (bare)' '
894 mk_test testrepo heads/main &&
898 git config receive.denyCurrentBranch true &&
899 git config core.bare true
901 git push testrepo main 2>stderr &&
902 ! grep "warning: updating the current branch" stderr
905 test_expect_success
'allow push to HEAD of non-bare repository (config)' '
906 mk_test testrepo heads/main &&
910 git config receive.denyCurrentBranch false
912 git push testrepo main 2>stderr &&
913 ! grep "warning: updating the current branch" stderr
916 test_expect_success
'fetch with branches' '
918 git branch second $the_first_commit &&
919 git checkout second &&
920 echo ".." > testrepo/.git/branches/branch1 &&
924 echo "$the_commit commit refs/heads/branch1" >expect &&
925 git for-each-ref refs/heads >actual &&
926 test_cmp expect actual
931 test_expect_success
'fetch with branches containing #' '
933 echo "..#second" > testrepo/.git/branches/branch2 &&
937 echo "$the_first_commit commit refs/heads/branch2" >expect &&
938 git for-each-ref refs/heads >actual &&
939 test_cmp expect actual
944 test_expect_success
'push with branches' '
946 git checkout second &&
947 echo "testrepo" > .git/branches/branch1 &&
951 echo "$the_first_commit commit refs/heads/main" >expect &&
952 git for-each-ref refs/heads >actual &&
953 test_cmp expect actual
957 test_expect_success
'push with branches containing #' '
959 echo "testrepo#branch3" > .git/branches/branch2 &&
963 echo "$the_first_commit commit refs/heads/branch3" >expect &&
964 git for-each-ref refs/heads >actual &&
965 test_cmp expect actual
970 test_expect_success
'push into aliased refs (consistent)' '
971 mk_test testrepo heads/main &&
972 mk_child testrepo child1 &&
973 mk_child testrepo child2 &&
977 git symbolic-ref refs/heads/bar refs/heads/foo &&
978 git config receive.denyCurrentBranch false
985 git commit -a -m child2 &&
988 git push ../child1 foo bar
992 test_expect_success
'push into aliased refs (inconsistent)' '
993 mk_test testrepo heads/main &&
994 mk_child testrepo child1 &&
995 mk_child testrepo child2 &&
999 git symbolic-ref refs/heads/bar refs/heads/foo &&
1000 git config receive.denyCurrentBranch false
1007 git commit -a -m child2 &&
1012 git commit -a -m child2 &&
1014 test_must_fail git push ../child1 foo bar 2>stderr &&
1015 grep "refusing inconsistent update" stderr
1019 test_force_push_tag
() {
1020 tag_type_description
=$1
1023 test_expect_success
"force pushing required to update $tag_type_description" "
1024 mk_test testrepo heads/main &&
1025 mk_child testrepo child1 &&
1026 mk_child testrepo child2 &&
1030 git push ../child2 testTag &&
1033 git commit -m 'file1' &&
1034 git tag $tag_args testTag &&
1035 test_must_fail git push ../child2 testTag &&
1036 git push --force ../child2 testTag &&
1037 git tag $tag_args testTag HEAD~ &&
1038 test_must_fail git push ../child2 testTag &&
1039 git push --force ../child2 testTag &&
1041 # Clobbering without + in refspec needs --force
1042 git tag -f testTag &&
1043 test_must_fail git push ../child2 'refs/tags/*:refs/tags/*' &&
1044 git push --force ../child2 'refs/tags/*:refs/tags/*' &&
1046 # Clobbering with + in refspec does not need --force
1047 git tag -f testTag HEAD~ &&
1048 git push ../child2 '+refs/tags/*:refs/tags/*' &&
1050 # Clobbering with --no-force still obeys + in refspec
1051 git tag -f testTag &&
1052 git push --no-force ../child2 '+refs/tags/*:refs/tags/*' &&
1054 # Clobbering with/without --force and 'tag <name>' format
1055 git tag -f testTag HEAD~ &&
1056 test_must_fail git push ../child2 tag testTag &&
1057 git push --force ../child2 tag testTag
1062 test_force_push_tag
"lightweight tag" "-f"
1063 test_force_push_tag
"annotated tag" "-f -a -m'tag message'"
1065 test_force_fetch_tag
() {
1066 tag_type_description
=$1
1069 test_expect_success
"fetch will not clobber an existing $tag_type_description without --force" "
1070 mk_test testrepo heads/main &&
1071 mk_child testrepo child1 &&
1072 mk_child testrepo child2 &&
1076 git -C ../child1 fetch origin tag testTag &&
1079 git commit -m 'file1' &&
1080 git tag $tag_args testTag &&
1081 test_must_fail git -C ../child1 fetch origin tag testTag &&
1082 git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*'
1087 test_force_fetch_tag
"lightweight tag" "-f"
1088 test_force_fetch_tag
"annotated tag" "-f -a -m'tag message'"
1090 test_expect_success
'push --porcelain' '
1091 mk_empty testrepo &&
1092 echo >.git/foo "To testrepo" &&
1093 echo >>.git/foo "* refs/heads/main:refs/remotes/origin/main [new reference]" &&
1094 echo >>.git/foo "Done" &&
1095 git push >.git/bar --porcelain testrepo refs/heads/main:refs/remotes/origin/main &&
1098 echo "$the_commit commit refs/remotes/origin/main" >expect &&
1099 git for-each-ref refs/remotes/origin >actual &&
1100 test_cmp expect actual
1102 test_cmp .git/foo .git/bar
1105 test_expect_success
'push --porcelain bad url' '
1106 mk_empty testrepo &&
1107 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/main:refs/remotes/origin/main &&
1108 ! grep -q Done .git/bar
1111 test_expect_success
'push --porcelain rejected' '
1112 mk_empty testrepo &&
1113 git push testrepo refs/heads/main:refs/remotes/origin/main &&
1115 git reset --hard origin/main^ &&
1116 git config receive.denyCurrentBranch true) &&
1118 echo >.git/foo "To testrepo" &&
1119 echo >>.git/foo "! refs/heads/main:refs/heads/main [remote rejected] (branch is currently checked out)" &&
1120 echo >>.git/foo "Done" &&
1122 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/main:refs/heads/main &&
1123 test_cmp .git/foo .git/bar
1126 test_expect_success
'push --porcelain --dry-run rejected' '
1127 mk_empty testrepo &&
1128 git push testrepo refs/heads/main:refs/remotes/origin/main &&
1130 git reset --hard origin/main &&
1131 git config receive.denyCurrentBranch true) &&
1133 echo >.git/foo "To testrepo" &&
1134 echo >>.git/foo "! refs/heads/main^:refs/heads/main [rejected] (non-fast-forward)" &&
1135 echo >>.git/foo "Done" &&
1137 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/main^:refs/heads/main &&
1138 test_cmp .git/foo .git/bar
1141 test_expect_success
'push --prune' '
1142 mk_test testrepo heads/main heads/second heads/foo heads/bar &&
1143 git push --prune testrepo : &&
1144 check_push_result testrepo $the_commit heads/main &&
1145 check_push_result testrepo $the_first_commit heads/second &&
1146 ! check_push_result testrepo $the_first_commit heads/foo heads/bar
1149 test_expect_success
'push --prune refspec' '
1150 mk_test testrepo tmp/main tmp/second tmp/foo tmp/bar &&
1151 git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
1152 check_push_result testrepo $the_commit tmp/main &&
1153 check_push_result testrepo $the_first_commit tmp/second &&
1154 ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
1157 for configsection
in transfer receive
1159 test_expect_success
"push to update a ref hidden by $configsection.hiderefs" '
1160 mk_test testrepo heads/main hidden/one hidden/two hidden/three &&
1163 git config $configsection.hiderefs refs/hidden
1166 # push to unhidden ref succeeds normally
1167 git push testrepo main:refs/heads/main &&
1168 check_push_result testrepo $the_commit heads/main &&
1170 # push to update a hidden ref should fail
1171 test_must_fail git push testrepo main:refs/hidden/one &&
1172 check_push_result testrepo $the_first_commit hidden/one &&
1174 # push to delete a hidden ref should fail
1175 test_must_fail git push testrepo :refs/hidden/two &&
1176 check_push_result testrepo $the_first_commit hidden/two &&
1178 # idempotent push to update a hidden ref should fail
1179 test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
1180 check_push_result testrepo $the_first_commit hidden/three
1184 test_expect_success
'fetch exact SHA1' '
1185 mk_test testrepo heads/main hidden/one &&
1186 git push testrepo main:refs/hidden/one &&
1189 git config transfer.hiderefs refs/hidden
1191 check_push_result testrepo $the_commit hidden/one &&
1193 mk_child testrepo child &&
1197 # make sure $the_commit does not exist here
1200 test_must_fail git cat-file -t $the_commit &&
1202 # Some protocol versions (e.g. 2) support fetching
1203 # unadvertised objects, so restrict this test to v0.
1205 # fetching the hidden object should fail by default
1206 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1207 git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err &&
1208 test_i18ngrep "Server does not allow request for unadvertised object" err &&
1209 test_must_fail git rev-parse --verify refs/heads/copy &&
1211 # the server side can allow it to succeed
1214 git config uploadpack.allowtipsha1inwant true
1217 git fetch -v ../testrepo $the_commit:refs/heads/copy main:refs/heads/extra &&
1218 cat >expect <<-EOF &&
1223 git rev-parse --verify refs/heads/copy &&
1224 git rev-parse --verify refs/heads/extra
1226 test_cmp expect actual
1230 test_expect_success
'fetch exact SHA1 in protocol v2' '
1231 mk_test testrepo heads/main hidden/one &&
1232 git push testrepo main:refs/hidden/one &&
1233 git -C testrepo config transfer.hiderefs refs/hidden &&
1234 check_push_result testrepo $the_commit hidden/one &&
1236 mk_child testrepo child &&
1237 git -C child config protocol.version 2 &&
1239 # make sure $the_commit does not exist here
1240 git -C child repack -a -d &&
1241 git -C child prune &&
1242 test_must_fail git -C child cat-file -t $the_commit &&
1244 # fetching the hidden object succeeds by default
1245 # NEEDSWORK: should this match the v0 behavior instead?
1246 git -C child fetch -v ../testrepo $the_commit:refs/heads/copy
1249 for configallowtipsha1inwant
in true false
1251 test_expect_success
"shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" '
1252 mk_empty testrepo &&
1255 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1256 git commit --allow-empty -m foo &&
1257 git commit --allow-empty -m bar
1259 SHA1=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1263 # Some protocol versions (e.g. 2) support fetching
1264 # unadvertised objects, so restrict this test to v0.
1265 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1266 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1267 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1268 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1269 git cat-file commit $SHA1
1273 test_expect_success
"deny fetch unreachable SHA1, allowtipsha1inwant=$configallowtipsha1inwant" '
1274 mk_empty testrepo &&
1277 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1278 git commit --allow-empty -m foo &&
1279 git commit --allow-empty -m bar &&
1280 git commit --allow-empty -m xyz
1282 SHA1_1=$(git --git-dir=testrepo/.git rev-parse HEAD^^) &&
1283 SHA1_2=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1284 SHA1_3=$(git --git-dir=testrepo/.git rev-parse HEAD) &&
1287 git reset --hard $SHA1_2 &&
1288 git cat-file commit $SHA1_1 &&
1289 git cat-file commit $SHA1_3
1294 # Some protocol versions (e.g. 2) support fetching
1295 # unadvertised objects, so restrict this test to v0.
1296 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1297 git fetch ../testrepo/.git $SHA1_3 &&
1298 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1299 git fetch ../testrepo/.git $SHA1_1 &&
1300 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1301 git fetch ../testrepo/.git $SHA1_1 &&
1302 git cat-file commit $SHA1_1 &&
1303 test_must_fail git cat-file commit $SHA1_2 &&
1304 git fetch ../testrepo/.git $SHA1_2 &&
1305 git cat-file commit $SHA1_2 &&
1306 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1307 git fetch ../testrepo/.git $SHA1_3 2>err &&
1308 # ideally we would insist this be on a "remote error:"
1309 # line, but it is racy; see the commit message
1310 test_i18ngrep "not our ref.*$SHA1_3\$" err
1315 test_expect_success
'fetch follows tags by default' '
1316 mk_test testrepo heads/main &&
1317 test_when_finished "rm -rf src" &&
1321 git pull ../testrepo main &&
1322 git tag -m "annotated" tag &&
1323 git for-each-ref >tmp1 &&
1324 sed -n "p; s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 |
1325 sort -k 3 >../expect
1327 test_when_finished "rm -rf dst" &&
1331 git remote add origin ../src &&
1332 git config branch.main.remote origin &&
1333 git config branch.main.merge refs/heads/main &&
1335 git for-each-ref >../actual
1337 test_cmp expect actual
1340 test_expect_success
'peeled advertisements are not considered ref tips' '
1341 mk_empty testrepo &&
1342 git -C testrepo commit --allow-empty -m one &&
1343 git -C testrepo commit --allow-empty -m two &&
1344 git -C testrepo tag -m foo mytag HEAD^ &&
1345 oid=$(git -C testrepo rev-parse mytag^{commit}) &&
1346 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1347 git fetch testrepo $oid 2>err &&
1348 test_i18ngrep "Server does not allow request for unadvertised object" err
1351 test_expect_success
'pushing a specific ref applies remote.$name.push as refmap' '
1352 mk_test testrepo heads/main &&
1353 test_when_finished "rm -rf src" &&
1355 test_when_finished "rm -rf dst" &&
1356 git init --bare dst &&
1359 git pull ../testrepo main &&
1361 git config remote.dst.url ../dst &&
1362 git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" &&
1363 git push dst main &&
1364 git show-ref refs/heads/main |
1365 sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect
1369 test_must_fail git show-ref refs/heads/next &&
1370 test_must_fail git show-ref refs/heads/main &&
1371 git show-ref refs/remotes/src/main >actual
1373 test_cmp dst/expect dst/actual
1376 test_expect_success
'with no remote.$name.push, it is not used as refmap' '
1377 mk_test testrepo heads/main &&
1378 test_when_finished "rm -rf src" &&
1380 test_when_finished "rm -rf dst" &&
1381 git init --bare dst &&
1384 git pull ../testrepo main &&
1386 git config remote.dst.url ../dst &&
1387 git config push.default matching &&
1388 git push dst main &&
1389 git show-ref refs/heads/main >../dst/expect
1393 test_must_fail git show-ref refs/heads/next &&
1394 git show-ref refs/heads/main >actual
1396 test_cmp dst/expect dst/actual
1399 test_expect_success
'with no remote.$name.push, upstream mapping is used' '
1400 mk_test testrepo heads/main &&
1401 test_when_finished "rm -rf src" &&
1403 test_when_finished "rm -rf dst" &&
1404 git init --bare dst &&
1407 git pull ../testrepo main &&
1409 git config remote.dst.url ../dst &&
1410 git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" &&
1411 git config push.default upstream &&
1413 git config branch.main.merge refs/heads/trunk &&
1414 git config branch.main.remote dst &&
1416 git push dst main &&
1417 git show-ref refs/heads/main |
1418 sed -e "s|refs/heads/main|refs/heads/trunk|" >../dst/expect
1422 test_must_fail git show-ref refs/heads/main &&
1423 test_must_fail git show-ref refs/heads/next &&
1424 git show-ref refs/heads/trunk >actual
1426 test_cmp dst/expect dst/actual
1429 test_expect_success
'push does not follow tags by default' '
1430 mk_test testrepo heads/main &&
1431 test_when_finished "rm -rf src" &&
1433 test_when_finished "rm -rf dst" &&
1434 git init --bare dst &&
1437 git pull ../testrepo main &&
1438 git tag -m "annotated" tag &&
1439 git checkout -b another &&
1440 git commit --allow-empty -m "future commit" &&
1441 git tag -m "future" future &&
1442 git checkout main &&
1443 git for-each-ref refs/heads/main >../expect &&
1444 git push ../dst main
1448 git for-each-ref >../actual
1450 test_cmp expect actual
1453 test_expect_success
'push --follow-tags only pushes relevant tags' '
1454 mk_test testrepo heads/main &&
1455 test_when_finished "rm -rf src" &&
1457 test_when_finished "rm -rf dst" &&
1458 git init --bare dst &&
1461 git pull ../testrepo main &&
1462 git tag -m "annotated" tag &&
1463 git checkout -b another &&
1464 git commit --allow-empty -m "future commit" &&
1465 git tag -m "future" future &&
1466 git checkout main &&
1467 git for-each-ref refs/heads/main refs/tags/tag >../expect &&
1468 git push --follow-tags ../dst main
1472 git for-each-ref >../actual
1474 test_cmp expect actual
1477 test_expect_success
'push --no-thin must produce non-thin pack' '
1478 cat >>path1 <<\EOF &&
1479 keep base version of path1 big enough, compared to the new changes
1480 later, in order to pass size heuristics in
1481 builtin/pack-objects.c:try_delta()
1483 git commit -am initial &&
1485 git --git-dir=no-thin/.git config receive.unpacklimit 0 &&
1486 git push no-thin/.git refs/heads/main:refs/heads/foo &&
1487 echo modified >> path1 &&
1488 git commit -am modified &&
1490 rcvpck="git receive-pack --reject-thin-pack-for-testing" &&
1491 git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/main:refs/heads/foo
1494 test_expect_success
'pushing a tag pushes the tagged object' '
1495 blob=$(echo unreferenced | git hash-object -w --stdin) &&
1496 git tag -m foo tag-of-blob $blob &&
1497 test_when_finished "rm -rf dst.git" &&
1498 git init --bare dst.git &&
1499 git push dst.git tag-of-blob &&
1500 # the receiving index-pack should have noticed
1501 # any problems, but we double check
1502 echo unreferenced >expect &&
1503 git --git-dir=dst.git cat-file blob tag-of-blob >actual &&
1504 test_cmp expect actual
1507 test_expect_success
'push into bare respects core.logallrefupdates' '
1508 test_when_finished "rm -rf dst.git" &&
1509 git init --bare dst.git &&
1510 git -C dst.git config core.logallrefupdates true &&
1512 # double push to test both with and without
1513 # the actual pack transfer
1514 git push dst.git main:one &&
1515 echo "one@{0} push" >expect &&
1516 git -C dst.git log -g --format="%gd %gs" one >actual &&
1517 test_cmp expect actual &&
1519 git push dst.git main:two &&
1520 echo "two@{0} push" >expect &&
1521 git -C dst.git log -g --format="%gd %gs" two >actual &&
1522 test_cmp expect actual
1525 test_expect_success
'fetch into bare respects core.logallrefupdates' '
1526 test_when_finished "rm -rf dst.git" &&
1527 git init --bare dst.git &&
1530 git config core.logallrefupdates true &&
1532 # as above, we double-fetch to test both
1533 # with and without pack transfer
1534 git fetch .. main:one &&
1535 echo "one@{0} fetch .. main:one: storing head" >expect &&
1536 git log -g --format="%gd %gs" one >actual &&
1537 test_cmp expect actual &&
1539 git fetch .. main:two &&
1540 echo "two@{0} fetch .. main:two: storing head" >expect &&
1541 git log -g --format="%gd %gs" two >actual &&
1542 test_cmp expect actual
1546 test_expect_success
'receive.denyCurrentBranch = updateInstead' '
1547 mk_empty testrepo &&
1548 git push testrepo main &&
1552 git config receive.denyCurrentBranch updateInstead
1554 test_commit third path2 &&
1556 # Try pushing into a repository with pristine working tree
1557 git push testrepo main &&
1560 git update-index -q --refresh &&
1561 git diff-files --quiet -- &&
1562 git diff-index --quiet --cached HEAD -- &&
1563 test third = "$(cat path2)" &&
1564 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1567 # Try pushing into a repository with working tree needing a refresh
1570 git reset --hard HEAD^ &&
1571 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1572 test-tool chmtime +100 path1
1574 git push testrepo main &&
1577 git update-index -q --refresh &&
1578 git diff-files --quiet -- &&
1579 git diff-index --quiet --cached HEAD -- &&
1580 test_cmp ../path1 path1 &&
1581 test third = "$(cat path2)" &&
1582 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1585 # Update what is to be pushed
1586 test_commit fourth path2 &&
1588 # Try pushing into a repository with a dirty working tree
1589 # (1) the working tree updated
1594 test_must_fail git push testrepo main &&
1597 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1598 git diff --quiet --cached &&
1599 test changed = "$(cat path1)"
1602 # (2) the index updated
1605 echo changed >path1 &&
1608 test_must_fail git push testrepo main &&
1611 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1613 test changed = "$(cat path1)"
1616 # Introduce a new file in the update
1617 test_commit fifth path3 &&
1619 # (3) the working tree has an untracked file that would interfere
1625 test_must_fail git push testrepo main &&
1628 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1630 git diff --quiet --cached &&
1631 test changed = "$(cat path3)"
1634 # (4) the target changes to what gets pushed but it still is a change
1638 echo fifth >path3 &&
1641 test_must_fail git push testrepo main &&
1644 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1646 test fifth = "$(cat path3)"
1649 # (5) push into void
1650 test_when_finished "rm -rf void" &&
1654 git config receive.denyCurrentBranch updateInstead
1656 git push void main &&
1659 test $(git -C .. rev-parse main) = $(git rev-parse HEAD) &&
1661 git diff --cached --quiet
1664 # (6) updateInstead intervened by fast-forward check
1665 test_must_fail git push void main^:main &&
1666 test $(git -C void rev-parse HEAD) = $(git rev-parse main) &&
1667 git -C void diff --quiet &&
1668 git -C void diff --cached --quiet
1671 test_expect_success
'updateInstead with push-to-checkout hook' '
1672 test_when_finished "rm -rf testrepo" &&
1673 git init testrepo &&
1674 git -C testrepo pull .. main &&
1675 git -C testrepo reset --hard HEAD^^ &&
1676 git -C testrepo tag initial &&
1677 git -C testrepo config receive.denyCurrentBranch updateInstead &&
1678 test_hook -C testrepo push-to-checkout <<-\EOF &&
1679 echo >&2 updating from $(git rev-parse HEAD)
1680 echo >&2 updating to "$1"
1682 git update-index -q --refresh &&
1683 git read-tree -u -m HEAD "$1" || {
1685 echo >&2 read-tree failed
1690 # Try pushing into a pristine
1691 git push testrepo main &&
1695 git diff HEAD --quiet &&
1696 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1699 # Try pushing into a repository with conflicting change
1702 git reset --hard initial &&
1703 echo conflicting >path2
1705 test_must_fail git push testrepo main &&
1708 test $(git rev-parse initial) = $(git rev-parse HEAD) &&
1709 test conflicting = "$(cat path2)" &&
1710 git diff-index --quiet --cached HEAD
1713 # Try pushing into a repository with unrelated change
1716 git reset --hard initial &&
1717 echo unrelated >path1 &&
1718 echo irrelevant >path5 &&
1721 git push testrepo main &&
1724 test "$(cat path1)" = unrelated &&
1725 test "$(cat path5)" = irrelevant &&
1726 test "$(git diff --name-only --cached HEAD)" = path5 &&
1727 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1731 test_when_finished "rm -rf void" &&
1733 git -C void config receive.denyCurrentBranch updateInstead &&
1734 test_hook -C void push-to-checkout <<-\EOF &&
1735 if git rev-parse --quiet --verify HEAD
1738 echo >&2 updating from $(git rev-parse HEAD)
1741 echo >&2 pushing into void
1743 echo >&2 updating to "$1"
1745 git update-index -q --refresh &&
1748 git read-tree -u -m HEAD "$1" ;;
1750 git read-tree -u -m "$1" ;;
1753 echo >&2 read-tree failed
1758 git push void main &&
1762 git diff --cached --quiet &&
1763 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1767 test_expect_success
'denyCurrentBranch and worktrees' '
1768 git worktree add new-wt &&
1769 git clone . cloned &&
1770 test_commit -C cloned first &&
1771 test_config receive.denyCurrentBranch refuse &&
1772 test_must_fail git -C cloned push origin HEAD:new-wt &&
1773 test_config receive.denyCurrentBranch updateInstead &&
1774 git -C cloned push origin HEAD:new-wt &&
1775 test_path_exists new-wt/first.t &&
1776 test_must_fail git -C cloned push --delete origin new-wt
1779 test_expect_success
'denyCurrentBranch and bare repository worktrees' '
1780 test_when_finished "rm -fr bare.git" &&
1781 git clone --bare . bare.git &&
1782 git -C bare.git worktree add wt &&
1783 test_commit grape &&
1784 git -C bare.git config receive.denyCurrentBranch refuse &&
1785 test_must_fail git push bare.git HEAD:wt &&
1786 git -C bare.git config receive.denyCurrentBranch updateInstead &&
1787 git push bare.git HEAD:wt &&
1788 test_path_exists bare.git/wt/grape.t &&
1789 test_must_fail git push --delete bare.git wt
1792 test_expect_success
'refuse fetch to current branch of worktree' '
1793 test_when_finished "git worktree remove --force wt && git branch -D wt" &&
1794 git worktree add wt &&
1795 test_commit apple &&
1796 test_must_fail git fetch . HEAD:wt &&
1797 git fetch -u . HEAD:wt
1800 test_expect_success
'refuse fetch to current branch of bare repository worktree' '
1801 test_when_finished "rm -fr bare.git" &&
1802 git clone --bare . bare.git &&
1803 git -C bare.git worktree add wt &&
1804 test_commit banana &&
1805 test_must_fail git -C bare.git fetch .. HEAD:wt &&
1806 git -C bare.git fetch -u .. HEAD:wt
1809 test_expect_success
'refuse to push a hidden ref, and make sure do not pollute the repository' '
1810 mk_empty testrepo &&
1811 git -C testrepo config receive.hiderefs refs/hidden &&
1812 git -C testrepo config receive.unpackLimit 1 &&
1813 test_must_fail git push testrepo HEAD:refs/hidden/foo &&
1814 test_dir_is_empty testrepo/.git/objects/pack