]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5516-fetch-push.sh
tests: mark tests relying on the current default for `init.defaultBranch`
[thirdparty/git.git] / t / t5516-fetch-push.sh
1 #!/bin/sh
2
3 test_description='Basic fetch/push functionality.
4
5 This test checks the following functionality:
6
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
15 '
16
17 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
18 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
19
20 . ./test-lib.sh
21
22 D=$(pwd)
23
24 mk_empty () {
25 repo_name="$1"
26 rm -fr "$repo_name" &&
27 mkdir "$repo_name" &&
28 (
29 cd "$repo_name" &&
30 git init &&
31 git config receive.denyCurrentBranch warn &&
32 mv .git/hooks .git/hooks-disabled
33 )
34 }
35
36 mk_test () {
37 repo_name="$1"
38 shift
39
40 mk_empty "$repo_name" &&
41 (
42 for ref in "$@"
43 do
44 git push "$repo_name" $the_first_commit:refs/$ref ||
45 exit
46 done &&
47 cd "$repo_name" &&
48 for ref in "$@"
49 do
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
56 )
57 }
58
59 mk_test_with_hooks() {
60 repo_name=$1
61 mk_test "$@" &&
62 (
63 cd "$repo_name" &&
64 mkdir .git/hooks &&
65 cd .git/hooks &&
66
67 cat >pre-receive <<-'EOF' &&
68 #!/bin/sh
69 cat - >>pre-receive.actual
70 EOF
71
72 cat >update <<-'EOF' &&
73 #!/bin/sh
74 printf "%s %s %s\n" "$@" >>update.actual
75 EOF
76
77 cat >post-receive <<-'EOF' &&
78 #!/bin/sh
79 cat - >>post-receive.actual
80 EOF
81
82 cat >post-update <<-'EOF' &&
83 #!/bin/sh
84 for ref in "$@"
85 do
86 printf "%s\n" "$ref" >>post-update.actual
87 done
88 EOF
89
90 chmod +x pre-receive update post-receive post-update
91 )
92 }
93
94 mk_child() {
95 rm -rf "$2" &&
96 git clone "$1" "$2"
97 }
98
99 check_push_result () {
100 test $# -ge 3 ||
101 BUG "check_push_result requires at least 3 parameters"
102
103 repo_name="$1"
104 shift
105
106 (
107 cd "$repo_name" &&
108 echo "$1" >expect &&
109 shift &&
110 for ref in "$@"
111 do
112 git show-ref -s --verify refs/$ref >actual &&
113 test_cmp expect actual ||
114 exit
115 done &&
116 git fsck --full
117 )
118 }
119
120 test_expect_success setup '
121
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/master) &&
127
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/master)
133
134 '
135
136 test_expect_success 'fetch without wildcard' '
137 mk_empty testrepo &&
138 (
139 cd testrepo &&
140 git fetch .. refs/heads/master:refs/remotes/origin/master &&
141
142 echo "$the_commit commit refs/remotes/origin/master" >expect &&
143 git for-each-ref refs/remotes/origin >actual &&
144 test_cmp expect actual
145 )
146 '
147
148 test_expect_success 'fetch with wildcard' '
149 mk_empty testrepo &&
150 (
151 cd testrepo &&
152 git config remote.up.url .. &&
153 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
154 git fetch up &&
155
156 echo "$the_commit commit refs/remotes/origin/master" >expect &&
157 git for-each-ref refs/remotes/origin >actual &&
158 test_cmp expect actual
159 )
160 '
161
162 test_expect_success 'fetch with insteadOf' '
163 mk_empty testrepo &&
164 (
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 &&
171
172 echo "$the_commit commit refs/remotes/origin/master" >expect &&
173 git for-each-ref refs/remotes/origin >actual &&
174 test_cmp expect actual
175 )
176 '
177
178 test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
179 mk_empty testrepo &&
180 (
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 &&
187
188 echo "$the_commit commit refs/remotes/origin/master" >expect &&
189 git for-each-ref refs/remotes/origin >actual &&
190 test_cmp expect actual
191 )
192 '
193
194 test_expect_success 'push without wildcard' '
195 mk_empty testrepo &&
196
197 git push testrepo refs/heads/master:refs/remotes/origin/master &&
198 (
199 cd testrepo &&
200 echo "$the_commit commit refs/remotes/origin/master" >expect &&
201 git for-each-ref refs/remotes/origin >actual &&
202 test_cmp expect actual
203 )
204 '
205
206 test_expect_success 'push with wildcard' '
207 mk_empty testrepo &&
208
209 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
210 (
211 cd testrepo &&
212 echo "$the_commit commit refs/remotes/origin/master" >expect &&
213 git for-each-ref refs/remotes/origin >actual &&
214 test_cmp expect actual
215 )
216 '
217
218 test_expect_success 'push with insteadOf' '
219 mk_empty testrepo &&
220 TRASH="$(pwd)/" &&
221 test_config "url.$TRASH.insteadOf" trash/ &&
222 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
223 (
224 cd testrepo &&
225 echo "$the_commit commit refs/remotes/origin/master" >expect &&
226 git for-each-ref refs/remotes/origin >actual &&
227 test_cmp expect actual
228 )
229 '
230
231 test_expect_success 'push with pushInsteadOf' '
232 mk_empty testrepo &&
233 TRASH="$(pwd)/" &&
234 test_config "url.$TRASH.pushInsteadOf" trash/ &&
235 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
236 (
237 cd testrepo &&
238 echo "$the_commit commit refs/remotes/origin/master" >expect &&
239 git for-each-ref refs/remotes/origin >actual &&
240 test_cmp expect actual
241 )
242 '
243
244 test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
245 mk_empty testrepo &&
246 test_config "url.trash2/.pushInsteadOf" testrepo/ &&
247 test_config "url.trash3/.pushInsteadOf" trash/wrong &&
248 test_config remote.r.url trash/wrong &&
249 test_config remote.r.pushurl "testrepo/" &&
250 git push r refs/heads/master:refs/remotes/origin/master &&
251 (
252 cd testrepo &&
253 echo "$the_commit commit refs/remotes/origin/master" >expect &&
254 git for-each-ref refs/remotes/origin >actual &&
255 test_cmp expect actual
256 )
257 '
258
259 test_expect_success 'push with matching heads' '
260
261 mk_test testrepo heads/master &&
262 git push testrepo : &&
263 check_push_result testrepo $the_commit heads/master
264
265 '
266
267 test_expect_success 'push with matching heads on the command line' '
268
269 mk_test testrepo heads/master &&
270 git push testrepo : &&
271 check_push_result testrepo $the_commit heads/master
272
273 '
274
275 test_expect_success 'failed (non-fast-forward) push with matching heads' '
276
277 mk_test testrepo heads/master &&
278 git push testrepo : &&
279 git commit --amend -massaged &&
280 test_must_fail git push testrepo &&
281 check_push_result testrepo $the_commit heads/master &&
282 git reset --hard $the_commit
283
284 '
285
286 test_expect_success 'push --force with matching heads' '
287
288 mk_test testrepo heads/master &&
289 git push testrepo : &&
290 git commit --amend -massaged &&
291 git push --force testrepo : &&
292 ! check_push_result testrepo $the_commit heads/master &&
293 git reset --hard $the_commit
294
295 '
296
297 test_expect_success 'push with matching heads and forced update' '
298
299 mk_test testrepo heads/master &&
300 git push testrepo : &&
301 git commit --amend -massaged &&
302 git push testrepo +: &&
303 ! check_push_result testrepo $the_commit heads/master &&
304 git reset --hard $the_commit
305
306 '
307
308 test_expect_success 'push with no ambiguity (1)' '
309
310 mk_test testrepo heads/master &&
311 git push testrepo master:master &&
312 check_push_result testrepo $the_commit heads/master
313
314 '
315
316 test_expect_success 'push with no ambiguity (2)' '
317
318 mk_test testrepo remotes/origin/master &&
319 git push testrepo master:origin/master &&
320 check_push_result testrepo $the_commit remotes/origin/master
321
322 '
323
324 test_expect_success 'push with colon-less refspec, no ambiguity' '
325
326 mk_test testrepo heads/master heads/t/master &&
327 git branch -f t/master master &&
328 git push testrepo master &&
329 check_push_result testrepo $the_commit heads/master &&
330 check_push_result testrepo $the_first_commit heads/t/master
331
332 '
333
334 test_expect_success 'push with weak ambiguity (1)' '
335
336 mk_test testrepo heads/master remotes/origin/master &&
337 git push testrepo master:master &&
338 check_push_result testrepo $the_commit heads/master &&
339 check_push_result testrepo $the_first_commit remotes/origin/master
340
341 '
342
343 test_expect_success 'push with weak ambiguity (2)' '
344
345 mk_test testrepo heads/master remotes/origin/master remotes/another/master &&
346 git push testrepo master:master &&
347 check_push_result testrepo $the_commit heads/master &&
348 check_push_result testrepo $the_first_commit remotes/origin/master remotes/another/master
349
350 '
351
352 test_expect_success 'push with ambiguity' '
353
354 mk_test testrepo heads/frotz tags/frotz &&
355 test_must_fail git push testrepo master:frotz &&
356 check_push_result testrepo $the_first_commit heads/frotz tags/frotz
357
358 '
359
360 test_expect_success 'push with colon-less refspec (1)' '
361
362 mk_test testrepo heads/frotz tags/frotz &&
363 git branch -f frotz master &&
364 git push testrepo frotz &&
365 check_push_result testrepo $the_commit heads/frotz &&
366 check_push_result testrepo $the_first_commit tags/frotz
367
368 '
369
370 test_expect_success 'push with colon-less refspec (2)' '
371
372 mk_test testrepo heads/frotz tags/frotz &&
373 if git show-ref --verify -q refs/heads/frotz
374 then
375 git branch -D frotz
376 fi &&
377 git tag -f frotz &&
378 git push -f testrepo frotz &&
379 check_push_result testrepo $the_commit tags/frotz &&
380 check_push_result testrepo $the_first_commit heads/frotz
381
382 '
383
384 test_expect_success 'push with colon-less refspec (3)' '
385
386 mk_test testrepo &&
387 if git show-ref --verify -q refs/tags/frotz
388 then
389 git tag -d frotz
390 fi &&
391 git branch -f frotz master &&
392 git push testrepo frotz &&
393 check_push_result testrepo $the_commit heads/frotz &&
394 test 1 = $( cd testrepo && git show-ref | wc -l )
395 '
396
397 test_expect_success 'push with colon-less refspec (4)' '
398
399 mk_test testrepo &&
400 if git show-ref --verify -q refs/heads/frotz
401 then
402 git branch -D frotz
403 fi &&
404 git tag -f frotz &&
405 git push testrepo frotz &&
406 check_push_result testrepo $the_commit tags/frotz &&
407 test 1 = $( cd testrepo && git show-ref | wc -l )
408
409 '
410
411 test_expect_success 'push head with non-existent, incomplete dest' '
412
413 mk_test testrepo &&
414 git push testrepo master:branch &&
415 check_push_result testrepo $the_commit heads/branch
416
417 '
418
419 test_expect_success 'push tag with non-existent, incomplete dest' '
420
421 mk_test testrepo &&
422 git tag -f v1.0 &&
423 git push testrepo v1.0:tag &&
424 check_push_result testrepo $the_commit tags/tag
425
426 '
427
428 test_expect_success 'push sha1 with non-existent, incomplete dest' '
429
430 mk_test testrepo &&
431 test_must_fail git push testrepo $(git rev-parse master):foo
432
433 '
434
435 test_expect_success 'push ref expression with non-existent, incomplete dest' '
436
437 mk_test testrepo &&
438 test_must_fail git push testrepo master^:branch
439
440 '
441
442 test_expect_success 'push with HEAD' '
443
444 mk_test testrepo heads/master &&
445 git checkout master &&
446 git push testrepo HEAD &&
447 check_push_result testrepo $the_commit heads/master
448
449 '
450
451 test_expect_success 'push with HEAD nonexisting at remote' '
452
453 mk_test testrepo heads/master &&
454 git checkout -b local master &&
455 git push testrepo HEAD &&
456 check_push_result testrepo $the_commit heads/local
457 '
458
459 test_expect_success 'push with +HEAD' '
460
461 mk_test testrepo heads/master &&
462 git checkout master &&
463 git branch -D local &&
464 git checkout -b local &&
465 git push testrepo master local &&
466 check_push_result testrepo $the_commit heads/master &&
467 check_push_result testrepo $the_commit heads/local &&
468
469 # Without force rewinding should fail
470 git reset --hard HEAD^ &&
471 test_must_fail git push testrepo HEAD &&
472 check_push_result testrepo $the_commit heads/local &&
473
474 # With force rewinding should succeed
475 git push testrepo +HEAD &&
476 check_push_result testrepo $the_first_commit heads/local
477
478 '
479
480 test_expect_success 'push HEAD with non-existent, incomplete dest' '
481
482 mk_test testrepo &&
483 git checkout master &&
484 git push testrepo HEAD:branch &&
485 check_push_result testrepo $the_commit heads/branch
486
487 '
488
489 test_expect_success 'push with config remote.*.push = HEAD' '
490
491 mk_test testrepo heads/local &&
492 git checkout master &&
493 git branch -f local $the_commit &&
494 (
495 cd testrepo &&
496 git checkout local &&
497 git reset --hard $the_first_commit
498 ) &&
499 test_config remote.there.url testrepo &&
500 test_config remote.there.push HEAD &&
501 test_config branch.master.remote there &&
502 git push &&
503 check_push_result testrepo $the_commit heads/master &&
504 check_push_result testrepo $the_first_commit heads/local
505 '
506
507 test_expect_success 'push with remote.pushdefault' '
508 mk_test up_repo heads/master &&
509 mk_test down_repo heads/master &&
510 test_config remote.up.url up_repo &&
511 test_config remote.down.url down_repo &&
512 test_config branch.master.remote up &&
513 test_config remote.pushdefault down &&
514 test_config push.default matching &&
515 git push &&
516 check_push_result up_repo $the_first_commit heads/master &&
517 check_push_result down_repo $the_commit heads/master
518 '
519
520 test_expect_success 'push with config remote.*.pushurl' '
521
522 mk_test testrepo heads/master &&
523 git checkout master &&
524 test_config remote.there.url test2repo &&
525 test_config remote.there.pushurl testrepo &&
526 git push there : &&
527 check_push_result testrepo $the_commit heads/master
528 '
529
530 test_expect_success 'push with config branch.*.pushremote' '
531 mk_test up_repo heads/master &&
532 mk_test side_repo heads/master &&
533 mk_test down_repo heads/master &&
534 test_config remote.up.url up_repo &&
535 test_config remote.pushdefault side_repo &&
536 test_config remote.down.url down_repo &&
537 test_config branch.master.remote up &&
538 test_config branch.master.pushremote down &&
539 test_config push.default matching &&
540 git push &&
541 check_push_result up_repo $the_first_commit heads/master &&
542 check_push_result side_repo $the_first_commit heads/master &&
543 check_push_result down_repo $the_commit heads/master
544 '
545
546 test_expect_success 'branch.*.pushremote config order is irrelevant' '
547 mk_test one_repo heads/master &&
548 mk_test two_repo heads/master &&
549 test_config remote.one.url one_repo &&
550 test_config remote.two.url two_repo &&
551 test_config branch.master.pushremote two_repo &&
552 test_config remote.pushdefault one_repo &&
553 test_config push.default matching &&
554 git push &&
555 check_push_result one_repo $the_first_commit heads/master &&
556 check_push_result two_repo $the_commit heads/master
557 '
558
559 test_expect_success 'push with dry-run' '
560
561 mk_test testrepo heads/master &&
562 old_commit=$(git -C testrepo show-ref -s --verify refs/heads/master) &&
563 git push --dry-run testrepo : &&
564 check_push_result testrepo $old_commit heads/master
565 '
566
567 test_expect_success 'push updates local refs' '
568
569 mk_test testrepo heads/master &&
570 mk_child testrepo child &&
571 (
572 cd child &&
573 git pull .. master &&
574 git push &&
575 test $(git rev-parse master) = \
576 $(git rev-parse remotes/origin/master)
577 )
578
579 '
580
581 test_expect_success 'push updates up-to-date local refs' '
582
583 mk_test testrepo heads/master &&
584 mk_child testrepo child1 &&
585 mk_child testrepo child2 &&
586 (cd child1 && git pull .. master && git push) &&
587 (
588 cd child2 &&
589 git pull ../child1 master &&
590 git push &&
591 test $(git rev-parse master) = \
592 $(git rev-parse remotes/origin/master)
593 )
594
595 '
596
597 test_expect_success 'push preserves up-to-date packed refs' '
598
599 mk_test testrepo heads/master &&
600 mk_child testrepo child &&
601 (
602 cd child &&
603 git push &&
604 ! test -f .git/refs/remotes/origin/master
605 )
606
607 '
608
609 test_expect_success 'push does not update local refs on failure' '
610
611 mk_test testrepo heads/master &&
612 mk_child testrepo child &&
613 mkdir testrepo/.git/hooks &&
614 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
615 chmod +x testrepo/.git/hooks/pre-receive &&
616 (
617 cd child &&
618 git pull .. master &&
619 test_must_fail git push &&
620 test $(git rev-parse master) != \
621 $(git rev-parse remotes/origin/master)
622 )
623
624 '
625
626 test_expect_success 'allow deleting an invalid remote ref' '
627
628 mk_test testrepo heads/master &&
629 rm -f testrepo/.git/objects/??/* &&
630 git push testrepo :refs/heads/master &&
631 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
632
633 '
634
635 test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' '
636 mk_test_with_hooks testrepo heads/master heads/next &&
637 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
638 newmaster=$(git show-ref -s --verify refs/heads/master) &&
639 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
640 newnext=$ZERO_OID &&
641 git push testrepo refs/heads/master:refs/heads/master :refs/heads/next &&
642 (
643 cd testrepo/.git &&
644 cat >pre-receive.expect <<-EOF &&
645 $orgmaster $newmaster refs/heads/master
646 $orgnext $newnext refs/heads/next
647 EOF
648
649 cat >update.expect <<-EOF &&
650 refs/heads/master $orgmaster $newmaster
651 refs/heads/next $orgnext $newnext
652 EOF
653
654 cat >post-receive.expect <<-EOF &&
655 $orgmaster $newmaster refs/heads/master
656 $orgnext $newnext refs/heads/next
657 EOF
658
659 cat >post-update.expect <<-EOF &&
660 refs/heads/master
661 refs/heads/next
662 EOF
663
664 test_cmp pre-receive.expect pre-receive.actual &&
665 test_cmp update.expect update.actual &&
666 test_cmp post-receive.expect post-receive.actual &&
667 test_cmp post-update.expect post-update.actual
668 )
669 '
670
671 test_expect_success 'deleting dangling ref triggers hooks with correct args' '
672 mk_test_with_hooks testrepo heads/master &&
673 rm -f testrepo/.git/objects/??/* &&
674 git push testrepo :refs/heads/master &&
675 (
676 cd testrepo/.git &&
677 cat >pre-receive.expect <<-EOF &&
678 $ZERO_OID $ZERO_OID refs/heads/master
679 EOF
680
681 cat >update.expect <<-EOF &&
682 refs/heads/master $ZERO_OID $ZERO_OID
683 EOF
684
685 cat >post-receive.expect <<-EOF &&
686 $ZERO_OID $ZERO_OID refs/heads/master
687 EOF
688
689 cat >post-update.expect <<-EOF &&
690 refs/heads/master
691 EOF
692
693 test_cmp pre-receive.expect pre-receive.actual &&
694 test_cmp update.expect update.actual &&
695 test_cmp post-receive.expect post-receive.actual &&
696 test_cmp post-update.expect post-update.actual
697 )
698 '
699
700 test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
701 mk_test_with_hooks testrepo heads/master &&
702 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
703 newmaster=$(git show-ref -s --verify refs/heads/master) &&
704 git push testrepo master :refs/heads/nonexistent &&
705 (
706 cd testrepo/.git &&
707 cat >pre-receive.expect <<-EOF &&
708 $orgmaster $newmaster refs/heads/master
709 $ZERO_OID $ZERO_OID refs/heads/nonexistent
710 EOF
711
712 cat >update.expect <<-EOF &&
713 refs/heads/master $orgmaster $newmaster
714 refs/heads/nonexistent $ZERO_OID $ZERO_OID
715 EOF
716
717 cat >post-receive.expect <<-EOF &&
718 $orgmaster $newmaster refs/heads/master
719 EOF
720
721 cat >post-update.expect <<-EOF &&
722 refs/heads/master
723 EOF
724
725 test_cmp pre-receive.expect pre-receive.actual &&
726 test_cmp update.expect update.actual &&
727 test_cmp post-receive.expect post-receive.actual &&
728 test_cmp post-update.expect post-update.actual
729 )
730 '
731
732 test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
733 mk_test_with_hooks testrepo heads/master &&
734 git push testrepo :refs/heads/nonexistent &&
735 (
736 cd testrepo/.git &&
737 cat >pre-receive.expect <<-EOF &&
738 $ZERO_OID $ZERO_OID refs/heads/nonexistent
739 EOF
740
741 cat >update.expect <<-EOF &&
742 refs/heads/nonexistent $ZERO_OID $ZERO_OID
743 EOF
744
745 test_cmp pre-receive.expect pre-receive.actual &&
746 test_cmp update.expect update.actual &&
747 test_path_is_missing post-receive.actual &&
748 test_path_is_missing post-update.actual
749 )
750 '
751
752 test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
753 mk_test_with_hooks testrepo heads/master heads/next heads/seen &&
754 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
755 newmaster=$(git show-ref -s --verify refs/heads/master) &&
756 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
757 newnext=$ZERO_OID &&
758 orgseen=$(cd testrepo && git show-ref -s --verify refs/heads/seen) &&
759 newseen=$(git show-ref -s --verify refs/heads/master) &&
760 git push testrepo refs/heads/master:refs/heads/master \
761 refs/heads/master:refs/heads/seen :refs/heads/next \
762 :refs/heads/nonexistent &&
763 (
764 cd testrepo/.git &&
765 cat >pre-receive.expect <<-EOF &&
766 $orgmaster $newmaster refs/heads/master
767 $orgnext $newnext refs/heads/next
768 $orgseen $newseen refs/heads/seen
769 $ZERO_OID $ZERO_OID refs/heads/nonexistent
770 EOF
771
772 cat >update.expect <<-EOF &&
773 refs/heads/master $orgmaster $newmaster
774 refs/heads/next $orgnext $newnext
775 refs/heads/seen $orgseen $newseen
776 refs/heads/nonexistent $ZERO_OID $ZERO_OID
777 EOF
778
779 cat >post-receive.expect <<-EOF &&
780 $orgmaster $newmaster refs/heads/master
781 $orgnext $newnext refs/heads/next
782 $orgseen $newseen refs/heads/seen
783 EOF
784
785 cat >post-update.expect <<-EOF &&
786 refs/heads/master
787 refs/heads/next
788 refs/heads/seen
789 EOF
790
791 test_cmp pre-receive.expect pre-receive.actual &&
792 test_cmp update.expect update.actual &&
793 test_cmp post-receive.expect post-receive.actual &&
794 test_cmp post-update.expect post-update.actual
795 )
796 '
797
798 test_expect_success 'allow deleting a ref using --delete' '
799 mk_test testrepo heads/master &&
800 (cd testrepo && git config receive.denyDeleteCurrent warn) &&
801 git push testrepo --delete master &&
802 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
803 '
804
805 test_expect_success 'allow deleting a tag using --delete' '
806 mk_test testrepo heads/master &&
807 git tag -a -m dummy_message deltag heads/master &&
808 git push testrepo --tags &&
809 (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
810 git push testrepo --delete tag deltag &&
811 (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
812 '
813
814 test_expect_success 'push --delete without args aborts' '
815 mk_test testrepo heads/master &&
816 test_must_fail git push testrepo --delete
817 '
818
819 test_expect_success 'push --delete refuses src:dest refspecs' '
820 mk_test testrepo heads/master &&
821 test_must_fail git push testrepo --delete master:foo
822 '
823
824 test_expect_success 'warn on push to HEAD of non-bare repository' '
825 mk_test testrepo heads/master &&
826 (
827 cd testrepo &&
828 git checkout master &&
829 git config receive.denyCurrentBranch warn
830 ) &&
831 git push testrepo master 2>stderr &&
832 grep "warning: updating the current branch" stderr
833 '
834
835 test_expect_success 'deny push to HEAD of non-bare repository' '
836 mk_test testrepo heads/master &&
837 (
838 cd testrepo &&
839 git checkout master &&
840 git config receive.denyCurrentBranch true
841 ) &&
842 test_must_fail git push testrepo master
843 '
844
845 test_expect_success 'allow push to HEAD of bare repository (bare)' '
846 mk_test testrepo heads/master &&
847 (
848 cd testrepo &&
849 git checkout master &&
850 git config receive.denyCurrentBranch true &&
851 git config core.bare true
852 ) &&
853 git push testrepo master 2>stderr &&
854 ! grep "warning: updating the current branch" stderr
855 '
856
857 test_expect_success 'allow push to HEAD of non-bare repository (config)' '
858 mk_test testrepo heads/master &&
859 (
860 cd testrepo &&
861 git checkout master &&
862 git config receive.denyCurrentBranch false
863 ) &&
864 git push testrepo master 2>stderr &&
865 ! grep "warning: updating the current branch" stderr
866 '
867
868 test_expect_success 'fetch with branches' '
869 mk_empty testrepo &&
870 git branch second $the_first_commit &&
871 git checkout second &&
872 echo ".." > testrepo/.git/branches/branch1 &&
873 (
874 cd testrepo &&
875 git fetch branch1 &&
876 echo "$the_commit commit refs/heads/branch1" >expect &&
877 git for-each-ref refs/heads >actual &&
878 test_cmp expect actual
879 ) &&
880 git checkout master
881 '
882
883 test_expect_success 'fetch with branches containing #' '
884 mk_empty testrepo &&
885 echo "..#second" > testrepo/.git/branches/branch2 &&
886 (
887 cd testrepo &&
888 git fetch branch2 &&
889 echo "$the_first_commit commit refs/heads/branch2" >expect &&
890 git for-each-ref refs/heads >actual &&
891 test_cmp expect actual
892 ) &&
893 git checkout master
894 '
895
896 test_expect_success 'push with branches' '
897 mk_empty testrepo &&
898 git checkout second &&
899 echo "testrepo" > .git/branches/branch1 &&
900 git push branch1 &&
901 (
902 cd testrepo &&
903 echo "$the_first_commit commit refs/heads/master" >expect &&
904 git for-each-ref refs/heads >actual &&
905 test_cmp expect actual
906 )
907 '
908
909 test_expect_success 'push with branches containing #' '
910 mk_empty testrepo &&
911 echo "testrepo#branch3" > .git/branches/branch2 &&
912 git push branch2 &&
913 (
914 cd testrepo &&
915 echo "$the_first_commit commit refs/heads/branch3" >expect &&
916 git for-each-ref refs/heads >actual &&
917 test_cmp expect actual
918 ) &&
919 git checkout master
920 '
921
922 test_expect_success 'push into aliased refs (consistent)' '
923 mk_test testrepo heads/master &&
924 mk_child testrepo child1 &&
925 mk_child testrepo child2 &&
926 (
927 cd child1 &&
928 git branch foo &&
929 git symbolic-ref refs/heads/bar refs/heads/foo &&
930 git config receive.denyCurrentBranch false
931 ) &&
932 (
933 cd child2 &&
934 >path2 &&
935 git add path2 &&
936 test_tick &&
937 git commit -a -m child2 &&
938 git branch foo &&
939 git branch bar &&
940 git push ../child1 foo bar
941 )
942 '
943
944 test_expect_success 'push into aliased refs (inconsistent)' '
945 mk_test testrepo heads/master &&
946 mk_child testrepo child1 &&
947 mk_child testrepo child2 &&
948 (
949 cd child1 &&
950 git branch foo &&
951 git symbolic-ref refs/heads/bar refs/heads/foo &&
952 git config receive.denyCurrentBranch false
953 ) &&
954 (
955 cd child2 &&
956 >path2 &&
957 git add path2 &&
958 test_tick &&
959 git commit -a -m child2 &&
960 git branch foo &&
961 >path3 &&
962 git add path3 &&
963 test_tick &&
964 git commit -a -m child2 &&
965 git branch bar &&
966 test_must_fail git push ../child1 foo bar 2>stderr &&
967 grep "refusing inconsistent update" stderr
968 )
969 '
970
971 test_force_push_tag () {
972 tag_type_description=$1
973 tag_args=$2
974
975 test_expect_success "force pushing required to update $tag_type_description" "
976 mk_test testrepo heads/master &&
977 mk_child testrepo child1 &&
978 mk_child testrepo child2 &&
979 (
980 cd child1 &&
981 git tag testTag &&
982 git push ../child2 testTag &&
983 >file1 &&
984 git add file1 &&
985 git commit -m 'file1' &&
986 git tag $tag_args testTag &&
987 test_must_fail git push ../child2 testTag &&
988 git push --force ../child2 testTag &&
989 git tag $tag_args testTag HEAD~ &&
990 test_must_fail git push ../child2 testTag &&
991 git push --force ../child2 testTag &&
992
993 # Clobbering without + in refspec needs --force
994 git tag -f testTag &&
995 test_must_fail git push ../child2 'refs/tags/*:refs/tags/*' &&
996 git push --force ../child2 'refs/tags/*:refs/tags/*' &&
997
998 # Clobbering with + in refspec does not need --force
999 git tag -f testTag HEAD~ &&
1000 git push ../child2 '+refs/tags/*:refs/tags/*' &&
1001
1002 # Clobbering with --no-force still obeys + in refspec
1003 git tag -f testTag &&
1004 git push --no-force ../child2 '+refs/tags/*:refs/tags/*' &&
1005
1006 # Clobbering with/without --force and 'tag <name>' format
1007 git tag -f testTag HEAD~ &&
1008 test_must_fail git push ../child2 tag testTag &&
1009 git push --force ../child2 tag testTag
1010 )
1011 "
1012 }
1013
1014 test_force_push_tag "lightweight tag" "-f"
1015 test_force_push_tag "annotated tag" "-f -a -m'tag message'"
1016
1017 test_force_fetch_tag () {
1018 tag_type_description=$1
1019 tag_args=$2
1020
1021 test_expect_success "fetch will not clobber an existing $tag_type_description without --force" "
1022 mk_test testrepo heads/master &&
1023 mk_child testrepo child1 &&
1024 mk_child testrepo child2 &&
1025 (
1026 cd testrepo &&
1027 git tag testTag &&
1028 git -C ../child1 fetch origin tag testTag &&
1029 >file1 &&
1030 git add file1 &&
1031 git commit -m 'file1' &&
1032 git tag $tag_args testTag &&
1033 test_must_fail git -C ../child1 fetch origin tag testTag &&
1034 git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*'
1035 )
1036 "
1037 }
1038
1039 test_force_fetch_tag "lightweight tag" "-f"
1040 test_force_fetch_tag "annotated tag" "-f -a -m'tag message'"
1041
1042 test_expect_success 'push --porcelain' '
1043 mk_empty testrepo &&
1044 echo >.git/foo "To testrepo" &&
1045 echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new reference]" &&
1046 echo >>.git/foo "Done" &&
1047 git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master &&
1048 (
1049 cd testrepo &&
1050 echo "$the_commit commit refs/remotes/origin/master" >expect &&
1051 git for-each-ref refs/remotes/origin >actual &&
1052 test_cmp expect actual
1053 ) &&
1054 test_cmp .git/foo .git/bar
1055 '
1056
1057 test_expect_success 'push --porcelain bad url' '
1058 mk_empty testrepo &&
1059 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
1060 ! grep -q Done .git/bar
1061 '
1062
1063 test_expect_success 'push --porcelain rejected' '
1064 mk_empty testrepo &&
1065 git push testrepo refs/heads/master:refs/remotes/origin/master &&
1066 (cd testrepo &&
1067 git reset --hard origin/master^ &&
1068 git config receive.denyCurrentBranch true) &&
1069
1070 echo >.git/foo "To testrepo" &&
1071 echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" &&
1072 echo >>.git/foo "Done" &&
1073
1074 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master &&
1075 test_cmp .git/foo .git/bar
1076 '
1077
1078 test_expect_success 'push --porcelain --dry-run rejected' '
1079 mk_empty testrepo &&
1080 git push testrepo refs/heads/master:refs/remotes/origin/master &&
1081 (cd testrepo &&
1082 git reset --hard origin/master &&
1083 git config receive.denyCurrentBranch true) &&
1084
1085 echo >.git/foo "To testrepo" &&
1086 echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" &&
1087 echo >>.git/foo "Done" &&
1088
1089 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master &&
1090 test_cmp .git/foo .git/bar
1091 '
1092
1093 test_expect_success 'push --prune' '
1094 mk_test testrepo heads/master heads/second heads/foo heads/bar &&
1095 git push --prune testrepo : &&
1096 check_push_result testrepo $the_commit heads/master &&
1097 check_push_result testrepo $the_first_commit heads/second &&
1098 ! check_push_result testrepo $the_first_commit heads/foo heads/bar
1099 '
1100
1101 test_expect_success 'push --prune refspec' '
1102 mk_test testrepo tmp/master tmp/second tmp/foo tmp/bar &&
1103 git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
1104 check_push_result testrepo $the_commit tmp/master &&
1105 check_push_result testrepo $the_first_commit tmp/second &&
1106 ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
1107 '
1108
1109 for configsection in transfer receive
1110 do
1111 test_expect_success "push to update a ref hidden by $configsection.hiderefs" '
1112 mk_test testrepo heads/master hidden/one hidden/two hidden/three &&
1113 (
1114 cd testrepo &&
1115 git config $configsection.hiderefs refs/hidden
1116 ) &&
1117
1118 # push to unhidden ref succeeds normally
1119 git push testrepo master:refs/heads/master &&
1120 check_push_result testrepo $the_commit heads/master &&
1121
1122 # push to update a hidden ref should fail
1123 test_must_fail git push testrepo master:refs/hidden/one &&
1124 check_push_result testrepo $the_first_commit hidden/one &&
1125
1126 # push to delete a hidden ref should fail
1127 test_must_fail git push testrepo :refs/hidden/two &&
1128 check_push_result testrepo $the_first_commit hidden/two &&
1129
1130 # idempotent push to update a hidden ref should fail
1131 test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
1132 check_push_result testrepo $the_first_commit hidden/three
1133 '
1134 done
1135
1136 test_expect_success 'fetch exact SHA1' '
1137 mk_test testrepo heads/master hidden/one &&
1138 git push testrepo master:refs/hidden/one &&
1139 (
1140 cd testrepo &&
1141 git config transfer.hiderefs refs/hidden
1142 ) &&
1143 check_push_result testrepo $the_commit hidden/one &&
1144
1145 mk_child testrepo child &&
1146 (
1147 cd child &&
1148
1149 # make sure $the_commit does not exist here
1150 git repack -a -d &&
1151 git prune &&
1152 test_must_fail git cat-file -t $the_commit &&
1153
1154 # Some protocol versions (e.g. 2) support fetching
1155 # unadvertised objects, so restrict this test to v0.
1156
1157 # fetching the hidden object should fail by default
1158 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1159 git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err &&
1160 test_i18ngrep "Server does not allow request for unadvertised object" err &&
1161 test_must_fail git rev-parse --verify refs/heads/copy &&
1162
1163 # the server side can allow it to succeed
1164 (
1165 cd ../testrepo &&
1166 git config uploadpack.allowtipsha1inwant true
1167 ) &&
1168
1169 git fetch -v ../testrepo $the_commit:refs/heads/copy master:refs/heads/extra &&
1170 cat >expect <<-EOF &&
1171 $the_commit
1172 $the_first_commit
1173 EOF
1174 {
1175 git rev-parse --verify refs/heads/copy &&
1176 git rev-parse --verify refs/heads/extra
1177 } >actual &&
1178 test_cmp expect actual
1179 )
1180 '
1181
1182 test_expect_success 'fetch exact SHA1 in protocol v2' '
1183 mk_test testrepo heads/master hidden/one &&
1184 git push testrepo master:refs/hidden/one &&
1185 git -C testrepo config transfer.hiderefs refs/hidden &&
1186 check_push_result testrepo $the_commit hidden/one &&
1187
1188 mk_child testrepo child &&
1189 git -C child config protocol.version 2 &&
1190
1191 # make sure $the_commit does not exist here
1192 git -C child repack -a -d &&
1193 git -C child prune &&
1194 test_must_fail git -C child cat-file -t $the_commit &&
1195
1196 # fetching the hidden object succeeds by default
1197 # NEEDSWORK: should this match the v0 behavior instead?
1198 git -C child fetch -v ../testrepo $the_commit:refs/heads/copy
1199 '
1200
1201 for configallowtipsha1inwant in true false
1202 do
1203 test_expect_success "shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" '
1204 mk_empty testrepo &&
1205 (
1206 cd testrepo &&
1207 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1208 git commit --allow-empty -m foo &&
1209 git commit --allow-empty -m bar
1210 ) &&
1211 SHA1=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1212 mk_empty shallow &&
1213 (
1214 cd shallow &&
1215 # Some protocol versions (e.g. 2) support fetching
1216 # unadvertised objects, so restrict this test to v0.
1217 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1218 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1219 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1220 git fetch --depth=1 ../testrepo/.git $SHA1 &&
1221 git cat-file commit $SHA1
1222 )
1223 '
1224
1225 test_expect_success "deny fetch unreachable SHA1, allowtipsha1inwant=$configallowtipsha1inwant" '
1226 mk_empty testrepo &&
1227 (
1228 cd testrepo &&
1229 git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant &&
1230 git commit --allow-empty -m foo &&
1231 git commit --allow-empty -m bar &&
1232 git commit --allow-empty -m xyz
1233 ) &&
1234 SHA1_1=$(git --git-dir=testrepo/.git rev-parse HEAD^^) &&
1235 SHA1_2=$(git --git-dir=testrepo/.git rev-parse HEAD^) &&
1236 SHA1_3=$(git --git-dir=testrepo/.git rev-parse HEAD) &&
1237 (
1238 cd testrepo &&
1239 git reset --hard $SHA1_2 &&
1240 git cat-file commit $SHA1_1 &&
1241 git cat-file commit $SHA1_3
1242 ) &&
1243 mk_empty shallow &&
1244 (
1245 cd shallow &&
1246 # Some protocol versions (e.g. 2) support fetching
1247 # unadvertised objects, so restrict this test to v0.
1248 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1249 git fetch ../testrepo/.git $SHA1_3 &&
1250 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1251 git fetch ../testrepo/.git $SHA1_1 &&
1252 git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true &&
1253 git fetch ../testrepo/.git $SHA1_1 &&
1254 git cat-file commit $SHA1_1 &&
1255 test_must_fail git cat-file commit $SHA1_2 &&
1256 git fetch ../testrepo/.git $SHA1_2 &&
1257 git cat-file commit $SHA1_2 &&
1258 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1259 git fetch ../testrepo/.git $SHA1_3 2>err &&
1260 test_i18ngrep "remote error:.*not our ref.*$SHA1_3\$" err
1261 )
1262 '
1263 done
1264
1265 test_expect_success 'fetch follows tags by default' '
1266 mk_test testrepo heads/master &&
1267 rm -fr src dst &&
1268 git init src &&
1269 (
1270 cd src &&
1271 git pull ../testrepo master &&
1272 git tag -m "annotated" tag &&
1273 git for-each-ref >tmp1 &&
1274 (
1275 cat tmp1
1276 sed -n "s|refs/heads/master$|refs/remotes/origin/master|p" tmp1
1277 ) |
1278 sort -k 3 >../expect
1279 ) &&
1280 git init dst &&
1281 (
1282 cd dst &&
1283 git remote add origin ../src &&
1284 git config branch.master.remote origin &&
1285 git config branch.master.merge refs/heads/master &&
1286 git pull &&
1287 git for-each-ref >../actual
1288 ) &&
1289 test_cmp expect actual
1290 '
1291
1292 test_expect_success 'peeled advertisements are not considered ref tips' '
1293 mk_empty testrepo &&
1294 git -C testrepo commit --allow-empty -m one &&
1295 git -C testrepo commit --allow-empty -m two &&
1296 git -C testrepo tag -m foo mytag HEAD^ &&
1297 oid=$(git -C testrepo rev-parse mytag^{commit}) &&
1298 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
1299 git fetch testrepo $oid 2>err &&
1300 test_i18ngrep "Server does not allow request for unadvertised object" err
1301 '
1302
1303 test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' '
1304 mk_test testrepo heads/master &&
1305 rm -fr src dst &&
1306 git init src &&
1307 git init --bare dst &&
1308 (
1309 cd src &&
1310 git pull ../testrepo master &&
1311 git branch next &&
1312 git config remote.dst.url ../dst &&
1313 git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" &&
1314 git push dst master &&
1315 git show-ref refs/heads/master |
1316 sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect
1317 ) &&
1318 (
1319 cd dst &&
1320 test_must_fail git show-ref refs/heads/next &&
1321 test_must_fail git show-ref refs/heads/master &&
1322 git show-ref refs/remotes/src/master >actual
1323 ) &&
1324 test_cmp dst/expect dst/actual
1325 '
1326
1327 test_expect_success 'with no remote.$name.push, it is not used as refmap' '
1328 mk_test testrepo heads/master &&
1329 rm -fr src dst &&
1330 git init src &&
1331 git init --bare dst &&
1332 (
1333 cd src &&
1334 git pull ../testrepo master &&
1335 git branch next &&
1336 git config remote.dst.url ../dst &&
1337 git config push.default matching &&
1338 git push dst master &&
1339 git show-ref refs/heads/master >../dst/expect
1340 ) &&
1341 (
1342 cd dst &&
1343 test_must_fail git show-ref refs/heads/next &&
1344 git show-ref refs/heads/master >actual
1345 ) &&
1346 test_cmp dst/expect dst/actual
1347 '
1348
1349 test_expect_success 'with no remote.$name.push, upstream mapping is used' '
1350 mk_test testrepo heads/master &&
1351 rm -fr src dst &&
1352 git init src &&
1353 git init --bare dst &&
1354 (
1355 cd src &&
1356 git pull ../testrepo master &&
1357 git branch next &&
1358 git config remote.dst.url ../dst &&
1359 git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" &&
1360 git config push.default upstream &&
1361
1362 git config branch.master.merge refs/heads/trunk &&
1363 git config branch.master.remote dst &&
1364
1365 git push dst master &&
1366 git show-ref refs/heads/master |
1367 sed -e "s|refs/heads/master|refs/heads/trunk|" >../dst/expect
1368 ) &&
1369 (
1370 cd dst &&
1371 test_must_fail git show-ref refs/heads/master &&
1372 test_must_fail git show-ref refs/heads/next &&
1373 git show-ref refs/heads/trunk >actual
1374 ) &&
1375 test_cmp dst/expect dst/actual
1376 '
1377
1378 test_expect_success 'push does not follow tags by default' '
1379 mk_test testrepo heads/master &&
1380 rm -fr src dst &&
1381 git init src &&
1382 git init --bare dst &&
1383 (
1384 cd src &&
1385 git pull ../testrepo master &&
1386 git tag -m "annotated" tag &&
1387 git checkout -b another &&
1388 git commit --allow-empty -m "future commit" &&
1389 git tag -m "future" future &&
1390 git checkout master &&
1391 git for-each-ref refs/heads/master >../expect &&
1392 git push ../dst master
1393 ) &&
1394 (
1395 cd dst &&
1396 git for-each-ref >../actual
1397 ) &&
1398 test_cmp expect actual
1399 '
1400
1401 test_expect_success 'push --follow-tags only pushes relevant tags' '
1402 mk_test testrepo heads/master &&
1403 rm -fr src dst &&
1404 git init src &&
1405 git init --bare dst &&
1406 (
1407 cd src &&
1408 git pull ../testrepo master &&
1409 git tag -m "annotated" tag &&
1410 git checkout -b another &&
1411 git commit --allow-empty -m "future commit" &&
1412 git tag -m "future" future &&
1413 git checkout master &&
1414 git for-each-ref refs/heads/master refs/tags/tag >../expect &&
1415 git push --follow-tags ../dst master
1416 ) &&
1417 (
1418 cd dst &&
1419 git for-each-ref >../actual
1420 ) &&
1421 test_cmp expect actual
1422 '
1423
1424 test_expect_success 'push --no-thin must produce non-thin pack' '
1425 cat >>path1 <<\EOF &&
1426 keep base version of path1 big enough, compared to the new changes
1427 later, in order to pass size heuristics in
1428 builtin/pack-objects.c:try_delta()
1429 EOF
1430 git commit -am initial &&
1431 git init no-thin &&
1432 git --git-dir=no-thin/.git config receive.unpacklimit 0 &&
1433 git push no-thin/.git refs/heads/master:refs/heads/foo &&
1434 echo modified >> path1 &&
1435 git commit -am modified &&
1436 git repack -adf &&
1437 rcvpck="git receive-pack --reject-thin-pack-for-testing" &&
1438 git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/master:refs/heads/foo
1439 '
1440
1441 test_expect_success 'pushing a tag pushes the tagged object' '
1442 rm -rf dst.git &&
1443 blob=$(echo unreferenced | git hash-object -w --stdin) &&
1444 git tag -m foo tag-of-blob $blob &&
1445 git init --bare dst.git &&
1446 git push dst.git tag-of-blob &&
1447 # the receiving index-pack should have noticed
1448 # any problems, but we double check
1449 echo unreferenced >expect &&
1450 git --git-dir=dst.git cat-file blob tag-of-blob >actual &&
1451 test_cmp expect actual
1452 '
1453
1454 test_expect_success 'push into bare respects core.logallrefupdates' '
1455 rm -rf dst.git &&
1456 git init --bare dst.git &&
1457 git -C dst.git config core.logallrefupdates true &&
1458
1459 # double push to test both with and without
1460 # the actual pack transfer
1461 git push dst.git master:one &&
1462 echo "one@{0} push" >expect &&
1463 git -C dst.git log -g --format="%gd %gs" one >actual &&
1464 test_cmp expect actual &&
1465
1466 git push dst.git master:two &&
1467 echo "two@{0} push" >expect &&
1468 git -C dst.git log -g --format="%gd %gs" two >actual &&
1469 test_cmp expect actual
1470 '
1471
1472 test_expect_success 'fetch into bare respects core.logallrefupdates' '
1473 rm -rf dst.git &&
1474 git init --bare dst.git &&
1475 (
1476 cd dst.git &&
1477 git config core.logallrefupdates true &&
1478
1479 # as above, we double-fetch to test both
1480 # with and without pack transfer
1481 git fetch .. master:one &&
1482 echo "one@{0} fetch .. master:one: storing head" >expect &&
1483 git log -g --format="%gd %gs" one >actual &&
1484 test_cmp expect actual &&
1485
1486 git fetch .. master:two &&
1487 echo "two@{0} fetch .. master:two: storing head" >expect &&
1488 git log -g --format="%gd %gs" two >actual &&
1489 test_cmp expect actual
1490 )
1491 '
1492
1493 test_expect_success 'receive.denyCurrentBranch = updateInstead' '
1494 git push testrepo master &&
1495 (
1496 cd testrepo &&
1497 git reset --hard &&
1498 git config receive.denyCurrentBranch updateInstead
1499 ) &&
1500 test_commit third path2 &&
1501
1502 # Try pushing into a repository with pristine working tree
1503 git push testrepo master &&
1504 (
1505 cd testrepo &&
1506 git update-index -q --refresh &&
1507 git diff-files --quiet -- &&
1508 git diff-index --quiet --cached HEAD -- &&
1509 test third = "$(cat path2)" &&
1510 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1511 ) &&
1512
1513 # Try pushing into a repository with working tree needing a refresh
1514 (
1515 cd testrepo &&
1516 git reset --hard HEAD^ &&
1517 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1518 test-tool chmtime +100 path1
1519 ) &&
1520 git push testrepo master &&
1521 (
1522 cd testrepo &&
1523 git update-index -q --refresh &&
1524 git diff-files --quiet -- &&
1525 git diff-index --quiet --cached HEAD -- &&
1526 test_cmp ../path1 path1 &&
1527 test third = "$(cat path2)" &&
1528 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1529 ) &&
1530
1531 # Update what is to be pushed
1532 test_commit fourth path2 &&
1533
1534 # Try pushing into a repository with a dirty working tree
1535 # (1) the working tree updated
1536 (
1537 cd testrepo &&
1538 echo changed >path1
1539 ) &&
1540 test_must_fail git push testrepo master &&
1541 (
1542 cd testrepo &&
1543 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1544 git diff --quiet --cached &&
1545 test changed = "$(cat path1)"
1546 ) &&
1547
1548 # (2) the index updated
1549 (
1550 cd testrepo &&
1551 echo changed >path1 &&
1552 git add path1
1553 ) &&
1554 test_must_fail git push testrepo master &&
1555 (
1556 cd testrepo &&
1557 test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1558 git diff --quiet &&
1559 test changed = "$(cat path1)"
1560 ) &&
1561
1562 # Introduce a new file in the update
1563 test_commit fifth path3 &&
1564
1565 # (3) the working tree has an untracked file that would interfere
1566 (
1567 cd testrepo &&
1568 git reset --hard &&
1569 echo changed >path3
1570 ) &&
1571 test_must_fail git push testrepo master &&
1572 (
1573 cd testrepo &&
1574 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1575 git diff --quiet &&
1576 git diff --quiet --cached &&
1577 test changed = "$(cat path3)"
1578 ) &&
1579
1580 # (4) the target changes to what gets pushed but it still is a change
1581 (
1582 cd testrepo &&
1583 git reset --hard &&
1584 echo fifth >path3 &&
1585 git add path3
1586 ) &&
1587 test_must_fail git push testrepo master &&
1588 (
1589 cd testrepo &&
1590 test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1591 git diff --quiet &&
1592 test fifth = "$(cat path3)"
1593 ) &&
1594
1595 # (5) push into void
1596 rm -fr void &&
1597 git init void &&
1598 (
1599 cd void &&
1600 git config receive.denyCurrentBranch updateInstead
1601 ) &&
1602 git push void master &&
1603 (
1604 cd void &&
1605 test $(git -C .. rev-parse master) = $(git rev-parse HEAD) &&
1606 git diff --quiet &&
1607 git diff --cached --quiet
1608 ) &&
1609
1610 # (6) updateInstead intervened by fast-forward check
1611 test_must_fail git push void master^:master &&
1612 test $(git -C void rev-parse HEAD) = $(git rev-parse master) &&
1613 git -C void diff --quiet &&
1614 git -C void diff --cached --quiet
1615 '
1616
1617 test_expect_success 'updateInstead with push-to-checkout hook' '
1618 rm -fr testrepo &&
1619 git init testrepo &&
1620 (
1621 cd testrepo &&
1622 git pull .. master &&
1623 git reset --hard HEAD^^ &&
1624 git tag initial &&
1625 git config receive.denyCurrentBranch updateInstead &&
1626 write_script .git/hooks/push-to-checkout <<-\EOF
1627 echo >&2 updating from $(git rev-parse HEAD)
1628 echo >&2 updating to "$1"
1629
1630 git update-index -q --refresh &&
1631 git read-tree -u -m HEAD "$1" || {
1632 status=$?
1633 echo >&2 read-tree failed
1634 exit $status
1635 }
1636 EOF
1637 ) &&
1638
1639 # Try pushing into a pristine
1640 git push testrepo master &&
1641 (
1642 cd testrepo &&
1643 git diff --quiet &&
1644 git diff HEAD --quiet &&
1645 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1646 ) &&
1647
1648 # Try pushing into a repository with conflicting change
1649 (
1650 cd testrepo &&
1651 git reset --hard initial &&
1652 echo conflicting >path2
1653 ) &&
1654 test_must_fail git push testrepo master &&
1655 (
1656 cd testrepo &&
1657 test $(git rev-parse initial) = $(git rev-parse HEAD) &&
1658 test conflicting = "$(cat path2)" &&
1659 git diff-index --quiet --cached HEAD
1660 ) &&
1661
1662 # Try pushing into a repository with unrelated change
1663 (
1664 cd testrepo &&
1665 git reset --hard initial &&
1666 echo unrelated >path1 &&
1667 echo irrelevant >path5 &&
1668 git add path5
1669 ) &&
1670 git push testrepo master &&
1671 (
1672 cd testrepo &&
1673 test "$(cat path1)" = unrelated &&
1674 test "$(cat path5)" = irrelevant &&
1675 test "$(git diff --name-only --cached HEAD)" = path5 &&
1676 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1677 ) &&
1678
1679 # push into void
1680 rm -fr void &&
1681 git init void &&
1682 (
1683 cd void &&
1684 git config receive.denyCurrentBranch updateInstead &&
1685 write_script .git/hooks/push-to-checkout <<-\EOF
1686 if git rev-parse --quiet --verify HEAD
1687 then
1688 has_head=yes
1689 echo >&2 updating from $(git rev-parse HEAD)
1690 else
1691 has_head=no
1692 echo >&2 pushing into void
1693 fi
1694 echo >&2 updating to "$1"
1695
1696 git update-index -q --refresh &&
1697 case "$has_head" in
1698 yes)
1699 git read-tree -u -m HEAD "$1" ;;
1700 no)
1701 git read-tree -u -m "$1" ;;
1702 esac || {
1703 status=$?
1704 echo >&2 read-tree failed
1705 exit $status
1706 }
1707 EOF
1708 ) &&
1709
1710 git push void master &&
1711 (
1712 cd void &&
1713 git diff --quiet &&
1714 git diff --cached --quiet &&
1715 test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1716 )
1717 '
1718
1719 test_expect_success 'denyCurrentBranch and worktrees' '
1720 git worktree add new-wt &&
1721 git clone . cloned &&
1722 test_commit -C cloned first &&
1723 test_config receive.denyCurrentBranch refuse &&
1724 test_must_fail git -C cloned push origin HEAD:new-wt &&
1725 test_config receive.denyCurrentBranch updateInstead &&
1726 git -C cloned push origin HEAD:new-wt &&
1727 test_must_fail git -C cloned push --delete origin new-wt
1728 '
1729
1730 test_done