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 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/main) &&
131 git commit -a -m second &&
132 the_commit=$(git show-ref -s --verify refs/heads/main)
136 test_expect_success
'fetch without wildcard' '
140 git fetch .. refs/heads/main:refs/remotes/origin/main &&
142 echo "$the_commit commit refs/remotes/origin/main" >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/main" >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/main" >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/main" >expect &&
189 git for-each-ref refs/remotes/origin >actual &&
190 test_cmp expect actual
197 grep 'write_pack_file/wrote.*"value":"'$1'"' $2
200 test_expect_success
'push with negotiation' '
201 # Without negotiation
203 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
204 test_commit -C testrepo unrelated_commit &&
205 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
206 echo now pushing without negotiation &&
207 GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 push testrepo refs/heads/main:refs/remotes/origin/main &&
208 grep_wrote 5 event && # 2 commits, 2 trees, 1 blob
210 # Same commands, but with negotiation
213 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
214 test_commit -C testrepo unrelated_commit &&
215 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
216 GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main &&
217 grep_wrote 2 event # 1 commit, 1 tree
220 test_expect_success
'push with negotiation proceeds anyway even if negotiation fails' '
223 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
224 test_commit -C testrepo unrelated_commit &&
225 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
226 GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" \
227 git -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
228 grep_wrote 5 event && # 2 commits, 2 trees, 1 blob
229 test_i18ngrep "push negotiation failed" err
232 test_expect_success
'push with negotiation does not attempt to fetch submodules' '
233 mk_empty submodule_upstream &&
234 test_commit -C submodule_upstream submodule_commit &&
235 git submodule add ./submodule_upstream submodule &&
237 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
238 test_commit -C testrepo unrelated_commit &&
239 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
240 git -c submodule.recurse=true -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
241 ! grep "Fetching submodule" err
244 test_expect_success
'push without wildcard' '
247 git push testrepo refs/heads/main:refs/remotes/origin/main &&
250 echo "$the_commit commit refs/remotes/origin/main" >expect &&
251 git for-each-ref refs/remotes/origin >actual &&
252 test_cmp expect actual
256 test_expect_success
'push with wildcard' '
259 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
262 echo "$the_commit commit refs/remotes/origin/main" >expect &&
263 git for-each-ref refs/remotes/origin >actual &&
264 test_cmp expect actual
268 test_expect_success
'push with insteadOf' '
271 test_config "url.$TRASH.insteadOf" trash/ &&
272 git push trash/testrepo refs/heads/main:refs/remotes/origin/main &&
275 echo "$the_commit commit refs/remotes/origin/main" >expect &&
276 git for-each-ref refs/remotes/origin >actual &&
277 test_cmp expect actual
281 test_expect_success
'push with pushInsteadOf' '
284 test_config "url.$TRASH.pushInsteadOf" trash/ &&
285 git push trash/testrepo 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 pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
296 test_config "url.trash2/.pushInsteadOf" testrepo/ &&
297 test_config "url.trash3/.pushInsteadOf" trash/wrong &&
298 test_config remote.r.url trash/wrong &&
299 test_config remote.r.pushurl "testrepo/" &&
300 git push r refs/heads/main:refs/remotes/origin/main &&
303 echo "$the_commit commit refs/remotes/origin/main" >expect &&
304 git for-each-ref refs/remotes/origin >actual &&
305 test_cmp expect actual
309 test_expect_success
'push with matching heads' '
311 mk_test testrepo heads/main &&
312 git push testrepo : &&
313 check_push_result testrepo $the_commit heads/main
317 test_expect_success
'push with matching heads on the command line' '
319 mk_test testrepo heads/main &&
320 git push testrepo : &&
321 check_push_result testrepo $the_commit heads/main
325 test_expect_success
'failed (non-fast-forward) push with matching heads' '
327 mk_test testrepo heads/main &&
328 git push testrepo : &&
329 git commit --amend -massaged &&
330 test_must_fail git push testrepo &&
331 check_push_result testrepo $the_commit heads/main &&
332 git reset --hard $the_commit
336 test_expect_success
'push --force with matching heads' '
338 mk_test testrepo heads/main &&
339 git push testrepo : &&
340 git commit --amend -massaged &&
341 git push --force testrepo : &&
342 ! check_push_result testrepo $the_commit heads/main &&
343 git reset --hard $the_commit
347 test_expect_success
'push with matching heads and forced update' '
349 mk_test testrepo heads/main &&
350 git push testrepo : &&
351 git commit --amend -massaged &&
352 git push testrepo +: &&
353 ! check_push_result testrepo $the_commit heads/main &&
354 git reset --hard $the_commit
358 test_expect_success
'push with no ambiguity (1)' '
360 mk_test testrepo heads/main &&
361 git push testrepo main:main &&
362 check_push_result testrepo $the_commit heads/main
366 test_expect_success
'push with no ambiguity (2)' '
368 mk_test testrepo remotes/origin/main &&
369 git push testrepo main:origin/main &&
370 check_push_result testrepo $the_commit remotes/origin/main
374 test_expect_success
'push with colon-less refspec, no ambiguity' '
376 mk_test testrepo heads/main heads/t/main &&
377 git branch -f t/main main &&
378 git push testrepo main &&
379 check_push_result testrepo $the_commit heads/main &&
380 check_push_result testrepo $the_first_commit heads/t/main
384 test_expect_success
'push with weak ambiguity (1)' '
386 mk_test testrepo heads/main remotes/origin/main &&
387 git push testrepo main:main &&
388 check_push_result testrepo $the_commit heads/main &&
389 check_push_result testrepo $the_first_commit remotes/origin/main
393 test_expect_success
'push with weak ambiguity (2)' '
395 mk_test testrepo heads/main remotes/origin/main remotes/another/main &&
396 git push testrepo main:main &&
397 check_push_result testrepo $the_commit heads/main &&
398 check_push_result testrepo $the_first_commit remotes/origin/main remotes/another/main
402 test_expect_success
'push with ambiguity' '
404 mk_test testrepo heads/frotz tags/frotz &&
405 test_must_fail git push testrepo main:frotz &&
406 check_push_result testrepo $the_first_commit heads/frotz tags/frotz
410 test_expect_success
'push with colon-less refspec (1)' '
412 mk_test testrepo heads/frotz tags/frotz &&
413 git branch -f frotz main &&
414 git push testrepo frotz &&
415 check_push_result testrepo $the_commit heads/frotz &&
416 check_push_result testrepo $the_first_commit tags/frotz
420 test_expect_success
'push with colon-less refspec (2)' '
422 mk_test testrepo heads/frotz tags/frotz &&
423 if git show-ref --verify -q refs/heads/frotz
428 git push -f testrepo frotz &&
429 check_push_result testrepo $the_commit tags/frotz &&
430 check_push_result testrepo $the_first_commit heads/frotz
434 test_expect_success
'push with colon-less refspec (3)' '
437 if git show-ref --verify -q refs/tags/frotz
441 git branch -f frotz main &&
442 git push testrepo frotz &&
443 check_push_result testrepo $the_commit heads/frotz &&
444 test 1 = $( cd testrepo && git show-ref | wc -l )
447 test_expect_success
'push with colon-less refspec (4)' '
450 if git show-ref --verify -q refs/heads/frotz
455 git push testrepo frotz &&
456 check_push_result testrepo $the_commit tags/frotz &&
457 test 1 = $( cd testrepo && git show-ref | wc -l )
461 test_expect_success
'push head with non-existent, incomplete dest' '
464 git push testrepo main:branch &&
465 check_push_result testrepo $the_commit heads/branch
469 test_expect_success
'push tag with non-existent, incomplete dest' '
473 git push testrepo v1.0:tag &&
474 check_push_result testrepo $the_commit tags/tag
478 test_expect_success
'push sha1 with non-existent, incomplete dest' '
481 test_must_fail git push testrepo $(git rev-parse main):foo
485 test_expect_success
'push ref expression with non-existent, incomplete dest' '
488 test_must_fail git push testrepo main^:branch
495 test_expect_success
"push with $head" '
496 mk_test testrepo heads/main &&
498 git push testrepo $head &&
499 check_push_result testrepo $the_commit heads/main
502 test_expect_success
"push with $head nonexisting at remote" '
503 mk_test testrepo heads/main &&
504 git checkout -b local main &&
505 test_when_finished "git checkout main; git branch -D local" &&
506 git push testrepo $head &&
507 check_push_result testrepo $the_commit heads/local
510 test_expect_success
"push with +$head" '
511 mk_test testrepo heads/main &&
512 git checkout -b local main &&
513 test_when_finished "git checkout main; git branch -D local" &&
514 git push testrepo main local &&
515 check_push_result testrepo $the_commit heads/main &&
516 check_push_result testrepo $the_commit heads/local &&
518 # Without force rewinding should fail
519 git reset --hard $head^ &&
520 test_must_fail git push testrepo $head &&
521 check_push_result testrepo $the_commit heads/local &&
523 # With force rewinding should succeed
524 git push testrepo +$head &&
525 check_push_result testrepo $the_first_commit heads/local
528 test_expect_success
"push $head with non-existent, incomplete dest" '
531 git push testrepo $head:branch &&
532 check_push_result testrepo $the_commit heads/branch
536 test_expect_success
"push with config remote.*.push = $head" '
537 mk_test testrepo heads/local &&
539 git branch -f local $the_commit &&
540 test_when_finished "git branch -D local" &&
543 git checkout local &&
544 git reset --hard $the_first_commit
546 test_config remote.there.url testrepo &&
547 test_config remote.there.push $head &&
548 test_config branch.main.remote there &&
550 check_push_result testrepo $the_commit heads/main &&
551 check_push_result testrepo $the_first_commit heads/local
556 test_expect_success
"push to remote with no explicit refspec and config remote.*.push = src:dest" '
557 mk_test testrepo heads/main &&
558 git checkout $the_first_commit &&
559 test_config remote.there.url testrepo &&
560 test_config remote.there.push refs/heads/main:refs/heads/main &&
562 check_push_result testrepo $the_commit heads/main
565 test_expect_success
'push with remote.pushdefault' '
566 mk_test up_repo heads/main &&
567 mk_test down_repo heads/main &&
568 test_config remote.up.url up_repo &&
569 test_config remote.down.url down_repo &&
570 test_config branch.main.remote up &&
571 test_config remote.pushdefault down &&
572 test_config push.default matching &&
574 check_push_result up_repo $the_first_commit heads/main &&
575 check_push_result down_repo $the_commit heads/main
578 test_expect_success
'push with config remote.*.pushurl' '
580 mk_test testrepo heads/main &&
582 test_config remote.there.url test2repo &&
583 test_config remote.there.pushurl testrepo &&
585 check_push_result testrepo $the_commit heads/main
588 test_expect_success
'push with config branch.*.pushremote' '
589 mk_test up_repo heads/main &&
590 mk_test side_repo heads/main &&
591 mk_test down_repo heads/main &&
592 test_config remote.up.url up_repo &&
593 test_config remote.pushdefault side_repo &&
594 test_config remote.down.url down_repo &&
595 test_config branch.main.remote up &&
596 test_config branch.main.pushremote down &&
597 test_config push.default matching &&
599 check_push_result up_repo $the_first_commit heads/main &&
600 check_push_result side_repo $the_first_commit heads/main &&
601 check_push_result down_repo $the_commit heads/main
604 test_expect_success
'branch.*.pushremote config order is irrelevant' '
605 mk_test one_repo heads/main &&
606 mk_test two_repo heads/main &&
607 test_config remote.one.url one_repo &&
608 test_config remote.two.url two_repo &&
609 test_config branch.main.pushremote two_repo &&
610 test_config remote.pushdefault one_repo &&
611 test_config push.default matching &&
613 check_push_result one_repo $the_first_commit heads/main &&
614 check_push_result two_repo $the_commit heads/main
617 test_expect_success
'push with dry-run' '
619 mk_test testrepo heads/main &&
620 old_commit=$(git -C testrepo show-ref -s --verify refs/heads/main) &&
621 git push --dry-run testrepo : &&
622 check_push_result testrepo $old_commit heads/main
625 test_expect_success
'push updates local refs' '
627 mk_test testrepo heads/main &&
628 mk_child testrepo child &&
633 test $(git rev-parse main) = \
634 $(git rev-parse remotes/origin/main)
639 test_expect_success
'push updates up-to-date local refs' '
641 mk_test testrepo heads/main &&
642 mk_child testrepo child1 &&
643 mk_child testrepo child2 &&
644 (cd child1 && git pull .. main && git push) &&
647 git pull ../child1 main &&
649 test $(git rev-parse main) = \
650 $(git rev-parse remotes/origin/main)
655 test_expect_success
'push preserves up-to-date packed refs' '
657 mk_test testrepo heads/main &&
658 mk_child testrepo child &&
662 ! test -f .git/refs/remotes/origin/main
667 test_expect_success
'push does not update local refs on failure' '
669 mk_test testrepo heads/main &&
670 mk_child testrepo child &&
671 mkdir testrepo/.git/hooks &&
672 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
673 chmod +x testrepo/.git/hooks/pre-receive &&
677 test_must_fail git push &&
678 test $(git rev-parse main) != \
679 $(git rev-parse remotes/origin/main)
684 test_expect_success
'allow deleting an invalid remote ref' '
686 mk_test testrepo heads/branch &&
687 rm -f testrepo/.git/objects/??/* &&
688 git push testrepo :refs/heads/branch &&
689 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/branch)
693 test_expect_success
'pushing valid refs triggers post-receive and post-update hooks' '
694 mk_test_with_hooks testrepo heads/main heads/next &&
695 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
696 newmain=$(git show-ref -s --verify refs/heads/main) &&
697 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
699 git push testrepo refs/heads/main:refs/heads/main :refs/heads/next &&
702 cat >pre-receive.expect <<-EOF &&
703 $orgmain $newmain refs/heads/main
704 $orgnext $newnext refs/heads/next
707 cat >update.expect <<-EOF &&
708 refs/heads/main $orgmain $newmain
709 refs/heads/next $orgnext $newnext
712 cat >post-receive.expect <<-EOF &&
713 $orgmain $newmain refs/heads/main
714 $orgnext $newnext refs/heads/next
717 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
'deleting dangling ref triggers hooks with correct args' '
730 mk_test_with_hooks testrepo heads/branch &&
731 orig=$(git -C testrepo rev-parse refs/heads/branch) &&
732 rm -f testrepo/.git/objects/??/* &&
733 git push testrepo :refs/heads/branch &&
736 cat >pre-receive.expect <<-EOF &&
737 $orig $ZERO_OID refs/heads/branch
740 cat >update.expect <<-EOF &&
741 refs/heads/branch $orig $ZERO_OID
744 cat >post-receive.expect <<-EOF &&
745 $orig $ZERO_OID refs/heads/branch
748 cat >post-update.expect <<-EOF &&
752 test_cmp pre-receive.expect pre-receive.actual &&
753 test_cmp update.expect update.actual &&
754 test_cmp post-receive.expect post-receive.actual &&
755 test_cmp post-update.expect post-update.actual
759 test_expect_success
'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
760 mk_test_with_hooks testrepo heads/main &&
761 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
762 newmain=$(git show-ref -s --verify refs/heads/main) &&
763 git push testrepo main :refs/heads/nonexistent &&
766 cat >pre-receive.expect <<-EOF &&
767 $orgmain $newmain refs/heads/main
768 $ZERO_OID $ZERO_OID refs/heads/nonexistent
771 cat >update.expect <<-EOF &&
772 refs/heads/main $orgmain $newmain
773 refs/heads/nonexistent $ZERO_OID $ZERO_OID
776 cat >post-receive.expect <<-EOF &&
777 $orgmain $newmain refs/heads/main
780 cat >post-update.expect <<-EOF &&
784 test_cmp pre-receive.expect pre-receive.actual &&
785 test_cmp update.expect update.actual &&
786 test_cmp post-receive.expect post-receive.actual &&
787 test_cmp post-update.expect post-update.actual
791 test_expect_success
'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
792 mk_test_with_hooks testrepo heads/main &&
793 git push testrepo :refs/heads/nonexistent &&
796 cat >pre-receive.expect <<-EOF &&
797 $ZERO_OID $ZERO_OID refs/heads/nonexistent
800 cat >update.expect <<-EOF &&
801 refs/heads/nonexistent $ZERO_OID $ZERO_OID
804 test_cmp pre-receive.expect pre-receive.actual &&
805 test_cmp update.expect update.actual &&
806 test_path_is_missing post-receive.actual &&
807 test_path_is_missing post-update.actual
811 test_expect_success
'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
812 mk_test_with_hooks testrepo heads/main heads/next heads/seen &&
813 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
814 newmain=$(git show-ref -s --verify refs/heads/main) &&
815 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
817 orgseen=$(cd testrepo && git show-ref -s --verify refs/heads/seen) &&
818 newseen=$(git show-ref -s --verify refs/heads/main) &&
819 git push testrepo refs/heads/main:refs/heads/main \
820 refs/heads/main:refs/heads/seen :refs/heads/next \
821 :refs/heads/nonexistent &&
824 cat >pre-receive.expect <<-EOF &&
825 $orgmain $newmain refs/heads/main
826 $orgnext $newnext refs/heads/next
827 $orgseen $newseen refs/heads/seen
828 $ZERO_OID $ZERO_OID refs/heads/nonexistent
831 cat >update.expect <<-EOF &&
832 refs/heads/main $orgmain $newmain
833 refs/heads/next $orgnext $newnext
834 refs/heads/seen $orgseen $newseen
835 refs/heads/nonexistent $ZERO_OID $ZERO_OID
838 cat >post-receive.expect <<-EOF &&
839 $orgmain $newmain refs/heads/main
840 $orgnext $newnext refs/heads/next
841 $orgseen $newseen refs/heads/seen
844 cat >post-update.expect <<-EOF &&
850 test_cmp pre-receive.expect pre-receive.actual &&
851 test_cmp update.expect update.actual &&
852 test_cmp post-receive.expect post-receive.actual &&
853 test_cmp post-update.expect post-update.actual
857 test_expect_success
'allow deleting a ref using --delete' '
858 mk_test testrepo heads/main &&
859 (cd testrepo && git config receive.denyDeleteCurrent warn) &&
860 git push testrepo --delete main &&
861 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/main)
864 test_expect_success
'allow deleting a tag using --delete' '
865 mk_test testrepo heads/main &&
866 git tag -a -m dummy_message deltag heads/main &&
867 git push testrepo --tags &&
868 (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
869 git push testrepo --delete tag deltag &&
870 (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
873 test_expect_success
'push --delete without args aborts' '
874 mk_test testrepo heads/main &&
875 test_must_fail git push testrepo --delete
878 test_expect_success
'push --delete refuses src:dest refspecs' '
879 mk_test testrepo heads/main &&
880 test_must_fail git push testrepo --delete main:foo
883 test_expect_success
'push --delete refuses empty string' '
884 mk_test testrepo heads/master &&
885 test_must_fail git push testrepo --delete ""
888 test_expect_success
'warn on push to HEAD of non-bare repository' '
889 mk_test testrepo heads/main &&
893 git config receive.denyCurrentBranch warn
895 git push testrepo main 2>stderr &&
896 grep "warning: updating the current branch" stderr
899 test_expect_success
'deny push to HEAD of non-bare repository' '
900 mk_test testrepo heads/main &&
904 git config receive.denyCurrentBranch true
906 test_must_fail git push testrepo main
909 test_expect_success
'allow push to HEAD of bare repository (bare)' '
910 mk_test testrepo heads/main &&
914 git config receive.denyCurrentBranch true &&
915 git config core.bare true
917 git push testrepo main 2>stderr &&
918 ! grep "warning: updating the current branch" stderr
921 test_expect_success
'allow push to HEAD of non-bare repository (config)' '
922 mk_test testrepo heads/main &&
926 git config receive.denyCurrentBranch false
928 git push testrepo main 2>stderr &&
929 ! grep "warning: updating the current branch" stderr
932 test_expect_success
'fetch with branches' '
934 git branch second $the_first_commit &&
935 git checkout second &&
936 echo ".." > testrepo/.git/branches/branch1 &&
940 echo "$the_commit commit refs/heads/branch1" >expect &&
941 git for-each-ref refs/heads >actual &&
942 test_cmp expect actual
947 test_expect_success
'fetch with branches containing #' '
949 echo "..#second" > testrepo/.git/branches/branch2 &&
953 echo "$the_first_commit commit refs/heads/branch2" >expect &&
954 git for-each-ref refs/heads >actual &&
955 test_cmp expect actual
960 test_expect_success
'push with branches' '
962 git checkout second &&
963 echo "testrepo" > .git/branches/branch1 &&
967 echo "$the_first_commit commit refs/heads/main" >expect &&
968 git for-each-ref refs/heads >actual &&
969 test_cmp expect actual
973 test_expect_success
'push with branches containing #' '
975 echo "testrepo#branch3" > .git/branches/branch2 &&
979 echo "$the_first_commit commit refs/heads/branch3" >expect &&
980 git for-each-ref refs/heads >actual &&
981 test_cmp expect actual
986 test_expect_success
'push into aliased refs (consistent)' '
987 mk_test testrepo heads/main &&
988 mk_child testrepo child1 &&
989 mk_child testrepo child2 &&
993 git symbolic-ref refs/heads/bar refs/heads/foo &&
994 git config receive.denyCurrentBranch false
1001 git commit -a -m child2 &&
1004 git push ../child1 foo bar
1008 test_expect_success
'push into aliased refs (inconsistent)' '
1009 mk_test testrepo heads/main &&
1010 mk_child testrepo child1 &&
1011 mk_child testrepo child2 &&
1015 git symbolic-ref refs/heads/bar refs/heads/foo &&
1016 git config receive.denyCurrentBranch false
1023 git commit -a -m child2 &&
1028 git commit -a -m child2 &&
1030 test_must_fail git push ../child1 foo bar 2>stderr &&
1031 grep "refusing inconsistent update" stderr
1035 test_force_push_tag
() {
1036 tag_type_description
=$1
1039 test_expect_success
"force pushing required to update $tag_type_description" "
1040 mk_test testrepo heads/main &&
1041 mk_child testrepo child1 &&
1042 mk_child testrepo child2 &&
1046 git push ../child2 testTag &&
1049 git commit -m 'file1' &&
1050 git tag $tag_args testTag &&
1051 test_must_fail git push ../child2 testTag &&
1052 git push --force ../child2 testTag &&
1053 git tag $tag_args testTag HEAD~ &&
1054 test_must_fail git push ../child2 testTag &&
1055 git push --force ../child2 testTag &&
1057 # Clobbering without + in refspec needs --force
1058 git tag -f testTag &&
1059 test_must_fail git push ../child2 'refs/tags/*:refs/tags/*' &&
1060 git push --force ../child2 'refs/tags/*:refs/tags/*' &&
1062 # Clobbering with + in refspec does not need --force
1063 git tag -f testTag HEAD~ &&
1064 git push ../child2 '+refs/tags/*:refs/tags/*' &&
1066 # Clobbering with --no-force still obeys + in refspec
1067 git tag -f testTag &&
1068 git push --no-force ../child2 '+refs/tags/*:refs/tags/*' &&
1070 # Clobbering with/without --force and 'tag <name>' format
1071 git tag -f testTag HEAD~ &&
1072 test_must_fail git push ../child2 tag testTag &&
1073 git push --force ../child2 tag testTag
1078 test_force_push_tag
"lightweight tag" "-f"
1079 test_force_push_tag
"annotated tag" "-f -a -m'tag message'"
1081 test_force_fetch_tag
() {
1082 tag_type_description
=$1
1085 test_expect_success
"fetch will not clobber an existing $tag_type_description without --force" "
1086 mk_test testrepo heads/main &&
1087 mk_child testrepo child1 &&
1088 mk_child testrepo child2 &&
1092 git -C ../child1 fetch origin tag testTag &&
1095 git commit -m 'file1' &&
1096 git tag $tag_args testTag &&
1097 test_must_fail git -C ../child1 fetch origin tag testTag &&
1098 git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*'
1103 test_force_fetch_tag
"lightweight tag" "-f"
1104 test_force_fetch_tag
"annotated tag" "-f -a -m'tag message'"
1106 test_expect_success
'push --porcelain' '
1107 mk_empty testrepo &&
1108 echo >.git/foo "To testrepo" &&
1109 echo >>.git/foo "* refs/heads/main:refs/remotes/origin/main [new reference]" &&
1110 echo >>.git/foo "Done" &&
1111 git push >.git/bar --porcelain testrepo refs/heads/main:refs/remotes/origin/main &&
1114 echo "$the_commit commit refs/remotes/origin/main" >expect &&
1115 git for-each-ref refs/remotes/origin >actual &&
1116 test_cmp expect actual
1118 test_cmp .git/foo .git/bar
1121 test_expect_success
'push --porcelain bad url' '
1122 mk_empty testrepo &&
1123 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/main:refs/remotes/origin/main &&
1124 ! grep -q Done .git/bar
1127 test_expect_success
'push --porcelain rejected' '
1128 mk_empty testrepo &&
1129 git push testrepo refs/heads/main:refs/remotes/origin/main &&
1131 git reset --hard origin/main^ &&
1132 git config receive.denyCurrentBranch true) &&
1134 echo >.git/foo "To testrepo" &&
1135 echo >>.git/foo "! refs/heads/main:refs/heads/main [remote rejected] (branch is currently checked out)" &&
1136 echo >>.git/foo "Done" &&
1138 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/main:refs/heads/main &&
1139 test_cmp .git/foo .git/bar
1142 test_expect_success
'push --porcelain --dry-run rejected' '
1143 mk_empty testrepo &&
1144 git push testrepo refs/heads/main:refs/remotes/origin/main &&
1146 git reset --hard origin/main &&
1147 git config receive.denyCurrentBranch true) &&
1149 echo >.git/foo "To testrepo" &&
1150 echo >>.git/foo "! refs/heads/main^:refs/heads/main [rejected] (non-fast-forward)" &&
1151 echo >>.git/foo "Done" &&
1153 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/main^:refs/heads/main &&
1154 test_cmp .git/foo .git/bar
1157 test_expect_success
'push --prune' '
1158 mk_test testrepo heads/main heads/second heads/foo heads/bar &&
1159 git push --prune testrepo : &&
1160 check_push_result testrepo $the_commit heads/main &&
1161 check_push_result testrepo $the_first_commit heads/second &&
1162 ! check_push_result testrepo $the_first_commit heads/foo heads/bar
1165 test_expect_success
'push --prune refspec' '
1166 mk_test testrepo tmp/main tmp/second tmp/foo tmp/bar &&
1167 git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
1168 check_push_result testrepo $the_commit tmp/main &&
1169 check_push_result testrepo $the_first_commit tmp/second &&
1170 ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
1173 for configsection
in transfer receive
1175 test_expect_success
"push to update a ref hidden by $configsection.hiderefs" '
1176 mk_test testrepo heads/main hidden/one hidden/two hidden/three &&
1179 git config $configsection.hiderefs refs/hidden
1182 # push to unhidden ref succeeds normally
1183 git push testrepo main:refs/heads/main &&
1184 check_push_result testrepo $the_commit heads/main &&
1186 # push to update a hidden ref should fail
1187 test_must_fail git push testrepo main:refs/hidden/one &&
1188 check_push_result testrepo $the_first_commit hidden/one &&
1190 # push to delete a hidden ref should fail
1191 test_must_fail git push testrepo :refs/hidden/two &&
1192 check_push_result testrepo $the_first_commit hidden/two &&
1194 # idempotent push to update a hidden ref should fail
1195 test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
1196 check_push_result testrepo $the_first_commit hidden/three
1200 test_expect_success
'fetch exact SHA1' '
1201 mk_test testrepo heads/main hidden/one &&
1202 git push testrepo main:refs/hidden/one &&
1205 git config transfer.hiderefs refs/hidden
1207 check_push_result testrepo $the_commit hidden/one &&
1209 mk_child testrepo child &&
1213 # make sure $the_commit does not exist here
1216 test_must_fail git cat-file -t $the_commit &&
1218 # Some protocol versions (e.g. 2) support fetching
1219 # unadvertised objects, so restrict this test to v0.
1221 # fetching the hidden object should fail by default
1222 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1223 git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err &&
1224 test_i18ngrep "Server does not allow request for unadvertised object" err &&
1225 test_must_fail git rev-parse --verify refs/heads/copy &&
1227 # the server side can allow it to succeed
1230 git config uploadpack.allowtipsha1inwant true
1233 git fetch -v ../testrepo $the_commit:refs/heads/copy main:refs/heads/extra &&
1234 cat >expect <<-EOF &&
1239 git rev-parse --verify refs/heads/copy &&
1240 git rev-parse --verify refs/heads/extra
1242 test_cmp expect actual
1246 test_expect_success
'fetch exact SHA1 in protocol v2' '
1247 mk_test testrepo heads/main hidden/one &&
1248 git push testrepo main:refs/hidden/one &&
1249 git -C testrepo config transfer.hiderefs refs/hidden &&
1250 check_push_result testrepo $the_commit hidden/one &&
1252 mk_child testrepo child &&
1253 git -C child config protocol.version 2 &&
1255 # make sure $the_commit does not exist here
1256 git -C child repack -a -d &&
1257 git -C child prune &&
1258 test_must_fail git -C child cat-file -t $the_commit &&
1260 # fetching the hidden object succeeds by default
1261 # NEEDSWORK: should this match the v0 behavior instead?
1262 git -C child fetch -v ../testrepo $the_commit:refs/heads/copy
1265 for configallowtipsha1inwant
in true false
1267 test_expect_success
"shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" '
1268 mk_empty testrepo &&
1271 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1272 git commit --allow-empty -m foo &&
1273 git commit --allow-empty -m bar
1275 SHA1=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1279 # Some protocol versions (e.g. 2) support fetching
1280 # unadvertised objects, so restrict this test to v0.
1281 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1282 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1283 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1284 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1285 git cat-file commit $SHA1
1289 test_expect_success
"deny fetch unreachable SHA1, allowtipsha1inwant=$configallowtipsha1inwant" '
1290 mk_empty testrepo &&
1293 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1294 git commit --allow-empty -m foo &&
1295 git commit --allow-empty -m bar &&
1296 git commit --allow-empty -m xyz
1298 SHA1_1=$(git --git-dir=testrepo/.git rev-parse HEAD^^) &&
1299 SHA1_2=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1300 SHA1_3=$(git --git-dir=testrepo/.git rev-parse HEAD) &&
1303 git reset --hard $SHA1_2 &&
1304 git cat-file commit $SHA1_1 &&
1305 git cat-file commit $SHA1_3
1310 # Some protocol versions (e.g. 2) support fetching
1311 # unadvertised objects, so restrict this test to v0.
1312 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1313 git fetch ../testrepo/.git $SHA1_3 &&
1314 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1315 git fetch ../testrepo/.git $SHA1_1 &&
1316 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1317 git fetch ../testrepo/.git $SHA1_1 &&
1318 git cat-file commit $SHA1_1 &&
1319 test_must_fail git cat-file commit $SHA1_2 &&
1320 git fetch ../testrepo/.git $SHA1_2 &&
1321 git cat-file commit $SHA1_2 &&
1322 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1323 git fetch ../testrepo/.git $SHA1_3 2>err &&
1324 # ideally we would insist this be on a "remote error:"
1325 # line, but it is racy; see the commit message
1326 test_i18ngrep "not our ref.*$SHA1_3\$" err
1331 test_expect_success
'fetch follows tags by default' '
1332 mk_test testrepo heads/main &&
1337 git pull ../testrepo main &&
1338 git tag -m "annotated" tag &&
1339 git for-each-ref >tmp1 &&
1340 sed -n "p; s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 |
1341 sort -k 3 >../expect
1346 git remote add origin ../src &&
1347 git config branch.main.remote origin &&
1348 git config branch.main.merge refs/heads/main &&
1350 git for-each-ref >../actual
1352 test_cmp expect actual
1355 test_expect_success
'peeled advertisements are not considered ref tips' '
1356 mk_empty testrepo &&
1357 git -C testrepo commit --allow-empty -m one &&
1358 git -C testrepo commit --allow-empty -m two &&
1359 git -C testrepo tag -m foo mytag HEAD^ &&
1360 oid=$(git -C testrepo rev-parse mytag^{commit}) &&
1361 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1362 git fetch testrepo $oid 2>err &&
1363 test_i18ngrep "Server does not allow request for unadvertised object" err
1366 test_expect_success
'pushing a specific ref applies remote.$name.push as refmap' '
1367 mk_test testrepo heads/main &&
1370 git init --bare dst &&
1373 git pull ../testrepo main &&
1375 git config remote.dst.url ../dst &&
1376 git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" &&
1377 git push dst main &&
1378 git show-ref refs/heads/main |
1379 sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect
1383 test_must_fail git show-ref refs/heads/next &&
1384 test_must_fail git show-ref refs/heads/main &&
1385 git show-ref refs/remotes/src/main >actual
1387 test_cmp dst/expect dst/actual
1390 test_expect_success
'with no remote.$name.push, it is not used as refmap' '
1391 mk_test testrepo heads/main &&
1394 git init --bare dst &&
1397 git pull ../testrepo main &&
1399 git config remote.dst.url ../dst &&
1400 git config push.default matching &&
1401 git push dst main &&
1402 git show-ref refs/heads/main >../dst/expect
1406 test_must_fail git show-ref refs/heads/next &&
1407 git show-ref refs/heads/main >actual
1409 test_cmp dst/expect dst/actual
1412 test_expect_success
'with no remote.$name.push, upstream mapping is used' '
1413 mk_test testrepo heads/main &&
1416 git init --bare dst &&
1419 git pull ../testrepo main &&
1421 git config remote.dst.url ../dst &&
1422 git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" &&
1423 git config push.default upstream &&
1425 git config branch.main.merge refs/heads/trunk &&
1426 git config branch.main.remote dst &&
1428 git push dst main &&
1429 git show-ref refs/heads/main |
1430 sed -e "s|refs/heads/main|refs/heads/trunk|" >../dst/expect
1434 test_must_fail git show-ref refs/heads/main &&
1435 test_must_fail git show-ref refs/heads/next &&
1436 git show-ref refs/heads/trunk >actual
1438 test_cmp dst/expect dst/actual
1441 test_expect_success
'push does not follow tags by default' '
1442 mk_test testrepo heads/main &&
1445 git init --bare dst &&
1448 git pull ../testrepo main &&
1449 git tag -m "annotated" tag &&
1450 git checkout -b another &&
1451 git commit --allow-empty -m "future commit" &&
1452 git tag -m "future" future &&
1453 git checkout main &&
1454 git for-each-ref refs/heads/main >../expect &&
1455 git push ../dst main
1459 git for-each-ref >../actual
1461 test_cmp expect actual
1464 test_expect_success
'push --follow-tags only pushes relevant tags' '
1465 mk_test testrepo heads/main &&
1468 git init --bare dst &&
1471 git pull ../testrepo main &&
1472 git tag -m "annotated" tag &&
1473 git checkout -b another &&
1474 git commit --allow-empty -m "future commit" &&
1475 git tag -m "future" future &&
1476 git checkout main &&
1477 git for-each-ref refs/heads/main refs/tags/tag >../expect &&
1478 git push --follow-tags ../dst main
1482 git for-each-ref >../actual
1484 test_cmp expect actual
1487 test_expect_success
'push --no-thin must produce non-thin pack' '
1488 cat >>path1 <<\EOF &&
1489 keep base version of path1 big enough, compared to the new changes
1490 later, in order to pass size heuristics in
1491 builtin/pack-objects.c:try_delta()
1493 git commit -am initial &&
1495 git --git-dir=no-thin/.git config receive.unpacklimit 0 &&
1496 git push no-thin/.git refs/heads/main:refs/heads/foo &&
1497 echo modified >> path1 &&
1498 git commit -am modified &&
1500 rcvpck="git receive-pack --reject-thin-pack-for-testing" &&
1501 git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/main:refs/heads/foo
1504 test_expect_success
'pushing a tag pushes the tagged object' '
1506 blob=$(echo unreferenced | git hash-object -w --stdin) &&
1507 git tag -m foo tag-of-blob $blob &&
1508 git init --bare dst.git &&
1509 git push dst.git tag-of-blob &&
1510 # the receiving index-pack should have noticed
1511 # any problems, but we double check
1512 echo unreferenced >expect &&
1513 git --git-dir=dst.git cat-file blob tag-of-blob >actual &&
1514 test_cmp expect actual
1517 test_expect_success
'push into bare respects core.logallrefupdates' '
1519 git init --bare dst.git &&
1520 git -C dst.git config core.logallrefupdates true &&
1522 # double push to test both with and without
1523 # the actual pack transfer
1524 git push dst.git main:one &&
1525 echo "one@{0} push" >expect &&
1526 git -C dst.git log -g --format="%gd %gs" one >actual &&
1527 test_cmp expect actual &&
1529 git push dst.git main:two &&
1530 echo "two@{0} push" >expect &&
1531 git -C dst.git log -g --format="%gd %gs" two >actual &&
1532 test_cmp expect actual
1535 test_expect_success
'fetch into bare respects core.logallrefupdates' '
1537 git init --bare dst.git &&
1540 git config core.logallrefupdates true &&
1542 # as above, we double-fetch to test both
1543 # with and without pack transfer
1544 git fetch .. main:one &&
1545 echo "one@{0} fetch .. main:one: storing head" >expect &&
1546 git log -g --format="%gd %gs" one >actual &&
1547 test_cmp expect actual &&
1549 git fetch .. main:two &&
1550 echo "two@{0} fetch .. main:two: storing head" >expect &&
1551 git log -g --format="%gd %gs" two >actual &&
1552 test_cmp expect actual
1556 test_expect_success
'receive.denyCurrentBranch = updateInstead' '
1557 git push testrepo main &&
1561 git config receive.denyCurrentBranch updateInstead
1563 test_commit third path2 &&
1565 # Try pushing into a repository with pristine working tree
1566 git push testrepo main &&
1569 git update-index -q --refresh &&
1570 git diff-files --quiet -- &&
1571 git diff-index --quiet --cached HEAD -- &&
1572 test third = "$(cat path2)" &&
1573 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1576 # Try pushing into a repository with working tree needing a refresh
1579 git reset --hard HEAD^ &&
1580 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1581 test-tool chmtime +100 path1
1583 git push testrepo main &&
1586 git update-index -q --refresh &&
1587 git diff-files --quiet -- &&
1588 git diff-index --quiet --cached HEAD -- &&
1589 test_cmp ../path1 path1 &&
1590 test third = "$(cat path2)" &&
1591 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1594 # Update what is to be pushed
1595 test_commit fourth path2 &&
1597 # Try pushing into a repository with a dirty working tree
1598 # (1) the working tree updated
1603 test_must_fail git push testrepo main &&
1606 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1607 git diff --quiet --cached &&
1608 test changed = "$(cat path1)"
1611 # (2) the index updated
1614 echo changed >path1 &&
1617 test_must_fail git push testrepo main &&
1620 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1622 test changed = "$(cat path1)"
1625 # Introduce a new file in the update
1626 test_commit fifth path3 &&
1628 # (3) the working tree has an untracked file that would interfere
1634 test_must_fail git push testrepo main &&
1637 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1639 git diff --quiet --cached &&
1640 test changed = "$(cat path3)"
1643 # (4) the target changes to what gets pushed but it still is a change
1647 echo fifth >path3 &&
1650 test_must_fail git push testrepo main &&
1653 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1655 test fifth = "$(cat path3)"
1658 # (5) push into void
1663 git config receive.denyCurrentBranch updateInstead
1665 git push void main &&
1668 test $(git -C .. rev-parse main) = $(git rev-parse HEAD) &&
1670 git diff --cached --quiet
1673 # (6) updateInstead intervened by fast-forward check
1674 test_must_fail git push void main^:main &&
1675 test $(git -C void rev-parse HEAD) = $(git rev-parse main) &&
1676 git -C void diff --quiet &&
1677 git -C void diff --cached --quiet
1680 test_expect_success
'updateInstead with push-to-checkout hook' '
1682 git init testrepo &&
1686 git reset --hard HEAD^^ &&
1688 git config receive.denyCurrentBranch updateInstead &&
1689 write_script .git/hooks/push-to-checkout <<-\EOF
1690 echo >&2 updating from $(git rev-parse HEAD)
1691 echo >&2 updating to "$1"
1693 git update-index -q --refresh &&
1694 git read-tree -u -m HEAD "$1" || {
1696 echo >&2 read-tree failed
1702 # Try pushing into a pristine
1703 git push testrepo main &&
1707 git diff HEAD --quiet &&
1708 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1711 # Try pushing into a repository with conflicting change
1714 git reset --hard initial &&
1715 echo conflicting >path2
1717 test_must_fail git push testrepo main &&
1720 test $(git rev-parse initial) = $(git rev-parse HEAD) &&
1721 test conflicting = "$(cat path2)" &&
1722 git diff-index --quiet --cached HEAD
1725 # Try pushing into a repository with unrelated change
1728 git reset --hard initial &&
1729 echo unrelated >path1 &&
1730 echo irrelevant >path5 &&
1733 git push testrepo main &&
1736 test "$(cat path1)" = unrelated &&
1737 test "$(cat path5)" = irrelevant &&
1738 test "$(git diff --name-only --cached HEAD)" = path5 &&
1739 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1747 git config receive.denyCurrentBranch updateInstead &&
1748 write_script .git/hooks/push-to-checkout <<-\EOF
1749 if git rev-parse --quiet --verify HEAD
1752 echo >&2 updating from $(git rev-parse HEAD)
1755 echo >&2 pushing into void
1757 echo >&2 updating to "$1"
1759 git update-index -q --refresh &&
1762 git read-tree -u -m HEAD "$1" ;;
1764 git read-tree -u -m "$1" ;;
1767 echo >&2 read-tree failed
1773 git push void main &&
1777 git diff --cached --quiet &&
1778 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1782 test_expect_success
'denyCurrentBranch and worktrees' '
1783 git worktree add new-wt &&
1784 git clone . cloned &&
1785 test_commit -C cloned first &&
1786 test_config receive.denyCurrentBranch refuse &&
1787 test_must_fail git -C cloned push origin HEAD:new-wt &&
1788 test_config receive.denyCurrentBranch updateInstead &&
1789 git -C cloned push origin HEAD:new-wt &&
1790 test_path_exists new-wt/first.t &&
1791 test_must_fail git -C cloned push --delete origin new-wt
1794 test_expect_success
'denyCurrentBranch and bare repository worktrees' '
1795 test_when_finished "rm -fr bare.git" &&
1796 git clone --bare . bare.git &&
1797 git -C bare.git worktree add wt &&
1798 test_commit grape &&
1799 git -C bare.git config receive.denyCurrentBranch refuse &&
1800 test_must_fail git push bare.git HEAD:wt &&
1801 git -C bare.git config receive.denyCurrentBranch updateInstead &&
1802 git push bare.git HEAD:wt &&
1803 test_path_exists bare.git/wt/grape.t &&
1804 test_must_fail git push --delete bare.git wt
1807 test_expect_success
'refuse fetch to current branch of worktree' '
1808 test_when_finished "git worktree remove --force wt && git branch -D wt" &&
1809 git worktree add wt &&
1810 test_commit apple &&
1811 test_must_fail git fetch . HEAD:wt &&
1812 git fetch -u . HEAD:wt
1815 test_expect_success
'refuse fetch to current branch of bare repository worktree' '
1816 test_when_finished "rm -fr bare.git" &&
1817 git clone --bare . bare.git &&
1818 git -C bare.git worktree add wt &&
1819 test_commit banana &&
1820 test_must_fail git -C bare.git fetch .. HEAD:wt &&
1821 git -C bare.git fetch -u .. HEAD:wt