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