branch: add test for -m renaming multiple config sections
[git.git] / t / t5505-remote.sh
bloba6c0178f3af6c3e3f01816197e51e9bca546b00a
1 #!/bin/sh
3 test_description='git remote porcelain-ish'
5 . ./test-lib.sh
7 setup_repository () {
8 mkdir "$1" && (
9 cd "$1" &&
10 git init &&
11 >file &&
12 git add file &&
13 test_tick &&
14 git commit -m "Initial" &&
15 git checkout -b side &&
16 >elif &&
17 git add elif &&
18 test_tick &&
19 git commit -m "Second" &&
20 git checkout master
24 tokens_match () {
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')
32 shift &&
33 tokens_match "$*" "$actual"
36 check_tracking_branch () {
37 f="" &&
38 r=$(git for-each-ref "--format=%(refname)" |
39 sed -ne "s|^refs/remotes/$1/||p") &&
40 shift &&
41 tokens_match "$*" "$r"
44 test_expect_success setup '
45 setup_repository one &&
46 setup_repository two &&
48 cd two &&
49 git branch another
50 ) &&
51 git clone one test
54 test_expect_success 'add remote whose URL agrees with url.<...>.insteadOf' '
55 test_config url.git@host.com:team/repo.git.insteadOf myremote &&
56 git remote add myremote git@host.com:team/repo.git
59 test_expect_success C_LOCALE_OUTPUT 'remote information for the origin' '
61 cd test &&
62 tokens_match origin "$(git remote)" &&
63 check_remote_track origin master side &&
64 check_tracking_branch origin HEAD master side
68 test_expect_success 'add another remote' '
70 cd test &&
71 git remote add -f second ../two &&
72 tokens_match "origin second" "$(git remote)" &&
73 check_tracking_branch second master side another &&
74 git for-each-ref "--format=%(refname)" refs/remotes |
75 sed -e "/^refs\/remotes\/origin\//d" \
76 -e "/^refs\/remotes\/second\//d" >actual &&
77 >expect &&
78 test_cmp expect actual
82 test_expect_success C_LOCALE_OUTPUT 'check remote-tracking' '
84 cd test &&
85 check_remote_track origin master side &&
86 check_remote_track second master side another
90 test_expect_success 'remote forces tracking branches' '
92 cd test &&
93 case $(git config remote.second.fetch) in
94 +*) true ;;
95 *) false ;;
96 esac
100 test_expect_success 'remove remote' '
102 cd test &&
103 git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master &&
104 git remote rm second
108 test_expect_success C_LOCALE_OUTPUT 'remove remote' '
110 cd test &&
111 tokens_match origin "$(git remote)" &&
112 check_remote_track origin master side &&
113 git for-each-ref "--format=%(refname)" refs/remotes |
114 sed -e "/^refs\/remotes\/origin\//d" >actual &&
115 >expect &&
116 test_cmp expect actual
120 test_expect_success 'remove remote protects local branches' '
122 cd test &&
123 cat >expect1 <<-\EOF &&
124 Note: A branch outside the refs/remotes/ hierarchy was not removed;
125 to delete it, use:
126 git branch -d master
128 cat >expect2 <<-\EOF &&
129 Note: Some branches outside the refs/remotes/ hierarchy were not removed;
130 to delete them, use:
131 git branch -d foobranch
132 git branch -d master
134 git tag footag &&
135 git config --add remote.oops.fetch "+refs/*:refs/*" &&
136 git remote remove oops 2>actual1 &&
137 git branch foobranch &&
138 git config --add remote.oops.fetch "+refs/*:refs/*" &&
139 git remote rm oops 2>actual2 &&
140 git branch -d foobranch &&
141 git tag -d footag &&
142 test_i18ncmp expect1 actual1 &&
143 test_i18ncmp expect2 actual2
147 test_expect_success 'remove errors out early when deleting non-existent branch' '
149 cd test &&
150 echo "fatal: No such remote: foo" >expect &&
151 test_must_fail git remote rm foo 2>actual &&
152 test_i18ncmp expect actual
156 test_expect_success 'remove remote with a branch without configured merge' '
157 test_when_finished "(
158 git -C test checkout master;
159 git -C test branch -D two;
160 git -C test config --remove-section remote.two;
161 git -C test config --remove-section branch.second;
162 true
163 )" &&
165 cd test &&
166 git remote add two ../two &&
167 git fetch two &&
168 git checkout -b second two/master^0 &&
169 git config branch.second.remote two &&
170 git checkout master &&
171 git remote rm two
175 test_expect_success 'rename errors out early when deleting non-existent branch' '
177 cd test &&
178 echo "fatal: No such remote: foo" >expect &&
179 test_must_fail git remote rename foo bar 2>actual &&
180 test_i18ncmp expect actual
184 test_expect_success 'add existing foreign_vcs remote' '
185 test_config remote.foo.vcs bar &&
186 echo "fatal: remote foo already exists." >expect &&
187 test_must_fail git remote add foo bar 2>actual &&
188 test_i18ncmp expect actual
191 test_expect_success 'add existing foreign_vcs remote' '
192 test_config remote.foo.vcs bar &&
193 test_config remote.bar.vcs bar &&
194 echo "fatal: remote bar already exists." >expect &&
195 test_must_fail git remote rename foo bar 2>actual &&
196 test_i18ncmp expect actual
199 cat >test/expect <<EOF
200 * remote origin
201 Fetch URL: $(pwd)/one
202 Push URL: $(pwd)/one
203 HEAD branch: master
204 Remote branches:
205 master new (next fetch will store in remotes/origin)
206 side tracked
207 Local branches configured for 'git pull':
208 ahead merges with remote master
209 master merges with remote master
210 octopus merges with remote topic-a
211 and with remote topic-b
212 and with remote topic-c
213 rebase rebases onto remote master
214 Local refs configured for 'git push':
215 master pushes to master (local out of date)
216 master pushes to upstream (create)
217 * remote two
218 Fetch URL: ../two
219 Push URL: ../three
220 HEAD branch: master
221 Local refs configured for 'git push':
222 ahead forces to master (fast-forwardable)
223 master pushes to another (up to date)
226 test_expect_success 'show' '
228 cd test &&
229 git config --add remote.origin.fetch refs/heads/master:refs/heads/upstream &&
230 git fetch &&
231 git checkout -b ahead origin/master &&
232 echo 1 >>file &&
233 test_tick &&
234 git commit -m update file &&
235 git checkout master &&
236 git branch --track octopus origin/master &&
237 git branch --track rebase origin/master &&
238 git branch -d -r origin/master &&
239 git config --add remote.two.url ../two &&
240 git config --add remote.two.pushurl ../three &&
241 git config branch.rebase.rebase true &&
242 git config branch.octopus.merge "topic-a topic-b topic-c" &&
244 cd ../one &&
245 echo 1 >file &&
246 test_tick &&
247 git commit -m update file
248 ) &&
249 git config --add remote.origin.push : &&
250 git config --add remote.origin.push refs/heads/master:refs/heads/upstream &&
251 git config --add remote.origin.push +refs/tags/lastbackup &&
252 git config --add remote.two.push +refs/heads/ahead:refs/heads/master &&
253 git config --add remote.two.push refs/heads/master:refs/heads/another &&
254 git remote show origin two >output &&
255 git branch -d rebase octopus &&
256 test_i18ncmp expect output
260 cat >test/expect <<EOF
261 * remote origin
262 Fetch URL: $(pwd)/one
263 Push URL: $(pwd)/one
264 HEAD branch: (not queried)
265 Remote branches: (status not queried)
266 master
267 side
268 Local branches configured for 'git pull':
269 ahead merges with remote master
270 master merges with remote master
271 Local refs configured for 'git push' (status not queried):
272 (matching) pushes to (matching)
273 refs/heads/master pushes to refs/heads/upstream
274 refs/tags/lastbackup forces to refs/tags/lastbackup
277 test_expect_success 'show -n' '
278 mv one one.unreachable &&
280 cd test &&
281 git remote show -n origin >output &&
282 mv ../one.unreachable ../one &&
283 test_i18ncmp expect output
287 test_expect_success 'prune' '
289 cd one &&
290 git branch -m side side2
291 ) &&
293 cd test &&
294 git fetch origin &&
295 git remote prune origin &&
296 git rev-parse refs/remotes/origin/side2 &&
297 test_must_fail git rev-parse refs/remotes/origin/side
301 test_expect_success 'set-head --delete' '
303 cd test &&
304 git symbolic-ref refs/remotes/origin/HEAD &&
305 git remote set-head --delete origin &&
306 test_must_fail git symbolic-ref refs/remotes/origin/HEAD
310 test_expect_success 'set-head --auto' '
312 cd test &&
313 git remote set-head --auto origin &&
314 echo refs/remotes/origin/master >expect &&
315 git symbolic-ref refs/remotes/origin/HEAD >output &&
316 test_cmp expect output
320 test_expect_success 'set-head --auto has no problem w/multiple HEADs' '
322 cd test &&
323 git fetch two "refs/heads/*:refs/remotes/two/*" &&
324 git remote set-head --auto two >output 2>&1 &&
325 echo "two/HEAD set to master" >expect &&
326 test_i18ncmp expect output
330 cat >test/expect <<\EOF
331 refs/remotes/origin/side2
334 test_expect_success 'set-head explicit' '
336 cd test &&
337 git remote set-head origin side2 &&
338 git symbolic-ref refs/remotes/origin/HEAD >output &&
339 git remote set-head origin master &&
340 test_cmp expect output
344 cat >test/expect <<EOF
345 Pruning origin
346 URL: $(pwd)/one
347 * [would prune] origin/side2
350 test_expect_success 'prune --dry-run' '
352 cd one &&
353 git branch -m side2 side) &&
355 cd test &&
356 git remote prune --dry-run origin >output &&
357 git rev-parse refs/remotes/origin/side2 &&
358 test_must_fail git rev-parse refs/remotes/origin/side &&
360 cd ../one &&
361 git branch -m side side2) &&
362 test_i18ncmp expect output
366 test_expect_success 'add --mirror && prune' '
367 mkdir mirror &&
369 cd mirror &&
370 git init --bare &&
371 git remote add --mirror -f origin ../one
372 ) &&
374 cd one &&
375 git branch -m side2 side
376 ) &&
378 cd mirror &&
379 git rev-parse --verify refs/heads/side2 &&
380 test_must_fail git rev-parse --verify refs/heads/side &&
381 git fetch origin &&
382 git remote prune origin &&
383 test_must_fail git rev-parse --verify refs/heads/side2 &&
384 git rev-parse --verify refs/heads/side
388 test_expect_success 'add --mirror=fetch' '
389 mkdir mirror-fetch &&
390 git init mirror-fetch/parent &&
392 cd mirror-fetch/parent &&
393 test_commit one
394 ) &&
395 git init --bare mirror-fetch/child &&
397 cd mirror-fetch/child &&
398 git remote add --mirror=fetch -f parent ../parent
402 test_expect_success 'fetch mirrors act as mirrors during fetch' '
404 cd mirror-fetch/parent &&
405 git branch new &&
406 git branch -m master renamed
407 ) &&
409 cd mirror-fetch/child &&
410 git fetch parent &&
411 git rev-parse --verify refs/heads/new &&
412 git rev-parse --verify refs/heads/renamed
416 test_expect_success 'fetch mirrors can prune' '
418 cd mirror-fetch/child &&
419 git remote prune parent &&
420 test_must_fail git rev-parse --verify refs/heads/master
424 test_expect_success 'fetch mirrors do not act as mirrors during push' '
426 cd mirror-fetch/parent &&
427 git checkout HEAD^0
428 ) &&
430 cd mirror-fetch/child &&
431 git branch -m renamed renamed2 &&
432 git push parent :
433 ) &&
435 cd mirror-fetch/parent &&
436 git rev-parse --verify renamed &&
437 test_must_fail git rev-parse --verify refs/heads/renamed2
441 test_expect_success 'add fetch mirror with specific branches' '
442 git init --bare mirror-fetch/track &&
444 cd mirror-fetch/track &&
445 git remote add --mirror=fetch -t heads/new parent ../parent
449 test_expect_success 'fetch mirror respects specific branches' '
451 cd mirror-fetch/track &&
452 git fetch parent &&
453 git rev-parse --verify refs/heads/new &&
454 test_must_fail git rev-parse --verify refs/heads/renamed
458 test_expect_success 'add --mirror=push' '
459 mkdir mirror-push &&
460 git init --bare mirror-push/public &&
461 git init mirror-push/private &&
463 cd mirror-push/private &&
464 test_commit one &&
465 git remote add --mirror=push public ../public
469 test_expect_success 'push mirrors act as mirrors during push' '
471 cd mirror-push/private &&
472 git branch new &&
473 git branch -m master renamed &&
474 git push public
475 ) &&
477 cd mirror-push/private &&
478 git rev-parse --verify refs/heads/new &&
479 git rev-parse --verify refs/heads/renamed &&
480 test_must_fail git rev-parse --verify refs/heads/master
484 test_expect_success 'push mirrors do not act as mirrors during fetch' '
486 cd mirror-push/public &&
487 git branch -m renamed renamed2 &&
488 git symbolic-ref HEAD refs/heads/renamed2
489 ) &&
491 cd mirror-push/private &&
492 git fetch public &&
493 git rev-parse --verify refs/heads/renamed &&
494 test_must_fail git rev-parse --verify refs/heads/renamed2
498 test_expect_success 'push mirrors do not allow you to specify refs' '
499 git init mirror-push/track &&
501 cd mirror-push/track &&
502 test_must_fail git remote add --mirror=push -t new public ../public
506 test_expect_success 'add alt && prune' '
507 mkdir alttst &&
509 cd alttst &&
510 git init &&
511 git remote add -f origin ../one &&
512 git config remote.alt.url ../one &&
513 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*"
514 ) &&
516 cd one &&
517 git branch -m side side2
518 ) &&
520 cd alttst &&
521 git rev-parse --verify refs/remotes/origin/side &&
522 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
523 git fetch alt &&
524 git remote prune alt &&
525 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
526 git rev-parse --verify refs/remotes/origin/side2
530 cat >test/expect <<\EOF
531 some-tag
534 test_expect_success 'add with reachable tags (default)' '
536 cd one &&
537 >foobar &&
538 git add foobar &&
539 git commit -m "Foobar" &&
540 git tag -a -m "Foobar tag" foobar-tag &&
541 git reset --hard HEAD~1 &&
542 git tag -a -m "Some tag" some-tag
543 ) &&
544 mkdir add-tags &&
546 cd add-tags &&
547 git init &&
548 git remote add -f origin ../one &&
549 git tag -l some-tag >../test/output &&
550 git tag -l foobar-tag >>../test/output &&
551 test_must_fail git config remote.origin.tagopt
552 ) &&
553 test_cmp test/expect test/output
556 cat >test/expect <<\EOF
557 some-tag
558 foobar-tag
559 --tags
562 test_expect_success 'add --tags' '
563 rm -rf add-tags &&
565 mkdir add-tags &&
566 cd add-tags &&
567 git init &&
568 git remote add -f --tags origin ../one &&
569 git tag -l some-tag >../test/output &&
570 git tag -l foobar-tag >>../test/output &&
571 git config remote.origin.tagopt >>../test/output
572 ) &&
573 test_cmp test/expect test/output
576 cat >test/expect <<\EOF
577 --no-tags
580 test_expect_success 'add --no-tags' '
581 rm -rf add-tags &&
583 mkdir add-no-tags &&
584 cd add-no-tags &&
585 git init &&
586 git remote add -f --no-tags origin ../one &&
587 git tag -l some-tag >../test/output &&
588 git tag -l foobar-tag >../test/output &&
589 git config remote.origin.tagopt >>../test/output
590 ) &&
592 cd one &&
593 git tag -d some-tag foobar-tag
594 ) &&
595 test_cmp test/expect test/output
598 test_expect_success 'reject --no-no-tags' '
600 cd add-no-tags &&
601 test_must_fail git remote add -f --no-no-tags neworigin ../one
605 cat >one/expect <<\EOF
606 apis/master
607 apis/side
608 drosophila/another
609 drosophila/master
610 drosophila/side
613 test_expect_success 'update' '
615 cd one &&
616 git remote add drosophila ../two &&
617 git remote add apis ../mirror &&
618 git remote update &&
619 git branch -r >output &&
620 test_cmp expect output
624 cat >one/expect <<\EOF
625 drosophila/another
626 drosophila/master
627 drosophila/side
628 manduca/master
629 manduca/side
630 megaloprepus/master
631 megaloprepus/side
634 test_expect_success 'update with arguments' '
636 cd one &&
637 for b in $(git branch -r)
639 git branch -r -d $b || exit 1
640 done &&
641 git remote add manduca ../mirror &&
642 git remote add megaloprepus ../mirror &&
643 git config remotes.phobaeticus "drosophila megaloprepus" &&
644 git config remotes.titanus manduca &&
645 git remote update phobaeticus titanus &&
646 git branch -r >output &&
647 test_cmp expect output
651 test_expect_success 'update --prune' '
653 cd one &&
654 git branch -m side2 side3
655 ) &&
657 cd test &&
658 git remote update --prune &&
660 cd ../one &&
661 git branch -m side3 side2
662 ) &&
663 git rev-parse refs/remotes/origin/side3 &&
664 test_must_fail git rev-parse refs/remotes/origin/side2
668 cat >one/expect <<-\EOF
669 apis/master
670 apis/side
671 manduca/master
672 manduca/side
673 megaloprepus/master
674 megaloprepus/side
677 test_expect_success 'update default' '
679 cd one &&
680 for b in $(git branch -r)
682 git branch -r -d $b || exit 1
683 done &&
684 git config remote.drosophila.skipDefaultUpdate true &&
685 git remote update default &&
686 git branch -r >output &&
687 test_cmp expect output
691 cat >one/expect <<\EOF
692 drosophila/another
693 drosophila/master
694 drosophila/side
697 test_expect_success 'update default (overridden, with funny whitespace)' '
699 cd one &&
700 for b in $(git branch -r)
702 git branch -r -d $b || exit 1
703 done &&
704 git config remotes.default "$(printf "\t drosophila \n")" &&
705 git remote update default &&
706 git branch -r >output &&
707 test_cmp expect output
711 test_expect_success 'update (with remotes.default defined)' '
713 cd one &&
714 for b in $(git branch -r)
716 git branch -r -d $b || exit 1
717 done &&
718 git config remotes.default "drosophila" &&
719 git remote update &&
720 git branch -r >output &&
721 test_cmp expect output
725 test_expect_success '"remote show" does not show symbolic refs' '
726 git clone one three &&
728 cd three &&
729 git remote show origin >output &&
730 ! grep "^ *HEAD$" < output &&
731 ! grep -i stale < output
735 test_expect_success 'reject adding remote with an invalid name' '
736 test_must_fail git remote add some:url desired-name
739 # The first three test if the tracking branches are properly renamed,
740 # the last two ones check if the config is updated.
742 test_expect_success 'rename a remote' '
743 git clone one four &&
745 cd four &&
746 git remote rename origin upstream &&
747 test -z "$(git for-each-ref refs/remotes/origin)" &&
748 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
749 test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
750 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
751 test "$(git config branch.master.remote)" = "upstream"
755 test_expect_success 'rename does not update a non-default fetch refspec' '
756 git clone one four.one &&
758 cd four.one &&
759 git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
760 git remote rename origin upstream &&
761 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" &&
762 git rev-parse -q origin/master
766 test_expect_success 'rename a remote with name part of fetch spec' '
767 git clone one four.two &&
769 cd four.two &&
770 git remote rename origin remote &&
771 git remote rename remote upstream &&
772 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*"
776 test_expect_success 'rename a remote with name prefix of other remote' '
777 git clone one four.three &&
779 cd four.three &&
780 git remote add o git://example.com/repo.git &&
781 git remote rename o upstream &&
782 test "$(git rev-parse origin/master)" = "$(git rev-parse master)"
786 test_expect_success 'rename succeeds with existing remote.<target>.prune' '
787 git clone one four.four &&
788 test_when_finished git config --global --unset remote.upstream.prune &&
789 git config --global remote.upstream.prune true &&
790 git -C four.four remote rename origin upstream
793 cat >remotes_origin <<EOF
794 URL: $(pwd)/one
795 Push: refs/heads/master:refs/heads/upstream
796 Push: refs/heads/next:refs/heads/upstream2
797 Pull: refs/heads/master:refs/heads/origin
798 Pull: refs/heads/next:refs/heads/origin2
801 test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
802 git clone one five &&
803 origin_url=$(pwd)/one &&
805 cd five &&
806 git remote remove origin &&
807 mkdir -p .git/remotes &&
808 cat ../remotes_origin >.git/remotes/origin &&
809 git remote rename origin origin &&
810 test_path_is_missing .git/remotes/origin &&
811 test "$(git config remote.origin.url)" = "$origin_url" &&
812 cat >push_expected <<-\EOF &&
813 refs/heads/master:refs/heads/upstream
814 refs/heads/next:refs/heads/upstream2
816 cat >fetch_expected <<-\EOF &&
817 refs/heads/master:refs/heads/origin
818 refs/heads/next:refs/heads/origin2
820 git config --get-all remote.origin.push >push_actual &&
821 git config --get-all remote.origin.fetch >fetch_actual &&
822 test_cmp push_expected push_actual &&
823 test_cmp fetch_expected fetch_actual
827 test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
828 git clone one six &&
829 origin_url=$(pwd)/one &&
831 cd six &&
832 git remote rm origin &&
833 echo "$origin_url" >.git/branches/origin &&
834 git remote rename origin origin &&
835 test_path_is_missing .git/branches/origin &&
836 test "$(git config remote.origin.url)" = "$origin_url" &&
837 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin" &&
838 test "$(git config remote.origin.push)" = "HEAD:refs/heads/master"
842 test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' '
843 git clone one seven &&
845 cd seven &&
846 git remote rm origin &&
847 echo "quux#foom" > .git/branches/origin &&
848 git remote rename origin origin &&
849 test_path_is_missing .git/branches/origin &&
850 test "$(git config remote.origin.url)" = "quux" &&
851 test "$(git config remote.origin.fetch)" = "refs/heads/foom:refs/heads/origin"
852 test "$(git config remote.origin.push)" = "HEAD:refs/heads/foom"
856 test_expect_success 'remote prune to cause a dangling symref' '
857 git clone one eight &&
859 cd one &&
860 git checkout side2 &&
861 git branch -D master
862 ) &&
864 cd eight &&
865 git remote prune origin
866 ) >err 2>&1 &&
867 test_i18ngrep "has become dangling" err &&
869 : And the dangling symref will not cause other annoying errors &&
871 cd eight &&
872 git branch -a
873 ) 2>err &&
874 ! grep "points nowhere" err &&
876 cd eight &&
877 test_must_fail git branch nomore origin
878 ) 2>err &&
879 grep "dangling symref" err
882 test_expect_success 'show empty remote' '
883 test_create_repo empty &&
884 git clone empty empty-clone &&
886 cd empty-clone &&
887 git remote show origin
891 test_expect_success 'remote set-branches requires a remote' '
892 test_must_fail git remote set-branches &&
893 test_must_fail git remote set-branches --add
896 test_expect_success 'remote set-branches' '
897 echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial &&
898 sort <<-\EOF >expect.add &&
899 +refs/heads/*:refs/remotes/scratch/*
900 +refs/heads/other:refs/remotes/scratch/other
902 sort <<-\EOF >expect.replace &&
903 +refs/heads/maint:refs/remotes/scratch/maint
904 +refs/heads/master:refs/remotes/scratch/master
905 +refs/heads/next:refs/remotes/scratch/next
907 sort <<-\EOF >expect.add-two &&
908 +refs/heads/maint:refs/remotes/scratch/maint
909 +refs/heads/master:refs/remotes/scratch/master
910 +refs/heads/next:refs/remotes/scratch/next
911 +refs/heads/pu:refs/remotes/scratch/pu
912 +refs/heads/t/topic:refs/remotes/scratch/t/topic
914 sort <<-\EOF >expect.setup-ffonly &&
915 refs/heads/master:refs/remotes/scratch/master
916 +refs/heads/next:refs/remotes/scratch/next
918 sort <<-\EOF >expect.respect-ffonly &&
919 refs/heads/master:refs/remotes/scratch/master
920 +refs/heads/next:refs/remotes/scratch/next
921 +refs/heads/pu:refs/remotes/scratch/pu
924 git clone .git/ setbranches &&
926 cd setbranches &&
927 git remote rename origin scratch &&
928 git config --get-all remote.scratch.fetch >config-result &&
929 sort <config-result >../actual.initial &&
931 git remote set-branches scratch --add other &&
932 git config --get-all remote.scratch.fetch >config-result &&
933 sort <config-result >../actual.add &&
935 git remote set-branches scratch maint master next &&
936 git config --get-all remote.scratch.fetch >config-result &&
937 sort <config-result >../actual.replace &&
939 git remote set-branches --add scratch pu t/topic &&
940 git config --get-all remote.scratch.fetch >config-result &&
941 sort <config-result >../actual.add-two &&
943 git config --unset-all remote.scratch.fetch &&
944 git config remote.scratch.fetch \
945 refs/heads/master:refs/remotes/scratch/master &&
946 git config --add remote.scratch.fetch \
947 +refs/heads/next:refs/remotes/scratch/next &&
948 git config --get-all remote.scratch.fetch >config-result &&
949 sort <config-result >../actual.setup-ffonly &&
951 git remote set-branches --add scratch pu &&
952 git config --get-all remote.scratch.fetch >config-result &&
953 sort <config-result >../actual.respect-ffonly
954 ) &&
955 test_cmp expect.initial actual.initial &&
956 test_cmp expect.add actual.add &&
957 test_cmp expect.replace actual.replace &&
958 test_cmp expect.add-two actual.add-two &&
959 test_cmp expect.setup-ffonly actual.setup-ffonly &&
960 test_cmp expect.respect-ffonly actual.respect-ffonly
963 test_expect_success 'remote set-branches with --mirror' '
964 echo "+refs/*:refs/*" >expect.initial &&
965 echo "+refs/heads/master:refs/heads/master" >expect.replace &&
966 git clone --mirror .git/ setbranches-mirror &&
968 cd setbranches-mirror &&
969 git remote rename origin scratch &&
970 git config --get-all remote.scratch.fetch >../actual.initial &&
972 git remote set-branches scratch heads/master &&
973 git config --get-all remote.scratch.fetch >../actual.replace
974 ) &&
975 test_cmp expect.initial actual.initial &&
976 test_cmp expect.replace actual.replace
979 test_expect_success 'new remote' '
980 git remote add someremote foo &&
981 echo foo >expect &&
982 git config --get-all remote.someremote.url >actual &&
983 cmp expect actual
986 get_url_test () {
987 cat >expect &&
988 git remote get-url "$@" >actual &&
989 test_cmp expect actual
992 test_expect_success 'get-url on new remote' '
993 echo foo | get_url_test someremote &&
994 echo foo | get_url_test --all someremote &&
995 echo foo | get_url_test --push someremote &&
996 echo foo | get_url_test --push --all someremote
999 test_expect_success 'remote set-url with locked config' '
1000 test_when_finished "rm -f .git/config.lock" &&
1001 git config --get-all remote.someremote.url >expect &&
1002 >.git/config.lock &&
1003 test_must_fail git remote set-url someremote baz &&
1004 git config --get-all remote.someremote.url >actual &&
1005 cmp expect actual
1008 test_expect_success 'remote set-url bar' '
1009 git remote set-url someremote bar &&
1010 echo bar >expect &&
1011 git config --get-all remote.someremote.url >actual &&
1012 cmp expect actual
1015 test_expect_success 'remote set-url baz bar' '
1016 git remote set-url someremote baz bar &&
1017 echo baz >expect &&
1018 git config --get-all remote.someremote.url >actual &&
1019 cmp expect actual
1022 test_expect_success 'remote set-url zot bar' '
1023 test_must_fail git remote set-url someremote zot bar &&
1024 echo baz >expect &&
1025 git config --get-all remote.someremote.url >actual &&
1026 cmp expect actual
1029 test_expect_success 'remote set-url --push zot baz' '
1030 test_must_fail git remote set-url --push someremote zot baz &&
1031 echo "YYY" >expect &&
1032 echo baz >>expect &&
1033 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1034 echo "YYY" >>actual &&
1035 git config --get-all remote.someremote.url >>actual &&
1036 cmp expect actual
1039 test_expect_success 'remote set-url --push zot' '
1040 git remote set-url --push someremote zot &&
1041 echo zot >expect &&
1042 echo "YYY" >>expect &&
1043 echo baz >>expect &&
1044 git config --get-all remote.someremote.pushurl >actual &&
1045 echo "YYY" >>actual &&
1046 git config --get-all remote.someremote.url >>actual &&
1047 cmp expect actual
1050 test_expect_success 'get-url with different urls' '
1051 echo baz | get_url_test someremote &&
1052 echo baz | get_url_test --all someremote &&
1053 echo zot | get_url_test --push someremote &&
1054 echo zot | get_url_test --push --all someremote
1057 test_expect_success 'remote set-url --push qux zot' '
1058 git remote set-url --push someremote qux zot &&
1059 echo qux >expect &&
1060 echo "YYY" >>expect &&
1061 echo baz >>expect &&
1062 git config --get-all remote.someremote.pushurl >actual &&
1063 echo "YYY" >>actual &&
1064 git config --get-all remote.someremote.url >>actual &&
1065 cmp expect actual
1068 test_expect_success 'remote set-url --push foo qu+x' '
1069 git remote set-url --push someremote foo qu+x &&
1070 echo foo >expect &&
1071 echo "YYY" >>expect &&
1072 echo baz >>expect &&
1073 git config --get-all remote.someremote.pushurl >actual &&
1074 echo "YYY" >>actual &&
1075 git config --get-all remote.someremote.url >>actual &&
1076 cmp expect actual
1079 test_expect_success 'remote set-url --push --add aaa' '
1080 git remote set-url --push --add someremote aaa &&
1081 echo foo >expect &&
1082 echo aaa >>expect &&
1083 echo "YYY" >>expect &&
1084 echo baz >>expect &&
1085 git config --get-all remote.someremote.pushurl >actual &&
1086 echo "YYY" >>actual &&
1087 git config --get-all remote.someremote.url >>actual &&
1088 cmp expect actual
1091 test_expect_success 'get-url on multi push remote' '
1092 echo foo | get_url_test --push someremote &&
1093 get_url_test --push --all someremote <<-\EOF
1099 test_expect_success 'remote set-url --push bar aaa' '
1100 git remote set-url --push someremote bar aaa &&
1101 echo foo >expect &&
1102 echo bar >>expect &&
1103 echo "YYY" >>expect &&
1104 echo baz >>expect &&
1105 git config --get-all remote.someremote.pushurl >actual &&
1106 echo "YYY" >>actual &&
1107 git config --get-all remote.someremote.url >>actual &&
1108 cmp expect actual
1111 test_expect_success 'remote set-url --push --delete bar' '
1112 git remote set-url --push --delete someremote bar &&
1113 echo foo >expect &&
1114 echo "YYY" >>expect &&
1115 echo baz >>expect &&
1116 git config --get-all remote.someremote.pushurl >actual &&
1117 echo "YYY" >>actual &&
1118 git config --get-all remote.someremote.url >>actual &&
1119 cmp expect actual
1122 test_expect_success 'remote set-url --push --delete foo' '
1123 git remote set-url --push --delete someremote foo &&
1124 echo "YYY" >expect &&
1125 echo baz >>expect &&
1126 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1127 echo "YYY" >>actual &&
1128 git config --get-all remote.someremote.url >>actual &&
1129 cmp expect actual
1132 test_expect_success 'remote set-url --add bbb' '
1133 git remote set-url --add someremote bbb &&
1134 echo "YYY" >expect &&
1135 echo baz >>expect &&
1136 echo bbb >>expect &&
1137 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1138 echo "YYY" >>actual &&
1139 git config --get-all remote.someremote.url >>actual &&
1140 cmp expect actual
1143 test_expect_success 'get-url on multi fetch remote' '
1144 echo baz | get_url_test someremote &&
1145 get_url_test --all someremote <<-\EOF
1151 test_expect_success 'remote set-url --delete .*' '
1152 test_must_fail git remote set-url --delete someremote .\* &&
1153 echo "YYY" >expect &&
1154 echo baz >>expect &&
1155 echo bbb >>expect &&
1156 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1157 echo "YYY" >>actual &&
1158 git config --get-all remote.someremote.url >>actual &&
1159 cmp expect actual
1162 test_expect_success 'remote set-url --delete bbb' '
1163 git remote set-url --delete someremote bbb &&
1164 echo "YYY" >expect &&
1165 echo baz >>expect &&
1166 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1167 echo "YYY" >>actual &&
1168 git config --get-all remote.someremote.url >>actual &&
1169 cmp expect actual
1172 test_expect_success 'remote set-url --delete baz' '
1173 test_must_fail git remote set-url --delete someremote baz &&
1174 echo "YYY" >expect &&
1175 echo baz >>expect &&
1176 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1177 echo "YYY" >>actual &&
1178 git config --get-all remote.someremote.url >>actual &&
1179 cmp expect actual
1182 test_expect_success 'remote set-url --add ccc' '
1183 git remote set-url --add someremote ccc &&
1184 echo "YYY" >expect &&
1185 echo baz >>expect &&
1186 echo ccc >>expect &&
1187 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1188 echo "YYY" >>actual &&
1189 git config --get-all remote.someremote.url >>actual &&
1190 cmp expect actual
1193 test_expect_success 'remote set-url --delete baz' '
1194 git remote set-url --delete someremote baz &&
1195 echo "YYY" >expect &&
1196 echo ccc >>expect &&
1197 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1198 echo "YYY" >>actual &&
1199 git config --get-all remote.someremote.url >>actual &&
1200 cmp expect actual
1203 test_expect_success 'extra args: setup' '
1204 # add a dummy origin so that this does not trigger failure
1205 git remote add origin .
1208 test_extra_arg () {
1209 test_expect_success "extra args: $*" "
1210 test_must_fail git remote $* bogus_extra_arg 2>actual &&
1211 test_i18ngrep '^usage:' actual
1215 test_extra_arg add nick url
1216 test_extra_arg rename origin newname
1217 test_extra_arg remove origin
1218 test_extra_arg set-head origin master
1219 # set-branches takes any number of args
1220 test_extra_arg get-url origin newurl
1221 test_extra_arg set-url origin newurl oldurl
1222 # show takes any number of args
1223 # prune takes any number of args
1224 # update takes any number of args
1226 test_expect_success 'add remote matching the "insteadOf" URL' '
1227 git config url.xyz@example.com.insteadOf backup &&
1228 git remote add backup xyz@example.com
1231 test_done