3 test_description
='git remote porcelain-ish'
14 git commit
-m "Initial" &&
15 git checkout
-b side
&&
19 git commit
-m "Second" &&
25 echo "$1" |
tr ' ' '\012' |
sort |
sed -e '/^$/d' >expect
&&
26 echo "$2" |
tr ' ' '\012' |
sort |
sed -e '/^$/d' >actual
&&
27 test_cmp expect actual
30 check_remote_track
() {
31 actual
=$
(git remote show
"$1" |
sed -ne 's|^ \(.*\) tracked$|\1|p')
33 tokens_match
"$*" "$actual"
36 check_tracking_branch
() {
38 r
=$
(git for-each-ref
"--format=%(refname)" |
39 sed -ne "s|^refs/remotes/$1/||p") &&
41 tokens_match
"$*" "$r"
44 test_expect_success setup
'
46 setup_repository one &&
47 setup_repository two &&
49 cd two && git branch another
55 test_expect_success
'remote information for the origin' '
58 tokens_match origin "$(git remote)" &&
59 check_remote_track origin master side &&
60 check_tracking_branch origin HEAD master side
64 test_expect_success
'add another remote' '
67 git remote add -f second ../two &&
68 tokens_match "origin second" "$(git remote)" &&
69 check_remote_track origin master side &&
70 check_remote_track second master side another &&
71 check_tracking_branch second master side another &&
72 git for-each-ref "--format=%(refname)" refs/remotes |
73 sed -e "/^refs\/remotes\/origin\//d" \
74 -e "/^refs\/remotes\/second\//d" >actual &&
76 test_cmp expect actual
80 test_expect_success
'remote forces tracking branches' '
83 case `git config remote.second.fetch` in
90 test_expect_success
'remove remote' '
93 git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master &&
98 test_expect_success
'remove remote' '
101 tokens_match origin "$(git remote)" &&
102 check_remote_track origin master side &&
103 git for-each-ref "--format=%(refname)" refs/remotes |
104 sed -e "/^refs\/remotes\/origin\//d" >actual &&
106 test_cmp expect actual
110 test_expect_success
'remove remote protects local branches' '
114 Note: A branch outside the refs/remotes/ hierarchy was not removed;
120 Note: Some branches outside the refs/remotes/ hierarchy were not removed;
122 git branch -d foobranch
127 git config --add remote.oops.fetch "+refs/*:refs/*" &&
128 git remote rm oops 2>actual1 &&
129 git branch foobranch &&
130 git config --add remote.oops.fetch "+refs/*:refs/*" &&
131 git remote rm oops 2>actual2 &&
132 git branch -d foobranch &&
134 test_cmp expect1 actual1 &&
135 test_cmp expect2 actual2
139 cat > test
/expect
<< EOF
141 Fetch URL: $(pwd)/one
145 master new (next fetch will store in remotes/origin)
147 Local branches configured for 'git pull':
148 ahead merges with remote master
149 master merges with remote master
150 octopus merges with remote topic-a
151 and with remote topic-b
152 and with remote topic-c
153 rebase rebases onto remote master
154 Local refs configured for 'git push':
155 master pushes to master (local out of date)
156 master pushes to upstream (create)
160 HEAD branch (remote HEAD is ambiguous, may be one of the following):
163 Local refs configured for 'git push':
164 ahead forces to master (fast-forwardable)
165 master pushes to another (up to date)
168 test_expect_success
'show' '
170 git config --add remote.origin.fetch refs/heads/master:refs/heads/upstream &&
172 git checkout -b ahead origin/master &&
175 git commit -m update file &&
176 git checkout master &&
177 git branch --track octopus origin/master &&
178 git branch --track rebase origin/master &&
179 git branch -d -r origin/master &&
180 git config --add remote.two.url ../two &&
181 git config --add remote.two.pushurl ../three &&
182 git config branch.rebase.rebase true &&
183 git config branch.octopus.merge "topic-a topic-b topic-c" &&
187 git commit -m update file) &&
188 git config --add remote.origin.push : &&
189 git config --add remote.origin.push refs/heads/master:refs/heads/upstream &&
190 git config --add remote.origin.push +refs/tags/lastbackup &&
191 git config --add remote.two.push +refs/heads/ahead:refs/heads/master &&
192 git config --add remote.two.push refs/heads/master:refs/heads/another &&
193 git remote show origin two > output &&
194 git branch -d rebase octopus &&
195 test_cmp expect output)
198 cat > test
/expect
<< EOF
200 Fetch URL: $(pwd)/one
202 HEAD branch: (not queried)
203 Remote branches: (status not queried)
206 Local branches configured for 'git pull':
207 ahead merges with remote master
208 master merges with remote master
209 Local refs configured for 'git push' (status not queried):
210 (matching) pushes to (matching)
211 refs/heads/master pushes to refs/heads/upstream
212 refs/tags/lastbackup forces to refs/tags/lastbackup
215 test_expect_success
'show -n' '
216 (mv one one.unreachable &&
218 git remote show -n origin > output &&
219 mv ../one.unreachable ../one &&
220 test_cmp expect output)
223 test_expect_success
'prune' '
225 git branch -m side side2) &&
228 git remote prune origin &&
229 git rev-parse refs/remotes/origin/side2 &&
230 test_must_fail git rev-parse refs/remotes/origin/side)
233 test_expect_success
'set-head --delete' '
235 git symbolic-ref refs/remotes/origin/HEAD &&
236 git remote set-head --delete origin &&
237 test_must_fail git symbolic-ref refs/remotes/origin/HEAD)
240 test_expect_success
'set-head --auto' '
242 git remote set-head --auto origin &&
243 echo refs/remotes/origin/master >expect &&
244 git symbolic-ref refs/remotes/origin/HEAD >output &&
245 test_cmp expect output
249 cat >test
/expect
<<EOF
250 error: Multiple remote HEAD branches. Please choose one explicitly with:
251 git remote set-head two another
252 git remote set-head two master
255 test_expect_success
'set-head --auto fails w/multiple HEADs' '
257 test_must_fail git remote set-head --auto two >output 2>&1 &&
258 test_cmp expect output)
261 cat >test
/expect
<<EOF
262 refs/remotes/origin/side2
265 test_expect_success
'set-head explicit' '
267 git remote set-head origin side2 &&
268 git symbolic-ref refs/remotes/origin/HEAD >output &&
269 git remote set-head origin master &&
270 test_cmp expect output)
273 cat > test
/expect
<< EOF
276 * [would prune] origin/side2
279 test_expect_success
'prune --dry-run' '
281 git branch -m side2 side) &&
283 git remote prune --dry-run origin > output &&
284 git rev-parse refs/remotes/origin/side2 &&
285 test_must_fail git rev-parse refs/remotes/origin/side &&
287 git branch -m side side2) &&
288 test_cmp expect output)
291 test_expect_success
'add --mirror && prune' '
295 git remote add --mirror -f origin ../one) &&
297 git branch -m side2 side) &&
299 git rev-parse --verify refs/heads/side2 &&
300 test_must_fail git rev-parse --verify refs/heads/side &&
302 git remote prune origin &&
303 test_must_fail git rev-parse --verify refs/heads/side2 &&
304 git rev-parse --verify refs/heads/side)
307 test_expect_success
'add --mirror=fetch' '
308 mkdir mirror-fetch &&
309 git init mirror-fetch/parent &&
310 (cd mirror-fetch/parent &&
312 git init --bare mirror-fetch/child &&
313 (cd mirror-fetch/child &&
314 git remote add --mirror=fetch -f parent ../parent)
317 test_expect_success
'fetch mirrors act as mirrors during fetch' '
318 (cd mirror-fetch/parent &&
320 git branch -m master renamed
322 (cd mirror-fetch/child &&
324 git rev-parse --verify refs/heads/new &&
325 git rev-parse --verify refs/heads/renamed
329 test_expect_success
'fetch mirrors can prune' '
330 (cd mirror-fetch/child &&
331 git remote prune parent &&
332 test_must_fail git rev-parse --verify refs/heads/master
336 test_expect_success
'fetch mirrors do not act as mirrors during push' '
337 (cd mirror-fetch/parent &&
340 (cd mirror-fetch/child &&
341 git branch -m renamed renamed2 &&
344 (cd mirror-fetch/parent &&
345 git rev-parse --verify renamed &&
346 test_must_fail git rev-parse --verify refs/heads/renamed2
350 test_expect_success
'add --mirror=push' '
352 git init --bare mirror-push/public &&
353 git init mirror-push/private &&
354 (cd mirror-push/private &&
356 git remote add --mirror=push public ../public
360 test_expect_success
'push mirrors act as mirrors during push' '
361 (cd mirror-push/private &&
363 git branch -m master renamed &&
366 (cd mirror-push/private &&
367 git rev-parse --verify refs/heads/new &&
368 git rev-parse --verify refs/heads/renamed &&
369 test_must_fail git rev-parse --verify refs/heads/master
373 test_expect_success
'push mirrors do not act as mirrors during fetch' '
374 (cd mirror-push/public &&
375 git branch -m renamed renamed2 &&
376 git symbolic-ref HEAD refs/heads/renamed2
378 (cd mirror-push/private &&
380 git rev-parse --verify refs/heads/renamed &&
381 test_must_fail git rev-parse --verify refs/heads/renamed2
385 test_expect_success
'add alt && prune' '
389 git remote add -f origin ../one &&
390 git config remote.alt.url ../one &&
391 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") &&
393 git branch -m side side2) &&
395 git rev-parse --verify refs/remotes/origin/side &&
396 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
398 git remote prune alt &&
399 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
400 git rev-parse --verify refs/remotes/origin/side2)
403 cat >test
/expect
<<\EOF
407 test_expect_success
'add with reachable tags (default)' '
411 git commit -m "Foobar" &&
412 git tag -a -m "Foobar tag" foobar-tag &&
413 git reset --hard HEAD~1 &&
414 git tag -a -m "Some tag" some-tag) &&
418 git remote add -f origin ../one &&
419 git tag -l some-tag >../test/output &&
420 git tag -l foobar-tag >>../test/output &&
421 test_must_fail git config remote.origin.tagopt) &&
422 test_cmp test/expect test/output
425 cat >test
/expect
<<\EOF
431 test_expect_success
'add --tags' '
436 git remote add -f --tags origin ../one &&
437 git tag -l some-tag >../test/output &&
438 git tag -l foobar-tag >>../test/output &&
439 git config remote.origin.tagopt >>../test/output) &&
440 test_cmp test/expect test/output
443 cat >test
/expect
<<\EOF
447 test_expect_success
'add --no-tags' '
452 git remote add -f --no-tags origin ../one &&
453 git tag -l some-tag >../test/output &&
454 git tag -l foobar-tag >../test/output &&
455 git config remote.origin.tagopt >>../test/output) &&
457 git tag -d some-tag foobar-tag) &&
458 test_cmp test/expect test/output
461 test_expect_success
'reject --no-no-tags' '
463 test_must_fail git remote add -f --no-no-tags neworigin ../one)
466 cat > one
/expect
<< EOF
474 test_expect_success
'update' '
477 git remote add drosophila ../two &&
478 git remote add apis ../mirror &&
480 git branch -r > output &&
481 test_cmp expect output)
485 cat > one
/expect
<< EOF
495 test_expect_success
'update with arguments' '
498 for b in $(git branch -r)
500 git branch -r -d $b || break
502 git remote add manduca ../mirror &&
503 git remote add megaloprepus ../mirror &&
504 git config remotes.phobaeticus "drosophila megaloprepus" &&
505 git config remotes.titanus manduca &&
506 git remote update phobaeticus titanus &&
507 git branch -r > output &&
508 test_cmp expect output)
512 test_expect_success
'update --prune' '
515 git branch -m side2 side3) &&
517 git remote update --prune &&
518 (cd ../one && git branch -m side3 side2) &&
519 git rev-parse refs/remotes/origin/side3 &&
520 test_must_fail git rev-parse refs/remotes/origin/side2)
523 cat > one
/expect
<< EOF
532 test_expect_success
'update default' '
535 for b in $(git branch -r)
537 git branch -r -d $b || break
539 git config remote.drosophila.skipDefaultUpdate true &&
540 git remote update default &&
541 git branch -r > output &&
542 test_cmp expect output)
546 cat > one
/expect
<< EOF
552 test_expect_success
'update default (overridden, with funny whitespace)' '
555 for b in $(git branch -r)
557 git branch -r -d $b || break
559 git config remotes.default "$(printf "\t drosophila \n")" &&
560 git remote update default &&
561 git branch -r > output &&
562 test_cmp expect output)
566 test_expect_success
'update (with remotes.default defined)' '
569 for b in $(git branch -r)
571 git branch -r -d $b || break
573 git config remotes.default "drosophila" &&
575 git branch -r > output &&
576 test_cmp expect output)
580 test_expect_success
'"remote show" does not show symbolic refs' '
582 git clone one three &&
584 git remote show origin > output &&
585 ! grep "^ *HEAD$" < output &&
586 ! grep -i stale < output)
590 test_expect_success
'reject adding remote with an invalid name' '
592 test_must_fail git remote add some:url desired-name
596 # The first three test if the tracking branches are properly renamed,
597 # the last two ones check if the config is updated.
599 test_expect_success
'rename a remote' '
601 git clone one four &&
603 git remote rename origin upstream &&
604 rmdir .git/refs/remotes/origin &&
605 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
606 test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
607 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
608 test "$(git config branch.master.remote)" = "upstream")
612 cat > remotes_origin
<< EOF
614 Push: refs/heads/master:refs/heads/upstream
615 Pull: refs/heads/master:refs/heads/origin
618 test_expect_success
'migrate a remote from named file in $GIT_DIR/remotes' '
619 git clone one five &&
620 origin_url=$(pwd)/one &&
622 git remote rm origin &&
623 mkdir -p .git/remotes &&
624 cat ../remotes_origin > .git/remotes/origin &&
625 git remote rename origin origin &&
626 ! test -f .git/remotes/origin &&
627 test "$(git config remote.origin.url)" = "$origin_url" &&
628 test "$(git config remote.origin.push)" = "refs/heads/master:refs/heads/upstream" &&
629 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
632 test_expect_success
'migrate a remote from named file in $GIT_DIR/branches' '
634 origin_url=$(pwd)/one &&
636 git remote rm origin &&
637 echo "$origin_url" > .git/branches/origin &&
638 git remote rename origin origin &&
639 ! test -f .git/branches/origin &&
640 test "$(git config remote.origin.url)" = "$origin_url" &&
641 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
644 test_expect_success
'remote prune to cause a dangling symref' '
645 git clone one seven &&
648 git checkout side2 &&
653 git remote prune origin
655 grep "has become dangling" err &&
657 : And the dangling symref will not cause other annoying errors &&
662 ! grep "points nowhere" err &&
665 test_must_fail git branch nomore origin
667 grep "dangling symref" err
670 test_expect_success
'show empty remote' '
672 test_create_repo empty &&
673 git clone empty empty-clone &&
676 git remote show origin
680 test_expect_success
'remote set-branches requires a remote' '
681 test_must_fail git remote set-branches &&
682 test_must_fail git remote set-branches --add
685 test_expect_success
'remote set-branches' '
686 echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial &&
687 sort <<-\EOF >expect.add &&
688 +refs/heads/*:refs/remotes/scratch/*
689 +refs/heads/other:refs/remotes/scratch/other
691 sort <<-\EOF >expect.replace &&
692 +refs/heads/maint:refs/remotes/scratch/maint
693 +refs/heads/master:refs/remotes/scratch/master
694 +refs/heads/next:refs/remotes/scratch/next
696 sort <<-\EOF >expect.add-two &&
697 +refs/heads/maint:refs/remotes/scratch/maint
698 +refs/heads/master:refs/remotes/scratch/master
699 +refs/heads/next:refs/remotes/scratch/next
700 +refs/heads/pu:refs/remotes/scratch/pu
701 +refs/heads/t/topic:refs/remotes/scratch/t/topic
703 sort <<-\EOF >expect.setup-ffonly &&
704 refs/heads/master:refs/remotes/scratch/master
705 +refs/heads/next:refs/remotes/scratch/next
707 sort <<-\EOF >expect.respect-ffonly &&
708 refs/heads/master:refs/remotes/scratch/master
709 +refs/heads/next:refs/remotes/scratch/next
710 +refs/heads/pu:refs/remotes/scratch/pu
713 git clone .git/ setbranches &&
716 git remote rename origin scratch &&
717 git config --get-all remote.scratch.fetch >config-result &&
718 sort <config-result >../actual.initial &&
720 git remote set-branches scratch --add other &&
721 git config --get-all remote.scratch.fetch >config-result &&
722 sort <config-result >../actual.add &&
724 git remote set-branches scratch maint master next &&
725 git config --get-all remote.scratch.fetch >config-result &&
726 sort <config-result >../actual.replace &&
728 git remote set-branches --add scratch pu t/topic &&
729 git config --get-all remote.scratch.fetch >config-result &&
730 sort <config-result >../actual.add-two &&
732 git config --unset-all remote.scratch.fetch &&
733 git config remote.scratch.fetch \
734 refs/heads/master:refs/remotes/scratch/master &&
735 git config --add remote.scratch.fetch \
736 +refs/heads/next:refs/remotes/scratch/next &&
737 git config --get-all remote.scratch.fetch >config-result &&
738 sort <config-result >../actual.setup-ffonly &&
740 git remote set-branches --add scratch pu &&
741 git config --get-all remote.scratch.fetch >config-result &&
742 sort <config-result >../actual.respect-ffonly
744 test_cmp expect.initial actual.initial &&
745 test_cmp expect.add actual.add &&
746 test_cmp expect.replace actual.replace &&
747 test_cmp expect.add-two actual.add-two &&
748 test_cmp expect.setup-ffonly actual.setup-ffonly &&
749 test_cmp expect.respect-ffonly actual.respect-ffonly
752 test_expect_success
'remote set-branches with --mirror' '
753 echo "+refs/*:refs/*" >expect.initial &&
754 echo "+refs/heads/master:refs/heads/master" >expect.replace &&
755 git clone --mirror .git/ setbranches-mirror &&
757 cd setbranches-mirror &&
758 git remote rename origin scratch &&
759 git config --get-all remote.scratch.fetch >../actual.initial &&
761 git remote set-branches scratch heads/master &&
762 git config --get-all remote.scratch.fetch >../actual.replace
764 test_cmp expect.initial actual.initial &&
765 test_cmp expect.replace actual.replace
768 test_expect_success
'new remote' '
769 git remote add someremote foo &&
771 git config --get-all remote.someremote.url >actual &&
775 test_expect_success
'remote set-url bar' '
776 git remote set-url someremote bar &&
778 git config --get-all remote.someremote.url >actual &&
782 test_expect_success
'remote set-url baz bar' '
783 git remote set-url someremote baz bar &&
785 git config --get-all remote.someremote.url >actual &&
789 test_expect_success
'remote set-url zot bar' '
790 test_must_fail git remote set-url someremote zot bar &&
792 git config --get-all remote.someremote.url >actual &&
796 test_expect_success
'remote set-url --push zot baz' '
797 test_must_fail git remote set-url --push someremote zot baz &&
798 echo "YYY" >expect &&
800 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
801 echo "YYY" >>actual &&
802 git config --get-all remote.someremote.url >>actual &&
806 test_expect_success
'remote set-url --push zot' '
807 git remote set-url --push someremote zot &&
809 echo "YYY" >>expect &&
811 git config --get-all remote.someremote.pushurl >actual &&
812 echo "YYY" >>actual &&
813 git config --get-all remote.someremote.url >>actual &&
817 test_expect_success
'remote set-url --push qux zot' '
818 git remote set-url --push someremote qux zot &&
820 echo "YYY" >>expect &&
822 git config --get-all remote.someremote.pushurl >actual &&
823 echo "YYY" >>actual &&
824 git config --get-all remote.someremote.url >>actual &&
828 test_expect_success
'remote set-url --push foo qu+x' '
829 git remote set-url --push someremote foo qu+x &&
831 echo "YYY" >>expect &&
833 git config --get-all remote.someremote.pushurl >actual &&
834 echo "YYY" >>actual &&
835 git config --get-all remote.someremote.url >>actual &&
839 test_expect_success
'remote set-url --push --add aaa' '
840 git remote set-url --push --add someremote aaa &&
843 echo "YYY" >>expect &&
845 git config --get-all remote.someremote.pushurl >actual &&
846 echo "YYY" >>actual &&
847 git config --get-all remote.someremote.url >>actual &&
851 test_expect_success
'remote set-url --push bar aaa' '
852 git remote set-url --push someremote bar aaa &&
855 echo "YYY" >>expect &&
857 git config --get-all remote.someremote.pushurl >actual &&
858 echo "YYY" >>actual &&
859 git config --get-all remote.someremote.url >>actual &&
863 test_expect_success
'remote set-url --push --delete bar' '
864 git remote set-url --push --delete someremote bar &&
866 echo "YYY" >>expect &&
868 git config --get-all remote.someremote.pushurl >actual &&
869 echo "YYY" >>actual &&
870 git config --get-all remote.someremote.url >>actual &&
874 test_expect_success
'remote set-url --push --delete foo' '
875 git remote set-url --push --delete someremote foo &&
876 echo "YYY" >expect &&
878 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
879 echo "YYY" >>actual &&
880 git config --get-all remote.someremote.url >>actual &&
884 test_expect_success
'remote set-url --add bbb' '
885 git remote set-url --add someremote bbb &&
886 echo "YYY" >expect &&
889 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
890 echo "YYY" >>actual &&
891 git config --get-all remote.someremote.url >>actual &&
895 test_expect_success
'remote set-url --delete .*' '
896 test_must_fail git remote set-url --delete someremote .\* &&
897 echo "YYY" >expect &&
900 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
901 echo "YYY" >>actual &&
902 git config --get-all remote.someremote.url >>actual &&
906 test_expect_success
'remote set-url --delete bbb' '
907 git remote set-url --delete someremote bbb &&
908 echo "YYY" >expect &&
910 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
911 echo "YYY" >>actual &&
912 git config --get-all remote.someremote.url >>actual &&
916 test_expect_success
'remote set-url --delete baz' '
917 test_must_fail git remote set-url --delete someremote baz &&
918 echo "YYY" >expect &&
920 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
921 echo "YYY" >>actual &&
922 git config --get-all remote.someremote.url >>actual &&
926 test_expect_success
'remote set-url --add ccc' '
927 git remote set-url --add someremote ccc &&
928 echo "YYY" >expect &&
931 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
932 echo "YYY" >>actual &&
933 git config --get-all remote.someremote.url >>actual &&
937 test_expect_success
'remote set-url --delete baz' '
938 git remote set-url --delete someremote baz &&
939 echo "YYY" >expect &&
941 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
942 echo "YYY" >>actual &&
943 git config --get-all remote.someremote.url >>actual &&