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