3 test_description='fetching and pushing, with or without wildcard'
15 mv .git/hooks .git/hooks-disabled
24 git push testrepo $the_first_commit:refs/$ref || {
25 echo "Oops, push refs/$ref failure"
32 r=$(git show-ref -s --verify refs/$ref) &&
33 test "z$r" = "z$the_first_commit" || {
34 echo "Oops, refs/$ref is wrong"
44 git clone testrepo "$1"
47 check_push_result () {
54 r=$(git show-ref -s --verify refs/$ref) &&
55 test "z$r" = "z$it" || {
56 echo "Oops, refs/$ref is wrong"
64 test_expect_success setup '
69 git commit -a -m repo &&
70 the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
75 git commit -a -m second &&
76 the_commit=$(git show-ref -s --verify refs/heads/master)
80 test_expect_success 'fetch without wildcard' '
84 git fetch .. refs/heads/master:refs/remotes/origin/master &&
86 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
87 test "z$r" = "z$the_commit" &&
89 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
93 test_expect_success 'fetch with wildcard' '
97 git config remote.up.url .. &&
98 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
101 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
102 test "z$r" = "z$the_commit" &&
104 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
108 test_expect_success 'fetch with insteadOf' '
113 git config "url.$TRASH.insteadOf" trash/ &&
114 git config remote.up.url trash/. &&
115 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
118 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
119 test "z$r" = "z$the_commit" &&
121 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
125 test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
130 git config "url.trash/.pushInsteadOf" "$TRASH" &&
131 git config remote.up.url "$TRASH." &&
132 git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
135 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
136 test "z$r" = "z$the_commit" &&
138 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
142 test_expect_success 'push without wildcard' '
145 git push testrepo refs/heads/master:refs/remotes/origin/master &&
148 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
149 test "z$r" = "z$the_commit" &&
151 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
155 test_expect_success 'push with wildcard' '
158 git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
161 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
162 test "z$r" = "z$the_commit" &&
164 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
168 test_expect_success 'push with insteadOf' '
171 git config "url.$TRASH.insteadOf" trash/ &&
172 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
175 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
176 test "z$r" = "z$the_commit" &&
178 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
182 test_expect_success 'push with pushInsteadOf' '
185 git config "url.$TRASH.pushInsteadOf" trash/ &&
186 git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
189 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
190 test "z$r" = "z$the_commit" &&
192 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
196 test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
199 git config "url.trash2/.pushInsteadOf" trash/ &&
200 git config remote.r.url trash/wrong &&
201 git config remote.r.pushurl "$TRASH/testrepo" &&
202 git push r refs/heads/master:refs/remotes/origin/master &&
205 r=$(git show-ref -s --verify refs/remotes/origin/master) &&
206 test "z$r" = "z$the_commit" &&
208 test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
212 test_expect_success 'push with matching heads' '
214 mk_test heads/master &&
216 check_push_result $the_commit heads/master
220 test_expect_success 'push with matching heads on the command line' '
222 mk_test heads/master &&
223 git push testrepo : &&
224 check_push_result $the_commit heads/master
228 test_expect_success 'failed (non-fast-forward) push with matching heads' '
230 mk_test heads/master &&
231 git push testrepo : &&
232 git commit --amend -massaged &&
233 test_must_fail git push testrepo &&
234 check_push_result $the_commit heads/master &&
235 git reset --hard $the_commit
239 test_expect_success 'push --force with matching heads' '
241 mk_test heads/master &&
242 git push testrepo : &&
243 git commit --amend -massaged &&
244 git push --force testrepo &&
245 ! check_push_result $the_commit heads/master &&
246 git reset --hard $the_commit
250 test_expect_success 'push with matching heads and forced update' '
252 mk_test heads/master &&
253 git push testrepo : &&
254 git commit --amend -massaged &&
255 git push testrepo +: &&
256 ! check_push_result $the_commit heads/master &&
257 git reset --hard $the_commit
261 test_expect_success 'push with no ambiguity (1)' '
263 mk_test heads/master &&
264 git push testrepo master:master &&
265 check_push_result $the_commit heads/master
269 test_expect_success 'push with no ambiguity (2)' '
271 mk_test remotes/origin/master &&
272 git push testrepo master:origin/master &&
273 check_push_result $the_commit remotes/origin/master
277 test_expect_success 'push with colon-less refspec, no ambiguity' '
279 mk_test heads/master heads/t/master &&
280 git branch -f t/master master &&
281 git push testrepo master &&
282 check_push_result $the_commit heads/master &&
283 check_push_result $the_first_commit heads/t/master
287 test_expect_success 'push with weak ambiguity (1)' '
289 mk_test heads/master remotes/origin/master &&
290 git push testrepo master:master &&
291 check_push_result $the_commit heads/master &&
292 check_push_result $the_first_commit remotes/origin/master
296 test_expect_success 'push with weak ambiguity (2)' '
298 mk_test heads/master remotes/origin/master remotes/another/master &&
299 git push testrepo master:master &&
300 check_push_result $the_commit heads/master &&
301 check_push_result $the_first_commit remotes/origin/master remotes/another/master
305 test_expect_success 'push with ambiguity' '
307 mk_test heads/frotz tags/frotz &&
308 if git push testrepo master:frotz
310 echo "Oops, should have failed"
313 check_push_result $the_first_commit heads/frotz tags/frotz
318 test_expect_success 'push with colon-less refspec (1)' '
320 mk_test heads/frotz tags/frotz &&
321 git branch -f frotz master &&
322 git push testrepo frotz &&
323 check_push_result $the_commit heads/frotz &&
324 check_push_result $the_first_commit tags/frotz
328 test_expect_success 'push with colon-less refspec (2)' '
330 mk_test heads/frotz tags/frotz &&
331 if git show-ref --verify -q refs/heads/frotz
336 git push testrepo frotz &&
337 check_push_result $the_commit tags/frotz &&
338 check_push_result $the_first_commit heads/frotz
342 test_expect_success 'push with colon-less refspec (3)' '
345 if git show-ref --verify -q refs/tags/frotz
349 git branch -f frotz master &&
350 git push testrepo frotz &&
351 check_push_result $the_commit heads/frotz &&
352 test 1 = $( cd testrepo && git show-ref | wc -l )
355 test_expect_success 'push with colon-less refspec (4)' '
358 if git show-ref --verify -q refs/heads/frotz
363 git push testrepo frotz &&
364 check_push_result $the_commit tags/frotz &&
365 test 1 = $( cd testrepo && git show-ref | wc -l )
369 test_expect_success 'push head with non-existant, incomplete dest' '
372 git push testrepo master:branch &&
373 check_push_result $the_commit heads/branch
377 test_expect_success 'push tag with non-existant, incomplete dest' '
381 git push testrepo v1.0:tag &&
382 check_push_result $the_commit tags/tag
386 test_expect_success 'push sha1 with non-existant, incomplete dest' '
389 test_must_fail git push testrepo `git rev-parse master`:foo
393 test_expect_success 'push ref expression with non-existant, incomplete dest' '
396 test_must_fail git push testrepo master^:branch
400 test_expect_success 'push with HEAD' '
402 mk_test heads/master &&
403 git checkout master &&
404 git push testrepo HEAD &&
405 check_push_result $the_commit heads/master
409 test_expect_success 'push with HEAD nonexisting at remote' '
411 mk_test heads/master &&
412 git checkout -b local master &&
413 git push testrepo HEAD &&
414 check_push_result $the_commit heads/local
417 test_expect_success 'push with +HEAD' '
419 mk_test heads/master &&
420 git checkout master &&
421 git branch -D local &&
422 git checkout -b local &&
423 git push testrepo master local &&
424 check_push_result $the_commit heads/master &&
425 check_push_result $the_commit heads/local &&
427 # Without force rewinding should fail
428 git reset --hard HEAD^ &&
429 test_must_fail git push testrepo HEAD &&
430 check_push_result $the_commit heads/local &&
432 # With force rewinding should succeed
433 git push testrepo +HEAD &&
434 check_push_result $the_first_commit heads/local
438 test_expect_success 'push HEAD with non-existant, incomplete dest' '
441 git checkout master &&
442 git push testrepo HEAD:branch &&
443 check_push_result $the_commit heads/branch
447 test_expect_success 'push with config remote.*.push = HEAD' '
449 mk_test heads/local &&
450 git checkout master &&
451 git branch -f local $the_commit &&
454 git checkout local &&
455 git reset --hard $the_first_commit
457 git config remote.there.url testrepo &&
458 git config remote.there.push HEAD &&
459 git config branch.master.remote there &&
461 check_push_result $the_commit heads/master &&
462 check_push_result $the_first_commit heads/local
465 # clean up the cruft left with the previous one
466 git config --remove-section remote.there
467 git config --remove-section branch.master
469 test_expect_success 'push with config remote.*.pushurl' '
471 mk_test heads/master &&
472 git checkout master &&
473 git config remote.there.url test2repo &&
474 git config remote.there.pushurl testrepo &&
476 check_push_result $the_commit heads/master
479 # clean up the cruft left with the previous one
480 git config --remove-section remote.there
482 test_expect_success 'push with dry-run' '
484 mk_test heads/master &&
486 old_commit=$(git show-ref -s --verify refs/heads/master)) &&
487 git push --dry-run testrepo &&
488 check_push_result $old_commit heads/master
491 test_expect_success 'push updates local refs' '
493 mk_test heads/master &&
496 git pull .. master &&
498 test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
502 test_expect_success 'push updates up-to-date local refs' '
504 mk_test heads/master &&
507 (cd child1 && git pull .. master && git push) &&
509 git pull ../child1 master &&
511 test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
515 test_expect_success 'push preserves up-to-date packed refs' '
517 mk_test heads/master &&
521 ! test -f .git/refs/remotes/origin/master)
525 test_expect_success 'push does not update local refs on failure' '
527 mk_test heads/master &&
529 mkdir testrepo/.git/hooks &&
530 echo exit 1 >testrepo/.git/hooks/pre-receive &&
531 chmod +x testrepo/.git/hooks/pre-receive &&
534 test_must_fail git push &&
535 test $(git rev-parse master) != \
536 $(git rev-parse remotes/origin/master))
540 test_expect_success 'allow deleting an invalid remote ref' '
542 mk_test heads/master &&
543 rm -f testrepo/.git/objects/??/* &&
544 git push testrepo :refs/heads/master &&
545 (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
549 test_expect_success 'warn on push to HEAD of non-bare repository' '
552 git checkout master &&
553 git config receive.denyCurrentBranch warn) &&
554 git push testrepo master 2>stderr &&
555 grep "warning: updating the current branch" stderr
558 test_expect_success 'deny push to HEAD of non-bare repository' '
561 git checkout master &&
562 git config receive.denyCurrentBranch true) &&
563 test_must_fail git push testrepo master
566 test_expect_success 'allow push to HEAD of bare repository (bare)' '
569 git checkout master &&
570 git config receive.denyCurrentBranch true &&
571 git config core.bare true) &&
572 git push testrepo master 2>stderr &&
573 ! grep "warning: updating the current branch" stderr
576 test_expect_success 'allow push to HEAD of non-bare repository (config)' '
579 git checkout master &&
580 git config receive.denyCurrentBranch false
582 git push testrepo master 2>stderr &&
583 ! grep "warning: updating the current branch" stderr
586 test_expect_success 'fetch with branches' '
588 git branch second $the_first_commit &&
589 git checkout second &&
590 echo ".." > testrepo/.git/branches/branch1 &&
593 r=$(git show-ref -s --verify refs/heads/branch1) &&
594 test "z$r" = "z$the_commit" &&
595 test 1 = $(git for-each-ref refs/heads | wc -l)
600 test_expect_success 'fetch with branches containing #' '
602 echo "..#second" > testrepo/.git/branches/branch2 &&
605 r=$(git show-ref -s --verify refs/heads/branch2) &&
606 test "z$r" = "z$the_first_commit" &&
607 test 1 = $(git for-each-ref refs/heads | wc -l)
612 test_expect_success 'push with branches' '
614 git checkout second &&
615 echo "testrepo" > .git/branches/branch1 &&
618 r=$(git show-ref -s --verify refs/heads/master) &&
619 test "z$r" = "z$the_first_commit" &&
620 test 1 = $(git for-each-ref refs/heads | wc -l)
624 test_expect_success 'push with branches containing #' '
626 echo "testrepo#branch3" > .git/branches/branch2 &&
629 r=$(git show-ref -s --verify refs/heads/branch3) &&
630 test "z$r" = "z$the_first_commit" &&
631 test 1 = $(git for-each-ref refs/heads | wc -l)