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
18 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
19 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
27 test_when_finished
"rm -rf \"$repo_name\"" &&
28 test_path_is_missing
"$repo_name" &&
29 git init
"$repo_name" &&
30 git
-C "$repo_name" config receive.denyCurrentBranch warn
37 mk_empty
"$repo_name" &&
41 git push
"$repo_name" $the_first_commit:refs
/$ref ||
47 echo "$the_first_commit" >expect
&&
48 git show-ref
-s --verify refs
/$ref >actual
&&
49 test_cmp expect actual ||
56 mk_test_with_hooks
() {
59 test_hook
-C "$repo_name" pre-receive
<<-'EOF' &&
60 cat - >>pre-receive.actual
63 test_hook
-C "$repo_name" update
<<-'EOF' &&
64 printf "%s %s %s\n" "$@" >>update.actual
67 test_hook
-C "$repo_name" post-receive
<<-'EOF' &&
68 cat - >>post-receive.actual
71 test_hook
-C "$repo_name" post-update
<<-'EOF'
74 printf "%s\n" "$ref" >>post-update.actual
80 test_when_finished
"rm -rf \"$2\"" &&
84 check_push_result
() {
86 BUG
"check_push_result requires at least 3 parameters"
97 git show-ref
-s --verify refs
/$ref >actual
&&
98 test_cmp expect actual ||
105 test_expect_success setup
'
110 git commit -a -m repo &&
111 the_first_commit=$(git show-ref -s --verify refs/heads/main) &&
116 git commit -a -m second &&
117 the_commit=$(git show-ref -s --verify refs/heads/main)
121 test_expect_success
'fetch without wildcard' '
125 git fetch .. refs/heads/main:refs/remotes/origin/main &&
127 echo "$the_commit commit refs/remotes/origin/main" >expect &&
128 git for-each-ref refs/remotes/origin >actual &&
129 test_cmp expect actual
133 test_expect_success
'fetch with wildcard' '
137 git config remote.up.url .. &&
138 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
141 echo "$the_commit commit refs/remotes/origin/main" >expect &&
142 git for-each-ref refs/remotes/origin >actual &&
143 test_cmp expect actual
147 test_expect_success
'fetch with insteadOf' '
152 git config "url.$TRASH.insteadOf" trash/ &&
153 git config remote.up.url trash/. &&
154 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
157 echo "$the_commit commit refs/remotes/origin/main" >expect &&
158 git for-each-ref refs/remotes/origin >actual &&
159 test_cmp expect actual
163 test_expect_success
'fetch with pushInsteadOf (should not rewrite)' '
168 git config "url.trash/.pushInsteadOf" "$TRASH" &&
169 git config remote.up.url "$TRASH." &&
170 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
173 echo "$the_commit commit refs/remotes/origin/main" >expect &&
174 git for-each-ref refs/remotes/origin >actual &&
175 test_cmp expect actual
182 grep 'write_pack_file/wrote.*"value":"'$1'"' $2
185 test_expect_success
'push without negotiation' '
187 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
188 test_commit -C testrepo unrelated_commit &&
189 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
190 test_when_finished "rm event" &&
191 GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 push testrepo refs/heads/main:refs/remotes/origin/main &&
192 grep_wrote 5 event # 2 commits, 2 trees, 1 blob
195 test_expect_success
'push with negotiation' '
197 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
198 test_commit -C testrepo unrelated_commit &&
199 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
200 test_when_finished "rm event" &&
201 GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main &&
202 grep_wrote 2 event # 1 commit, 1 tree
205 test_expect_success
'push with negotiation proceeds anyway even if negotiation fails' '
207 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
208 test_commit -C testrepo unrelated_commit &&
209 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
210 test_when_finished "rm event" &&
211 GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" \
212 git -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
213 grep_wrote 5 event && # 2 commits, 2 trees, 1 blob
214 test_i18ngrep "push negotiation failed" err
217 test_expect_success
'push with negotiation does not attempt to fetch submodules' '
218 mk_empty submodule_upstream &&
219 test_commit -C submodule_upstream submodule_commit &&
220 test_config_global protocol.file.allow always &&
221 git submodule add ./submodule_upstream submodule &&
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 -c submodule.recurse=true -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
227 ! grep "Fetching submodule" err
230 test_expect_success
'push without wildcard' '
233 git push testrepo refs/heads/main:refs/remotes/origin/main &&
236 echo "$the_commit commit refs/remotes/origin/main" >expect &&
237 git for-each-ref refs/remotes/origin >actual &&
238 test_cmp expect actual
242 test_expect_success
'push with wildcard' '
245 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
248 echo "$the_commit commit refs/remotes/origin/main" >expect &&
249 git for-each-ref refs/remotes/origin >actual &&
250 test_cmp expect actual
254 test_expect_success
'push with insteadOf' '
257 test_config "url.$TRASH.insteadOf" trash/ &&
258 git push trash/testrepo refs/heads/main:refs/remotes/origin/main &&
261 echo "$the_commit commit refs/remotes/origin/main" >expect &&
262 git for-each-ref refs/remotes/origin >actual &&
263 test_cmp expect actual
267 test_expect_success
'push with pushInsteadOf' '
270 test_config "url.$TRASH.pushInsteadOf" trash/ &&
271 git push trash/testrepo refs/heads/main:refs/remotes/origin/main &&
274 echo "$the_commit commit refs/remotes/origin/main" >expect &&
275 git for-each-ref refs/remotes/origin >actual &&
276 test_cmp expect actual
280 test_expect_success
'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
282 test_config "url.trash2/.pushInsteadOf" testrepo/ &&
283 test_config "url.trash3/.pushInsteadOf" trash/wrong &&
284 test_config remote.r.url trash/wrong &&
285 test_config remote.r.pushurl "testrepo/" &&
286 git push r refs/heads/main:refs/remotes/origin/main &&
289 echo "$the_commit commit refs/remotes/origin/main" >expect &&
290 git for-each-ref refs/remotes/origin >actual &&
291 test_cmp expect actual
295 test_expect_success
'push with matching heads' '
297 mk_test testrepo heads/main &&
298 git push testrepo : &&
299 check_push_result testrepo $the_commit heads/main
303 test_expect_success
'push with matching heads on the command line' '
305 mk_test testrepo heads/main &&
306 git push testrepo : &&
307 check_push_result testrepo $the_commit heads/main
311 test_expect_success
'failed (non-fast-forward) push with matching heads' '
313 mk_test testrepo heads/main &&
314 git push testrepo : &&
315 git commit --amend -massaged &&
316 test_must_fail git push testrepo &&
317 check_push_result testrepo $the_commit heads/main &&
318 git reset --hard $the_commit
322 test_expect_success
'push --force with matching heads' '
324 mk_test testrepo heads/main &&
325 git push testrepo : &&
326 git commit --amend -massaged &&
327 git push --force testrepo : &&
328 ! check_push_result testrepo $the_commit heads/main &&
329 git reset --hard $the_commit
333 test_expect_success
'push with matching heads and forced update' '
335 mk_test testrepo heads/main &&
336 git push testrepo : &&
337 git commit --amend -massaged &&
338 git push testrepo +: &&
339 ! check_push_result testrepo $the_commit heads/main &&
340 git reset --hard $the_commit
344 test_expect_success
'push with no ambiguity (1)' '
346 mk_test testrepo heads/main &&
347 git push testrepo main:main &&
348 check_push_result testrepo $the_commit heads/main
352 test_expect_success
'push with no ambiguity (2)' '
354 mk_test testrepo remotes/origin/main &&
355 git push testrepo main:origin/main &&
356 check_push_result testrepo $the_commit remotes/origin/main
360 test_expect_success
'push with colon-less refspec, no ambiguity' '
362 mk_test testrepo heads/main heads/t/main &&
363 git branch -f t/main main &&
364 git push testrepo main &&
365 check_push_result testrepo $the_commit heads/main &&
366 check_push_result testrepo $the_first_commit heads/t/main
370 test_expect_success
'push with weak ambiguity (1)' '
372 mk_test testrepo heads/main remotes/origin/main &&
373 git push testrepo main:main &&
374 check_push_result testrepo $the_commit heads/main &&
375 check_push_result testrepo $the_first_commit remotes/origin/main
379 test_expect_success
'push with weak ambiguity (2)' '
381 mk_test testrepo heads/main remotes/origin/main remotes/another/main &&
382 git push testrepo main:main &&
383 check_push_result testrepo $the_commit heads/main &&
384 check_push_result testrepo $the_first_commit remotes/origin/main remotes/another/main
388 test_expect_success
'push with ambiguity' '
390 mk_test testrepo heads/frotz tags/frotz &&
391 test_must_fail git push testrepo main:frotz &&
392 check_push_result testrepo $the_first_commit heads/frotz tags/frotz
396 test_expect_success
'push with colon-less refspec (1)' '
398 mk_test testrepo heads/frotz tags/frotz &&
399 git branch -f frotz main &&
400 git push testrepo frotz &&
401 check_push_result testrepo $the_commit heads/frotz &&
402 check_push_result testrepo $the_first_commit tags/frotz
406 test_expect_success
'push with colon-less refspec (2)' '
408 mk_test testrepo heads/frotz tags/frotz &&
409 if git show-ref --verify -q refs/heads/frotz
414 git push -f testrepo frotz &&
415 check_push_result testrepo $the_commit tags/frotz &&
416 check_push_result testrepo $the_first_commit heads/frotz
420 test_expect_success
'push with colon-less refspec (3)' '
423 if git show-ref --verify -q refs/tags/frotz
427 git branch -f frotz main &&
428 git push testrepo frotz &&
429 check_push_result testrepo $the_commit heads/frotz &&
430 test 1 = $( cd testrepo && git show-ref | wc -l )
433 test_expect_success
'push with colon-less refspec (4)' '
436 if git show-ref --verify -q refs/heads/frotz
441 git push testrepo frotz &&
442 check_push_result testrepo $the_commit tags/frotz &&
443 test 1 = $( cd testrepo && git show-ref | wc -l )
447 test_expect_success
'push head with non-existent, incomplete dest' '
450 git push testrepo main:branch &&
451 check_push_result testrepo $the_commit heads/branch
455 test_expect_success
'push tag with non-existent, incomplete dest' '
459 git push testrepo v1.0:tag &&
460 check_push_result testrepo $the_commit tags/tag
464 test_expect_success
'push sha1 with non-existent, incomplete dest' '
467 test_must_fail git push testrepo $(git rev-parse main):foo
471 test_expect_success
'push ref expression with non-existent, incomplete dest' '
474 test_must_fail git push testrepo main^:branch
481 test_expect_success
"push with $head" '
482 mk_test testrepo heads/main &&
484 git push testrepo $head &&
485 check_push_result testrepo $the_commit heads/main
488 test_expect_success
"push with $head nonexisting at remote" '
489 mk_test testrepo heads/main &&
490 git checkout -b local main &&
491 test_when_finished "git checkout main; git branch -D local" &&
492 git push testrepo $head &&
493 check_push_result testrepo $the_commit heads/local
496 test_expect_success
"push with +$head" '
497 mk_test testrepo heads/main &&
498 git checkout -b local main &&
499 test_when_finished "git checkout main; git branch -D local" &&
500 git push testrepo main local &&
501 check_push_result testrepo $the_commit heads/main &&
502 check_push_result testrepo $the_commit heads/local &&
504 # Without force rewinding should fail
505 git reset --hard $head^ &&
506 test_must_fail git push testrepo $head &&
507 check_push_result testrepo $the_commit heads/local &&
509 # With force rewinding should succeed
510 git push testrepo +$head &&
511 check_push_result testrepo $the_first_commit heads/local
514 test_expect_success
"push $head with non-existent, incomplete dest" '
517 git push testrepo $head:branch &&
518 check_push_result testrepo $the_commit heads/branch
522 test_expect_success
"push with config remote.*.push = $head" '
523 mk_test testrepo heads/local &&
525 git branch -f local $the_commit &&
526 test_when_finished "git branch -D local" &&
529 git checkout local &&
530 git reset --hard $the_first_commit
532 test_config remote.there.url testrepo &&
533 test_config remote.there.push $head &&
534 test_config branch.main.remote there &&
536 check_push_result testrepo $the_commit heads/main &&
537 check_push_result testrepo $the_first_commit heads/local
542 test_expect_success
"push to remote with no explicit refspec and config remote.*.push = src:dest" '
543 mk_test testrepo heads/main &&
544 git checkout $the_first_commit &&
545 test_config remote.there.url testrepo &&
546 test_config remote.there.push refs/heads/main:refs/heads/main &&
548 check_push_result testrepo $the_commit heads/main
551 test_expect_success
'push with remote.pushdefault' '
552 mk_test up_repo heads/main &&
553 mk_test down_repo heads/main &&
554 test_config remote.up.url up_repo &&
555 test_config remote.down.url down_repo &&
556 test_config branch.main.remote up &&
557 test_config remote.pushdefault down &&
558 test_config push.default matching &&
560 check_push_result up_repo $the_first_commit heads/main &&
561 check_push_result down_repo $the_commit heads/main
564 test_expect_success
'push with config remote.*.pushurl' '
566 mk_test testrepo heads/main &&
568 test_config remote.there.url test2repo &&
569 test_config remote.there.pushurl testrepo &&
571 check_push_result testrepo $the_commit heads/main
574 test_expect_success
'push with config branch.*.pushremote' '
575 mk_test up_repo heads/main &&
576 mk_test side_repo heads/main &&
577 mk_test down_repo heads/main &&
578 test_config remote.up.url up_repo &&
579 test_config remote.pushdefault side_repo &&
580 test_config remote.down.url down_repo &&
581 test_config branch.main.remote up &&
582 test_config branch.main.pushremote down &&
583 test_config push.default matching &&
585 check_push_result up_repo $the_first_commit heads/main &&
586 check_push_result side_repo $the_first_commit heads/main &&
587 check_push_result down_repo $the_commit heads/main
590 test_expect_success
'branch.*.pushremote config order is irrelevant' '
591 mk_test one_repo heads/main &&
592 mk_test two_repo heads/main &&
593 test_config remote.one.url one_repo &&
594 test_config remote.two.url two_repo &&
595 test_config branch.main.pushremote two_repo &&
596 test_config remote.pushdefault one_repo &&
597 test_config push.default matching &&
599 check_push_result one_repo $the_first_commit heads/main &&
600 check_push_result two_repo $the_commit heads/main
603 test_expect_success
'push rejects empty branch name entries' '
604 mk_test one_repo heads/main &&
605 test_config remote.one.url one_repo &&
606 test_config branch..remote one &&
607 test_config branch..merge refs/heads/ &&
608 test_config branch.main.remote one &&
609 test_config branch.main.merge refs/heads/main &&
610 test_must_fail git push 2>err &&
611 grep "bad config variable .branch\.\." err
614 test_expect_success
'push ignores "branch." config without subsection' '
615 mk_test one_repo heads/main &&
616 test_config remote.one.url one_repo &&
617 test_config branch.autoSetupMerge true &&
618 test_config branch.main.remote one &&
619 test_config branch.main.merge refs/heads/main &&
623 test_expect_success
'push with dry-run' '
625 mk_test testrepo heads/main &&
626 old_commit=$(git -C testrepo show-ref -s --verify refs/heads/main) &&
627 git push --dry-run testrepo : &&
628 check_push_result testrepo $old_commit heads/main
631 test_expect_success
'push updates local refs' '
633 mk_test testrepo heads/main &&
634 mk_child testrepo child &&
639 test $(git rev-parse main) = \
640 $(git rev-parse remotes/origin/main)
645 test_expect_success
'push updates up-to-date local refs' '
647 mk_test testrepo heads/main &&
648 mk_child testrepo child1 &&
649 mk_child testrepo child2 &&
650 (cd child1 && git pull .. main && git push) &&
653 git pull ../child1 main &&
655 test $(git rev-parse main) = \
656 $(git rev-parse remotes/origin/main)
661 test_expect_success
'push preserves up-to-date packed refs' '
663 mk_test testrepo heads/main &&
664 mk_child testrepo child &&
668 ! test -f .git/refs/remotes/origin/main
673 test_expect_success
'push does not update local refs on failure' '
675 mk_test testrepo heads/main &&
676 mk_child testrepo child &&
677 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
678 chmod +x testrepo/.git/hooks/pre-receive &&
682 test_must_fail git push &&
683 test $(git rev-parse main) != \
684 $(git rev-parse remotes/origin/main)
689 test_expect_success
'allow deleting an invalid remote ref' '
691 mk_test testrepo heads/branch &&
692 rm -f testrepo/.git/objects/??/* &&
693 git push testrepo :refs/heads/branch &&
694 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/branch)
698 test_expect_success
'pushing valid refs triggers post-receive and post-update hooks' '
699 mk_test_with_hooks testrepo heads/main heads/next &&
700 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
701 newmain=$(git show-ref -s --verify refs/heads/main) &&
702 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
704 git push testrepo refs/heads/main:refs/heads/main :refs/heads/next &&
707 cat >pre-receive.expect <<-EOF &&
708 $orgmain $newmain refs/heads/main
709 $orgnext $newnext refs/heads/next
712 cat >update.expect <<-EOF &&
713 refs/heads/main $orgmain $newmain
714 refs/heads/next $orgnext $newnext
717 cat >post-receive.expect <<-EOF &&
718 $orgmain $newmain refs/heads/main
719 $orgnext $newnext refs/heads/next
722 cat >post-update.expect <<-EOF &&
727 test_cmp pre-receive.expect pre-receive.actual &&
728 test_cmp update.expect update.actual &&
729 test_cmp post-receive.expect post-receive.actual &&
730 test_cmp post-update.expect post-update.actual
734 test_expect_success
'deleting dangling ref triggers hooks with correct args' '
735 mk_test_with_hooks testrepo heads/branch &&
736 orig=$(git -C testrepo rev-parse refs/heads/branch) &&
737 rm -f testrepo/.git/objects/??/* &&
738 git push testrepo :refs/heads/branch &&
741 cat >pre-receive.expect <<-EOF &&
742 $orig $ZERO_OID refs/heads/branch
745 cat >update.expect <<-EOF &&
746 refs/heads/branch $orig $ZERO_OID
749 cat >post-receive.expect <<-EOF &&
750 $orig $ZERO_OID refs/heads/branch
753 cat >post-update.expect <<-EOF &&
757 test_cmp pre-receive.expect pre-receive.actual &&
758 test_cmp update.expect update.actual &&
759 test_cmp post-receive.expect post-receive.actual &&
760 test_cmp post-update.expect post-update.actual
764 test_expect_success
'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
765 mk_test_with_hooks testrepo heads/main &&
766 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
767 newmain=$(git show-ref -s --verify refs/heads/main) &&
768 git push testrepo main :refs/heads/nonexistent &&
771 cat >pre-receive.expect <<-EOF &&
772 $orgmain $newmain refs/heads/main
773 $ZERO_OID $ZERO_OID refs/heads/nonexistent
776 cat >update.expect <<-EOF &&
777 refs/heads/main $orgmain $newmain
778 refs/heads/nonexistent $ZERO_OID $ZERO_OID
781 cat >post-receive.expect <<-EOF &&
782 $orgmain $newmain refs/heads/main
785 cat >post-update.expect <<-EOF &&
789 test_cmp pre-receive.expect pre-receive.actual &&
790 test_cmp update.expect update.actual &&
791 test_cmp post-receive.expect post-receive.actual &&
792 test_cmp post-update.expect post-update.actual
796 test_expect_success
'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
797 mk_test_with_hooks testrepo heads/main &&
798 git push testrepo :refs/heads/nonexistent &&
801 cat >pre-receive.expect <<-EOF &&
802 $ZERO_OID $ZERO_OID refs/heads/nonexistent
805 cat >update.expect <<-EOF &&
806 refs/heads/nonexistent $ZERO_OID $ZERO_OID
809 test_cmp pre-receive.expect pre-receive.actual &&
810 test_cmp update.expect update.actual &&
811 test_path_is_missing post-receive.actual &&
812 test_path_is_missing post-update.actual
816 test_expect_success
'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
817 mk_test_with_hooks testrepo heads/main heads/next heads/seen &&
818 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
819 newmain=$(git show-ref -s --verify refs/heads/main) &&
820 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
822 orgseen=$(cd testrepo && git show-ref -s --verify refs/heads/seen) &&
823 newseen=$(git show-ref -s --verify refs/heads/main) &&
824 git push testrepo refs/heads/main:refs/heads/main \
825 refs/heads/main:refs/heads/seen :refs/heads/next \
826 :refs/heads/nonexistent &&
829 cat >pre-receive.expect <<-EOF &&
830 $orgmain $newmain refs/heads/main
831 $orgnext $newnext refs/heads/next
832 $orgseen $newseen refs/heads/seen
833 $ZERO_OID $ZERO_OID refs/heads/nonexistent
836 cat >update.expect <<-EOF &&
837 refs/heads/main $orgmain $newmain
838 refs/heads/next $orgnext $newnext
839 refs/heads/seen $orgseen $newseen
840 refs/heads/nonexistent $ZERO_OID $ZERO_OID
843 cat >post-receive.expect <<-EOF &&
844 $orgmain $newmain refs/heads/main
845 $orgnext $newnext refs/heads/next
846 $orgseen $newseen refs/heads/seen
849 cat >post-update.expect <<-EOF &&
855 test_cmp pre-receive.expect pre-receive.actual &&
856 test_cmp update.expect update.actual &&
857 test_cmp post-receive.expect post-receive.actual &&
858 test_cmp post-update.expect post-update.actual
862 test_expect_success
'allow deleting a ref using --delete' '
863 mk_test testrepo heads/main &&
864 (cd testrepo && git config receive.denyDeleteCurrent warn) &&
865 git push testrepo --delete main &&
866 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/main)
869 test_expect_success
'allow deleting a tag using --delete' '
870 mk_test testrepo heads/main &&
871 git tag -a -m dummy_message deltag heads/main &&
872 git push testrepo --tags &&
873 (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
874 git push testrepo --delete tag deltag &&
875 (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
878 test_expect_success
'push --delete without args aborts' '
879 mk_test testrepo heads/main &&
880 test_must_fail git push testrepo --delete
883 test_expect_success
'push --delete refuses src:dest refspecs' '
884 mk_test testrepo heads/main &&
885 test_must_fail git push testrepo --delete main:foo
888 test_expect_success
'push --delete refuses empty string' '
889 mk_test testrepo heads/master &&
890 test_must_fail git push testrepo --delete ""
893 test_expect_success
'warn on push to HEAD of non-bare repository' '
894 mk_test testrepo heads/main &&
898 git config receive.denyCurrentBranch warn
900 git push testrepo main 2>stderr &&
901 grep "warning: updating the current branch" stderr
904 test_expect_success
'deny push to HEAD of non-bare repository' '
905 mk_test testrepo heads/main &&
909 git config receive.denyCurrentBranch true
911 test_must_fail git push testrepo main
914 test_expect_success
'allow push to HEAD of bare repository (bare)' '
915 mk_test testrepo heads/main &&
919 git config receive.denyCurrentBranch true &&
920 git config core.bare true
922 git push testrepo main 2>stderr &&
923 ! grep "warning: updating the current branch" stderr
926 test_expect_success
'allow push to HEAD of non-bare repository (config)' '
927 mk_test testrepo heads/main &&
931 git config receive.denyCurrentBranch false
933 git push testrepo main 2>stderr &&
934 ! grep "warning: updating the current branch" stderr
937 test_expect_success
'fetch with branches' '
939 git branch second $the_first_commit &&
940 git checkout second &&
941 echo ".." > testrepo/.git/branches/branch1 &&
945 echo "$the_commit commit refs/heads/branch1" >expect &&
946 git for-each-ref refs/heads >actual &&
947 test_cmp expect actual
952 test_expect_success
'fetch with branches containing #' '
954 echo "..#second" > testrepo/.git/branches/branch2 &&
958 echo "$the_first_commit commit refs/heads/branch2" >expect &&
959 git for-each-ref refs/heads >actual &&
960 test_cmp expect actual
965 test_expect_success
'push with branches' '
967 git checkout second &&
968 echo "testrepo" > .git/branches/branch1 &&
972 echo "$the_first_commit commit refs/heads/main" >expect &&
973 git for-each-ref refs/heads >actual &&
974 test_cmp expect actual
978 test_expect_success
'push with branches containing #' '
980 echo "testrepo#branch3" > .git/branches/branch2 &&
984 echo "$the_first_commit commit refs/heads/branch3" >expect &&
985 git for-each-ref refs/heads >actual &&
986 test_cmp expect actual
991 test_expect_success
'push into aliased refs (consistent)' '
992 mk_test testrepo heads/main &&
993 mk_child testrepo child1 &&
994 mk_child testrepo child2 &&
998 git symbolic-ref refs/heads/bar refs/heads/foo &&
999 git config receive.denyCurrentBranch false
1006 git commit -a -m child2 &&
1009 git push ../child1 foo bar
1013 test_expect_success
'push into aliased refs (inconsistent)' '
1014 mk_test testrepo heads/main &&
1015 mk_child testrepo child1 &&
1016 mk_child testrepo child2 &&
1020 git symbolic-ref refs/heads/bar refs/heads/foo &&
1021 git config receive.denyCurrentBranch false
1028 git commit -a -m child2 &&
1033 git commit -a -m child2 &&
1035 test_must_fail git push ../child1 foo bar 2>stderr &&
1036 grep "refusing inconsistent update" stderr
1040 test_force_push_tag
() {
1041 tag_type_description
=$1
1044 test_expect_success
"force pushing required to update $tag_type_description" "
1045 mk_test testrepo heads/main &&
1046 mk_child testrepo child1 &&
1047 mk_child testrepo child2 &&
1051 git push ../child2 testTag &&
1054 git commit -m 'file1' &&
1055 git tag $tag_args testTag &&
1056 test_must_fail git push ../child2 testTag &&
1057 git push --force ../child2 testTag &&
1058 git tag $tag_args testTag HEAD~ &&
1059 test_must_fail git push ../child2 testTag &&
1060 git push --force ../child2 testTag &&
1062 # Clobbering without + in refspec needs --force
1063 git tag -f testTag &&
1064 test_must_fail git push ../child2 'refs/tags/*:refs/tags/*' &&
1065 git push --force ../child2 'refs/tags/*:refs/tags/*' &&
1067 # Clobbering with + in refspec does not need --force
1068 git tag -f testTag HEAD~ &&
1069 git push ../child2 '+refs/tags/*:refs/tags/*' &&
1071 # Clobbering with --no-force still obeys + in refspec
1072 git tag -f testTag &&
1073 git push --no-force ../child2 '+refs/tags/*:refs/tags/*' &&
1075 # Clobbering with/without --force and 'tag <name>' format
1076 git tag -f testTag HEAD~ &&
1077 test_must_fail git push ../child2 tag testTag &&
1078 git push --force ../child2 tag testTag
1083 test_force_push_tag
"lightweight tag" "-f"
1084 test_force_push_tag
"annotated tag" "-f -a -m'tag message'"
1086 test_force_fetch_tag
() {
1087 tag_type_description
=$1
1090 test_expect_success
"fetch will not clobber an existing $tag_type_description without --force" "
1091 mk_test testrepo heads/main &&
1092 mk_child testrepo child1 &&
1093 mk_child testrepo child2 &&
1097 git -C ../child1 fetch origin tag testTag &&
1100 git commit -m 'file1' &&
1101 git tag $tag_args testTag &&
1102 test_must_fail git -C ../child1 fetch origin tag testTag &&
1103 git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*'
1108 test_force_fetch_tag
"lightweight tag" "-f"
1109 test_force_fetch_tag
"annotated tag" "-f -a -m'tag message'"
1111 test_expect_success
'push --porcelain' '
1112 mk_empty testrepo &&
1113 echo >.git/foo "To testrepo" &&
1114 echo >>.git/foo "* refs/heads/main:refs/remotes/origin/main [new reference]" &&
1115 echo >>.git/foo "Done" &&
1116 git push >.git/bar --porcelain testrepo refs/heads/main:refs/remotes/origin/main &&
1119 echo "$the_commit commit refs/remotes/origin/main" >expect &&
1120 git for-each-ref refs/remotes/origin >actual &&
1121 test_cmp expect actual
1123 test_cmp .git/foo .git/bar
1126 test_expect_success
'push --porcelain bad url' '
1127 mk_empty testrepo &&
1128 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/main:refs/remotes/origin/main &&
1129 ! grep -q Done .git/bar
1132 test_expect_success
'push --porcelain rejected' '
1133 mk_empty testrepo &&
1134 git push testrepo refs/heads/main:refs/remotes/origin/main &&
1136 git reset --hard origin/main^ &&
1137 git config receive.denyCurrentBranch true) &&
1139 echo >.git/foo "To testrepo" &&
1140 echo >>.git/foo "! refs/heads/main:refs/heads/main [remote rejected] (branch is currently checked out)" &&
1141 echo >>.git/foo "Done" &&
1143 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/main:refs/heads/main &&
1144 test_cmp .git/foo .git/bar
1147 test_expect_success
'push --porcelain --dry-run rejected' '
1148 mk_empty testrepo &&
1149 git push testrepo refs/heads/main:refs/remotes/origin/main &&
1151 git reset --hard origin/main &&
1152 git config receive.denyCurrentBranch true) &&
1154 echo >.git/foo "To testrepo" &&
1155 echo >>.git/foo "! refs/heads/main^:refs/heads/main [rejected] (non-fast-forward)" &&
1156 echo >>.git/foo "Done" &&
1158 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/main^:refs/heads/main &&
1159 test_cmp .git/foo .git/bar
1162 test_expect_success
'push --prune' '
1163 mk_test testrepo heads/main heads/second heads/foo heads/bar &&
1164 git push --prune testrepo : &&
1165 check_push_result testrepo $the_commit heads/main &&
1166 check_push_result testrepo $the_first_commit heads/second &&
1167 ! check_push_result testrepo $the_first_commit heads/foo heads/bar
1170 test_expect_success
'push --prune refspec' '
1171 mk_test testrepo tmp/main tmp/second tmp/foo tmp/bar &&
1172 git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
1173 check_push_result testrepo $the_commit tmp/main &&
1174 check_push_result testrepo $the_first_commit tmp/second &&
1175 ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
1178 for configsection
in transfer receive
1180 test_expect_success
"push to update a ref hidden by $configsection.hiderefs" '
1181 mk_test testrepo heads/main hidden/one hidden/two hidden/three &&
1184 git config $configsection.hiderefs refs/hidden
1187 # push to unhidden ref succeeds normally
1188 git push testrepo main:refs/heads/main &&
1189 check_push_result testrepo $the_commit heads/main &&
1191 # push to update a hidden ref should fail
1192 test_must_fail git push testrepo main:refs/hidden/one &&
1193 check_push_result testrepo $the_first_commit hidden/one &&
1195 # push to delete a hidden ref should fail
1196 test_must_fail git push testrepo :refs/hidden/two &&
1197 check_push_result testrepo $the_first_commit hidden/two &&
1199 # idempotent push to update a hidden ref should fail
1200 test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
1201 check_push_result testrepo $the_first_commit hidden/three
1205 test_expect_success
'fetch exact SHA1' '
1206 mk_test testrepo heads/main hidden/one &&
1207 git push testrepo main:refs/hidden/one &&
1210 git config transfer.hiderefs refs/hidden
1212 check_push_result testrepo $the_commit hidden/one &&
1214 mk_child testrepo child &&
1218 # make sure $the_commit does not exist here
1221 test_must_fail git cat-file -t $the_commit &&
1223 # Some protocol versions (e.g. 2) support fetching
1224 # unadvertised objects, so restrict this test to v0.
1226 # fetching the hidden object should fail by default
1227 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1228 git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err &&
1229 test_i18ngrep "Server does not allow request for unadvertised object" err &&
1230 test_must_fail git rev-parse --verify refs/heads/copy &&
1232 # the server side can allow it to succeed
1235 git config uploadpack.allowtipsha1inwant true
1238 git fetch -v ../testrepo $the_commit:refs/heads/copy main:refs/heads/extra &&
1239 cat >expect <<-EOF &&
1244 git rev-parse --verify refs/heads/copy &&
1245 git rev-parse --verify refs/heads/extra
1247 test_cmp expect actual
1251 test_expect_success
'fetch exact SHA1 in protocol v2' '
1252 mk_test testrepo heads/main hidden/one &&
1253 git push testrepo main:refs/hidden/one &&
1254 git -C testrepo config transfer.hiderefs refs/hidden &&
1255 check_push_result testrepo $the_commit hidden/one &&
1257 mk_child testrepo child &&
1258 git -C child config protocol.version 2 &&
1260 # make sure $the_commit does not exist here
1261 git -C child repack -a -d &&
1262 git -C child prune &&
1263 test_must_fail git -C child cat-file -t $the_commit &&
1265 # fetching the hidden object succeeds by default
1266 # NEEDSWORK: should this match the v0 behavior instead?
1267 git -C child fetch -v ../testrepo $the_commit:refs/heads/copy
1270 for configallowtipsha1inwant
in true false
1272 test_expect_success
"shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" '
1273 mk_empty testrepo &&
1276 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1277 git commit --allow-empty -m foo &&
1278 git commit --allow-empty -m bar
1280 SHA1=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1284 # Some protocol versions (e.g. 2) support fetching
1285 # unadvertised objects, so restrict this test to v0.
1286 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1287 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1288 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1289 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1290 git cat-file commit $SHA1
1294 test_expect_success
"deny fetch unreachable SHA1, allowtipsha1inwant=$configallowtipsha1inwant" '
1295 mk_empty testrepo &&
1298 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1299 git commit --allow-empty -m foo &&
1300 git commit --allow-empty -m bar &&
1301 git commit --allow-empty -m xyz
1303 SHA1_1=$(git --git-dir=testrepo/.git rev-parse HEAD^^) &&
1304 SHA1_2=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1305 SHA1_3=$(git --git-dir=testrepo/.git rev-parse HEAD) &&
1308 git reset --hard $SHA1_2 &&
1309 git cat-file commit $SHA1_1 &&
1310 git cat-file commit $SHA1_3
1315 # Some protocol versions (e.g. 2) support fetching
1316 # unadvertised objects, so restrict this test to v0.
1317 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1318 git fetch ../testrepo/.git $SHA1_3 &&
1319 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1320 git fetch ../testrepo/.git $SHA1_1 &&
1321 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1322 git fetch ../testrepo/.git $SHA1_1 &&
1323 git cat-file commit $SHA1_1 &&
1324 test_must_fail git cat-file commit $SHA1_2 &&
1325 git fetch ../testrepo/.git $SHA1_2 &&
1326 git cat-file commit $SHA1_2 &&
1327 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1328 git fetch ../testrepo/.git $SHA1_3 2>err &&
1329 # ideally we would insist this be on a "remote error:"
1330 # line, but it is racy; see the commit message
1331 test_i18ngrep "not our ref.*$SHA1_3\$" err
1336 test_expect_success
'fetch follows tags by default' '
1337 mk_test testrepo heads/main &&
1338 test_when_finished "rm -rf src" &&
1342 git pull ../testrepo main &&
1343 git tag -m "annotated" tag &&
1344 git for-each-ref >tmp1 &&
1345 sed -n "p; s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 |
1346 sort -k 3 >../expect
1348 test_when_finished "rm -rf dst" &&
1352 git remote add origin ../src &&
1353 git config branch.main.remote origin &&
1354 git config branch.main.merge refs/heads/main &&
1356 git for-each-ref >../actual
1358 test_cmp expect actual
1361 test_expect_success
'peeled advertisements are not considered ref tips' '
1362 mk_empty testrepo &&
1363 git -C testrepo commit --allow-empty -m one &&
1364 git -C testrepo commit --allow-empty -m two &&
1365 git -C testrepo tag -m foo mytag HEAD^ &&
1366 oid=$(git -C testrepo rev-parse mytag^{commit}) &&
1367 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1368 git fetch testrepo $oid 2>err &&
1369 test_i18ngrep "Server does not allow request for unadvertised object" err
1372 test_expect_success
'pushing a specific ref applies remote.$name.push as refmap' '
1373 mk_test testrepo heads/main &&
1374 test_when_finished "rm -rf src" &&
1376 test_when_finished "rm -rf dst" &&
1377 git init --bare dst &&
1380 git pull ../testrepo main &&
1382 git config remote.dst.url ../dst &&
1383 git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" &&
1384 git push dst main &&
1385 git show-ref refs/heads/main |
1386 sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect
1390 test_must_fail git show-ref refs/heads/next &&
1391 test_must_fail git show-ref refs/heads/main &&
1392 git show-ref refs/remotes/src/main >actual
1394 test_cmp dst/expect dst/actual
1397 test_expect_success
'with no remote.$name.push, it is not used as refmap' '
1398 mk_test testrepo heads/main &&
1399 test_when_finished "rm -rf src" &&
1401 test_when_finished "rm -rf dst" &&
1402 git init --bare dst &&
1405 git pull ../testrepo main &&
1407 git config remote.dst.url ../dst &&
1408 git config push.default matching &&
1409 git push dst main &&
1410 git show-ref refs/heads/main >../dst/expect
1414 test_must_fail git show-ref refs/heads/next &&
1415 git show-ref refs/heads/main >actual
1417 test_cmp dst/expect dst/actual
1420 test_expect_success
'with no remote.$name.push, upstream mapping is used' '
1421 mk_test testrepo heads/main &&
1422 test_when_finished "rm -rf src" &&
1424 test_when_finished "rm -rf dst" &&
1425 git init --bare dst &&
1428 git pull ../testrepo main &&
1430 git config remote.dst.url ../dst &&
1431 git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" &&
1432 git config push.default upstream &&
1434 git config branch.main.merge refs/heads/trunk &&
1435 git config branch.main.remote dst &&
1437 git push dst main &&
1438 git show-ref refs/heads/main |
1439 sed -e "s|refs/heads/main|refs/heads/trunk|" >../dst/expect
1443 test_must_fail git show-ref refs/heads/main &&
1444 test_must_fail git show-ref refs/heads/next &&
1445 git show-ref refs/heads/trunk >actual
1447 test_cmp dst/expect dst/actual
1450 test_expect_success
'push does not follow tags by default' '
1451 mk_test testrepo heads/main &&
1452 test_when_finished "rm -rf src" &&
1454 test_when_finished "rm -rf dst" &&
1455 git init --bare dst &&
1458 git pull ../testrepo main &&
1459 git tag -m "annotated" tag &&
1460 git checkout -b another &&
1461 git commit --allow-empty -m "future commit" &&
1462 git tag -m "future" future &&
1463 git checkout main &&
1464 git for-each-ref refs/heads/main >../expect &&
1465 git push ../dst main
1469 git for-each-ref >../actual
1471 test_cmp expect actual
1474 test_expect_success
'push --follow-tags only pushes relevant tags' '
1475 mk_test testrepo heads/main &&
1476 test_when_finished "rm -rf src" &&
1478 test_when_finished "rm -rf dst" &&
1479 git init --bare dst &&
1482 git pull ../testrepo main &&
1483 git tag -m "annotated" tag &&
1484 git checkout -b another &&
1485 git commit --allow-empty -m "future commit" &&
1486 git tag -m "future" future &&
1487 git checkout main &&
1488 git for-each-ref refs/heads/main refs/tags/tag >../expect &&
1489 git push --follow-tags ../dst main
1493 git for-each-ref >../actual
1495 test_cmp expect actual
1498 test_expect_success
'push --no-thin must produce non-thin pack' '
1499 cat >>path1 <<\EOF &&
1500 keep base version of path1 big enough, compared to the new changes
1501 later, in order to pass size heuristics in
1502 builtin/pack-objects.c:try_delta()
1504 git commit -am initial &&
1506 git --git-dir=no-thin/.git config receive.unpacklimit 0 &&
1507 git push no-thin/.git refs/heads/main:refs/heads/foo &&
1508 echo modified >> path1 &&
1509 git commit -am modified &&
1511 rcvpck="git receive-pack --reject-thin-pack-for-testing" &&
1512 git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/main:refs/heads/foo
1515 test_expect_success
'pushing a tag pushes the tagged object' '
1516 blob=$(echo unreferenced | git hash-object -w --stdin) &&
1517 git tag -m foo tag-of-blob $blob &&
1518 test_when_finished "rm -rf dst.git" &&
1519 git init --bare dst.git &&
1520 git push dst.git tag-of-blob &&
1521 # the receiving index-pack should have noticed
1522 # any problems, but we double check
1523 echo unreferenced >expect &&
1524 git --git-dir=dst.git cat-file blob tag-of-blob >actual &&
1525 test_cmp expect actual
1528 test_expect_success
'push into bare respects core.logallrefupdates' '
1529 test_when_finished "rm -rf dst.git" &&
1530 git init --bare dst.git &&
1531 git -C dst.git config core.logallrefupdates true &&
1533 # double push to test both with and without
1534 # the actual pack transfer
1535 git push dst.git main:one &&
1536 echo "one@{0} push" >expect &&
1537 git -C dst.git log -g --format="%gd %gs" one >actual &&
1538 test_cmp expect actual &&
1540 git push dst.git main:two &&
1541 echo "two@{0} push" >expect &&
1542 git -C dst.git log -g --format="%gd %gs" two >actual &&
1543 test_cmp expect actual
1546 test_expect_success
'fetch into bare respects core.logallrefupdates' '
1547 test_when_finished "rm -rf dst.git" &&
1548 git init --bare dst.git &&
1551 git config core.logallrefupdates true &&
1553 # as above, we double-fetch to test both
1554 # with and without pack transfer
1555 git fetch .. main:one &&
1556 echo "one@{0} fetch .. main:one: storing head" >expect &&
1557 git log -g --format="%gd %gs" one >actual &&
1558 test_cmp expect actual &&
1560 git fetch .. main:two &&
1561 echo "two@{0} fetch .. main:two: storing head" >expect &&
1562 git log -g --format="%gd %gs" two >actual &&
1563 test_cmp expect actual
1567 test_expect_success
'receive.denyCurrentBranch = updateInstead' '
1568 mk_empty testrepo &&
1569 git push testrepo main &&
1573 git config receive.denyCurrentBranch updateInstead
1575 test_commit third path2 &&
1577 # Try pushing into a repository with pristine working tree
1578 git push testrepo main &&
1581 git update-index -q --refresh &&
1582 git diff-files --quiet -- &&
1583 git diff-index --quiet --cached HEAD -- &&
1584 test third = "$(cat path2)" &&
1585 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1588 # Try pushing into a repository with working tree needing a refresh
1591 git reset --hard HEAD^ &&
1592 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1593 test-tool chmtime +100 path1
1595 git push testrepo main &&
1598 git update-index -q --refresh &&
1599 git diff-files --quiet -- &&
1600 git diff-index --quiet --cached HEAD -- &&
1601 test_cmp ../path1 path1 &&
1602 test third = "$(cat path2)" &&
1603 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1606 # Update what is to be pushed
1607 test_commit fourth path2 &&
1609 # Try pushing into a repository with a dirty working tree
1610 # (1) the working tree updated
1615 test_must_fail git push testrepo main &&
1618 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1619 git diff --quiet --cached &&
1620 test changed = "$(cat path1)"
1623 # (2) the index updated
1626 echo changed >path1 &&
1629 test_must_fail git push testrepo main &&
1632 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1634 test changed = "$(cat path1)"
1637 # Introduce a new file in the update
1638 test_commit fifth path3 &&
1640 # (3) the working tree has an untracked file that would interfere
1646 test_must_fail git push testrepo main &&
1649 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1651 git diff --quiet --cached &&
1652 test changed = "$(cat path3)"
1655 # (4) the target changes to what gets pushed but it still is a change
1659 echo fifth >path3 &&
1662 test_must_fail git push testrepo main &&
1665 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1667 test fifth = "$(cat path3)"
1670 # (5) push into void
1671 test_when_finished "rm -rf void" &&
1675 git config receive.denyCurrentBranch updateInstead
1677 git push void main &&
1680 test $(git -C .. rev-parse main) = $(git rev-parse HEAD) &&
1682 git diff --cached --quiet
1685 # (6) updateInstead intervened by fast-forward check
1686 test_must_fail git push void main^:main &&
1687 test $(git -C void rev-parse HEAD) = $(git rev-parse main) &&
1688 git -C void diff --quiet &&
1689 git -C void diff --cached --quiet
1692 test_expect_success
'updateInstead with push-to-checkout hook' '
1693 test_when_finished "rm -rf testrepo" &&
1694 git init testrepo &&
1695 git -C testrepo pull .. main &&
1696 git -C testrepo reset --hard HEAD^^ &&
1697 git -C testrepo tag initial &&
1698 git -C testrepo config receive.denyCurrentBranch updateInstead &&
1699 test_hook -C testrepo push-to-checkout <<-\EOF &&
1700 echo >&2 updating from $(git rev-parse HEAD)
1701 echo >&2 updating to "$1"
1703 git update-index -q --refresh &&
1704 git read-tree -u -m HEAD "$1" || {
1706 echo >&2 read-tree failed
1711 # Try pushing into a pristine
1712 git push testrepo main &&
1716 git diff HEAD --quiet &&
1717 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1720 # Try pushing into a repository with conflicting change
1723 git reset --hard initial &&
1724 echo conflicting >path2
1726 test_must_fail git push testrepo main &&
1729 test $(git rev-parse initial) = $(git rev-parse HEAD) &&
1730 test conflicting = "$(cat path2)" &&
1731 git diff-index --quiet --cached HEAD
1734 # Try pushing into a repository with unrelated change
1737 git reset --hard initial &&
1738 echo unrelated >path1 &&
1739 echo irrelevant >path5 &&
1742 git push testrepo main &&
1745 test "$(cat path1)" = unrelated &&
1746 test "$(cat path5)" = irrelevant &&
1747 test "$(git diff --name-only --cached HEAD)" = path5 &&
1748 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1752 test_when_finished "rm -rf void" &&
1754 git -C void config receive.denyCurrentBranch updateInstead &&
1755 test_hook -C void push-to-checkout <<-\EOF &&
1756 if git rev-parse --quiet --verify HEAD
1759 echo >&2 updating from $(git rev-parse HEAD)
1762 echo >&2 pushing into void
1764 echo >&2 updating to "$1"
1766 git update-index -q --refresh &&
1769 git read-tree -u -m HEAD "$1" ;;
1771 git read-tree -u -m "$1" ;;
1774 echo >&2 read-tree failed
1779 git push void main &&
1783 git diff --cached --quiet &&
1784 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1788 test_expect_success
'denyCurrentBranch and worktrees' '
1789 git worktree add new-wt &&
1790 git clone . cloned &&
1791 test_commit -C cloned first &&
1792 test_config receive.denyCurrentBranch refuse &&
1793 test_must_fail git -C cloned push origin HEAD:new-wt &&
1794 test_config receive.denyCurrentBranch updateInstead &&
1795 git -C cloned push origin HEAD:new-wt &&
1796 test_path_exists new-wt/first.t &&
1797 test_must_fail git -C cloned push --delete origin new-wt
1800 test_expect_success
'denyCurrentBranch and bare repository worktrees' '
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 grape &&
1805 git -C bare.git config receive.denyCurrentBranch refuse &&
1806 test_must_fail git push bare.git HEAD:wt &&
1807 git -C bare.git config receive.denyCurrentBranch updateInstead &&
1808 git push bare.git HEAD:wt &&
1809 test_path_exists bare.git/wt/grape.t &&
1810 test_must_fail git push --delete bare.git wt
1813 test_expect_success
'refuse fetch to current branch of worktree' '
1814 test_when_finished "git worktree remove --force wt && git branch -D wt" &&
1815 git worktree add wt &&
1816 test_commit apple &&
1817 test_must_fail git fetch . HEAD:wt &&
1818 git fetch -u . HEAD:wt
1821 test_expect_success
'refuse fetch to current branch of bare repository worktree' '
1822 test_when_finished "rm -fr bare.git" &&
1823 git clone --bare . bare.git &&
1824 git -C bare.git worktree add wt &&
1825 test_commit banana &&
1826 test_must_fail git -C bare.git fetch .. HEAD:wt &&
1827 git -C bare.git fetch -u .. HEAD:wt
1830 test_expect_success
'refuse to push a hidden ref, and make sure do not pollute the repository' '
1831 mk_empty testrepo &&
1832 git -C testrepo config receive.hiderefs refs/hidden &&
1833 git -C testrepo config receive.unpackLimit 1 &&
1834 test_must_fail git push testrepo HEAD:refs/hidden/foo &&
1835 test_dir_is_empty testrepo/.git/objects/pack
1838 test_expect_success LIBCURL
'fetch warns or fails when using username:password' '
1839 message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" &&
1840 test_must_fail git -c transfer.credentialsInUrl=allow fetch https://username:password@localhost 2>err &&
1841 ! grep "$message" err &&
1843 test_must_fail git -c transfer.credentialsInUrl=warn fetch https://username:password@localhost 2>err &&
1844 grep "warning: $message" err >warnings &&
1845 test_line_count = 3 warnings &&
1847 test_must_fail git -c transfer.credentialsInUrl=die fetch https://username:password@localhost 2>err &&
1848 grep "fatal: $message" err >warnings &&
1849 test_line_count = 1 warnings &&
1851 test_must_fail git -c transfer.credentialsInUrl=die fetch https://username:@localhost 2>err &&
1852 grep "fatal: $message" err >warnings &&
1853 test_line_count = 1 warnings
1857 test_expect_success LIBCURL
'push warns or fails when using username:password' '
1858 message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" &&
1859 test_must_fail git -c transfer.credentialsInUrl=allow push https://username:password@localhost 2>err &&
1860 ! grep "$message" err &&
1862 test_must_fail git -c transfer.credentialsInUrl=warn push https://username:password@localhost 2>err &&
1863 grep "warning: $message" err >warnings &&
1864 test_must_fail git -c transfer.credentialsInUrl=die push https://username:password@localhost 2>err &&
1865 grep "fatal: $message" err >warnings &&
1866 test_line_count = 1 warnings