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
21 TEST_CREATE_REPO_NO_TEMPLATE
=1
22 TEST_PASSES_SANITIZE_LEAK
=true
29 test_when_finished
"rm -rf \"$repo_name\"" &&
30 test_path_is_missing
"$repo_name" &&
31 git init
--template= "$repo_name" &&
32 mkdir
"$repo_name"/.git
/hooks
&&
33 git
-C "$repo_name" config receive.denyCurrentBranch warn
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
() {
62 test_hook
-C "$repo_name" pre-receive
<<-'EOF' &&
63 cat - >>pre-receive.actual
66 test_hook
-C "$repo_name" update
<<-'EOF' &&
67 printf "%s %s %s\n" "$@" >>update.actual
70 test_hook
-C "$repo_name" post-receive
<<-'EOF' &&
71 cat - >>post-receive.actual
74 test_hook
-C "$repo_name" post-update
<<-'EOF'
77 printf "%s\n" "$ref" >>post-update.actual
83 test_when_finished
"rm -rf \"$2\"" &&
84 git clone
--template= "$1" "$2"
87 check_push_result
() {
89 BUG
"check_push_result requires at least 3 parameters"
100 git show-ref
-s --verify refs
/$ref >actual
&&
101 test_cmp expect actual ||
108 test_expect_success setup
'
113 git commit -a -m repo &&
114 the_first_commit=$(git show-ref -s --verify refs/heads/main) &&
119 git commit -a -m second &&
120 the_commit=$(git show-ref -s --verify refs/heads/main)
124 for cmd
in push fetch
128 test_expect_success
"reject 'git $cmd --no-$opt'" '
129 test_must_fail git $cmd --no-$opt 2>err &&
130 grep "unknown option .no-$opt" err
135 test_expect_success
'fetch without wildcard' '
139 git fetch .. refs/heads/main:refs/remotes/origin/main &&
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 wildcard' '
151 git config remote.up.url .. &&
152 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
155 echo "$the_commit commit refs/remotes/origin/main" >expect &&
156 git for-each-ref refs/remotes/origin >actual &&
157 test_cmp expect actual
161 test_expect_success
'fetch with insteadOf' '
166 git config "url.$TRASH.insteadOf" trash/ &&
167 git config remote.up.url trash/. &&
168 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
171 echo "$the_commit commit refs/remotes/origin/main" >expect &&
172 git for-each-ref refs/remotes/origin >actual &&
173 test_cmp expect actual
177 test_expect_success
'fetch with pushInsteadOf (should not rewrite)' '
182 git config "url.trash/.pushInsteadOf" "$TRASH" &&
183 git config remote.up.url "$TRASH." &&
184 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
187 echo "$the_commit commit refs/remotes/origin/main" >expect &&
188 git for-each-ref refs/remotes/origin >actual &&
189 test_cmp expect actual
196 grep 'write_pack_file/wrote.*"value":"'$1'"' $2
199 test_expect_success
'push without negotiation' '
201 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
202 test_commit -C testrepo unrelated_commit &&
203 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
204 test_when_finished "rm event" &&
205 GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 push testrepo refs/heads/main:refs/remotes/origin/main &&
206 grep_wrote 5 event # 2 commits, 2 trees, 1 blob
209 test_expect_success
'push with negotiation' '
211 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
212 test_commit -C testrepo unrelated_commit &&
213 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
214 test_when_finished "rm event" &&
215 GIT_TRACE2_EVENT="$(pwd)/event" \
216 git -c protocol.version=2 -c push.negotiate=1 \
217 push testrepo refs/heads/main:refs/remotes/origin/main &&
218 grep \"key\":\"total_rounds\",\"value\":\"1\" event &&
219 grep_wrote 2 event # 1 commit, 1 tree
222 test_expect_success
'push with negotiation proceeds anyway even if negotiation fails' '
224 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
225 test_commit -C testrepo unrelated_commit &&
226 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
227 test_when_finished "rm event" &&
228 GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" \
229 git -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
230 grep_wrote 5 event && # 2 commits, 2 trees, 1 blob
231 test_grep "push negotiation failed" err
234 test_expect_success
'push deletion with negotiation' '
236 git push testrepo $the_first_commit:refs/heads/master &&
237 git -c push.negotiate=1 push testrepo \
238 :master $the_first_commit:refs/heads/next 2>errors-2 &&
239 test_grep ! "negotiate-only needs one or " errors-2 &&
240 git -c push.negotiate=1 push testrepo :next 2>errors-1 &&
241 test_grep ! "negotiate-only needs one or " errors-1
244 test_expect_success
'push with negotiation does not attempt to fetch submodules' '
245 mk_empty submodule_upstream &&
246 test_commit -C submodule_upstream submodule_commit &&
247 test_config_global protocol.file.allow always &&
248 git submodule add ./submodule_upstream submodule &&
250 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
251 test_commit -C testrepo unrelated_commit &&
252 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
253 GIT_TRACE2_EVENT="$(pwd)/event" git -c submodule.recurse=true \
254 -c protocol.version=2 -c push.negotiate=1 \
255 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
256 grep \"key\":\"total_rounds\",\"value\":\"1\" event &&
257 ! grep "Fetching submodule" err
260 test_expect_success
'push without wildcard' '
263 git push testrepo refs/heads/main:refs/remotes/origin/main &&
266 echo "$the_commit commit refs/remotes/origin/main" >expect &&
267 git for-each-ref refs/remotes/origin >actual &&
268 test_cmp expect actual
272 test_expect_success
'push with wildcard' '
275 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
278 echo "$the_commit commit refs/remotes/origin/main" >expect &&
279 git for-each-ref refs/remotes/origin >actual &&
280 test_cmp expect actual
284 test_expect_success
'push with insteadOf' '
287 test_config "url.$TRASH.insteadOf" trash/ &&
288 git push trash/testrepo refs/heads/main:refs/remotes/origin/main &&
291 echo "$the_commit commit refs/remotes/origin/main" >expect &&
292 git for-each-ref refs/remotes/origin >actual &&
293 test_cmp expect actual
297 test_expect_success
'push with pushInsteadOf' '
300 test_config "url.$TRASH.pushInsteadOf" trash/ &&
301 git push trash/testrepo refs/heads/main:refs/remotes/origin/main &&
304 echo "$the_commit commit refs/remotes/origin/main" >expect &&
305 git for-each-ref refs/remotes/origin >actual &&
306 test_cmp expect actual
310 test_expect_success
'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
312 test_config "url.trash2/.pushInsteadOf" testrepo/ &&
313 test_config "url.trash3/.pushInsteadOf" trash/wrong &&
314 test_config remote.r.url trash/wrong &&
315 test_config remote.r.pushurl "testrepo/" &&
316 git push r refs/heads/main:refs/remotes/origin/main &&
319 echo "$the_commit commit refs/remotes/origin/main" >expect &&
320 git for-each-ref refs/remotes/origin >actual &&
321 test_cmp expect actual
325 test_expect_success
'push with matching heads' '
327 mk_test testrepo heads/main &&
328 git push testrepo : &&
329 check_push_result testrepo $the_commit heads/main
333 test_expect_success
'push with matching heads on the command line' '
335 mk_test testrepo heads/main &&
336 git push testrepo : &&
337 check_push_result testrepo $the_commit heads/main
341 test_expect_success
'failed (non-fast-forward) push with matching heads' '
343 mk_test testrepo heads/main &&
344 git push testrepo : &&
345 git commit --amend -massaged &&
346 test_must_fail git push testrepo &&
347 check_push_result testrepo $the_commit heads/main &&
348 git reset --hard $the_commit
352 test_expect_success
'push --force with matching heads' '
354 mk_test testrepo heads/main &&
355 git push testrepo : &&
356 git commit --amend -massaged &&
357 git push --force testrepo : &&
358 ! check_push_result testrepo $the_commit heads/main &&
359 git reset --hard $the_commit
363 test_expect_success
'push with matching heads and forced update' '
365 mk_test testrepo heads/main &&
366 git push testrepo : &&
367 git commit --amend -massaged &&
368 git push testrepo +: &&
369 ! check_push_result testrepo $the_commit heads/main &&
370 git reset --hard $the_commit
374 test_expect_success
'push with no ambiguity (1)' '
376 mk_test testrepo heads/main &&
377 git push testrepo main:main &&
378 check_push_result testrepo $the_commit heads/main
382 test_expect_success
'push with no ambiguity (2)' '
384 mk_test testrepo remotes/origin/main &&
385 git push testrepo main:origin/main &&
386 check_push_result testrepo $the_commit remotes/origin/main
390 test_expect_success
'push with colon-less refspec, no ambiguity' '
392 mk_test testrepo heads/main heads/t/main &&
393 git branch -f t/main main &&
394 git push testrepo main &&
395 check_push_result testrepo $the_commit heads/main &&
396 check_push_result testrepo $the_first_commit heads/t/main
400 test_expect_success
'push with weak ambiguity (1)' '
402 mk_test testrepo heads/main remotes/origin/main &&
403 git push testrepo main:main &&
404 check_push_result testrepo $the_commit heads/main &&
405 check_push_result testrepo $the_first_commit remotes/origin/main
409 test_expect_success
'push with weak ambiguity (2)' '
411 mk_test testrepo heads/main remotes/origin/main remotes/another/main &&
412 git push testrepo main:main &&
413 check_push_result testrepo $the_commit heads/main &&
414 check_push_result testrepo $the_first_commit remotes/origin/main remotes/another/main
418 test_expect_success
'push with ambiguity' '
420 mk_test testrepo heads/frotz tags/frotz &&
421 test_must_fail git push testrepo main:frotz &&
422 check_push_result testrepo $the_first_commit heads/frotz tags/frotz
426 test_expect_success
'push with onelevel ref' '
427 mk_test testrepo heads/main &&
428 test_must_fail git push testrepo HEAD:refs/onelevel
431 test_expect_success
'push with colon-less refspec (1)' '
433 mk_test testrepo heads/frotz tags/frotz &&
434 git branch -f frotz main &&
435 git push testrepo frotz &&
436 check_push_result testrepo $the_commit heads/frotz &&
437 check_push_result testrepo $the_first_commit tags/frotz
441 test_expect_success
'push with colon-less refspec (2)' '
443 mk_test testrepo heads/frotz tags/frotz &&
444 if git show-ref --verify -q refs/heads/frotz
449 git push -f testrepo frotz &&
450 check_push_result testrepo $the_commit tags/frotz &&
451 check_push_result testrepo $the_first_commit heads/frotz
455 test_expect_success
'push with colon-less refspec (3)' '
458 if git show-ref --verify -q refs/tags/frotz
462 git branch -f frotz main &&
463 git push testrepo frotz &&
464 check_push_result testrepo $the_commit heads/frotz &&
465 test 1 = $( cd testrepo && git show-ref | wc -l )
468 test_expect_success
'push with colon-less refspec (4)' '
471 if git show-ref --verify -q refs/heads/frotz
476 git push testrepo frotz &&
477 check_push_result testrepo $the_commit tags/frotz &&
478 test 1 = $( cd testrepo && git show-ref | wc -l )
482 test_expect_success
'push head with non-existent, incomplete dest' '
485 git push testrepo main:branch &&
486 check_push_result testrepo $the_commit heads/branch
490 test_expect_success
'push tag with non-existent, incomplete dest' '
494 git push testrepo v1.0:tag &&
495 check_push_result testrepo $the_commit tags/tag
499 test_expect_success
'push sha1 with non-existent, incomplete dest' '
502 test_must_fail git push testrepo $(git rev-parse main):foo
506 test_expect_success
'push ref expression with non-existent, incomplete dest' '
509 test_must_fail git push testrepo main^:branch
516 test_expect_success
"push with $head" '
517 mk_test testrepo heads/main &&
519 git push testrepo $head &&
520 check_push_result testrepo $the_commit heads/main
523 test_expect_success
"push with $head nonexisting at remote" '
524 mk_test testrepo heads/main &&
525 git checkout -b local main &&
526 test_when_finished "git checkout main; git branch -D local" &&
527 git push testrepo $head &&
528 check_push_result testrepo $the_commit heads/local
531 test_expect_success
"push with +$head" '
532 mk_test testrepo heads/main &&
533 git checkout -b local main &&
534 test_when_finished "git checkout main; git branch -D local" &&
535 git push testrepo main local &&
536 check_push_result testrepo $the_commit heads/main &&
537 check_push_result testrepo $the_commit heads/local &&
539 # Without force rewinding should fail
540 git reset --hard $head^ &&
541 test_must_fail git push testrepo $head &&
542 check_push_result testrepo $the_commit heads/local &&
544 # With force rewinding should succeed
545 git push testrepo +$head &&
546 check_push_result testrepo $the_first_commit heads/local
549 test_expect_success
"push $head with non-existent, incomplete dest" '
552 git push testrepo $head:branch &&
553 check_push_result testrepo $the_commit heads/branch
557 test_expect_success
"push with config remote.*.push = $head" '
558 mk_test testrepo heads/local &&
560 git branch -f local $the_commit &&
561 test_when_finished "git branch -D local" &&
564 git checkout local &&
565 git reset --hard $the_first_commit
567 test_config remote.there.url testrepo &&
568 test_config remote.there.push $head &&
569 test_config branch.main.remote there &&
571 check_push_result testrepo $the_commit heads/main &&
572 check_push_result testrepo $the_first_commit heads/local
577 test_expect_success
"push to remote with no explicit refspec and config remote.*.push = src:dest" '
578 mk_test testrepo heads/main &&
579 git checkout $the_first_commit &&
580 test_config remote.there.url testrepo &&
581 test_config remote.there.push refs/heads/main:refs/heads/main &&
583 check_push_result testrepo $the_commit heads/main
586 test_expect_success
'push with remote.pushdefault' '
587 mk_test up_repo heads/main &&
588 mk_test down_repo heads/main &&
589 test_config remote.up.url up_repo &&
590 test_config remote.down.url down_repo &&
591 test_config branch.main.remote up &&
592 test_config remote.pushdefault down &&
593 test_config push.default matching &&
595 check_push_result up_repo $the_first_commit heads/main &&
596 check_push_result down_repo $the_commit heads/main
599 test_expect_success
'push with config remote.*.pushurl' '
601 mk_test testrepo heads/main &&
603 test_config remote.there.url test2repo &&
604 test_config remote.there.pushurl testrepo &&
606 check_push_result testrepo $the_commit heads/main
609 test_expect_success
'push with config branch.*.pushremote' '
610 mk_test up_repo heads/main &&
611 mk_test side_repo heads/main &&
612 mk_test down_repo heads/main &&
613 test_config remote.up.url up_repo &&
614 test_config remote.pushdefault side_repo &&
615 test_config remote.down.url down_repo &&
616 test_config branch.main.remote up &&
617 test_config branch.main.pushremote down &&
618 test_config push.default matching &&
620 check_push_result up_repo $the_first_commit heads/main &&
621 check_push_result side_repo $the_first_commit heads/main &&
622 check_push_result down_repo $the_commit heads/main
625 test_expect_success
'branch.*.pushremote config order is irrelevant' '
626 mk_test one_repo heads/main &&
627 mk_test two_repo heads/main &&
628 test_config remote.one.url one_repo &&
629 test_config remote.two.url two_repo &&
630 test_config branch.main.pushremote two_repo &&
631 test_config remote.pushdefault one_repo &&
632 test_config push.default matching &&
634 check_push_result one_repo $the_first_commit heads/main &&
635 check_push_result two_repo $the_commit heads/main
638 test_expect_success
'push rejects empty branch name entries' '
639 mk_test one_repo heads/main &&
640 test_config remote.one.url one_repo &&
641 test_config branch..remote one &&
642 test_config branch..merge refs/heads/ &&
643 test_config branch.main.remote one &&
644 test_config branch.main.merge refs/heads/main &&
645 test_must_fail git push 2>err &&
646 grep "bad config variable .branch\.\." err
649 test_expect_success
'push ignores "branch." config without subsection' '
650 mk_test one_repo heads/main &&
651 test_config remote.one.url one_repo &&
652 test_config branch.autoSetupMerge true &&
653 test_config branch.main.remote one &&
654 test_config branch.main.merge refs/heads/main &&
658 test_expect_success
'push with dry-run' '
660 mk_test testrepo heads/main &&
661 old_commit=$(git -C testrepo show-ref -s --verify refs/heads/main) &&
662 git push --dry-run testrepo : &&
663 check_push_result testrepo $old_commit heads/main
666 test_expect_success
'push updates local refs' '
668 mk_test testrepo heads/main &&
669 mk_child testrepo child &&
674 test $(git rev-parse main) = \
675 $(git rev-parse remotes/origin/main)
680 test_expect_success
'push updates up-to-date local refs' '
682 mk_test testrepo heads/main &&
683 mk_child testrepo child1 &&
684 mk_child testrepo child2 &&
685 (cd child1 && git pull .. main && git push) &&
688 git pull ../child1 main &&
690 test $(git rev-parse main) = \
691 $(git rev-parse remotes/origin/main)
696 test_expect_success
'push preserves up-to-date packed refs' '
698 mk_test testrepo heads/main &&
699 mk_child testrepo child &&
703 ! test -f .git/refs/remotes/origin/main
708 test_expect_success
'push does not update local refs on failure' '
710 mk_test testrepo heads/main &&
711 mk_child testrepo child &&
712 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
713 chmod +x testrepo/.git/hooks/pre-receive &&
717 test_must_fail git push &&
718 test $(git rev-parse main) != \
719 $(git rev-parse remotes/origin/main)
724 test_expect_success
'allow deleting an invalid remote ref' '
726 mk_test testrepo heads/branch &&
727 rm -f testrepo/.git/objects/??/* &&
728 git push testrepo :refs/heads/branch &&
729 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/branch)
733 test_expect_success
'pushing valid refs triggers post-receive and post-update hooks' '
734 mk_test_with_hooks testrepo heads/main heads/next &&
735 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
736 newmain=$(git show-ref -s --verify refs/heads/main) &&
737 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
739 git push testrepo refs/heads/main:refs/heads/main :refs/heads/next &&
742 cat >pre-receive.expect <<-EOF &&
743 $orgmain $newmain refs/heads/main
744 $orgnext $newnext refs/heads/next
747 cat >update.expect <<-EOF &&
748 refs/heads/main $orgmain $newmain
749 refs/heads/next $orgnext $newnext
752 cat >post-receive.expect <<-EOF &&
753 $orgmain $newmain refs/heads/main
754 $orgnext $newnext refs/heads/next
757 cat >post-update.expect <<-EOF &&
762 test_cmp pre-receive.expect pre-receive.actual &&
763 test_cmp update.expect update.actual &&
764 test_cmp post-receive.expect post-receive.actual &&
765 test_cmp post-update.expect post-update.actual
769 test_expect_success
'deleting dangling ref triggers hooks with correct args' '
770 mk_test_with_hooks testrepo heads/branch &&
771 orig=$(git -C testrepo rev-parse refs/heads/branch) &&
772 rm -f testrepo/.git/objects/??/* &&
773 git push testrepo :refs/heads/branch &&
776 cat >pre-receive.expect <<-EOF &&
777 $orig $ZERO_OID refs/heads/branch
780 cat >update.expect <<-EOF &&
781 refs/heads/branch $orig $ZERO_OID
784 cat >post-receive.expect <<-EOF &&
785 $orig $ZERO_OID refs/heads/branch
788 cat >post-update.expect <<-EOF &&
792 test_cmp pre-receive.expect pre-receive.actual &&
793 test_cmp update.expect update.actual &&
794 test_cmp post-receive.expect post-receive.actual &&
795 test_cmp post-update.expect post-update.actual
799 test_expect_success
'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
800 mk_test_with_hooks testrepo heads/main &&
801 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
802 newmain=$(git show-ref -s --verify refs/heads/main) &&
803 git push testrepo main :refs/heads/nonexistent &&
806 cat >pre-receive.expect <<-EOF &&
807 $orgmain $newmain refs/heads/main
808 $ZERO_OID $ZERO_OID refs/heads/nonexistent
811 cat >update.expect <<-EOF &&
812 refs/heads/main $orgmain $newmain
813 refs/heads/nonexistent $ZERO_OID $ZERO_OID
816 cat >post-receive.expect <<-EOF &&
817 $orgmain $newmain refs/heads/main
820 cat >post-update.expect <<-EOF &&
824 test_cmp pre-receive.expect pre-receive.actual &&
825 test_cmp update.expect update.actual &&
826 test_cmp post-receive.expect post-receive.actual &&
827 test_cmp post-update.expect post-update.actual
831 test_expect_success
'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
832 mk_test_with_hooks testrepo heads/main &&
833 git push testrepo :refs/heads/nonexistent &&
836 cat >pre-receive.expect <<-EOF &&
837 $ZERO_OID $ZERO_OID refs/heads/nonexistent
840 cat >update.expect <<-EOF &&
841 refs/heads/nonexistent $ZERO_OID $ZERO_OID
844 test_cmp pre-receive.expect pre-receive.actual &&
845 test_cmp update.expect update.actual &&
846 test_path_is_missing post-receive.actual &&
847 test_path_is_missing post-update.actual
851 test_expect_success
'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
852 mk_test_with_hooks testrepo heads/main heads/next heads/seen &&
853 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
854 newmain=$(git show-ref -s --verify refs/heads/main) &&
855 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
857 orgseen=$(cd testrepo && git show-ref -s --verify refs/heads/seen) &&
858 newseen=$(git show-ref -s --verify refs/heads/main) &&
859 git push testrepo refs/heads/main:refs/heads/main \
860 refs/heads/main:refs/heads/seen :refs/heads/next \
861 :refs/heads/nonexistent &&
864 cat >pre-receive.expect <<-EOF &&
865 $orgmain $newmain refs/heads/main
866 $orgnext $newnext refs/heads/next
867 $orgseen $newseen refs/heads/seen
868 $ZERO_OID $ZERO_OID refs/heads/nonexistent
871 cat >update.expect <<-EOF &&
872 refs/heads/main $orgmain $newmain
873 refs/heads/next $orgnext $newnext
874 refs/heads/seen $orgseen $newseen
875 refs/heads/nonexistent $ZERO_OID $ZERO_OID
878 cat >post-receive.expect <<-EOF &&
879 $orgmain $newmain refs/heads/main
880 $orgnext $newnext refs/heads/next
881 $orgseen $newseen refs/heads/seen
884 cat >post-update.expect <<-EOF &&
890 test_cmp pre-receive.expect pre-receive.actual &&
891 test_cmp update.expect update.actual &&
892 test_cmp post-receive.expect post-receive.actual &&
893 test_cmp post-update.expect post-update.actual
897 test_expect_success
'allow deleting a ref using --delete' '
898 mk_test testrepo heads/main &&
899 (cd testrepo && git config receive.denyDeleteCurrent warn) &&
900 git push testrepo --delete main &&
901 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/main)
904 test_expect_success
'allow deleting a tag using --delete' '
905 mk_test testrepo heads/main &&
906 git tag -a -m dummy_message deltag heads/main &&
907 git push testrepo --tags &&
908 (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
909 git push testrepo --delete tag deltag &&
910 (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
913 test_expect_success
'push --delete without args aborts' '
914 mk_test testrepo heads/main &&
915 test_must_fail git push testrepo --delete
918 test_expect_success
'push --delete refuses src:dest refspecs' '
919 mk_test testrepo heads/main &&
920 test_must_fail git push testrepo --delete main:foo
923 test_expect_success
'push --delete refuses empty string' '
924 mk_test testrepo heads/master &&
925 test_must_fail git push testrepo --delete ""
928 test_expect_success
'push --delete onelevel refspecs' '
929 mk_test testrepo heads/main &&
930 git -C testrepo update-ref refs/onelevel refs/heads/main &&
931 git push testrepo --delete refs/onelevel &&
932 test_must_fail git -C testrepo rev-parse --verify refs/onelevel
935 test_expect_success
'warn on push to HEAD of non-bare repository' '
936 mk_test testrepo heads/main &&
940 git config receive.denyCurrentBranch warn
942 git push testrepo main 2>stderr &&
943 grep "warning: updating the current branch" stderr
946 test_expect_success
'deny push to HEAD of non-bare repository' '
947 mk_test testrepo heads/main &&
951 git config receive.denyCurrentBranch true
953 test_must_fail git push testrepo main
956 test_expect_success
'allow push to HEAD of bare repository (bare)' '
957 mk_test testrepo heads/main &&
961 git config receive.denyCurrentBranch true &&
962 git config core.bare true
964 git push testrepo main 2>stderr &&
965 ! grep "warning: updating the current branch" stderr
968 test_expect_success
'allow push to HEAD of non-bare repository (config)' '
969 mk_test testrepo heads/main &&
973 git config receive.denyCurrentBranch false
975 git push testrepo main 2>stderr &&
976 ! grep "warning: updating the current branch" stderr
979 test_expect_success
'fetch with branches' '
981 git branch second $the_first_commit &&
982 git checkout second &&
983 mkdir testrepo/.git/branches &&
984 echo ".." > testrepo/.git/branches/branch1 &&
988 echo "$the_commit commit refs/heads/branch1" >expect &&
989 git for-each-ref refs/heads >actual &&
990 test_cmp expect actual
995 test_expect_success
'fetch with branches containing #' '
997 mkdir testrepo/.git/branches &&
998 echo "..#second" > testrepo/.git/branches/branch2 &&
1001 git fetch branch2 &&
1002 echo "$the_first_commit commit refs/heads/branch2" >expect &&
1003 git for-each-ref refs/heads >actual &&
1004 test_cmp expect actual
1009 test_expect_success
'push with branches' '
1010 mk_empty testrepo &&
1011 git checkout second &&
1013 test_when_finished "rm -rf .git/branches" &&
1014 mkdir .git/branches &&
1015 echo "testrepo" > .git/branches/branch1 &&
1020 echo "$the_first_commit commit refs/heads/main" >expect &&
1021 git for-each-ref refs/heads >actual &&
1022 test_cmp expect actual
1026 test_expect_success
'push with branches containing #' '
1027 mk_empty testrepo &&
1029 test_when_finished "rm -rf .git/branches" &&
1030 mkdir .git/branches &&
1031 echo "testrepo#branch3" > .git/branches/branch2 &&
1036 echo "$the_first_commit commit refs/heads/branch3" >expect &&
1037 git for-each-ref refs/heads >actual &&
1038 test_cmp expect actual
1043 test_expect_success
'push into aliased refs (consistent)' '
1044 mk_test testrepo heads/main &&
1045 mk_child testrepo child1 &&
1046 mk_child testrepo child2 &&
1050 git symbolic-ref refs/heads/bar refs/heads/foo &&
1051 git config receive.denyCurrentBranch false
1058 git commit -a -m child2 &&
1061 git push ../child1 foo bar
1065 test_expect_success
'push into aliased refs (inconsistent)' '
1066 mk_test testrepo heads/main &&
1067 mk_child testrepo child1 &&
1068 mk_child testrepo child2 &&
1072 git symbolic-ref refs/heads/bar refs/heads/foo &&
1073 git config receive.denyCurrentBranch false
1080 git commit -a -m child2 &&
1085 git commit -a -m child2 &&
1087 test_must_fail git push ../child1 foo bar 2>stderr &&
1088 grep "refusing inconsistent update" stderr
1092 test_force_push_tag
() {
1093 tag_type_description
=$1
1096 test_expect_success
"force pushing required to update $tag_type_description" "
1097 mk_test testrepo heads/main &&
1098 mk_child testrepo child1 &&
1099 mk_child testrepo child2 &&
1103 git push ../child2 testTag &&
1106 git commit -m 'file1' &&
1107 git tag $tag_args testTag &&
1108 test_must_fail git push ../child2 testTag &&
1109 git push --force ../child2 testTag &&
1110 git tag $tag_args testTag HEAD~ &&
1111 test_must_fail git push ../child2 testTag &&
1112 git push --force ../child2 testTag &&
1114 # Clobbering without + in refspec needs --force
1115 git tag -f testTag &&
1116 test_must_fail git push ../child2 'refs/tags/*:refs/tags/*' &&
1117 git push --force ../child2 'refs/tags/*:refs/tags/*' &&
1119 # Clobbering with + in refspec does not need --force
1120 git tag -f testTag HEAD~ &&
1121 git push ../child2 '+refs/tags/*:refs/tags/*' &&
1123 # Clobbering with --no-force still obeys + in refspec
1124 git tag -f testTag &&
1125 git push --no-force ../child2 '+refs/tags/*:refs/tags/*' &&
1127 # Clobbering with/without --force and 'tag <name>' format
1128 git tag -f testTag HEAD~ &&
1129 test_must_fail git push ../child2 tag testTag &&
1130 git push --force ../child2 tag testTag
1135 test_force_push_tag
"lightweight tag" "-f"
1136 test_force_push_tag
"annotated tag" "-f -a -m'tag message'"
1138 test_force_fetch_tag
() {
1139 tag_type_description
=$1
1142 test_expect_success
"fetch will not clobber an existing $tag_type_description without --force" "
1143 mk_test testrepo heads/main &&
1144 mk_child testrepo child1 &&
1145 mk_child testrepo child2 &&
1149 git -C ../child1 fetch origin tag testTag &&
1152 git commit -m 'file1' &&
1153 git tag $tag_args testTag &&
1154 test_must_fail git -C ../child1 fetch origin tag testTag &&
1155 git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*'
1160 test_force_fetch_tag
"lightweight tag" "-f"
1161 test_force_fetch_tag
"annotated tag" "-f -a -m'tag message'"
1163 test_expect_success
'push --porcelain' '
1164 mk_empty testrepo &&
1165 echo >.git/foo "To testrepo" &&
1166 echo >>.git/foo "* refs/heads/main:refs/remotes/origin/main [new reference]" &&
1167 echo >>.git/foo "Done" &&
1168 git push >.git/bar --porcelain testrepo refs/heads/main:refs/remotes/origin/main &&
1171 echo "$the_commit commit refs/remotes/origin/main" >expect &&
1172 git for-each-ref refs/remotes/origin >actual &&
1173 test_cmp expect actual
1175 test_cmp .git/foo .git/bar
1178 test_expect_success
'push --porcelain bad url' '
1179 mk_empty testrepo &&
1180 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/main:refs/remotes/origin/main &&
1181 ! grep -q Done .git/bar
1184 test_expect_success
'push --porcelain rejected' '
1185 mk_empty testrepo &&
1186 git push testrepo refs/heads/main:refs/remotes/origin/main &&
1188 git reset --hard origin/main^ &&
1189 git config receive.denyCurrentBranch true) &&
1191 echo >.git/foo "To testrepo" &&
1192 echo >>.git/foo "! refs/heads/main:refs/heads/main [remote rejected] (branch is currently checked out)" &&
1193 echo >>.git/foo "Done" &&
1195 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/main:refs/heads/main &&
1196 test_cmp .git/foo .git/bar
1199 test_expect_success
'push --porcelain --dry-run rejected' '
1200 mk_empty testrepo &&
1201 git push testrepo refs/heads/main:refs/remotes/origin/main &&
1203 git reset --hard origin/main &&
1204 git config receive.denyCurrentBranch true) &&
1206 echo >.git/foo "To testrepo" &&
1207 echo >>.git/foo "! refs/heads/main^:refs/heads/main [rejected] (non-fast-forward)" &&
1208 echo >>.git/foo "Done" &&
1210 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/main^:refs/heads/main &&
1211 test_cmp .git/foo .git/bar
1214 test_expect_success
'push --prune' '
1215 mk_test testrepo heads/main heads/second heads/foo heads/bar &&
1216 git push --prune testrepo : &&
1217 check_push_result testrepo $the_commit heads/main &&
1218 check_push_result testrepo $the_first_commit heads/second &&
1219 ! check_push_result testrepo $the_first_commit heads/foo heads/bar
1222 test_expect_success
'push --prune refspec' '
1223 mk_test testrepo tmp/main tmp/second tmp/foo tmp/bar &&
1224 git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
1225 check_push_result testrepo $the_commit tmp/main &&
1226 check_push_result testrepo $the_first_commit tmp/second &&
1227 ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
1230 for configsection
in transfer receive
1232 test_expect_success
"push to update a ref hidden by $configsection.hiderefs" '
1233 mk_test testrepo heads/main hidden/one hidden/two hidden/three &&
1236 git config $configsection.hiderefs refs/hidden
1239 # push to unhidden ref succeeds normally
1240 git push testrepo main:refs/heads/main &&
1241 check_push_result testrepo $the_commit heads/main &&
1243 # push to update a hidden ref should fail
1244 test_must_fail git push testrepo main:refs/hidden/one &&
1245 check_push_result testrepo $the_first_commit hidden/one &&
1247 # push to delete a hidden ref should fail
1248 test_must_fail git push testrepo :refs/hidden/two &&
1249 check_push_result testrepo $the_first_commit hidden/two &&
1251 # idempotent push to update a hidden ref should fail
1252 test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
1253 check_push_result testrepo $the_first_commit hidden/three
1257 test_expect_success
'fetch exact SHA1' '
1258 mk_test testrepo heads/main hidden/one &&
1259 git push testrepo main:refs/hidden/one &&
1262 git config transfer.hiderefs refs/hidden
1264 check_push_result testrepo $the_commit hidden/one &&
1266 mk_child testrepo child &&
1270 # make sure $the_commit does not exist here
1273 test_must_fail git cat-file -t $the_commit &&
1275 # Some protocol versions (e.g. 2) support fetching
1276 # unadvertised objects, so restrict this test to v0.
1278 # fetching the hidden object should fail by default
1279 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1280 git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err &&
1281 test_grep "Server does not allow request for unadvertised object" err &&
1282 test_must_fail git rev-parse --verify refs/heads/copy &&
1284 # the server side can allow it to succeed
1287 git config uploadpack.allowtipsha1inwant true
1290 git fetch -v ../testrepo $the_commit:refs/heads/copy main:refs/heads/extra &&
1291 cat >expect <<-EOF &&
1296 git rev-parse --verify refs/heads/copy &&
1297 git rev-parse --verify refs/heads/extra
1299 test_cmp expect actual
1303 test_expect_success
'fetch exact SHA1 in protocol v2' '
1304 mk_test testrepo heads/main hidden/one &&
1305 git push testrepo main:refs/hidden/one &&
1306 git -C testrepo config transfer.hiderefs refs/hidden &&
1307 check_push_result testrepo $the_commit hidden/one &&
1309 mk_child testrepo child &&
1310 git -C child config protocol.version 2 &&
1312 # make sure $the_commit does not exist here
1313 git -C child repack -a -d &&
1314 git -C child prune &&
1315 test_must_fail git -C child cat-file -t $the_commit &&
1317 # fetching the hidden object succeeds by default
1318 # NEEDSWORK: should this match the v0 behavior instead?
1319 git -C child fetch -v ../testrepo $the_commit:refs/heads/copy
1322 for configallowtipsha1inwant
in true false
1324 test_expect_success
"shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" '
1325 mk_empty testrepo &&
1328 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1329 git commit --allow-empty -m foo &&
1330 git commit --allow-empty -m bar
1332 SHA1=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1336 # Some protocol versions (e.g. 2) support fetching
1337 # unadvertised objects, so restrict this test to v0.
1338 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1339 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1340 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1341 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1342 git cat-file commit $SHA1
1346 test_expect_success
"deny fetch unreachable SHA1, allowtipsha1inwant=$configallowtipsha1inwant" '
1347 mk_empty testrepo &&
1350 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1351 git commit --allow-empty -m foo &&
1352 git commit --allow-empty -m bar &&
1353 git commit --allow-empty -m xyz
1355 SHA1_1=$(git --git-dir=testrepo/.git rev-parse HEAD^^) &&
1356 SHA1_2=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1357 SHA1_3=$(git --git-dir=testrepo/.git rev-parse HEAD) &&
1360 git reset --hard $SHA1_2 &&
1361 git cat-file commit $SHA1_1 &&
1362 git cat-file commit $SHA1_3
1367 # Some protocol versions (e.g. 2) support fetching
1368 # unadvertised objects, so restrict this test to v0.
1369 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1370 git fetch ../testrepo/.git $SHA1_3 &&
1371 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1372 git fetch ../testrepo/.git $SHA1_1 &&
1373 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1374 git fetch ../testrepo/.git $SHA1_1 &&
1375 git cat-file commit $SHA1_1 &&
1376 test_must_fail git cat-file commit $SHA1_2 &&
1377 git fetch ../testrepo/.git $SHA1_2 &&
1378 git cat-file commit $SHA1_2 &&
1379 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1380 git fetch ../testrepo/.git $SHA1_3 2>err &&
1381 # ideally we would insist this be on a "remote error:"
1382 # line, but it is racy; see the commit message
1383 test_grep "not our ref.*$SHA1_3\$" err
1388 test_expect_success
'fetch follows tags by default' '
1389 mk_test testrepo heads/main &&
1390 test_when_finished "rm -rf src" &&
1394 git pull ../testrepo main &&
1395 git tag -m "annotated" tag &&
1396 git for-each-ref >tmp1 &&
1397 sed -n "p; s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 |
1398 sort -k 3 >../expect
1400 test_when_finished "rm -rf dst" &&
1404 git remote add origin ../src &&
1405 git config branch.main.remote origin &&
1406 git config branch.main.merge refs/heads/main &&
1408 git for-each-ref >../actual
1410 test_cmp expect actual
1413 test_expect_success
'peeled advertisements are not considered ref tips' '
1414 mk_empty testrepo &&
1415 git -C testrepo commit --allow-empty -m one &&
1416 git -C testrepo commit --allow-empty -m two &&
1417 git -C testrepo tag -m foo mytag HEAD^ &&
1418 oid=$(git -C testrepo rev-parse mytag^{commit}) &&
1419 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1420 git fetch testrepo $oid 2>err &&
1421 test_grep "Server does not allow request for unadvertised object" err
1424 test_expect_success
'pushing a specific ref applies remote.$name.push as refmap' '
1425 mk_test testrepo heads/main &&
1426 test_when_finished "rm -rf src" &&
1428 test_when_finished "rm -rf dst" &&
1429 git init --bare dst &&
1432 git pull ../testrepo main &&
1434 git config remote.dst.url ../dst &&
1435 git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" &&
1436 git push dst main &&
1437 git show-ref refs/heads/main |
1438 sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect
1442 test_must_fail git show-ref refs/heads/next &&
1443 test_must_fail git show-ref refs/heads/main &&
1444 git show-ref refs/remotes/src/main >actual
1446 test_cmp dst/expect dst/actual
1449 test_expect_success
'with no remote.$name.push, it is not used as refmap' '
1450 mk_test testrepo heads/main &&
1451 test_when_finished "rm -rf src" &&
1453 test_when_finished "rm -rf dst" &&
1454 git init --bare dst &&
1457 git pull ../testrepo main &&
1459 git config remote.dst.url ../dst &&
1460 git config push.default matching &&
1461 git push dst main &&
1462 git show-ref refs/heads/main >../dst/expect
1466 test_must_fail git show-ref refs/heads/next &&
1467 git show-ref refs/heads/main >actual
1469 test_cmp dst/expect dst/actual
1472 test_expect_success
'with no remote.$name.push, upstream mapping is used' '
1473 mk_test testrepo heads/main &&
1474 test_when_finished "rm -rf src" &&
1476 test_when_finished "rm -rf dst" &&
1477 git init --bare dst &&
1480 git pull ../testrepo main &&
1482 git config remote.dst.url ../dst &&
1483 git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" &&
1484 git config push.default upstream &&
1486 git config branch.main.merge refs/heads/trunk &&
1487 git config branch.main.remote dst &&
1489 git push dst main &&
1490 git show-ref refs/heads/main |
1491 sed -e "s|refs/heads/main|refs/heads/trunk|" >../dst/expect
1495 test_must_fail git show-ref refs/heads/main &&
1496 test_must_fail git show-ref refs/heads/next &&
1497 git show-ref refs/heads/trunk >actual
1499 test_cmp dst/expect dst/actual
1502 test_expect_success
'push does not follow tags by default' '
1503 mk_test testrepo heads/main &&
1504 test_when_finished "rm -rf src" &&
1506 test_when_finished "rm -rf dst" &&
1507 git init --bare dst &&
1510 git pull ../testrepo main &&
1511 git tag -m "annotated" tag &&
1512 git checkout -b another &&
1513 git commit --allow-empty -m "future commit" &&
1514 git tag -m "future" future &&
1515 git checkout main &&
1516 git for-each-ref refs/heads/main >../expect &&
1517 git push ../dst main
1521 git for-each-ref >../actual
1523 test_cmp expect actual
1526 test_expect_success
'push --follow-tags only pushes relevant tags' '
1527 mk_test testrepo heads/main &&
1528 test_when_finished "rm -rf src" &&
1530 test_when_finished "rm -rf dst" &&
1531 git init --bare dst &&
1534 git pull ../testrepo main &&
1535 git tag -m "annotated" tag &&
1536 git checkout -b another &&
1537 git commit --allow-empty -m "future commit" &&
1538 git tag -m "future" future &&
1539 git checkout main &&
1540 git for-each-ref refs/heads/main refs/tags/tag >../expect &&
1541 git push --follow-tags ../dst main
1545 git for-each-ref >../actual
1547 test_cmp expect actual
1550 test_expect_success
'push --no-thin must produce non-thin pack' '
1551 cat >>path1 <<\EOF &&
1552 keep base version of path1 big enough, compared to the new changes
1553 later, in order to pass size heuristics in
1554 builtin/pack-objects.c:try_delta()
1556 git commit -am initial &&
1558 git --git-dir=no-thin/.git config receive.unpacklimit 0 &&
1559 git push no-thin/.git refs/heads/main:refs/heads/foo &&
1560 echo modified >> path1 &&
1561 git commit -am modified &&
1563 rcvpck="git receive-pack --reject-thin-pack-for-testing" &&
1564 git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/main:refs/heads/foo
1567 test_expect_success
'pushing a tag pushes the tagged object' '
1568 blob=$(echo unreferenced | git hash-object -w --stdin) &&
1569 git tag -m foo tag-of-blob $blob &&
1570 test_when_finished "rm -rf dst.git" &&
1571 git init --bare dst.git &&
1572 git push dst.git tag-of-blob &&
1573 # the receiving index-pack should have noticed
1574 # any problems, but we double check
1575 echo unreferenced >expect &&
1576 git --git-dir=dst.git cat-file blob tag-of-blob >actual &&
1577 test_cmp expect actual
1580 test_expect_success
'push into bare respects core.logallrefupdates' '
1581 test_when_finished "rm -rf dst.git" &&
1582 git init --bare dst.git &&
1583 git -C dst.git config core.logallrefupdates true &&
1585 # double push to test both with and without
1586 # the actual pack transfer
1587 git push dst.git main:one &&
1588 echo "one@{0} push" >expect &&
1589 git -C dst.git log -g --format="%gd %gs" one >actual &&
1590 test_cmp expect actual &&
1592 git push dst.git main:two &&
1593 echo "two@{0} push" >expect &&
1594 git -C dst.git log -g --format="%gd %gs" two >actual &&
1595 test_cmp expect actual
1598 test_expect_success
'fetch into bare respects core.logallrefupdates' '
1599 test_when_finished "rm -rf dst.git" &&
1600 git init --bare dst.git &&
1603 git config core.logallrefupdates true &&
1605 # as above, we double-fetch to test both
1606 # with and without pack transfer
1607 git fetch .. main:one &&
1608 echo "one@{0} fetch .. main:one: storing head" >expect &&
1609 git log -g --format="%gd %gs" one >actual &&
1610 test_cmp expect actual &&
1612 git fetch .. main:two &&
1613 echo "two@{0} fetch .. main:two: storing head" >expect &&
1614 git log -g --format="%gd %gs" two >actual &&
1615 test_cmp expect actual
1619 test_expect_success
'receive.denyCurrentBranch = updateInstead' '
1620 mk_empty testrepo &&
1621 git push testrepo main &&
1625 git config receive.denyCurrentBranch updateInstead
1627 test_commit third path2 &&
1629 # Try pushing into a repository with pristine working tree
1630 git push testrepo main &&
1633 git update-index -q --refresh &&
1634 git diff-files --quiet -- &&
1635 git diff-index --quiet --cached HEAD -- &&
1636 test third = "$(cat path2)" &&
1637 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1640 # Try pushing into a repository with working tree needing a refresh
1643 git reset --hard HEAD^ &&
1644 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1645 test-tool chmtime +100 path1
1647 git push testrepo main &&
1650 git update-index -q --refresh &&
1651 git diff-files --quiet -- &&
1652 git diff-index --quiet --cached HEAD -- &&
1653 test_cmp ../path1 path1 &&
1654 test third = "$(cat path2)" &&
1655 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1658 # Update what is to be pushed
1659 test_commit fourth path2 &&
1661 # Try pushing into a repository with a dirty working tree
1662 # (1) the working tree updated
1667 test_must_fail git push testrepo main &&
1670 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1671 git diff --quiet --cached &&
1672 test changed = "$(cat path1)"
1675 # (2) the index updated
1678 echo changed >path1 &&
1681 test_must_fail git push testrepo main &&
1684 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1686 test changed = "$(cat path1)"
1689 # Introduce a new file in the update
1690 test_commit fifth path3 &&
1692 # (3) the working tree has an untracked file that would interfere
1698 test_must_fail git push testrepo main &&
1701 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1703 git diff --quiet --cached &&
1704 test changed = "$(cat path3)"
1707 # (4) the target changes to what gets pushed but it still is a change
1711 echo fifth >path3 &&
1714 test_must_fail git push testrepo main &&
1717 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1719 test fifth = "$(cat path3)"
1722 # (5) push into void
1723 test_when_finished "rm -rf void" &&
1727 git config receive.denyCurrentBranch updateInstead
1729 git push void main &&
1732 test $(git -C .. rev-parse main) = $(git rev-parse HEAD) &&
1734 git diff --cached --quiet
1737 # (6) updateInstead intervened by fast-forward check
1738 test_must_fail git push void main^:main &&
1739 test $(git -C void rev-parse HEAD) = $(git rev-parse main) &&
1740 git -C void diff --quiet &&
1741 git -C void diff --cached --quiet
1744 test_expect_success
'updateInstead with push-to-checkout hook' '
1745 test_when_finished "rm -rf testrepo" &&
1746 git init testrepo &&
1747 git -C testrepo pull .. main &&
1748 git -C testrepo reset --hard HEAD^^ &&
1749 git -C testrepo tag initial &&
1750 git -C testrepo config receive.denyCurrentBranch updateInstead &&
1751 test_hook -C testrepo push-to-checkout <<-\EOF &&
1752 echo >&2 updating from $(git rev-parse HEAD)
1753 echo >&2 updating to "$1"
1755 git update-index -q --refresh &&
1756 git read-tree -u -m HEAD "$1" || {
1758 echo >&2 read-tree failed
1763 # Try pushing into a pristine
1764 git push testrepo main &&
1768 git diff HEAD --quiet &&
1769 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1772 # Try pushing into a repository with conflicting change
1775 git reset --hard initial &&
1776 echo conflicting >path2
1778 test_must_fail git push testrepo main &&
1781 test $(git rev-parse initial) = $(git rev-parse HEAD) &&
1782 test conflicting = "$(cat path2)" &&
1783 git diff-index --quiet --cached HEAD
1786 # Try pushing into a repository with unrelated change
1789 git reset --hard initial &&
1790 echo unrelated >path1 &&
1791 echo irrelevant >path5 &&
1794 git push testrepo main &&
1797 test "$(cat path1)" = unrelated &&
1798 test "$(cat path5)" = irrelevant &&
1799 test "$(git diff --name-only --cached HEAD)" = path5 &&
1800 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1804 test_when_finished "rm -rf void" &&
1806 git -C void config receive.denyCurrentBranch updateInstead &&
1807 test_hook -C void push-to-checkout <<-\EOF &&
1808 if git rev-parse --quiet --verify HEAD
1811 echo >&2 updating from $(git rev-parse HEAD)
1814 echo >&2 pushing into void
1816 echo >&2 updating to "$1"
1818 git update-index -q --refresh &&
1821 git read-tree -u -m HEAD "$1" ;;
1823 git read-tree -u -m "$1" ;;
1826 echo >&2 read-tree failed
1831 git push void main &&
1835 git diff --cached --quiet &&
1836 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1840 test_expect_success
'denyCurrentBranch and worktrees' '
1841 git worktree add new-wt &&
1842 git clone . cloned &&
1843 test_commit -C cloned first &&
1844 test_config receive.denyCurrentBranch refuse &&
1845 test_must_fail git -C cloned push origin HEAD:new-wt &&
1846 test_config receive.denyCurrentBranch updateInstead &&
1847 git -C cloned push origin HEAD:new-wt &&
1848 test_path_exists new-wt/first.t &&
1849 test_must_fail git -C cloned push --delete origin new-wt
1852 test_expect_success
'denyCurrentBranch and bare repository worktrees' '
1853 test_when_finished "rm -fr bare.git" &&
1854 git clone --bare . bare.git &&
1855 git -C bare.git worktree add wt &&
1856 test_commit grape &&
1857 git -C bare.git config receive.denyCurrentBranch refuse &&
1858 test_must_fail git push bare.git HEAD:wt &&
1859 git -C bare.git config receive.denyCurrentBranch updateInstead &&
1860 git push bare.git HEAD:wt &&
1861 test_path_exists bare.git/wt/grape.t &&
1862 test_must_fail git push --delete bare.git wt
1865 test_expect_success
'refuse fetch to current branch of worktree' '
1866 test_when_finished "git worktree remove --force wt && git branch -D wt" &&
1867 git worktree add wt &&
1868 test_commit apple &&
1869 test_must_fail git fetch . HEAD:wt &&
1870 git fetch -u . HEAD:wt
1873 test_expect_success
'refuse fetch to current branch of bare repository worktree' '
1874 test_when_finished "rm -fr bare.git" &&
1875 git clone --bare . bare.git &&
1876 git -C bare.git worktree add wt &&
1877 test_commit banana &&
1878 test_must_fail git -C bare.git fetch .. HEAD:wt &&
1879 git -C bare.git fetch -u .. HEAD:wt
1882 test_expect_success
'refuse to push a hidden ref, and make sure do not pollute the repository' '
1883 mk_empty testrepo &&
1884 git -C testrepo config receive.hiderefs refs/hidden &&
1885 git -C testrepo config receive.unpackLimit 1 &&
1886 test_must_fail git push testrepo HEAD:refs/hidden/foo &&
1887 test_dir_is_empty testrepo/.git/objects/pack
1890 test_expect_success
'push with config push.useBitmaps' '
1891 mk_test testrepo heads/main &&
1892 git checkout main &&
1893 test_unconfig push.useBitmaps &&
1894 GIT_TRACE2_EVENT="$PWD/default" \
1895 git push --quiet testrepo main:test &&
1896 test_subcommand git pack-objects --all-progress-implied --revs --stdout \
1897 --thin --delta-base-offset -q <default &&
1899 test_config push.useBitmaps true &&
1900 GIT_TRACE2_EVENT="$PWD/true" \
1901 git push --quiet testrepo main:test2 &&
1902 test_subcommand git pack-objects --all-progress-implied --revs --stdout \
1903 --thin --delta-base-offset -q <true &&
1905 test_config push.useBitmaps false &&
1906 GIT_TRACE2_EVENT="$PWD/false" \
1907 git push --quiet testrepo main:test3 &&
1908 test_subcommand git pack-objects --all-progress-implied --revs --stdout \
1909 --thin --delta-base-offset -q --no-use-bitmap-index <false