]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5516-fetch-push.sh
push: use remote.$name.push as a refmap
[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
14'
bcdb34f7
JH
15
16. ./test-lib.sh
17
18D=`pwd`
19
20mk_empty () {
2e433b78
JK
21 repo_name="$1"
22 rm -fr "$repo_name" &&
23 mkdir "$repo_name" &&
bcdb34f7 24 (
2e433b78 25 cd "$repo_name" &&
586e4ce2 26 git init &&
acd2a45b 27 git config receive.denyCurrentBranch warn &&
586e4ce2 28 mv .git/hooks .git/hooks-disabled
bcdb34f7
JH
29 )
30}
31
6125796f 32mk_test () {
2e433b78
JK
33 repo_name="$1"
34 shift
35
36 mk_empty "$repo_name" &&
6125796f
JH
37 (
38 for ref in "$@"
39 do
2e433b78 40 git push "$repo_name" $the_first_commit:refs/$ref ||
5bd81c73 41 exit
6125796f 42 done &&
2e433b78 43 cd "$repo_name" &&
6125796f
JH
44 for ref in "$@"
45 do
848575d8
JN
46 echo "$the_first_commit" >expect &&
47 git show-ref -s --verify refs/$ref >actual &&
48 test_cmp expect actual ||
49 exit
6125796f
JH
50 done &&
51 git fsck --full
52 )
53}
54
160b81ed 55mk_test_with_hooks() {
2e433b78 56 repo_name=$1
160b81ed
PYH
57 mk_test "$@" &&
58 (
2e433b78 59 cd "$repo_name" &&
160b81ed
PYH
60 mkdir .git/hooks &&
61 cd .git/hooks &&
62
63 cat >pre-receive <<-'EOF' &&
64 #!/bin/sh
65 cat - >>pre-receive.actual
66 EOF
67
68 cat >update <<-'EOF' &&
69 #!/bin/sh
70 printf "%s %s %s\n" "$@" >>update.actual
71 EOF
72
73 cat >post-receive <<-'EOF' &&
74 #!/bin/sh
75 cat - >>post-receive.actual
76 EOF
77
78 cat >post-update <<-'EOF' &&
79 #!/bin/sh
80 for ref in "$@"
81 do
82 printf "%s\n" "$ref" >>post-update.actual
83 done
84 EOF
85
86 chmod +x pre-receive update post-receive post-update
87 )
88}
89
b2dc968e 90mk_child() {
2e433b78
JK
91 rm -rf "$2" &&
92 git clone "$1" "$2"
b2dc968e
JK
93}
94
6125796f 95check_push_result () {
2e433b78
JK
96 repo_name="$1"
97 shift
98
6125796f 99 (
2e433b78 100 cd "$repo_name" &&
848575d8
JN
101 echo "$1" >expect &&
102 shift &&
6125796f
JH
103 for ref in "$@"
104 do
848575d8
JN
105 git show-ref -s --verify refs/$ref >actual &&
106 test_cmp expect actual ||
107 exit
6125796f
JH
108 done &&
109 git fsck --full
110 )
111}
112
bcdb34f7
JH
113test_expect_success setup '
114
d4785cd1 115 >path1 &&
bcdb34f7
JH
116 git add path1 &&
117 test_tick &&
118 git commit -a -m repo &&
6125796f
JH
119 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
120
d4785cd1 121 >path2 &&
6125796f
JH
122 git add path2 &&
123 test_tick &&
124 git commit -a -m second &&
bcdb34f7
JH
125 the_commit=$(git show-ref -s --verify refs/heads/master)
126
127'
128
129test_expect_success 'fetch without wildcard' '
2e433b78 130 mk_empty testrepo &&
bcdb34f7
JH
131 (
132 cd testrepo &&
133 git fetch .. refs/heads/master:refs/remotes/origin/master &&
134
848575d8
JN
135 echo "$the_commit commit refs/remotes/origin/master" >expect &&
136 git for-each-ref refs/remotes/origin >actual &&
137 test_cmp expect actual
bcdb34f7
JH
138 )
139'
140
141test_expect_success 'fetch with wildcard' '
2e433b78 142 mk_empty testrepo &&
bcdb34f7
JH
143 (
144 cd testrepo &&
145 git config remote.up.url .. &&
146 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
147 git fetch up &&
148
848575d8
JN
149 echo "$the_commit commit refs/remotes/origin/master" >expect &&
150 git for-each-ref refs/remotes/origin >actual &&
151 test_cmp expect actual
bcdb34f7
JH
152 )
153'
154
55029ae4 155test_expect_success 'fetch with insteadOf' '
2e433b78 156 mk_empty testrepo &&
55029ae4 157 (
60e3aba9 158 TRASH=$(pwd)/ &&
55029ae4 159 cd testrepo &&
f69e836f 160 git config "url.$TRASH.insteadOf" trash/ &&
55029ae4
DB
161 git config remote.up.url trash/. &&
162 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
163 git fetch up &&
164
848575d8
JN
165 echo "$the_commit commit refs/remotes/origin/master" >expect &&
166 git for-each-ref refs/remotes/origin >actual &&
167 test_cmp expect actual
55029ae4
DB
168 )
169'
170
1c2eafb8 171test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
2e433b78 172 mk_empty testrepo &&
1c2eafb8
JT
173 (
174 TRASH=$(pwd)/ &&
175 cd testrepo &&
176 git config "url.trash/.pushInsteadOf" "$TRASH" &&
177 git config remote.up.url "$TRASH." &&
178 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
179 git fetch up &&
180
848575d8
JN
181 echo "$the_commit commit refs/remotes/origin/master" >expect &&
182 git for-each-ref refs/remotes/origin >actual &&
183 test_cmp expect actual
1c2eafb8
JT
184 )
185'
186
bcdb34f7 187test_expect_success 'push without wildcard' '
2e433b78 188 mk_empty testrepo &&
bcdb34f7
JH
189
190 git push testrepo refs/heads/master:refs/remotes/origin/master &&
191 (
192 cd testrepo &&
848575d8
JN
193 echo "$the_commit commit refs/remotes/origin/master" >expect &&
194 git for-each-ref refs/remotes/origin >actual &&
195 test_cmp expect actual
bcdb34f7
JH
196 )
197'
198
199test_expect_success 'push with wildcard' '
2e433b78 200 mk_empty testrepo &&
bcdb34f7
JH
201
202 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
203 (
204 cd testrepo &&
848575d8
JN
205 echo "$the_commit commit refs/remotes/origin/master" >expect &&
206 git for-each-ref refs/remotes/origin >actual &&
207 test_cmp expect actual
bcdb34f7
JH
208 )
209'
210
55029ae4 211test_expect_success 'push with insteadOf' '
2e433b78 212 mk_empty testrepo &&
f69e836f 213 TRASH="$(pwd)/" &&
3c695523 214 test_config "url.$TRASH.insteadOf" trash/ &&
55029ae4
DB
215 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
216 (
217 cd testrepo &&
848575d8
JN
218 echo "$the_commit commit refs/remotes/origin/master" >expect &&
219 git for-each-ref refs/remotes/origin >actual &&
220 test_cmp expect actual
55029ae4
DB
221 )
222'
223
1c2eafb8 224test_expect_success 'push with pushInsteadOf' '
2e433b78 225 mk_empty testrepo &&
1c2eafb8 226 TRASH="$(pwd)/" &&
3c695523 227 test_config "url.$TRASH.pushInsteadOf" trash/ &&
1c2eafb8
JT
228 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
229 (
230 cd testrepo &&
848575d8
JN
231 echo "$the_commit commit refs/remotes/origin/master" >expect &&
232 git for-each-ref refs/remotes/origin >actual &&
233 test_cmp expect actual
1c2eafb8
JT
234 )
235'
236
237test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
2e433b78 238 mk_empty testrepo &&
41ae34d1
JH
239 test_config "url.trash2/.pushInsteadOf" testrepo/ &&
240 test_config "url.trash3/.pusnInsteadOf" trash/wrong &&
3c695523 241 test_config remote.r.url trash/wrong &&
41ae34d1 242 test_config remote.r.pushurl "testrepo/" &&
1c2eafb8
JT
243 git push r refs/heads/master:refs/remotes/origin/master &&
244 (
245 cd testrepo &&
848575d8
JN
246 echo "$the_commit commit refs/remotes/origin/master" >expect &&
247 git for-each-ref refs/remotes/origin >actual &&
248 test_cmp expect actual
1c2eafb8
JT
249 )
250'
251
6125796f
JH
252test_expect_success 'push with matching heads' '
253
2e433b78 254 mk_test testrepo heads/master &&
0a42ac03 255 git push testrepo : &&
2e433b78 256 check_push_result testrepo $the_commit heads/master
6125796f
JH
257
258'
259
a83619d6
PB
260test_expect_success 'push with matching heads on the command line' '
261
2e433b78 262 mk_test testrepo heads/master &&
a83619d6 263 git push testrepo : &&
2e433b78 264 check_push_result testrepo $the_commit heads/master
a83619d6
PB
265
266'
267
268test_expect_success 'failed (non-fast-forward) push with matching heads' '
269
2e433b78 270 mk_test testrepo heads/master &&
a83619d6
PB
271 git push testrepo : &&
272 git commit --amend -massaged &&
d492b31c 273 test_must_fail git push testrepo &&
2e433b78 274 check_push_result testrepo $the_commit heads/master &&
a83619d6
PB
275 git reset --hard $the_commit
276
277'
278
279test_expect_success 'push --force with matching heads' '
280
2e433b78 281 mk_test testrepo heads/master &&
a83619d6
PB
282 git push testrepo : &&
283 git commit --amend -massaged &&
0a42ac03 284 git push --force testrepo : &&
2e433b78 285 ! check_push_result testrepo $the_commit heads/master &&
a83619d6
PB
286 git reset --hard $the_commit
287
288'
289
290test_expect_success 'push with matching heads and forced update' '
291
2e433b78 292 mk_test testrepo heads/master &&
a83619d6
PB
293 git push testrepo : &&
294 git commit --amend -massaged &&
295 git push testrepo +: &&
2e433b78 296 ! check_push_result testrepo $the_commit heads/master &&
a83619d6
PB
297 git reset --hard $the_commit
298
299'
300
6125796f
JH
301test_expect_success 'push with no ambiguity (1)' '
302
2e433b78 303 mk_test testrepo heads/master &&
6125796f 304 git push testrepo master:master &&
2e433b78 305 check_push_result testrepo $the_commit heads/master
6125796f
JH
306
307'
308
309test_expect_success 'push with no ambiguity (2)' '
310
2e433b78 311 mk_test testrepo remotes/origin/master &&
ae36bdcf 312 git push testrepo master:origin/master &&
2e433b78 313 check_push_result testrepo $the_commit remotes/origin/master
6125796f
JH
314
315'
316
ae36bdcf
SP
317test_expect_success 'push with colon-less refspec, no ambiguity' '
318
2e433b78 319 mk_test testrepo heads/master heads/t/master &&
ae36bdcf
SP
320 git branch -f t/master master &&
321 git push testrepo master &&
2e433b78
JK
322 check_push_result testrepo $the_commit heads/master &&
323 check_push_result testrepo $the_first_commit heads/t/master
ae36bdcf
SP
324
325'
326
6125796f
JH
327test_expect_success 'push with weak ambiguity (1)' '
328
2e433b78 329 mk_test testrepo heads/master remotes/origin/master &&
6125796f 330 git push testrepo master:master &&
2e433b78
JK
331 check_push_result testrepo $the_commit heads/master &&
332 check_push_result testrepo $the_first_commit remotes/origin/master
6125796f
JH
333
334'
335
336test_expect_success 'push with weak ambiguity (2)' '
337
2e433b78 338 mk_test testrepo heads/master remotes/origin/master remotes/another/master &&
6125796f 339 git push testrepo master:master &&
2e433b78
JK
340 check_push_result testrepo $the_commit heads/master &&
341 check_push_result testrepo $the_first_commit remotes/origin/master remotes/another/master
6125796f
JH
342
343'
344
3ef6a1fe 345test_expect_success 'push with ambiguity' '
6125796f 346
2e433b78 347 mk_test testrepo heads/frotz tags/frotz &&
5bd81c73 348 test_must_fail git push testrepo master:frotz &&
2e433b78 349 check_push_result testrepo $the_first_commit heads/frotz tags/frotz
1ed10b88
JH
350
351'
352
353test_expect_success 'push with colon-less refspec (1)' '
354
2e433b78 355 mk_test testrepo heads/frotz tags/frotz &&
1ed10b88
JH
356 git branch -f frotz master &&
357 git push testrepo frotz &&
2e433b78
JK
358 check_push_result testrepo $the_commit heads/frotz &&
359 check_push_result testrepo $the_first_commit tags/frotz
1ed10b88
JH
360
361'
362
363test_expect_success 'push with colon-less refspec (2)' '
364
2e433b78 365 mk_test testrepo heads/frotz tags/frotz &&
1ed10b88
JH
366 if git show-ref --verify -q refs/heads/frotz
367 then
368 git branch -D frotz
369 fi &&
370 git tag -f frotz &&
dbfeddb1 371 git push -f testrepo frotz &&
2e433b78
JK
372 check_push_result testrepo $the_commit tags/frotz &&
373 check_push_result testrepo $the_first_commit heads/frotz
1ed10b88
JH
374
375'
376
377test_expect_success 'push with colon-less refspec (3)' '
378
2e433b78 379 mk_test testrepo &&
1ed10b88
JH
380 if git show-ref --verify -q refs/tags/frotz
381 then
382 git tag -d frotz
383 fi &&
384 git branch -f frotz master &&
385 git push testrepo frotz &&
2e433b78 386 check_push_result testrepo $the_commit heads/frotz &&
9a3c6f7b 387 test 1 = $( cd testrepo && git show-ref | wc -l )
1ed10b88
JH
388'
389
390test_expect_success 'push with colon-less refspec (4)' '
391
2e433b78 392 mk_test testrepo &&
1ed10b88
JH
393 if git show-ref --verify -q refs/heads/frotz
394 then
395 git branch -D frotz
396 fi &&
397 git tag -f frotz &&
398 git push testrepo frotz &&
2e433b78 399 check_push_result testrepo $the_commit tags/frotz &&
9a3c6f7b 400 test 1 = $( cd testrepo && git show-ref | wc -l )
1ed10b88 401
6125796f
JH
402'
403
7be8b3ba 404test_expect_success 'push head with non-existent, incomplete dest' '
f8aae120 405
2e433b78 406 mk_test testrepo &&
f8aae120 407 git push testrepo master:branch &&
2e433b78 408 check_push_result testrepo $the_commit heads/branch
f8aae120
JK
409
410'
411
7be8b3ba 412test_expect_success 'push tag with non-existent, incomplete dest' '
f8aae120 413
2e433b78 414 mk_test testrepo &&
f8aae120
JK
415 git tag -f v1.0 &&
416 git push testrepo v1.0:tag &&
2e433b78 417 check_push_result testrepo $the_commit tags/tag
f8aae120
JK
418
419'
420
7be8b3ba 421test_expect_success 'push sha1 with non-existent, incomplete dest' '
f8aae120 422
2e433b78 423 mk_test testrepo &&
f8aae120
JK
424 test_must_fail git push testrepo `git rev-parse master`:foo
425
426'
427
7be8b3ba 428test_expect_success 'push ref expression with non-existent, incomplete dest' '
f8aae120 429
2e433b78 430 mk_test testrepo &&
f8aae120
JK
431 test_must_fail git push testrepo master^:branch
432
433'
434
47d996a2
SP
435test_expect_success 'push with HEAD' '
436
2e433b78 437 mk_test testrepo heads/master &&
47d996a2
SP
438 git checkout master &&
439 git push testrepo HEAD &&
2e433b78 440 check_push_result testrepo $the_commit heads/master
47d996a2
SP
441
442'
443
444test_expect_success 'push with HEAD nonexisting at remote' '
445
2e433b78 446 mk_test testrepo heads/master &&
47d996a2
SP
447 git checkout -b local master &&
448 git push testrepo HEAD &&
2e433b78 449 check_push_result testrepo $the_commit heads/local
47d996a2
SP
450'
451
9f0ea7e8
DB
452test_expect_success 'push with +HEAD' '
453
2e433b78 454 mk_test testrepo heads/master &&
9f0ea7e8
DB
455 git checkout master &&
456 git branch -D local &&
457 git checkout -b local &&
458 git push testrepo master local &&
2e433b78
JK
459 check_push_result testrepo $the_commit heads/master &&
460 check_push_result testrepo $the_commit heads/local &&
9f0ea7e8
DB
461
462 # Without force rewinding should fail
463 git reset --hard HEAD^ &&
d492b31c 464 test_must_fail git push testrepo HEAD &&
2e433b78 465 check_push_result testrepo $the_commit heads/local &&
9f0ea7e8
DB
466
467 # With force rewinding should succeed
468 git push testrepo +HEAD &&
2e433b78 469 check_push_result testrepo $the_first_commit heads/local
9f0ea7e8
DB
470
471'
472
7be8b3ba 473test_expect_success 'push HEAD with non-existent, incomplete dest' '
f8aae120 474
2e433b78 475 mk_test testrepo &&
f8aae120
JK
476 git checkout master &&
477 git push testrepo HEAD:branch &&
2e433b78 478 check_push_result testrepo $the_commit heads/branch
f8aae120
JK
479
480'
481
9f0ea7e8
DB
482test_expect_success 'push with config remote.*.push = HEAD' '
483
2e433b78 484 mk_test testrepo heads/local &&
9f0ea7e8
DB
485 git checkout master &&
486 git branch -f local $the_commit &&
487 (
488 cd testrepo &&
489 git checkout local &&
490 git reset --hard $the_first_commit
491 ) &&
3c695523
JN
492 test_config remote.there.url testrepo &&
493 test_config remote.there.push HEAD &&
494 test_config branch.master.remote there &&
9f0ea7e8 495 git push &&
2e433b78
JK
496 check_push_result testrepo $the_commit heads/master &&
497 check_push_result testrepo $the_first_commit heads/local
9f0ea7e8
DB
498'
499
224c2171
RR
500test_expect_success 'push with remote.pushdefault' '
501 mk_test up_repo heads/master &&
502 mk_test down_repo heads/master &&
503 test_config remote.up.url up_repo &&
504 test_config remote.down.url down_repo &&
505 test_config branch.master.remote up &&
506 test_config remote.pushdefault down &&
54a3c673 507 test_config push.default matching &&
224c2171
RR
508 git push &&
509 check_push_result up_repo $the_first_commit heads/master &&
510 check_push_result down_repo $the_commit heads/master
9f0ea7e8
DB
511'
512
e1ca4241
MG
513test_expect_success 'push with config remote.*.pushurl' '
514
2e433b78 515 mk_test testrepo heads/master &&
e1ca4241 516 git checkout master &&
3c695523
JN
517 test_config remote.there.url test2repo &&
518 test_config remote.there.pushurl testrepo &&
0a42ac03 519 git push there : &&
2e433b78 520 check_push_result testrepo $the_commit heads/master
e1ca4241
MG
521'
522
9f765ce6
RR
523test_expect_success 'push with config branch.*.pushremote' '
524 mk_test up_repo heads/master &&
525 mk_test side_repo heads/master &&
526 mk_test down_repo heads/master &&
527 test_config remote.up.url up_repo &&
528 test_config remote.pushdefault side_repo &&
529 test_config remote.down.url down_repo &&
530 test_config branch.master.remote up &&
531 test_config branch.master.pushremote down &&
54a3c673 532 test_config push.default matching &&
9f765ce6
RR
533 git push &&
534 check_push_result up_repo $the_first_commit heads/master &&
535 check_push_result side_repo $the_first_commit heads/master &&
536 check_push_result down_repo $the_commit heads/master
e1ca4241
MG
537'
538
11f2441f
BE
539test_expect_success 'push with dry-run' '
540
2e433b78 541 mk_test testrepo heads/master &&
d4785cd1
JS
542 (
543 cd testrepo &&
544 old_commit=$(git show-ref -s --verify refs/heads/master)
545 ) &&
0a42ac03 546 git push --dry-run testrepo : &&
2e433b78 547 check_push_result testrepo $old_commit heads/master
11f2441f
BE
548'
549
28391a80
JS
550test_expect_success 'push updates local refs' '
551
2e433b78
JK
552 mk_test testrepo heads/master &&
553 mk_child testrepo child &&
d4785cd1
JS
554 (
555 cd child &&
b2dc968e 556 git pull .. master &&
28391a80 557 git push &&
d4785cd1
JS
558 test $(git rev-parse master) = \
559 $(git rev-parse remotes/origin/master)
560 )
28391a80
JS
561
562'
563
16ed2f48
CB
564test_expect_success 'push updates up-to-date local refs' '
565
2e433b78
JK
566 mk_test testrepo heads/master &&
567 mk_child testrepo child1 &&
568 mk_child testrepo child2 &&
b2dc968e 569 (cd child1 && git pull .. master && git push) &&
d4785cd1
JS
570 (
571 cd child2 &&
16ed2f48
CB
572 git pull ../child1 master &&
573 git push &&
d4785cd1
JS
574 test $(git rev-parse master) = \
575 $(git rev-parse remotes/origin/master)
576 )
16ed2f48
CB
577
578'
579
580test_expect_success 'push preserves up-to-date packed refs' '
581
2e433b78
JK
582 mk_test testrepo heads/master &&
583 mk_child testrepo child &&
d4785cd1
JS
584 (
585 cd child &&
16ed2f48 586 git push &&
d4785cd1
JS
587 ! test -f .git/refs/remotes/origin/master
588 )
16ed2f48
CB
589
590'
591
28391a80
JS
592test_expect_success 'push does not update local refs on failure' '
593
2e433b78
JK
594 mk_test testrepo heads/master &&
595 mk_child testrepo child &&
b2dc968e 596 mkdir testrepo/.git/hooks &&
fc012c28 597 echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
b2dc968e 598 chmod +x testrepo/.git/hooks/pre-receive &&
d4785cd1
JS
599 (
600 cd child &&
b2dc968e 601 git pull .. master
d492b31c 602 test_must_fail git push &&
28391a80 603 test $(git rev-parse master) != \
d4785cd1
JS
604 $(git rev-parse remotes/origin/master)
605 )
28391a80
JS
606
607'
608
609test_expect_success 'allow deleting an invalid remote ref' '
610
2e433b78 611 mk_test testrepo heads/master &&
28391a80
JS
612 rm -f testrepo/.git/objects/??/* &&
613 git push testrepo :refs/heads/master &&
d492b31c 614 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
28391a80
JS
615
616'
617
160b81ed 618test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' '
2e433b78 619 mk_test_with_hooks testrepo heads/master heads/next &&
160b81ed
PYH
620 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
621 newmaster=$(git show-ref -s --verify refs/heads/master) &&
622 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
623 newnext=$_z40 &&
624 git push testrepo refs/heads/master:refs/heads/master :refs/heads/next &&
625 (
626 cd testrepo/.git &&
627 cat >pre-receive.expect <<-EOF &&
628 $orgmaster $newmaster refs/heads/master
629 $orgnext $newnext refs/heads/next
630 EOF
631
632 cat >update.expect <<-EOF &&
633 refs/heads/master $orgmaster $newmaster
634 refs/heads/next $orgnext $newnext
635 EOF
636
637 cat >post-receive.expect <<-EOF &&
638 $orgmaster $newmaster refs/heads/master
639 $orgnext $newnext refs/heads/next
640 EOF
641
642 cat >post-update.expect <<-EOF &&
643 refs/heads/master
644 refs/heads/next
645 EOF
646
647 test_cmp pre-receive.expect pre-receive.actual &&
648 test_cmp update.expect update.actual &&
649 test_cmp post-receive.expect post-receive.actual &&
650 test_cmp post-update.expect post-update.actual
651 )
652'
653
654test_expect_success 'deleting dangling ref triggers hooks with correct args' '
2e433b78 655 mk_test_with_hooks testrepo heads/master &&
160b81ed
PYH
656 rm -f testrepo/.git/objects/??/* &&
657 git push testrepo :refs/heads/master &&
658 (
659 cd testrepo/.git &&
660 cat >pre-receive.expect <<-EOF &&
661 $_z40 $_z40 refs/heads/master
662 EOF
663
664 cat >update.expect <<-EOF &&
665 refs/heads/master $_z40 $_z40
666 EOF
667
668 cat >post-receive.expect <<-EOF &&
669 $_z40 $_z40 refs/heads/master
670 EOF
671
672 cat >post-update.expect <<-EOF &&
673 refs/heads/master
674 EOF
675
676 test_cmp pre-receive.expect pre-receive.actual &&
677 test_cmp update.expect update.actual &&
678 test_cmp post-receive.expect post-receive.actual &&
679 test_cmp post-update.expect post-update.actual
680 )
681'
682
683test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
2e433b78 684 mk_test_with_hooks testrepo heads/master &&
160b81ed
PYH
685 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
686 newmaster=$(git show-ref -s --verify refs/heads/master) &&
687 git push testrepo master :refs/heads/nonexistent &&
688 (
689 cd testrepo/.git &&
690 cat >pre-receive.expect <<-EOF &&
691 $orgmaster $newmaster refs/heads/master
692 $_z40 $_z40 refs/heads/nonexistent
693 EOF
694
695 cat >update.expect <<-EOF &&
696 refs/heads/master $orgmaster $newmaster
697 refs/heads/nonexistent $_z40 $_z40
698 EOF
699
700 cat >post-receive.expect <<-EOF &&
701 $orgmaster $newmaster refs/heads/master
702 EOF
703
704 cat >post-update.expect <<-EOF &&
705 refs/heads/master
706 EOF
707
708 test_cmp pre-receive.expect pre-receive.actual &&
709 test_cmp update.expect update.actual &&
710 test_cmp post-receive.expect post-receive.actual &&
711 test_cmp post-update.expect post-update.actual
712 )
713'
714
715test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
2e433b78 716 mk_test_with_hooks testrepo heads/master &&
160b81ed
PYH
717 git push testrepo :refs/heads/nonexistent &&
718 (
719 cd testrepo/.git &&
720 cat >pre-receive.expect <<-EOF &&
721 $_z40 $_z40 refs/heads/nonexistent
722 EOF
723
724 cat >update.expect <<-EOF &&
725 refs/heads/nonexistent $_z40 $_z40
726 EOF
727
728 test_cmp pre-receive.expect pre-receive.actual &&
729 test_cmp update.expect update.actual &&
730 test_path_is_missing post-receive.actual &&
731 test_path_is_missing post-update.actual
732 )
733'
734
735test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
2e433b78 736 mk_test_with_hooks testrepo heads/master heads/next heads/pu &&
160b81ed
PYH
737 orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
738 newmaster=$(git show-ref -s --verify refs/heads/master) &&
739 orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
740 newnext=$_z40 &&
741 orgpu=$(cd testrepo && git show-ref -s --verify refs/heads/pu) &&
742 newpu=$(git show-ref -s --verify refs/heads/master) &&
743 git push testrepo refs/heads/master:refs/heads/master \
744 refs/heads/master:refs/heads/pu :refs/heads/next \
745 :refs/heads/nonexistent &&
746 (
747 cd testrepo/.git &&
748 cat >pre-receive.expect <<-EOF &&
749 $orgmaster $newmaster refs/heads/master
750 $orgnext $newnext refs/heads/next
751 $orgpu $newpu refs/heads/pu
752 $_z40 $_z40 refs/heads/nonexistent
753 EOF
754
755 cat >update.expect <<-EOF &&
756 refs/heads/master $orgmaster $newmaster
757 refs/heads/next $orgnext $newnext
758 refs/heads/pu $orgpu $newpu
759 refs/heads/nonexistent $_z40 $_z40
760 EOF
761
762 cat >post-receive.expect <<-EOF &&
763 $orgmaster $newmaster refs/heads/master
764 $orgnext $newnext refs/heads/next
765 $orgpu $newpu refs/heads/pu
766 EOF
767
768 cat >post-update.expect <<-EOF &&
769 refs/heads/master
770 refs/heads/next
771 refs/heads/pu
772 EOF
773
774 test_cmp pre-receive.expect pre-receive.actual &&
775 test_cmp update.expect update.actual &&
776 test_cmp post-receive.expect post-receive.actual &&
777 test_cmp post-update.expect post-update.actual
778 )
779'
780
f517f1f2 781test_expect_success 'allow deleting a ref using --delete' '
2e433b78 782 mk_test testrepo heads/master &&
f517f1f2
JK
783 (cd testrepo && git config receive.denyDeleteCurrent warn) &&
784 git push testrepo --delete master &&
785 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
786'
787
788test_expect_success 'allow deleting a tag using --delete' '
2e433b78 789 mk_test testrepo heads/master &&
f517f1f2
JK
790 git tag -a -m dummy_message deltag heads/master &&
791 git push testrepo --tags &&
792 (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
793 git push testrepo --delete tag deltag &&
794 (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag)
795'
796
797test_expect_success 'push --delete without args aborts' '
2e433b78 798 mk_test testrepo heads/master &&
f517f1f2
JK
799 test_must_fail git push testrepo --delete
800'
801
802test_expect_success 'push --delete refuses src:dest refspecs' '
2e433b78 803 mk_test testrepo heads/master &&
f517f1f2
JK
804 test_must_fail git push testrepo --delete master:foo
805'
806
986e8239 807test_expect_success 'warn on push to HEAD of non-bare repository' '
2e433b78 808 mk_test testrepo heads/master &&
d4785cd1
JS
809 (
810 cd testrepo &&
986e8239 811 git checkout master &&
d4785cd1
JS
812 git config receive.denyCurrentBranch warn
813 ) &&
986e8239 814 git push testrepo master 2>stderr &&
3d95d92b 815 grep "warning: updating the current branch" stderr
986e8239
JK
816'
817
818test_expect_success 'deny push to HEAD of non-bare repository' '
2e433b78 819 mk_test testrepo heads/master &&
d4785cd1
JS
820 (
821 cd testrepo &&
986e8239 822 git checkout master &&
d4785cd1
JS
823 git config receive.denyCurrentBranch true
824 ) &&
986e8239
JK
825 test_must_fail git push testrepo master
826'
827
828test_expect_success 'allow push to HEAD of bare repository (bare)' '
2e433b78 829 mk_test testrepo heads/master &&
d4785cd1
JS
830 (
831 cd testrepo &&
986e8239
JK
832 git checkout master &&
833 git config receive.denyCurrentBranch true &&
d4785cd1
JS
834 git config core.bare true
835 ) &&
986e8239 836 git push testrepo master 2>stderr &&
3d95d92b 837 ! grep "warning: updating the current branch" stderr
986e8239
JK
838'
839
840test_expect_success 'allow push to HEAD of non-bare repository (config)' '
2e433b78 841 mk_test testrepo heads/master &&
d4785cd1
JS
842 (
843 cd testrepo &&
986e8239
JK
844 git checkout master &&
845 git config receive.denyCurrentBranch false
846 ) &&
847 git push testrepo master 2>stderr &&
3d95d92b 848 ! grep "warning: updating the current branch" stderr
986e8239
JK
849'
850
18afe101 851test_expect_success 'fetch with branches' '
2e433b78 852 mk_empty testrepo &&
18afe101
MK
853 git branch second $the_first_commit &&
854 git checkout second &&
855 echo ".." > testrepo/.git/branches/branch1 &&
d4785cd1
JS
856 (
857 cd testrepo &&
18afe101 858 git fetch branch1 &&
848575d8
JN
859 echo "$the_commit commit refs/heads/branch1" >expect &&
860 git for-each-ref refs/heads >actual &&
861 test_cmp expect actual
18afe101
MK
862 ) &&
863 git checkout master
864'
865
866test_expect_success 'fetch with branches containing #' '
2e433b78 867 mk_empty testrepo &&
18afe101 868 echo "..#second" > testrepo/.git/branches/branch2 &&
d4785cd1
JS
869 (
870 cd testrepo &&
18afe101 871 git fetch branch2 &&
848575d8
JN
872 echo "$the_first_commit commit refs/heads/branch2" >expect &&
873 git for-each-ref refs/heads >actual &&
874 test_cmp expect actual
18afe101
MK
875 ) &&
876 git checkout master
877'
878
879test_expect_success 'push with branches' '
2e433b78 880 mk_empty testrepo &&
18afe101
MK
881 git checkout second &&
882 echo "testrepo" > .git/branches/branch1 &&
883 git push branch1 &&
d4785cd1
JS
884 (
885 cd testrepo &&
848575d8
JN
886 echo "$the_first_commit commit refs/heads/master" >expect &&
887 git for-each-ref refs/heads >actual &&
888 test_cmp expect actual
18afe101
MK
889 )
890'
891
892test_expect_success 'push with branches containing #' '
2e433b78 893 mk_empty testrepo &&
18afe101
MK
894 echo "testrepo#branch3" > .git/branches/branch2 &&
895 git push branch2 &&
d4785cd1
JS
896 (
897 cd testrepo &&
848575d8
JN
898 echo "$the_first_commit commit refs/heads/branch3" >expect &&
899 git for-each-ref refs/heads >actual &&
900 test_cmp expect actual
18afe101
MK
901 ) &&
902 git checkout master
903'
904
da3efdb1 905test_expect_success 'push into aliased refs (consistent)' '
2e433b78
JK
906 mk_test testrepo heads/master &&
907 mk_child testrepo child1 &&
908 mk_child testrepo child2 &&
da3efdb1
JS
909 (
910 cd child1 &&
911 git branch foo &&
912 git symbolic-ref refs/heads/bar refs/heads/foo
913 git config receive.denyCurrentBranch false
914 ) &&
915 (
916 cd child2 &&
917 >path2 &&
918 git add path2 &&
919 test_tick &&
920 git commit -a -m child2 &&
921 git branch foo &&
922 git branch bar &&
923 git push ../child1 foo bar
924 )
925'
926
927test_expect_success 'push into aliased refs (inconsistent)' '
2e433b78
JK
928 mk_test testrepo heads/master &&
929 mk_child testrepo child1 &&
930 mk_child testrepo child2 &&
da3efdb1
JS
931 (
932 cd child1 &&
933 git branch foo &&
934 git symbolic-ref refs/heads/bar refs/heads/foo
935 git config receive.denyCurrentBranch false
936 ) &&
937 (
938 cd child2 &&
939 >path2 &&
940 git add path2 &&
941 test_tick &&
942 git commit -a -m child2 &&
943 git branch foo &&
944 >path3 &&
945 git add path3 &&
946 test_tick &&
947 git commit -a -m child2 &&
948 git branch bar &&
949 test_must_fail git push ../child1 foo bar 2>stderr &&
950 grep "refusing inconsistent update" stderr
951 )
952'
953
dbfeddb1 954test_expect_success 'push requires --force to update lightweight tag' '
2e433b78
JK
955 mk_test testrepo heads/master &&
956 mk_child testrepo child1 &&
957 mk_child testrepo child2 &&
dbfeddb1
CR
958 (
959 cd child1 &&
960 git tag Tag &&
961 git push ../child2 Tag &&
962 git push ../child2 Tag &&
963 >file1 &&
964 git add file1 &&
965 git commit -m "file1" &&
966 git tag -f Tag &&
967 test_must_fail git push ../child2 Tag &&
968 git push --force ../child2 Tag &&
969 git tag -f Tag &&
970 test_must_fail git push ../child2 Tag HEAD~ &&
971 git push --force ../child2 Tag
972 )
973'
974
fbe4f447 975test_expect_success 'push --porcelain' '
2e433b78 976 mk_empty testrepo &&
fbe4f447
LA
977 echo >.git/foo "To testrepo" &&
978 echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" &&
979 echo >>.git/foo "Done" &&
980 git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master &&
981 (
982 cd testrepo &&
848575d8
JN
983 echo "$the_commit commit refs/remotes/origin/master" >expect &&
984 git for-each-ref refs/remotes/origin >actual &&
985 test_cmp expect actual
fbe4f447 986 ) &&
c296134d 987 test_cmp .git/foo .git/bar
fbe4f447
LA
988'
989
990test_expect_success 'push --porcelain bad url' '
2e433b78 991 mk_empty testrepo &&
fbe4f447
LA
992 test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
993 test_must_fail grep -q Done .git/bar
994'
995
996test_expect_success 'push --porcelain rejected' '
2e433b78 997 mk_empty testrepo &&
fbe4f447
LA
998 git push testrepo refs/heads/master:refs/remotes/origin/master &&
999 (cd testrepo &&
1000 git reset --hard origin/master^
1001 git config receive.denyCurrentBranch true) &&
1002
1003 echo >.git/foo "To testrepo" &&
1004 echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" &&
1005
1006 test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master &&
c296134d 1007 test_cmp .git/foo .git/bar
fbe4f447
LA
1008'
1009
1010test_expect_success 'push --porcelain --dry-run rejected' '
2e433b78 1011 mk_empty testrepo &&
fbe4f447
LA
1012 git push testrepo refs/heads/master:refs/remotes/origin/master &&
1013 (cd testrepo &&
1014 git reset --hard origin/master
1015 git config receive.denyCurrentBranch true) &&
1016
1017 echo >.git/foo "To testrepo" &&
1018 echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" &&
1019 echo >>.git/foo "Done" &&
1020
1021 test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master &&
c296134d 1022 test_cmp .git/foo .git/bar
fbe4f447
LA
1023'
1024
6ddba5e2 1025test_expect_success 'push --prune' '
2e433b78 1026 mk_test testrepo heads/master heads/second heads/foo heads/bar &&
0a42ac03 1027 git push --prune testrepo : &&
2e433b78
JK
1028 check_push_result testrepo $the_commit heads/master &&
1029 check_push_result testrepo $the_first_commit heads/second &&
1030 ! check_push_result testrepo $the_first_commit heads/foo heads/bar
6ddba5e2
FC
1031'
1032
1033test_expect_success 'push --prune refspec' '
2e433b78 1034 mk_test testrepo tmp/master tmp/second tmp/foo tmp/bar &&
6ddba5e2 1035 git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
2e433b78
JK
1036 check_push_result testrepo $the_commit tmp/master &&
1037 check_push_result testrepo $the_first_commit tmp/second &&
1038 ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
6ddba5e2
FC
1039'
1040
daebaa78
JH
1041for configsection in transfer receive
1042do
1043 test_expect_success "push to update a ref hidden by $configsection.hiderefs" '
2e433b78 1044 mk_test testrepo heads/master hidden/one hidden/two hidden/three &&
daebaa78
JH
1045 (
1046 cd testrepo &&
1047 git config $configsection.hiderefs refs/hidden
1048 ) &&
1049
1050 # push to unhidden ref succeeds normally
1051 git push testrepo master:refs/heads/master &&
2e433b78 1052 check_push_result testrepo $the_commit heads/master &&
daebaa78
JH
1053
1054 # push to update a hidden ref should fail
1055 test_must_fail git push testrepo master:refs/hidden/one &&
2e433b78 1056 check_push_result testrepo $the_first_commit hidden/one &&
daebaa78
JH
1057
1058 # push to delete a hidden ref should fail
1059 test_must_fail git push testrepo :refs/hidden/two &&
2e433b78 1060 check_push_result testrepo $the_first_commit hidden/two &&
daebaa78
JH
1061
1062 # idempotent push to update a hidden ref should fail
1063 test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
2e433b78 1064 check_push_result testrepo $the_first_commit hidden/three
daebaa78
JH
1065 '
1066done
1067
6e7b66ee 1068test_expect_success 'fetch exact SHA1' '
2e433b78 1069 mk_test testrepo heads/master hidden/one &&
6e7b66ee
JH
1070 git push testrepo master:refs/hidden/one &&
1071 (
1072 cd testrepo &&
1073 git config transfer.hiderefs refs/hidden
1074 ) &&
2e433b78 1075 check_push_result testrepo $the_commit hidden/one &&
6e7b66ee 1076
2e433b78 1077 mk_child testrepo child &&
6e7b66ee
JH
1078 (
1079 cd child &&
1080
1081 # make sure $the_commit does not exist here
1082 git repack -a -d &&
1083 git prune &&
1084 test_must_fail git cat-file -t $the_commit &&
1085
1086 # fetching the hidden object should fail by default
1087 test_must_fail git fetch -v ../testrepo $the_commit:refs/heads/copy &&
1088 test_must_fail git rev-parse --verify refs/heads/copy &&
1089
1090 # the server side can allow it to succeed
1091 (
1092 cd ../testrepo &&
1093 git config uploadpack.allowtipsha1inwant true
1094 ) &&
1095
1096 git fetch -v ../testrepo $the_commit:refs/heads/copy &&
1097 result=$(git rev-parse --verify refs/heads/copy) &&
1098 test "$the_commit" = "$result"
1099 )
1100'
1101
c2aba155 1102test_expect_success 'fetch follows tags by default' '
2e433b78 1103 mk_test testrepo heads/master &&
c2aba155
JH
1104 rm -fr src dst &&
1105 git init src &&
1106 (
1107 cd src &&
1108 git pull ../testrepo master &&
1109 git tag -m "annotated" tag &&
1110 git for-each-ref >tmp1 &&
1111 (
1112 cat tmp1
1113 sed -n "s|refs/heads/master$|refs/remotes/origin/master|p" tmp1
1114 ) |
1115 sort -k 3 >../expect
1116 ) &&
1117 git init dst &&
1118 (
1119 cd dst &&
1120 git remote add origin ../src &&
1121 git config branch.master.remote origin &&
1122 git config branch.master.merge refs/heads/master &&
1123 git pull &&
1124 git for-each-ref >../actual
1125 ) &&
1126 test_cmp expect actual
1127'
1128
ca02465b
JH
1129test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' '
1130 mk_test testrepo heads/master &&
1131 rm -fr src dst &&
1132 git init src &&
1133 git init --bare dst &&
1134 (
1135 cd src &&
1136 git pull ../testrepo master &&
1137 git branch next &&
1138 git config remote.dst.url ../dst &&
1139 git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" &&
1140 git push dst master &&
1141 git show-ref refs/heads/master |
1142 sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect
1143 ) &&
1144 (
1145 cd dst &&
1146 test_must_fail git show-ref refs/heads/next &&
1147 test_must_fail git show-ref refs/heads/master &&
1148 git show-ref refs/remotes/src/master >actual
1149 ) &&
1150 test_cmp dst/expect dst/actual
1151'
1152
1153test_expect_success 'with no remote.$name.push, it is not used as refmap' '
1154 mk_test testrepo heads/master &&
1155 rm -fr src dst &&
1156 git init src &&
1157 git init --bare dst &&
1158 (
1159 cd src &&
1160 git pull ../testrepo master &&
1161 git branch next &&
1162 git config remote.dst.url ../dst &&
1163 git push dst master &&
1164 git show-ref refs/heads/master >../dst/expect
1165 ) &&
1166 (
1167 cd dst &&
1168 test_must_fail git show-ref refs/heads/next &&
1169 git show-ref refs/heads/master >actual
1170 ) &&
1171 test_cmp dst/expect dst/actual
1172'
1173
c2aba155 1174test_expect_success 'push does not follow tags by default' '
2e433b78 1175 mk_test testrepo heads/master &&
c2aba155
JH
1176 rm -fr src dst &&
1177 git init src &&
1178 git init --bare dst &&
1179 (
1180 cd src &&
1181 git pull ../testrepo master &&
1182 git tag -m "annotated" tag &&
1183 git checkout -b another &&
1184 git commit --allow-empty -m "future commit" &&
1185 git tag -m "future" future &&
1186 git checkout master &&
1187 git for-each-ref refs/heads/master >../expect &&
1188 git push ../dst master
1189 ) &&
1190 (
1191 cd dst &&
1192 git for-each-ref >../actual
1193 ) &&
1194 test_cmp expect actual
1195'
1196
1197test_expect_success 'push --follow-tag only pushes relevant tags' '
2e433b78 1198 mk_test testrepo heads/master &&
c2aba155
JH
1199 rm -fr src dst &&
1200 git init src &&
1201 git init --bare dst &&
1202 (
1203 cd src &&
1204 git pull ../testrepo master &&
1205 git tag -m "annotated" tag &&
1206 git checkout -b another &&
1207 git commit --allow-empty -m "future commit" &&
1208 git tag -m "future" future &&
1209 git checkout master &&
1210 git for-each-ref refs/heads/master refs/tags/tag >../expect
1211 git push --follow-tag ../dst master
1212 ) &&
1213 (
1214 cd dst &&
1215 git for-each-ref >../actual
1216 ) &&
1217 test_cmp expect actual
1218'
1219
f7c815c3
NTND
1220test_expect_success 'push --no-thin must produce non-thin pack' '
1221 cat >>path1 <<\EOF &&
1222keep base version of path1 big enough, compared to the new changes
1223later, in order to pass size heuristics in
1224builtin/pack-objects.c:try_delta()
1225EOF
1226 git commit -am initial &&
1227 git init no-thin &&
1228 git --git-dir=no-thin/.git config receive.unpacklimit 0 &&
1229 git push no-thin/.git refs/heads/master:refs/heads/foo &&
1230 echo modified >> path1 &&
1231 git commit -am modified &&
1232 git repack -adf &&
1233 rcvpck="git receive-pack --reject-thin-pack-for-testing" &&
1234 git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/master:refs/heads/foo
1235'
1236
bcdb34f7 1237test_done