l10n: bg.po: Updated Bulgarian translation (5210t)
[git/debian.git] / t / t5516-fetch-push.sh
blob8212ca56dc5b132edb552fba714657eed3579681
1 #!/bin/sh
3 test_description='Basic fetch/push functionality.
5 This test checks the following functionality:
7 * command-line syntax
8 * refspecs
9 * fast-forward detection, and overriding it
10 * configuration
11 * hooks
12 * --porcelain output format
13 * hiderefs
14 * reflogs
17 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
18 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
20 . ./test-lib.sh
22 D=$(pwd)
24 mk_empty () {
25 repo_name="$1"
26 rm -fr "$repo_name" &&
27 mkdir "$repo_name" &&
29 cd "$repo_name" &&
30 git init &&
31 git config receive.denyCurrentBranch warn &&
32 mv .git/hooks .git/hooks-disabled
36 mk_test () {
37 repo_name="$1"
38 shift
40 mk_empty "$repo_name" &&
42 for ref in "$@"
44 git push "$repo_name" $the_first_commit:refs/$ref ||
45 exit
46 done &&
47 cd "$repo_name" &&
48 for ref in "$@"
50 echo "$the_first_commit" >expect &&
51 git show-ref -s --verify refs/$ref >actual &&
52 test_cmp expect actual ||
53 exit
54 done &&
55 git fsck --full
59 mk_test_with_hooks() {
60 repo_name=$1
61 mk_test "$@" &&
63 cd "$repo_name" &&
64 mkdir .git/hooks &&
65 cd .git/hooks &&
67 cat >pre-receive <<-'EOF' &&
68 #!/bin/sh
69 cat - >>pre-receive.actual
70 EOF
72 cat >update <<-'EOF' &&
73 #!/bin/sh
74 printf "%s %s %s\n" "$@" >>update.actual
75 EOF
77 cat >post-receive <<-'EOF' &&
78 #!/bin/sh
79 cat - >>post-receive.actual
80 EOF
82 cat >post-update <<-'EOF' &&
83 #!/bin/sh
84 for ref in "$@"
86 printf "%s\n" "$ref" >>post-update.actual
87 done
88 EOF
90 chmod +x pre-receive update post-receive post-update
94 mk_child() {
95 rm -rf "$2" &&
96 git clone "$1" "$2"
99 check_push_result () {
100 test $# -ge 3 ||
101 BUG "check_push_result requires at least 3 parameters"
103 repo_name="$1"
104 shift
107 cd "$repo_name" &&
108 echo "$1" >expect &&
109 shift &&
110 for ref in "$@"
112 git show-ref -s --verify refs/$ref >actual &&
113 test_cmp expect actual ||
114 exit
115 done &&
116 git fsck --full
120 test_expect_success setup '
122 >path1 &&
123 git add path1 &&
124 test_tick &&
125 git commit -a -m repo &&
126 the_first_commit=$(git show-ref -s --verify refs/heads/main) &&
128 >path2 &&
129 git add path2 &&
130 test_tick &&
131 git commit -a -m second &&
132 the_commit=$(git show-ref -s --verify refs/heads/main)
136 test_expect_success 'fetch without wildcard' '
137 mk_empty testrepo &&
139 cd testrepo &&
140 git fetch .. refs/heads/main:refs/remotes/origin/main &&
142 echo "$the_commit commit refs/remotes/origin/main" >expect &&
143 git for-each-ref refs/remotes/origin >actual &&
144 test_cmp expect actual
148 test_expect_success 'fetch with wildcard' '
149 mk_empty testrepo &&
151 cd testrepo &&
152 git config remote.up.url .. &&
153 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
154 git fetch up &&
156 echo "$the_commit commit refs/remotes/origin/main" >expect &&
157 git for-each-ref refs/remotes/origin >actual &&
158 test_cmp expect actual
162 test_expect_success 'fetch with insteadOf' '
163 mk_empty testrepo &&
165 TRASH=$(pwd)/ &&
166 cd testrepo &&
167 git config "url.$TRASH.insteadOf" trash/ &&
168 git config remote.up.url trash/. &&
169 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
170 git fetch up &&
172 echo "$the_commit commit refs/remotes/origin/main" >expect &&
173 git for-each-ref refs/remotes/origin >actual &&
174 test_cmp expect actual
178 test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
179 mk_empty testrepo &&
181 TRASH=$(pwd)/ &&
182 cd testrepo &&
183 git config "url.trash/.pushInsteadOf" "$TRASH" &&
184 git config remote.up.url "$TRASH." &&
185 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
186 git fetch up &&
188 echo "$the_commit commit refs/remotes/origin/main" >expect &&
189 git for-each-ref refs/remotes/origin >actual &&
190 test_cmp expect actual
194 grep_wrote () {
195 object_count=$1
196 file_name=$2
197 grep 'write_pack_file/wrote.*"value":"'$1'"' $2
200 test_expect_success 'push with negotiation' '
201 # Without negotiation
202 mk_empty testrepo &&
203 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
204 test_commit -C testrepo unrelated_commit &&
205 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
206 echo now pushing without negotiation &&
207 GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 push testrepo refs/heads/main:refs/remotes/origin/main &&
208 grep_wrote 5 event && # 2 commits, 2 trees, 1 blob
210 # Same commands, but with negotiation
211 rm event &&
212 mk_empty testrepo &&
213 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
214 test_commit -C testrepo unrelated_commit &&
215 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
216 GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main &&
217 grep_wrote 2 event # 1 commit, 1 tree
220 test_expect_success 'push with negotiation proceeds anyway even if negotiation fails' '
221 rm event &&
222 mk_empty testrepo &&
223 git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
224 test_commit -C testrepo unrelated_commit &&
225 git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
226 GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" \
227 git -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
228 grep_wrote 5 event && # 2 commits, 2 trees, 1 blob
229 test_i18ngrep "push negotiation failed" err
232 test_expect_success 'push without wildcard' '
233 mk_empty testrepo &&
235 git push testrepo refs/heads/main:refs/remotes/origin/main &&
237 cd testrepo &&
238 echo "$the_commit commit refs/remotes/origin/main" >expect &&
239 git for-each-ref refs/remotes/origin >actual &&
240 test_cmp expect actual
244 test_expect_success 'push with wildcard' '
245 mk_empty testrepo &&
247 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
249 cd testrepo &&
250 echo "$the_commit commit refs/remotes/origin/main" >expect &&
251 git for-each-ref refs/remotes/origin >actual &&
252 test_cmp expect actual
256 test_expect_success 'push with insteadOf' '
257 mk_empty testrepo &&
258 TRASH="$(pwd)/" &&
259 test_config "url.$TRASH.insteadOf" trash/ &&
260 git push trash/testrepo refs/heads/main:refs/remotes/origin/main &&
262 cd testrepo &&
263 echo "$the_commit commit refs/remotes/origin/main" >expect &&
264 git for-each-ref refs/remotes/origin >actual &&
265 test_cmp expect actual
269 test_expect_success 'push with pushInsteadOf' '
270 mk_empty testrepo &&
271 TRASH="$(pwd)/" &&
272 test_config "url.$TRASH.pushInsteadOf" trash/ &&
273 git push trash/testrepo refs/heads/main:refs/remotes/origin/main &&
275 cd testrepo &&
276 echo "$the_commit commit refs/remotes/origin/main" >expect &&
277 git for-each-ref refs/remotes/origin >actual &&
278 test_cmp expect actual
282 test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
283 mk_empty testrepo &&
284 test_config "url.trash2/.pushInsteadOf" testrepo/ &&
285 test_config "url.trash3/.pushInsteadOf" trash/wrong &&
286 test_config remote.r.url trash/wrong &&
287 test_config remote.r.pushurl "testrepo/" &&
288 git push r refs/heads/main:refs/remotes/origin/main &&
290 cd testrepo &&
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 matching heads' '
299 mk_test testrepo heads/main &&
300 git push testrepo : &&
301 check_push_result testrepo $the_commit heads/main
305 test_expect_success 'push with matching heads on the command line' '
307 mk_test testrepo heads/main &&
308 git push testrepo : &&
309 check_push_result testrepo $the_commit heads/main
313 test_expect_success 'failed (non-fast-forward) push with matching heads' '
315 mk_test testrepo heads/main &&
316 git push testrepo : &&
317 git commit --amend -massaged &&
318 test_must_fail git push testrepo &&
319 check_push_result testrepo $the_commit heads/main &&
320 git reset --hard $the_commit
324 test_expect_success 'push --force with matching heads' '
326 mk_test testrepo heads/main &&
327 git push testrepo : &&
328 git commit --amend -massaged &&
329 git push --force testrepo : &&
330 ! check_push_result testrepo $the_commit heads/main &&
331 git reset --hard $the_commit
335 test_expect_success 'push with matching heads and forced update' '
337 mk_test testrepo heads/main &&
338 git push testrepo : &&
339 git commit --amend -massaged &&
340 git push testrepo +: &&
341 ! check_push_result testrepo $the_commit heads/main &&
342 git reset --hard $the_commit
346 test_expect_success 'push with no ambiguity (1)' '
348 mk_test testrepo heads/main &&
349 git push testrepo main:main &&
350 check_push_result testrepo $the_commit heads/main
354 test_expect_success 'push with no ambiguity (2)' '
356 mk_test testrepo remotes/origin/main &&
357 git push testrepo main:origin/main &&
358 check_push_result testrepo $the_commit remotes/origin/main
362 test_expect_success 'push with colon-less refspec, no ambiguity' '
364 mk_test testrepo heads/main heads/t/main &&
365 git branch -f t/main main &&
366 git push testrepo main &&
367 check_push_result testrepo $the_commit heads/main &&
368 check_push_result testrepo $the_first_commit heads/t/main
372 test_expect_success 'push with weak ambiguity (1)' '
374 mk_test testrepo heads/main remotes/origin/main &&
375 git push testrepo main:main &&
376 check_push_result testrepo $the_commit heads/main &&
377 check_push_result testrepo $the_first_commit remotes/origin/main
381 test_expect_success 'push with weak ambiguity (2)' '
383 mk_test testrepo heads/main remotes/origin/main remotes/another/main &&
384 git push testrepo main:main &&
385 check_push_result testrepo $the_commit heads/main &&
386 check_push_result testrepo $the_first_commit remotes/origin/main remotes/another/main
390 test_expect_success 'push with ambiguity' '
392 mk_test testrepo heads/frotz tags/frotz &&
393 test_must_fail git push testrepo main:frotz &&
394 check_push_result testrepo $the_first_commit heads/frotz tags/frotz
398 test_expect_success 'push with colon-less refspec (1)' '
400 mk_test testrepo heads/frotz tags/frotz &&
401 git branch -f frotz main &&
402 git push testrepo frotz &&
403 check_push_result testrepo $the_commit heads/frotz &&
404 check_push_result testrepo $the_first_commit tags/frotz
408 test_expect_success 'push with colon-less refspec (2)' '
410 mk_test testrepo heads/frotz tags/frotz &&
411 if git show-ref --verify -q refs/heads/frotz
412 then
413 git branch -D frotz
414 fi &&
415 git tag -f frotz &&
416 git push -f testrepo frotz &&
417 check_push_result testrepo $the_commit tags/frotz &&
418 check_push_result testrepo $the_first_commit heads/frotz
422 test_expect_success 'push with colon-less refspec (3)' '
424 mk_test testrepo &&
425 if git show-ref --verify -q refs/tags/frotz
426 then
427 git tag -d frotz
428 fi &&
429 git branch -f frotz main &&
430 git push testrepo frotz &&
431 check_push_result testrepo $the_commit heads/frotz &&
432 test 1 = $( cd testrepo && git show-ref | wc -l )
435 test_expect_success 'push with colon-less refspec (4)' '
437 mk_test testrepo &&
438 if git show-ref --verify -q refs/heads/frotz
439 then
440 git branch -D frotz
441 fi &&
442 git tag -f frotz &&
443 git push testrepo frotz &&
444 check_push_result testrepo $the_commit tags/frotz &&
445 test 1 = $( cd testrepo && git show-ref | wc -l )
449 test_expect_success 'push head with non-existent, incomplete dest' '
451 mk_test testrepo &&
452 git push testrepo main:branch &&
453 check_push_result testrepo $the_commit heads/branch
457 test_expect_success 'push tag with non-existent, incomplete dest' '
459 mk_test testrepo &&
460 git tag -f v1.0 &&
461 git push testrepo v1.0:tag &&
462 check_push_result testrepo $the_commit tags/tag
466 test_expect_success 'push sha1 with non-existent, incomplete dest' '
468 mk_test testrepo &&
469 test_must_fail git push testrepo $(git rev-parse main):foo
473 test_expect_success 'push ref expression with non-existent, incomplete dest' '
475 mk_test testrepo &&
476 test_must_fail git push testrepo main^:branch
480 for head in HEAD @
483 test_expect_success "push with $head" '
484 mk_test testrepo heads/main &&
485 git checkout main &&
486 git push testrepo $head &&
487 check_push_result testrepo $the_commit heads/main
490 test_expect_success "push with $head nonexisting at remote" '
491 mk_test testrepo heads/main &&
492 git checkout -b local main &&
493 test_when_finished "git checkout main; git branch -D local" &&
494 git push testrepo $head &&
495 check_push_result testrepo $the_commit heads/local
498 test_expect_success "push with +$head" '
499 mk_test testrepo heads/main &&
500 git checkout -b local main &&
501 test_when_finished "git checkout main; git branch -D local" &&
502 git push testrepo main local &&
503 check_push_result testrepo $the_commit heads/main &&
504 check_push_result testrepo $the_commit heads/local &&
506 # Without force rewinding should fail
507 git reset --hard $head^ &&
508 test_must_fail git push testrepo $head &&
509 check_push_result testrepo $the_commit heads/local &&
511 # With force rewinding should succeed
512 git push testrepo +$head &&
513 check_push_result testrepo $the_first_commit heads/local
516 test_expect_success "push $head with non-existent, incomplete dest" '
517 mk_test testrepo &&
518 git checkout main &&
519 git push testrepo $head:branch &&
520 check_push_result testrepo $the_commit heads/branch
524 test_expect_success "push with config remote.*.push = $head" '
525 mk_test testrepo heads/local &&
526 git checkout main &&
527 git branch -f local $the_commit &&
528 test_when_finished "git branch -D local" &&
530 cd testrepo &&
531 git checkout local &&
532 git reset --hard $the_first_commit
533 ) &&
534 test_config remote.there.url testrepo &&
535 test_config remote.there.push $head &&
536 test_config branch.main.remote there &&
537 git push &&
538 check_push_result testrepo $the_commit heads/main &&
539 check_push_result testrepo $the_first_commit heads/local
542 done
544 test_expect_success 'push with remote.pushdefault' '
545 mk_test up_repo heads/main &&
546 mk_test down_repo heads/main &&
547 test_config remote.up.url up_repo &&
548 test_config remote.down.url down_repo &&
549 test_config branch.main.remote up &&
550 test_config remote.pushdefault down &&
551 test_config push.default matching &&
552 git push &&
553 check_push_result up_repo $the_first_commit heads/main &&
554 check_push_result down_repo $the_commit heads/main
557 test_expect_success 'push with config remote.*.pushurl' '
559 mk_test testrepo heads/main &&
560 git checkout main &&
561 test_config remote.there.url test2repo &&
562 test_config remote.there.pushurl testrepo &&
563 git push there : &&
564 check_push_result testrepo $the_commit heads/main
567 test_expect_success 'push with config branch.*.pushremote' '
568 mk_test up_repo heads/main &&
569 mk_test side_repo heads/main &&
570 mk_test down_repo heads/main &&
571 test_config remote.up.url up_repo &&
572 test_config remote.pushdefault side_repo &&
573 test_config remote.down.url down_repo &&
574 test_config branch.main.remote up &&
575 test_config branch.main.pushremote down &&
576 test_config push.default matching &&
577 git push &&
578 check_push_result up_repo $the_first_commit heads/main &&
579 check_push_result side_repo $the_first_commit heads/main &&
580 check_push_result down_repo $the_commit heads/main
583 test_expect_success 'branch.*.pushremote config order is irrelevant' '
584 mk_test one_repo heads/main &&
585 mk_test two_repo heads/main &&
586 test_config remote.one.url one_repo &&
587 test_config remote.two.url two_repo &&
588 test_config branch.main.pushremote two_repo &&
589 test_config remote.pushdefault one_repo &&
590 test_config push.default matching &&
591 git push &&
592 check_push_result one_repo $the_first_commit heads/main &&
593 check_push_result two_repo $the_commit heads/main
596 test_expect_success 'push with dry-run' '
598 mk_test testrepo heads/main &&
599 old_commit=$(git -C testrepo show-ref -s --verify refs/heads/main) &&
600 git push --dry-run testrepo : &&
601 check_push_result testrepo $old_commit heads/main
604 test_expect_success 'push updates local refs' '
606 mk_test testrepo heads/main &&
607 mk_child testrepo child &&
609 cd child &&
610 git pull .. main &&
611 git push &&
612 test $(git rev-parse main) = \
613 $(git rev-parse remotes/origin/main)
618 test_expect_success 'push updates up-to-date local refs' '
620 mk_test testrepo heads/main &&
621 mk_child testrepo child1 &&
622 mk_child testrepo child2 &&
623 (cd child1 && git pull .. main && git push) &&
625 cd child2 &&
626 git pull ../child1 main &&
627 git push &&
628 test $(git rev-parse main) = \
629 $(git rev-parse remotes/origin/main)
634 test_expect_success 'push preserves up-to-date packed refs' '
636 mk_test testrepo heads/main &&
637 mk_child testrepo child &&
639 cd child &&
640 git push &&
641 ! test -f .git/refs/remotes/origin/main
646 test_expect_success 'push does not update local refs on failure' '
648 mk_test testrepo heads/main &&
649 mk_child testrepo child &&
650 mkdir testrepo/.git/hooks &&
651 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
652 chmod +x testrepo/.git/hooks/pre-receive &&
654 cd child &&
655 git pull .. main &&
656 test_must_fail git push &&
657 test $(git rev-parse main) != \
658 $(git rev-parse remotes/origin/main)
663 test_expect_success 'allow deleting an invalid remote ref' '
665 mk_test testrepo heads/branch &&
666 rm -f testrepo/.git/objects/??/* &&
667 git push testrepo :refs/heads/branch &&
668 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/branch)
672 test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' '
673 mk_test_with_hooks testrepo heads/main heads/next &&
674 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
675 newmain=$(git show-ref -s --verify refs/heads/main) &&
676 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
677 newnext=$ZERO_OID &&
678 git push testrepo refs/heads/main:refs/heads/main :refs/heads/next &&
680 cd testrepo/.git &&
681 cat >pre-receive.expect <<-EOF &&
682 $orgmain $newmain refs/heads/main
683 $orgnext $newnext refs/heads/next
686 cat >update.expect <<-EOF &&
687 refs/heads/main $orgmain $newmain
688 refs/heads/next $orgnext $newnext
691 cat >post-receive.expect <<-EOF &&
692 $orgmain $newmain refs/heads/main
693 $orgnext $newnext refs/heads/next
696 cat >post-update.expect <<-EOF &&
697 refs/heads/main
698 refs/heads/next
701 test_cmp pre-receive.expect pre-receive.actual &&
702 test_cmp update.expect update.actual &&
703 test_cmp post-receive.expect post-receive.actual &&
704 test_cmp post-update.expect post-update.actual
708 test_expect_success 'deleting dangling ref triggers hooks with correct args' '
709 mk_test_with_hooks testrepo heads/branch &&
710 orig=$(git -C testrepo rev-parse refs/heads/branch) &&
711 rm -f testrepo/.git/objects/??/* &&
712 git push testrepo :refs/heads/branch &&
714 cd testrepo/.git &&
715 cat >pre-receive.expect <<-EOF &&
716 $orig $ZERO_OID refs/heads/branch
719 cat >update.expect <<-EOF &&
720 refs/heads/branch $orig $ZERO_OID
723 cat >post-receive.expect <<-EOF &&
724 $orig $ZERO_OID refs/heads/branch
727 cat >post-update.expect <<-EOF &&
728 refs/heads/branch
731 test_cmp pre-receive.expect pre-receive.actual &&
732 test_cmp update.expect update.actual &&
733 test_cmp post-receive.expect post-receive.actual &&
734 test_cmp post-update.expect post-update.actual
738 test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
739 mk_test_with_hooks testrepo heads/main &&
740 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
741 newmain=$(git show-ref -s --verify refs/heads/main) &&
742 git push testrepo main :refs/heads/nonexistent &&
744 cd testrepo/.git &&
745 cat >pre-receive.expect <<-EOF &&
746 $orgmain $newmain refs/heads/main
747 $ZERO_OID $ZERO_OID refs/heads/nonexistent
750 cat >update.expect <<-EOF &&
751 refs/heads/main $orgmain $newmain
752 refs/heads/nonexistent $ZERO_OID $ZERO_OID
755 cat >post-receive.expect <<-EOF &&
756 $orgmain $newmain refs/heads/main
759 cat >post-update.expect <<-EOF &&
760 refs/heads/main
763 test_cmp pre-receive.expect pre-receive.actual &&
764 test_cmp update.expect update.actual &&
765 test_cmp post-receive.expect post-receive.actual &&
766 test_cmp post-update.expect post-update.actual
770 test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
771 mk_test_with_hooks testrepo heads/main &&
772 git push testrepo :refs/heads/nonexistent &&
774 cd testrepo/.git &&
775 cat >pre-receive.expect <<-EOF &&
776 $ZERO_OID $ZERO_OID refs/heads/nonexistent
779 cat >update.expect <<-EOF &&
780 refs/heads/nonexistent $ZERO_OID $ZERO_OID
783 test_cmp pre-receive.expect pre-receive.actual &&
784 test_cmp update.expect update.actual &&
785 test_path_is_missing post-receive.actual &&
786 test_path_is_missing post-update.actual
790 test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
791 mk_test_with_hooks testrepo heads/main heads/next heads/seen &&
792 orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) &&
793 newmain=$(git show-ref -s --verify refs/heads/main) &&
794 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
795 newnext=$ZERO_OID &&
796 orgseen=$(cd testrepo && git show-ref -s --verify refs/heads/seen) &&
797 newseen=$(git show-ref -s --verify refs/heads/main) &&
798 git push testrepo refs/heads/main:refs/heads/main \
799 refs/heads/main:refs/heads/seen :refs/heads/next \
800 :refs/heads/nonexistent &&
802 cd testrepo/.git &&
803 cat >pre-receive.expect <<-EOF &&
804 $orgmain $newmain refs/heads/main
805 $orgnext $newnext refs/heads/next
806 $orgseen $newseen refs/heads/seen
807 $ZERO_OID $ZERO_OID refs/heads/nonexistent
810 cat >update.expect <<-EOF &&
811 refs/heads/main $orgmain $newmain
812 refs/heads/next $orgnext $newnext
813 refs/heads/seen $orgseen $newseen
814 refs/heads/nonexistent $ZERO_OID $ZERO_OID
817 cat >post-receive.expect <<-EOF &&
818 $orgmain $newmain refs/heads/main
819 $orgnext $newnext refs/heads/next
820 $orgseen $newseen refs/heads/seen
823 cat >post-update.expect <<-EOF &&
824 refs/heads/main
825 refs/heads/next
826 refs/heads/seen
829 test_cmp pre-receive.expect pre-receive.actual &&
830 test_cmp update.expect update.actual &&
831 test_cmp post-receive.expect post-receive.actual &&
832 test_cmp post-update.expect post-update.actual
836 test_expect_success 'allow deleting a ref using --delete' '
837 mk_test testrepo heads/main &&
838 (cd testrepo && git config receive.denyDeleteCurrent warn) &&
839 git push testrepo --delete main &&
840 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/main)
843 test_expect_success 'allow deleting a tag using --delete' '
844 mk_test testrepo heads/main &&
845 git tag -a -m dummy_message deltag heads/main &&
846 git push testrepo --tags &&
847 (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
848 git push testrepo --delete tag deltag &&
849 (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
852 test_expect_success 'push --delete without args aborts' '
853 mk_test testrepo heads/main &&
854 test_must_fail git push testrepo --delete
857 test_expect_success 'push --delete refuses src:dest refspecs' '
858 mk_test testrepo heads/main &&
859 test_must_fail git push testrepo --delete main:foo
862 test_expect_success 'push --delete refuses empty string' '
863 mk_test testrepo heads/master &&
864 test_must_fail git push testrepo --delete ""
867 test_expect_success 'warn on push to HEAD of non-bare repository' '
868 mk_test testrepo heads/main &&
870 cd testrepo &&
871 git checkout main &&
872 git config receive.denyCurrentBranch warn
873 ) &&
874 git push testrepo main 2>stderr &&
875 grep "warning: updating the current branch" stderr
878 test_expect_success 'deny push to HEAD of non-bare repository' '
879 mk_test testrepo heads/main &&
881 cd testrepo &&
882 git checkout main &&
883 git config receive.denyCurrentBranch true
884 ) &&
885 test_must_fail git push testrepo main
888 test_expect_success 'allow push to HEAD of bare repository (bare)' '
889 mk_test testrepo heads/main &&
891 cd testrepo &&
892 git checkout main &&
893 git config receive.denyCurrentBranch true &&
894 git config core.bare true
895 ) &&
896 git push testrepo main 2>stderr &&
897 ! grep "warning: updating the current branch" stderr
900 test_expect_success 'allow push to HEAD of non-bare repository (config)' '
901 mk_test testrepo heads/main &&
903 cd testrepo &&
904 git checkout main &&
905 git config receive.denyCurrentBranch false
906 ) &&
907 git push testrepo main 2>stderr &&
908 ! grep "warning: updating the current branch" stderr
911 test_expect_success 'fetch with branches' '
912 mk_empty testrepo &&
913 git branch second $the_first_commit &&
914 git checkout second &&
915 echo ".." > testrepo/.git/branches/branch1 &&
917 cd testrepo &&
918 git fetch branch1 &&
919 echo "$the_commit commit refs/heads/branch1" >expect &&
920 git for-each-ref refs/heads >actual &&
921 test_cmp expect actual
922 ) &&
923 git checkout main
926 test_expect_success 'fetch with branches containing #' '
927 mk_empty testrepo &&
928 echo "..#second" > testrepo/.git/branches/branch2 &&
930 cd testrepo &&
931 git fetch branch2 &&
932 echo "$the_first_commit commit refs/heads/branch2" >expect &&
933 git for-each-ref refs/heads >actual &&
934 test_cmp expect actual
935 ) &&
936 git checkout main
939 test_expect_success 'push with branches' '
940 mk_empty testrepo &&
941 git checkout second &&
942 echo "testrepo" > .git/branches/branch1 &&
943 git push branch1 &&
945 cd testrepo &&
946 echo "$the_first_commit commit refs/heads/main" >expect &&
947 git for-each-ref refs/heads >actual &&
948 test_cmp expect actual
952 test_expect_success 'push with branches containing #' '
953 mk_empty testrepo &&
954 echo "testrepo#branch3" > .git/branches/branch2 &&
955 git push branch2 &&
957 cd testrepo &&
958 echo "$the_first_commit commit refs/heads/branch3" >expect &&
959 git for-each-ref refs/heads >actual &&
960 test_cmp expect actual
961 ) &&
962 git checkout main
965 test_expect_success 'push into aliased refs (consistent)' '
966 mk_test testrepo heads/main &&
967 mk_child testrepo child1 &&
968 mk_child testrepo child2 &&
970 cd child1 &&
971 git branch foo &&
972 git symbolic-ref refs/heads/bar refs/heads/foo &&
973 git config receive.denyCurrentBranch false
974 ) &&
976 cd child2 &&
977 >path2 &&
978 git add path2 &&
979 test_tick &&
980 git commit -a -m child2 &&
981 git branch foo &&
982 git branch bar &&
983 git push ../child1 foo bar
987 test_expect_success 'push into aliased refs (inconsistent)' '
988 mk_test testrepo heads/main &&
989 mk_child testrepo child1 &&
990 mk_child testrepo child2 &&
992 cd child1 &&
993 git branch foo &&
994 git symbolic-ref refs/heads/bar refs/heads/foo &&
995 git config receive.denyCurrentBranch false
996 ) &&
998 cd child2 &&
999 >path2 &&
1000 git add path2 &&
1001 test_tick &&
1002 git commit -a -m child2 &&
1003 git branch foo &&
1004 >path3 &&
1005 git add path3 &&
1006 test_tick &&
1007 git commit -a -m child2 &&
1008 git branch bar &&
1009 test_must_fail git push ../child1 foo bar 2>stderr &&
1010 grep "refusing inconsistent update" stderr
1014 test_force_push_tag () {
1015 tag_type_description=$1
1016 tag_args=$2
1018 test_expect_success "force pushing required to update $tag_type_description" "
1019 mk_test testrepo heads/main &&
1020 mk_child testrepo child1 &&
1021 mk_child testrepo child2 &&
1023 cd child1 &&
1024 git tag testTag &&
1025 git push ../child2 testTag &&
1026 >file1 &&
1027 git add file1 &&
1028 git commit -m 'file1' &&
1029 git tag $tag_args testTag &&
1030 test_must_fail git push ../child2 testTag &&
1031 git push --force ../child2 testTag &&
1032 git tag $tag_args testTag HEAD~ &&
1033 test_must_fail git push ../child2 testTag &&
1034 git push --force ../child2 testTag &&
1036 # Clobbering without + in refspec needs --force
1037 git tag -f testTag &&
1038 test_must_fail git push ../child2 'refs/tags/*:refs/tags/*' &&
1039 git push --force ../child2 'refs/tags/*:refs/tags/*' &&
1041 # Clobbering with + in refspec does not need --force
1042 git tag -f testTag HEAD~ &&
1043 git push ../child2 '+refs/tags/*:refs/tags/*' &&
1045 # Clobbering with --no-force still obeys + in refspec
1046 git tag -f testTag &&
1047 git push --no-force ../child2 '+refs/tags/*:refs/tags/*' &&
1049 # Clobbering with/without --force and 'tag <name>' format
1050 git tag -f testTag HEAD~ &&
1051 test_must_fail git push ../child2 tag testTag &&
1052 git push --force ../child2 tag testTag
1057 test_force_push_tag "lightweight tag" "-f"
1058 test_force_push_tag "annotated tag" "-f -a -m'tag message'"
1060 test_force_fetch_tag () {
1061 tag_type_description=$1
1062 tag_args=$2
1064 test_expect_success "fetch will not clobber an existing $tag_type_description without --force" "
1065 mk_test testrepo heads/main &&
1066 mk_child testrepo child1 &&
1067 mk_child testrepo child2 &&
1069 cd testrepo &&
1070 git tag testTag &&
1071 git -C ../child1 fetch origin tag testTag &&
1072 >file1 &&
1073 git add file1 &&
1074 git commit -m 'file1' &&
1075 git tag $tag_args testTag &&
1076 test_must_fail git -C ../child1 fetch origin tag testTag &&
1077 git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*'
1082 test_force_fetch_tag "lightweight tag" "-f"
1083 test_force_fetch_tag "annotated tag" "-f -a -m'tag message'"
1085 test_expect_success 'push --porcelain' '
1086 mk_empty testrepo &&
1087 echo >.git/foo "To testrepo" &&
1088 echo >>.git/foo "* refs/heads/main:refs/remotes/origin/main [new reference]" &&
1089 echo >>.git/foo "Done" &&
1090 git push >.git/bar --porcelain testrepo refs/heads/main:refs/remotes/origin/main &&
1092 cd testrepo &&
1093 echo "$the_commit commit refs/remotes/origin/main" >expect &&
1094 git for-each-ref refs/remotes/origin >actual &&
1095 test_cmp expect actual
1096 ) &&
1097 test_cmp .git/foo .git/bar
1100 test_expect_success 'push --porcelain bad url' '
1101 mk_empty testrepo &&
1102 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/main:refs/remotes/origin/main &&
1103 ! grep -q Done .git/bar
1106 test_expect_success 'push --porcelain rejected' '
1107 mk_empty testrepo &&
1108 git push testrepo refs/heads/main:refs/remotes/origin/main &&
1109 (cd testrepo &&
1110 git reset --hard origin/main^ &&
1111 git config receive.denyCurrentBranch true) &&
1113 echo >.git/foo "To testrepo" &&
1114 echo >>.git/foo "! refs/heads/main:refs/heads/main [remote rejected] (branch is currently checked out)" &&
1115 echo >>.git/foo "Done" &&
1117 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/main:refs/heads/main &&
1118 test_cmp .git/foo .git/bar
1121 test_expect_success 'push --porcelain --dry-run rejected' '
1122 mk_empty testrepo &&
1123 git push testrepo refs/heads/main:refs/remotes/origin/main &&
1124 (cd testrepo &&
1125 git reset --hard origin/main &&
1126 git config receive.denyCurrentBranch true) &&
1128 echo >.git/foo "To testrepo" &&
1129 echo >>.git/foo "! refs/heads/main^:refs/heads/main [rejected] (non-fast-forward)" &&
1130 echo >>.git/foo "Done" &&
1132 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/main^:refs/heads/main &&
1133 test_cmp .git/foo .git/bar
1136 test_expect_success 'push --prune' '
1137 mk_test testrepo heads/main heads/second heads/foo heads/bar &&
1138 git push --prune testrepo : &&
1139 check_push_result testrepo $the_commit heads/main &&
1140 check_push_result testrepo $the_first_commit heads/second &&
1141 ! check_push_result testrepo $the_first_commit heads/foo heads/bar
1144 test_expect_success 'push --prune refspec' '
1145 mk_test testrepo tmp/main tmp/second tmp/foo tmp/bar &&
1146 git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
1147 check_push_result testrepo $the_commit tmp/main &&
1148 check_push_result testrepo $the_first_commit tmp/second &&
1149 ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
1152 for configsection in transfer receive
1154 test_expect_success "push to update a ref hidden by $configsection.hiderefs" '
1155 mk_test testrepo heads/main hidden/one hidden/two hidden/three &&
1157 cd testrepo &&
1158 git config $configsection.hiderefs refs/hidden
1159 ) &&
1161 # push to unhidden ref succeeds normally
1162 git push testrepo main:refs/heads/main &&
1163 check_push_result testrepo $the_commit heads/main &&
1165 # push to update a hidden ref should fail
1166 test_must_fail git push testrepo main:refs/hidden/one &&
1167 check_push_result testrepo $the_first_commit hidden/one &&
1169 # push to delete a hidden ref should fail
1170 test_must_fail git push testrepo :refs/hidden/two &&
1171 check_push_result testrepo $the_first_commit hidden/two &&
1173 # idempotent push to update a hidden ref should fail
1174 test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
1175 check_push_result testrepo $the_first_commit hidden/three
1177 done
1179 test_expect_success 'fetch exact SHA1' '
1180 mk_test testrepo heads/main hidden/one &&
1181 git push testrepo main:refs/hidden/one &&
1183 cd testrepo &&
1184 git config transfer.hiderefs refs/hidden
1185 ) &&
1186 check_push_result testrepo $the_commit hidden/one &&
1188 mk_child testrepo child &&
1190 cd child &&
1192 # make sure $the_commit does not exist here
1193 git repack -a -d &&
1194 git prune &&
1195 test_must_fail git cat-file -t $the_commit &&
1197 # Some protocol versions (e.g. 2) support fetching
1198 # unadvertised objects, so restrict this test to v0.
1200 # fetching the hidden object should fail by default
1201 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1202 git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err &&
1203 test_i18ngrep "Server does not allow request for unadvertised object" err &&
1204 test_must_fail git rev-parse --verify refs/heads/copy &&
1206 # the server side can allow it to succeed
1208 cd ../testrepo &&
1209 git config uploadpack.allowtipsha1inwant true
1210 ) &&
1212 git fetch -v ../testrepo $the_commit:refs/heads/copy main:refs/heads/extra &&
1213 cat >expect <<-EOF &&
1214 $the_commit
1215 $the_first_commit
1218 git rev-parse --verify refs/heads/copy &&
1219 git rev-parse --verify refs/heads/extra
1220 } >actual &&
1221 test_cmp expect actual
1225 test_expect_success 'fetch exact SHA1 in protocol v2' '
1226 mk_test testrepo heads/main hidden/one &&
1227 git push testrepo main:refs/hidden/one &&
1228 git -C testrepo config transfer.hiderefs refs/hidden &&
1229 check_push_result testrepo $the_commit hidden/one &&
1231 mk_child testrepo child &&
1232 git -C child config protocol.version 2 &&
1234 # make sure $the_commit does not exist here
1235 git -C child repack -a -d &&
1236 git -C child prune &&
1237 test_must_fail git -C child cat-file -t $the_commit &&
1239 # fetching the hidden object succeeds by default
1240 # NEEDSWORK: should this match the v0 behavior instead?
1241 git -C child fetch -v ../testrepo $the_commit:refs/heads/copy
1244 for configallowtipsha1inwant in true false
1246 test_expect_success "shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" '
1247 mk_empty testrepo &&
1249 cd testrepo &&
1250 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1251 git commit --allow-empty -m foo &&
1252 git commit --allow-empty -m bar
1253 ) &&
1254 SHA1=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1255 mk_empty shallow &&
1257 cd shallow &&
1258 # Some protocol versions (e.g. 2) support fetching
1259 # unadvertised objects, so restrict this test to v0.
1260 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1261 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1262 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1263 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1264 git cat-file commit $SHA1
1268 test_expect_success "deny fetch unreachable SHA1, allowtipsha1inwant=$configallowtipsha1inwant" '
1269 mk_empty testrepo &&
1271 cd testrepo &&
1272 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1273 git commit --allow-empty -m foo &&
1274 git commit --allow-empty -m bar &&
1275 git commit --allow-empty -m xyz
1276 ) &&
1277 SHA1_1=$(git --git-dir=testrepo/.git rev-parse HEAD^^) &&
1278 SHA1_2=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1279 SHA1_3=$(git --git-dir=testrepo/.git rev-parse HEAD) &&
1281 cd testrepo &&
1282 git reset --hard $SHA1_2 &&
1283 git cat-file commit $SHA1_1 &&
1284 git cat-file commit $SHA1_3
1285 ) &&
1286 mk_empty shallow &&
1288 cd shallow &&
1289 # Some protocol versions (e.g. 2) support fetching
1290 # unadvertised objects, so restrict this test to v0.
1291 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1292 git fetch ../testrepo/.git $SHA1_3 &&
1293 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1294 git fetch ../testrepo/.git $SHA1_1 &&
1295 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1296 git fetch ../testrepo/.git $SHA1_1 &&
1297 git cat-file commit $SHA1_1 &&
1298 test_must_fail git cat-file commit $SHA1_2 &&
1299 git fetch ../testrepo/.git $SHA1_2 &&
1300 git cat-file commit $SHA1_2 &&
1301 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1302 git fetch ../testrepo/.git $SHA1_3 2>err &&
1303 # ideally we would insist this be on a "remote error:"
1304 # line, but it is racy; see the commit message
1305 test_i18ngrep "not our ref.*$SHA1_3\$" err
1308 done
1310 test_expect_success 'fetch follows tags by default' '
1311 mk_test testrepo heads/main &&
1312 rm -fr src dst &&
1313 git init src &&
1315 cd src &&
1316 git pull ../testrepo main &&
1317 git tag -m "annotated" tag &&
1318 git for-each-ref >tmp1 &&
1320 cat tmp1
1321 sed -n "s|refs/heads/main$|refs/remotes/origin/main|p" tmp1
1323 sort -k 3 >../expect
1324 ) &&
1325 git init dst &&
1327 cd dst &&
1328 git remote add origin ../src &&
1329 git config branch.main.remote origin &&
1330 git config branch.main.merge refs/heads/main &&
1331 git pull &&
1332 git for-each-ref >../actual
1333 ) &&
1334 test_cmp expect actual
1337 test_expect_success 'peeled advertisements are not considered ref tips' '
1338 mk_empty testrepo &&
1339 git -C testrepo commit --allow-empty -m one &&
1340 git -C testrepo commit --allow-empty -m two &&
1341 git -C testrepo tag -m foo mytag HEAD^ &&
1342 oid=$(git -C testrepo rev-parse mytag^{commit}) &&
1343 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1344 git fetch testrepo $oid 2>err &&
1345 test_i18ngrep "Server does not allow request for unadvertised object" err
1348 test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' '
1349 mk_test testrepo heads/main &&
1350 rm -fr src dst &&
1351 git init src &&
1352 git init --bare dst &&
1354 cd src &&
1355 git pull ../testrepo main &&
1356 git branch next &&
1357 git config remote.dst.url ../dst &&
1358 git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" &&
1359 git push dst main &&
1360 git show-ref refs/heads/main |
1361 sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect
1362 ) &&
1364 cd dst &&
1365 test_must_fail git show-ref refs/heads/next &&
1366 test_must_fail git show-ref refs/heads/main &&
1367 git show-ref refs/remotes/src/main >actual
1368 ) &&
1369 test_cmp dst/expect dst/actual
1372 test_expect_success 'with no remote.$name.push, it is not used as refmap' '
1373 mk_test testrepo heads/main &&
1374 rm -fr src dst &&
1375 git init src &&
1376 git init --bare dst &&
1378 cd src &&
1379 git pull ../testrepo main &&
1380 git branch next &&
1381 git config remote.dst.url ../dst &&
1382 git config push.default matching &&
1383 git push dst main &&
1384 git show-ref refs/heads/main >../dst/expect
1385 ) &&
1387 cd dst &&
1388 test_must_fail git show-ref refs/heads/next &&
1389 git show-ref refs/heads/main >actual
1390 ) &&
1391 test_cmp dst/expect dst/actual
1394 test_expect_success 'with no remote.$name.push, upstream mapping is used' '
1395 mk_test testrepo heads/main &&
1396 rm -fr src dst &&
1397 git init src &&
1398 git init --bare dst &&
1400 cd src &&
1401 git pull ../testrepo main &&
1402 git branch next &&
1403 git config remote.dst.url ../dst &&
1404 git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" &&
1405 git config push.default upstream &&
1407 git config branch.main.merge refs/heads/trunk &&
1408 git config branch.main.remote dst &&
1410 git push dst main &&
1411 git show-ref refs/heads/main |
1412 sed -e "s|refs/heads/main|refs/heads/trunk|" >../dst/expect
1413 ) &&
1415 cd dst &&
1416 test_must_fail git show-ref refs/heads/main &&
1417 test_must_fail git show-ref refs/heads/next &&
1418 git show-ref refs/heads/trunk >actual
1419 ) &&
1420 test_cmp dst/expect dst/actual
1423 test_expect_success 'push does not follow tags by default' '
1424 mk_test testrepo heads/main &&
1425 rm -fr src dst &&
1426 git init src &&
1427 git init --bare dst &&
1429 cd src &&
1430 git pull ../testrepo main &&
1431 git tag -m "annotated" tag &&
1432 git checkout -b another &&
1433 git commit --allow-empty -m "future commit" &&
1434 git tag -m "future" future &&
1435 git checkout main &&
1436 git for-each-ref refs/heads/main >../expect &&
1437 git push ../dst main
1438 ) &&
1440 cd dst &&
1441 git for-each-ref >../actual
1442 ) &&
1443 test_cmp expect actual
1446 test_expect_success 'push --follow-tags only pushes relevant tags' '
1447 mk_test testrepo heads/main &&
1448 rm -fr src dst &&
1449 git init src &&
1450 git init --bare dst &&
1452 cd src &&
1453 git pull ../testrepo main &&
1454 git tag -m "annotated" tag &&
1455 git checkout -b another &&
1456 git commit --allow-empty -m "future commit" &&
1457 git tag -m "future" future &&
1458 git checkout main &&
1459 git for-each-ref refs/heads/main refs/tags/tag >../expect &&
1460 git push --follow-tags ../dst main
1461 ) &&
1463 cd dst &&
1464 git for-each-ref >../actual
1465 ) &&
1466 test_cmp expect actual
1469 test_expect_success 'push --no-thin must produce non-thin pack' '
1470 cat >>path1 <<\EOF &&
1471 keep base version of path1 big enough, compared to the new changes
1472 later, in order to pass size heuristics in
1473 builtin/pack-objects.c:try_delta()
1475 git commit -am initial &&
1476 git init no-thin &&
1477 git --git-dir=no-thin/.git config receive.unpacklimit 0 &&
1478 git push no-thin/.git refs/heads/main:refs/heads/foo &&
1479 echo modified >> path1 &&
1480 git commit -am modified &&
1481 git repack -adf &&
1482 rcvpck="git receive-pack --reject-thin-pack-for-testing" &&
1483 git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/main:refs/heads/foo
1486 test_expect_success 'pushing a tag pushes the tagged object' '
1487 rm -rf dst.git &&
1488 blob=$(echo unreferenced | git hash-object -w --stdin) &&
1489 git tag -m foo tag-of-blob $blob &&
1490 git init --bare dst.git &&
1491 git push dst.git tag-of-blob &&
1492 # the receiving index-pack should have noticed
1493 # any problems, but we double check
1494 echo unreferenced >expect &&
1495 git --git-dir=dst.git cat-file blob tag-of-blob >actual &&
1496 test_cmp expect actual
1499 test_expect_success 'push into bare respects core.logallrefupdates' '
1500 rm -rf dst.git &&
1501 git init --bare dst.git &&
1502 git -C dst.git config core.logallrefupdates true &&
1504 # double push to test both with and without
1505 # the actual pack transfer
1506 git push dst.git main:one &&
1507 echo "one@{0} push" >expect &&
1508 git -C dst.git log -g --format="%gd %gs" one >actual &&
1509 test_cmp expect actual &&
1511 git push dst.git main:two &&
1512 echo "two@{0} push" >expect &&
1513 git -C dst.git log -g --format="%gd %gs" two >actual &&
1514 test_cmp expect actual
1517 test_expect_success 'fetch into bare respects core.logallrefupdates' '
1518 rm -rf dst.git &&
1519 git init --bare dst.git &&
1521 cd dst.git &&
1522 git config core.logallrefupdates true &&
1524 # as above, we double-fetch to test both
1525 # with and without pack transfer
1526 git fetch .. main:one &&
1527 echo "one@{0} fetch .. main:one: storing head" >expect &&
1528 git log -g --format="%gd %gs" one >actual &&
1529 test_cmp expect actual &&
1531 git fetch .. main:two &&
1532 echo "two@{0} fetch .. main:two: storing head" >expect &&
1533 git log -g --format="%gd %gs" two >actual &&
1534 test_cmp expect actual
1538 test_expect_success 'receive.denyCurrentBranch = updateInstead' '
1539 git push testrepo main &&
1541 cd testrepo &&
1542 git reset --hard &&
1543 git config receive.denyCurrentBranch updateInstead
1544 ) &&
1545 test_commit third path2 &&
1547 # Try pushing into a repository with pristine working tree
1548 git push testrepo main &&
1550 cd testrepo &&
1551 git update-index -q --refresh &&
1552 git diff-files --quiet -- &&
1553 git diff-index --quiet --cached HEAD -- &&
1554 test third = "$(cat path2)" &&
1555 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1556 ) &&
1558 # Try pushing into a repository with working tree needing a refresh
1560 cd testrepo &&
1561 git reset --hard HEAD^ &&
1562 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1563 test-tool chmtime +100 path1
1564 ) &&
1565 git push testrepo main &&
1567 cd testrepo &&
1568 git update-index -q --refresh &&
1569 git diff-files --quiet -- &&
1570 git diff-index --quiet --cached HEAD -- &&
1571 test_cmp ../path1 path1 &&
1572 test third = "$(cat path2)" &&
1573 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1574 ) &&
1576 # Update what is to be pushed
1577 test_commit fourth path2 &&
1579 # Try pushing into a repository with a dirty working tree
1580 # (1) the working tree updated
1582 cd testrepo &&
1583 echo changed >path1
1584 ) &&
1585 test_must_fail git push testrepo main &&
1587 cd testrepo &&
1588 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1589 git diff --quiet --cached &&
1590 test changed = "$(cat path1)"
1591 ) &&
1593 # (2) the index updated
1595 cd testrepo &&
1596 echo changed >path1 &&
1597 git add path1
1598 ) &&
1599 test_must_fail git push testrepo main &&
1601 cd testrepo &&
1602 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1603 git diff --quiet &&
1604 test changed = "$(cat path1)"
1605 ) &&
1607 # Introduce a new file in the update
1608 test_commit fifth path3 &&
1610 # (3) the working tree has an untracked file that would interfere
1612 cd testrepo &&
1613 git reset --hard &&
1614 echo changed >path3
1615 ) &&
1616 test_must_fail git push testrepo main &&
1618 cd testrepo &&
1619 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1620 git diff --quiet &&
1621 git diff --quiet --cached &&
1622 test changed = "$(cat path3)"
1623 ) &&
1625 # (4) the target changes to what gets pushed but it still is a change
1627 cd testrepo &&
1628 git reset --hard &&
1629 echo fifth >path3 &&
1630 git add path3
1631 ) &&
1632 test_must_fail git push testrepo main &&
1634 cd testrepo &&
1635 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1636 git diff --quiet &&
1637 test fifth = "$(cat path3)"
1638 ) &&
1640 # (5) push into void
1641 rm -fr void &&
1642 git init void &&
1644 cd void &&
1645 git config receive.denyCurrentBranch updateInstead
1646 ) &&
1647 git push void main &&
1649 cd void &&
1650 test $(git -C .. rev-parse main) = $(git rev-parse HEAD) &&
1651 git diff --quiet &&
1652 git diff --cached --quiet
1653 ) &&
1655 # (6) updateInstead intervened by fast-forward check
1656 test_must_fail git push void main^:main &&
1657 test $(git -C void rev-parse HEAD) = $(git rev-parse main) &&
1658 git -C void diff --quiet &&
1659 git -C void diff --cached --quiet
1662 test_expect_success 'updateInstead with push-to-checkout hook' '
1663 rm -fr testrepo &&
1664 git init testrepo &&
1666 cd testrepo &&
1667 git pull .. main &&
1668 git reset --hard HEAD^^ &&
1669 git tag initial &&
1670 git config receive.denyCurrentBranch updateInstead &&
1671 write_script .git/hooks/push-to-checkout <<-\EOF
1672 echo >&2 updating from $(git rev-parse HEAD)
1673 echo >&2 updating to "$1"
1675 git update-index -q --refresh &&
1676 git read-tree -u -m HEAD "$1" || {
1677 status=$?
1678 echo >&2 read-tree failed
1679 exit $status
1682 ) &&
1684 # Try pushing into a pristine
1685 git push testrepo main &&
1687 cd testrepo &&
1688 git diff --quiet &&
1689 git diff HEAD --quiet &&
1690 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1691 ) &&
1693 # Try pushing into a repository with conflicting change
1695 cd testrepo &&
1696 git reset --hard initial &&
1697 echo conflicting >path2
1698 ) &&
1699 test_must_fail git push testrepo main &&
1701 cd testrepo &&
1702 test $(git rev-parse initial) = $(git rev-parse HEAD) &&
1703 test conflicting = "$(cat path2)" &&
1704 git diff-index --quiet --cached HEAD
1705 ) &&
1707 # Try pushing into a repository with unrelated change
1709 cd testrepo &&
1710 git reset --hard initial &&
1711 echo unrelated >path1 &&
1712 echo irrelevant >path5 &&
1713 git add path5
1714 ) &&
1715 git push testrepo main &&
1717 cd testrepo &&
1718 test "$(cat path1)" = unrelated &&
1719 test "$(cat path5)" = irrelevant &&
1720 test "$(git diff --name-only --cached HEAD)" = path5 &&
1721 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1722 ) &&
1724 # push into void
1725 rm -fr void &&
1726 git init void &&
1728 cd void &&
1729 git config receive.denyCurrentBranch updateInstead &&
1730 write_script .git/hooks/push-to-checkout <<-\EOF
1731 if git rev-parse --quiet --verify HEAD
1732 then
1733 has_head=yes
1734 echo >&2 updating from $(git rev-parse HEAD)
1735 else
1736 has_head=no
1737 echo >&2 pushing into void
1739 echo >&2 updating to "$1"
1741 git update-index -q --refresh &&
1742 case "$has_head" in
1743 yes)
1744 git read-tree -u -m HEAD "$1" ;;
1746 git read-tree -u -m "$1" ;;
1747 esac || {
1748 status=$?
1749 echo >&2 read-tree failed
1750 exit $status
1753 ) &&
1755 git push void main &&
1757 cd void &&
1758 git diff --quiet &&
1759 git diff --cached --quiet &&
1760 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1764 test_expect_success 'denyCurrentBranch and worktrees' '
1765 git worktree add new-wt &&
1766 git clone . cloned &&
1767 test_commit -C cloned first &&
1768 test_config receive.denyCurrentBranch refuse &&
1769 test_must_fail git -C cloned push origin HEAD:new-wt &&
1770 test_config receive.denyCurrentBranch updateInstead &&
1771 git -C cloned push origin HEAD:new-wt &&
1772 test_must_fail git -C cloned push --delete origin new-wt
1774 test_done