range-diff: update stale summary of --no-dual-color
[git/raj.git] / t / t5505-remote.sh
blob11e14a1e0fd591c053e3cb50a1a40e49b2b93e09
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' '
351 git -C one branch -m side2 side &&
352 test_when_finished "git -C one branch -m side side2" &&
354 cd test &&
355 git remote prune --dry-run origin >output &&
356 git rev-parse refs/remotes/origin/side2 &&
357 test_must_fail git rev-parse refs/remotes/origin/side &&
358 test_i18ncmp expect output
362 test_expect_success 'add --mirror && prune' '
363 mkdir mirror &&
365 cd mirror &&
366 git init --bare &&
367 git remote add --mirror -f origin ../one
368 ) &&
370 cd one &&
371 git branch -m side2 side
372 ) &&
374 cd mirror &&
375 git rev-parse --verify refs/heads/side2 &&
376 test_must_fail git rev-parse --verify refs/heads/side &&
377 git fetch origin &&
378 git remote prune origin &&
379 test_must_fail git rev-parse --verify refs/heads/side2 &&
380 git rev-parse --verify refs/heads/side
384 test_expect_success 'add --mirror=fetch' '
385 mkdir mirror-fetch &&
386 git init mirror-fetch/parent &&
388 cd mirror-fetch/parent &&
389 test_commit one
390 ) &&
391 git init --bare mirror-fetch/child &&
393 cd mirror-fetch/child &&
394 git remote add --mirror=fetch -f parent ../parent
398 test_expect_success 'fetch mirrors act as mirrors during fetch' '
400 cd mirror-fetch/parent &&
401 git branch new &&
402 git branch -m master renamed
403 ) &&
405 cd mirror-fetch/child &&
406 git fetch parent &&
407 git rev-parse --verify refs/heads/new &&
408 git rev-parse --verify refs/heads/renamed
412 test_expect_success 'fetch mirrors can prune' '
414 cd mirror-fetch/child &&
415 git remote prune parent &&
416 test_must_fail git rev-parse --verify refs/heads/master
420 test_expect_success 'fetch mirrors do not act as mirrors during push' '
422 cd mirror-fetch/parent &&
423 git checkout HEAD^0
424 ) &&
426 cd mirror-fetch/child &&
427 git branch -m renamed renamed2 &&
428 git push parent :
429 ) &&
431 cd mirror-fetch/parent &&
432 git rev-parse --verify renamed &&
433 test_must_fail git rev-parse --verify refs/heads/renamed2
437 test_expect_success 'add fetch mirror with specific branches' '
438 git init --bare mirror-fetch/track &&
440 cd mirror-fetch/track &&
441 git remote add --mirror=fetch -t heads/new parent ../parent
445 test_expect_success 'fetch mirror respects specific branches' '
447 cd mirror-fetch/track &&
448 git fetch parent &&
449 git rev-parse --verify refs/heads/new &&
450 test_must_fail git rev-parse --verify refs/heads/renamed
454 test_expect_success 'add --mirror=push' '
455 mkdir mirror-push &&
456 git init --bare mirror-push/public &&
457 git init mirror-push/private &&
459 cd mirror-push/private &&
460 test_commit one &&
461 git remote add --mirror=push public ../public
465 test_expect_success 'push mirrors act as mirrors during push' '
467 cd mirror-push/private &&
468 git branch new &&
469 git branch -m master renamed &&
470 git push public
471 ) &&
473 cd mirror-push/private &&
474 git rev-parse --verify refs/heads/new &&
475 git rev-parse --verify refs/heads/renamed &&
476 test_must_fail git rev-parse --verify refs/heads/master
480 test_expect_success 'push mirrors do not act as mirrors during fetch' '
482 cd mirror-push/public &&
483 git branch -m renamed renamed2 &&
484 git symbolic-ref HEAD refs/heads/renamed2
485 ) &&
487 cd mirror-push/private &&
488 git fetch public &&
489 git rev-parse --verify refs/heads/renamed &&
490 test_must_fail git rev-parse --verify refs/heads/renamed2
494 test_expect_success 'push mirrors do not allow you to specify refs' '
495 git init mirror-push/track &&
497 cd mirror-push/track &&
498 test_must_fail git remote add --mirror=push -t new public ../public
502 test_expect_success 'add alt && prune' '
503 mkdir alttst &&
505 cd alttst &&
506 git init &&
507 git remote add -f origin ../one &&
508 git config remote.alt.url ../one &&
509 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*"
510 ) &&
512 cd one &&
513 git branch -m side side2
514 ) &&
516 cd alttst &&
517 git rev-parse --verify refs/remotes/origin/side &&
518 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
519 git fetch alt &&
520 git remote prune alt &&
521 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
522 git rev-parse --verify refs/remotes/origin/side2
526 cat >test/expect <<\EOF
527 some-tag
530 test_expect_success 'add with reachable tags (default)' '
532 cd one &&
533 >foobar &&
534 git add foobar &&
535 git commit -m "Foobar" &&
536 git tag -a -m "Foobar tag" foobar-tag &&
537 git reset --hard HEAD~1 &&
538 git tag -a -m "Some tag" some-tag
539 ) &&
540 mkdir add-tags &&
542 cd add-tags &&
543 git init &&
544 git remote add -f origin ../one &&
545 git tag -l some-tag >../test/output &&
546 git tag -l foobar-tag >>../test/output &&
547 test_must_fail git config remote.origin.tagopt
548 ) &&
549 test_cmp test/expect test/output
552 cat >test/expect <<\EOF
553 some-tag
554 foobar-tag
555 --tags
558 test_expect_success 'add --tags' '
559 rm -rf add-tags &&
561 mkdir add-tags &&
562 cd add-tags &&
563 git init &&
564 git remote add -f --tags origin ../one &&
565 git tag -l some-tag >../test/output &&
566 git tag -l foobar-tag >>../test/output &&
567 git config remote.origin.tagopt >>../test/output
568 ) &&
569 test_cmp test/expect test/output
572 cat >test/expect <<\EOF
573 --no-tags
576 test_expect_success 'add --no-tags' '
577 rm -rf add-tags &&
579 mkdir add-no-tags &&
580 cd add-no-tags &&
581 git init &&
582 git remote add -f --no-tags origin ../one &&
583 git tag -l some-tag >../test/output &&
584 git tag -l foobar-tag >../test/output &&
585 git config remote.origin.tagopt >>../test/output
586 ) &&
588 cd one &&
589 git tag -d some-tag foobar-tag
590 ) &&
591 test_cmp test/expect test/output
594 test_expect_success 'reject --no-no-tags' '
596 cd add-no-tags &&
597 test_must_fail git remote add -f --no-no-tags neworigin ../one
601 cat >one/expect <<\EOF
602 apis/master
603 apis/side
604 drosophila/another
605 drosophila/master
606 drosophila/side
609 test_expect_success 'update' '
611 cd one &&
612 git remote add drosophila ../two &&
613 git remote add apis ../mirror &&
614 git remote update &&
615 git branch -r >output &&
616 test_cmp expect output
620 cat >one/expect <<\EOF
621 drosophila/another
622 drosophila/master
623 drosophila/side
624 manduca/master
625 manduca/side
626 megaloprepus/master
627 megaloprepus/side
630 test_expect_success 'update with arguments' '
632 cd one &&
633 for b in $(git branch -r)
635 git branch -r -d $b || exit 1
636 done &&
637 git remote add manduca ../mirror &&
638 git remote add megaloprepus ../mirror &&
639 git config remotes.phobaeticus "drosophila megaloprepus" &&
640 git config remotes.titanus manduca &&
641 git remote update phobaeticus titanus &&
642 git branch -r >output &&
643 test_cmp expect output
647 test_expect_success 'update --prune' '
649 cd one &&
650 git branch -m side2 side3
651 ) &&
653 cd test &&
654 git remote update --prune &&
656 cd ../one &&
657 git branch -m side3 side2
658 ) &&
659 git rev-parse refs/remotes/origin/side3 &&
660 test_must_fail git rev-parse refs/remotes/origin/side2
664 cat >one/expect <<-\EOF
665 apis/master
666 apis/side
667 manduca/master
668 manduca/side
669 megaloprepus/master
670 megaloprepus/side
673 test_expect_success 'update default' '
675 cd one &&
676 for b in $(git branch -r)
678 git branch -r -d $b || exit 1
679 done &&
680 git config remote.drosophila.skipDefaultUpdate true &&
681 git remote update default &&
682 git branch -r >output &&
683 test_cmp expect output
687 cat >one/expect <<\EOF
688 drosophila/another
689 drosophila/master
690 drosophila/side
693 test_expect_success 'update default (overridden, with funny whitespace)' '
695 cd one &&
696 for b in $(git branch -r)
698 git branch -r -d $b || exit 1
699 done &&
700 git config remotes.default "$(printf "\t drosophila \n")" &&
701 git remote update default &&
702 git branch -r >output &&
703 test_cmp expect output
707 test_expect_success 'update (with remotes.default defined)' '
709 cd one &&
710 for b in $(git branch -r)
712 git branch -r -d $b || exit 1
713 done &&
714 git config remotes.default "drosophila" &&
715 git remote update &&
716 git branch -r >output &&
717 test_cmp expect output
721 test_expect_success '"remote show" does not show symbolic refs' '
722 git clone one three &&
724 cd three &&
725 git remote show origin >output &&
726 ! grep "^ *HEAD$" < output &&
727 ! grep -i stale < output
731 test_expect_success 'reject adding remote with an invalid name' '
732 test_must_fail git remote add some:url desired-name
735 # The first three test if the tracking branches are properly renamed,
736 # the last two ones check if the config is updated.
738 test_expect_success 'rename a remote' '
739 git clone one four &&
741 cd four &&
742 git remote rename origin upstream &&
743 test -z "$(git for-each-ref refs/remotes/origin)" &&
744 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
745 test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
746 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
747 test "$(git config branch.master.remote)" = "upstream"
751 test_expect_success 'rename does not update a non-default fetch refspec' '
752 git clone one four.one &&
754 cd four.one &&
755 git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
756 git remote rename origin upstream &&
757 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" &&
758 git rev-parse -q origin/master
762 test_expect_success 'rename a remote with name part of fetch spec' '
763 git clone one four.two &&
765 cd four.two &&
766 git remote rename origin remote &&
767 git remote rename remote upstream &&
768 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*"
772 test_expect_success 'rename a remote with name prefix of other remote' '
773 git clone one four.three &&
775 cd four.three &&
776 git remote add o git://example.com/repo.git &&
777 git remote rename o upstream &&
778 test "$(git rev-parse origin/master)" = "$(git rev-parse master)"
782 test_expect_success 'rename succeeds with existing remote.<target>.prune' '
783 git clone one four.four &&
784 test_when_finished git config --global --unset remote.upstream.prune &&
785 git config --global remote.upstream.prune true &&
786 git -C four.four remote rename origin upstream
789 cat >remotes_origin <<EOF
790 URL: $(pwd)/one
791 Push: refs/heads/master:refs/heads/upstream
792 Push: refs/heads/next:refs/heads/upstream2
793 Pull: refs/heads/master:refs/heads/origin
794 Pull: refs/heads/next:refs/heads/origin2
797 test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
798 git clone one five &&
799 origin_url=$(pwd)/one &&
801 cd five &&
802 git remote remove origin &&
803 mkdir -p .git/remotes &&
804 cat ../remotes_origin >.git/remotes/origin &&
805 git remote rename origin origin &&
806 test_path_is_missing .git/remotes/origin &&
807 test "$(git config remote.origin.url)" = "$origin_url" &&
808 cat >push_expected <<-\EOF &&
809 refs/heads/master:refs/heads/upstream
810 refs/heads/next:refs/heads/upstream2
812 cat >fetch_expected <<-\EOF &&
813 refs/heads/master:refs/heads/origin
814 refs/heads/next:refs/heads/origin2
816 git config --get-all remote.origin.push >push_actual &&
817 git config --get-all remote.origin.fetch >fetch_actual &&
818 test_cmp push_expected push_actual &&
819 test_cmp fetch_expected fetch_actual
823 test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
824 git clone one six &&
825 origin_url=$(pwd)/one &&
827 cd six &&
828 git remote rm origin &&
829 echo "$origin_url" >.git/branches/origin &&
830 git remote rename origin origin &&
831 test_path_is_missing .git/branches/origin &&
832 test "$(git config remote.origin.url)" = "$origin_url" &&
833 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin" &&
834 test "$(git config remote.origin.push)" = "HEAD:refs/heads/master"
838 test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' '
839 git clone one seven &&
841 cd seven &&
842 git remote rm origin &&
843 echo "quux#foom" > .git/branches/origin &&
844 git remote rename origin origin &&
845 test_path_is_missing .git/branches/origin &&
846 test "$(git config remote.origin.url)" = "quux" &&
847 test "$(git config remote.origin.fetch)" = "refs/heads/foom:refs/heads/origin" &&
848 test "$(git config remote.origin.push)" = "HEAD:refs/heads/foom"
852 test_expect_success 'remote prune to cause a dangling symref' '
853 git clone one eight &&
855 cd one &&
856 git checkout side2 &&
857 git branch -D master
858 ) &&
860 cd eight &&
861 git remote prune origin
862 ) >err 2>&1 &&
863 test_i18ngrep "has become dangling" err &&
865 : And the dangling symref will not cause other annoying errors &&
867 cd eight &&
868 git branch -a
869 ) 2>err &&
870 ! grep "points nowhere" err &&
872 cd eight &&
873 test_must_fail git branch nomore origin
874 ) 2>err &&
875 grep "dangling symref" err
878 test_expect_success 'show empty remote' '
879 test_create_repo empty &&
880 git clone empty empty-clone &&
882 cd empty-clone &&
883 git remote show origin
887 test_expect_success 'remote set-branches requires a remote' '
888 test_must_fail git remote set-branches &&
889 test_must_fail git remote set-branches --add
892 test_expect_success 'remote set-branches' '
893 echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial &&
894 sort <<-\EOF >expect.add &&
895 +refs/heads/*:refs/remotes/scratch/*
896 +refs/heads/other:refs/remotes/scratch/other
898 sort <<-\EOF >expect.replace &&
899 +refs/heads/maint:refs/remotes/scratch/maint
900 +refs/heads/master:refs/remotes/scratch/master
901 +refs/heads/next:refs/remotes/scratch/next
903 sort <<-\EOF >expect.add-two &&
904 +refs/heads/maint:refs/remotes/scratch/maint
905 +refs/heads/master:refs/remotes/scratch/master
906 +refs/heads/next:refs/remotes/scratch/next
907 +refs/heads/pu:refs/remotes/scratch/pu
908 +refs/heads/t/topic:refs/remotes/scratch/t/topic
910 sort <<-\EOF >expect.setup-ffonly &&
911 refs/heads/master:refs/remotes/scratch/master
912 +refs/heads/next:refs/remotes/scratch/next
914 sort <<-\EOF >expect.respect-ffonly &&
915 refs/heads/master:refs/remotes/scratch/master
916 +refs/heads/next:refs/remotes/scratch/next
917 +refs/heads/pu:refs/remotes/scratch/pu
920 git clone .git/ setbranches &&
922 cd setbranches &&
923 git remote rename origin scratch &&
924 git config --get-all remote.scratch.fetch >config-result &&
925 sort <config-result >../actual.initial &&
927 git remote set-branches scratch --add other &&
928 git config --get-all remote.scratch.fetch >config-result &&
929 sort <config-result >../actual.add &&
931 git remote set-branches scratch maint master next &&
932 git config --get-all remote.scratch.fetch >config-result &&
933 sort <config-result >../actual.replace &&
935 git remote set-branches --add scratch pu t/topic &&
936 git config --get-all remote.scratch.fetch >config-result &&
937 sort <config-result >../actual.add-two &&
939 git config --unset-all remote.scratch.fetch &&
940 git config remote.scratch.fetch \
941 refs/heads/master:refs/remotes/scratch/master &&
942 git config --add remote.scratch.fetch \
943 +refs/heads/next:refs/remotes/scratch/next &&
944 git config --get-all remote.scratch.fetch >config-result &&
945 sort <config-result >../actual.setup-ffonly &&
947 git remote set-branches --add scratch pu &&
948 git config --get-all remote.scratch.fetch >config-result &&
949 sort <config-result >../actual.respect-ffonly
950 ) &&
951 test_cmp expect.initial actual.initial &&
952 test_cmp expect.add actual.add &&
953 test_cmp expect.replace actual.replace &&
954 test_cmp expect.add-two actual.add-two &&
955 test_cmp expect.setup-ffonly actual.setup-ffonly &&
956 test_cmp expect.respect-ffonly actual.respect-ffonly
959 test_expect_success 'remote set-branches with --mirror' '
960 echo "+refs/*:refs/*" >expect.initial &&
961 echo "+refs/heads/master:refs/heads/master" >expect.replace &&
962 git clone --mirror .git/ setbranches-mirror &&
964 cd setbranches-mirror &&
965 git remote rename origin scratch &&
966 git config --get-all remote.scratch.fetch >../actual.initial &&
968 git remote set-branches scratch heads/master &&
969 git config --get-all remote.scratch.fetch >../actual.replace
970 ) &&
971 test_cmp expect.initial actual.initial &&
972 test_cmp expect.replace actual.replace
975 test_expect_success 'new remote' '
976 git remote add someremote foo &&
977 echo foo >expect &&
978 git config --get-all remote.someremote.url >actual &&
979 cmp expect actual
982 get_url_test () {
983 cat >expect &&
984 git remote get-url "$@" >actual &&
985 test_cmp expect actual
988 test_expect_success 'get-url on new remote' '
989 echo foo | get_url_test someremote &&
990 echo foo | get_url_test --all someremote &&
991 echo foo | get_url_test --push someremote &&
992 echo foo | get_url_test --push --all someremote
995 test_expect_success 'remote set-url with locked config' '
996 test_when_finished "rm -f .git/config.lock" &&
997 git config --get-all remote.someremote.url >expect &&
998 >.git/config.lock &&
999 test_must_fail git remote set-url someremote baz &&
1000 git config --get-all remote.someremote.url >actual &&
1001 cmp expect actual
1004 test_expect_success 'remote set-url bar' '
1005 git remote set-url someremote bar &&
1006 echo bar >expect &&
1007 git config --get-all remote.someremote.url >actual &&
1008 cmp expect actual
1011 test_expect_success 'remote set-url baz bar' '
1012 git remote set-url someremote baz bar &&
1013 echo baz >expect &&
1014 git config --get-all remote.someremote.url >actual &&
1015 cmp expect actual
1018 test_expect_success 'remote set-url zot bar' '
1019 test_must_fail git remote set-url someremote zot bar &&
1020 echo baz >expect &&
1021 git config --get-all remote.someremote.url >actual &&
1022 cmp expect actual
1025 test_expect_success 'remote set-url --push zot baz' '
1026 test_must_fail git remote set-url --push someremote zot baz &&
1027 echo "YYY" >expect &&
1028 echo baz >>expect &&
1029 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1030 echo "YYY" >>actual &&
1031 git config --get-all remote.someremote.url >>actual &&
1032 cmp expect actual
1035 test_expect_success 'remote set-url --push zot' '
1036 git remote set-url --push someremote zot &&
1037 echo zot >expect &&
1038 echo "YYY" >>expect &&
1039 echo baz >>expect &&
1040 git config --get-all remote.someremote.pushurl >actual &&
1041 echo "YYY" >>actual &&
1042 git config --get-all remote.someremote.url >>actual &&
1043 cmp expect actual
1046 test_expect_success 'get-url with different urls' '
1047 echo baz | get_url_test someremote &&
1048 echo baz | get_url_test --all someremote &&
1049 echo zot | get_url_test --push someremote &&
1050 echo zot | get_url_test --push --all someremote
1053 test_expect_success 'remote set-url --push qux zot' '
1054 git remote set-url --push someremote qux zot &&
1055 echo qux >expect &&
1056 echo "YYY" >>expect &&
1057 echo baz >>expect &&
1058 git config --get-all remote.someremote.pushurl >actual &&
1059 echo "YYY" >>actual &&
1060 git config --get-all remote.someremote.url >>actual &&
1061 cmp expect actual
1064 test_expect_success 'remote set-url --push foo qu+x' '
1065 git remote set-url --push someremote foo qu+x &&
1066 echo foo >expect &&
1067 echo "YYY" >>expect &&
1068 echo baz >>expect &&
1069 git config --get-all remote.someremote.pushurl >actual &&
1070 echo "YYY" >>actual &&
1071 git config --get-all remote.someremote.url >>actual &&
1072 cmp expect actual
1075 test_expect_success 'remote set-url --push --add aaa' '
1076 git remote set-url --push --add someremote aaa &&
1077 echo foo >expect &&
1078 echo aaa >>expect &&
1079 echo "YYY" >>expect &&
1080 echo baz >>expect &&
1081 git config --get-all remote.someremote.pushurl >actual &&
1082 echo "YYY" >>actual &&
1083 git config --get-all remote.someremote.url >>actual &&
1084 cmp expect actual
1087 test_expect_success 'get-url on multi push remote' '
1088 echo foo | get_url_test --push someremote &&
1089 get_url_test --push --all someremote <<-\EOF
1095 test_expect_success 'remote set-url --push bar aaa' '
1096 git remote set-url --push someremote bar aaa &&
1097 echo foo >expect &&
1098 echo bar >>expect &&
1099 echo "YYY" >>expect &&
1100 echo baz >>expect &&
1101 git config --get-all remote.someremote.pushurl >actual &&
1102 echo "YYY" >>actual &&
1103 git config --get-all remote.someremote.url >>actual &&
1104 cmp expect actual
1107 test_expect_success 'remote set-url --push --delete bar' '
1108 git remote set-url --push --delete someremote bar &&
1109 echo foo >expect &&
1110 echo "YYY" >>expect &&
1111 echo baz >>expect &&
1112 git config --get-all remote.someremote.pushurl >actual &&
1113 echo "YYY" >>actual &&
1114 git config --get-all remote.someremote.url >>actual &&
1115 cmp expect actual
1118 test_expect_success 'remote set-url --push --delete foo' '
1119 git remote set-url --push --delete someremote foo &&
1120 echo "YYY" >expect &&
1121 echo baz >>expect &&
1122 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1123 echo "YYY" >>actual &&
1124 git config --get-all remote.someremote.url >>actual &&
1125 cmp expect actual
1128 test_expect_success 'remote set-url --add bbb' '
1129 git remote set-url --add someremote bbb &&
1130 echo "YYY" >expect &&
1131 echo baz >>expect &&
1132 echo bbb >>expect &&
1133 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1134 echo "YYY" >>actual &&
1135 git config --get-all remote.someremote.url >>actual &&
1136 cmp expect actual
1139 test_expect_success 'get-url on multi fetch remote' '
1140 echo baz | get_url_test someremote &&
1141 get_url_test --all someremote <<-\EOF
1147 test_expect_success 'remote set-url --delete .*' '
1148 test_must_fail git remote set-url --delete someremote .\* &&
1149 echo "YYY" >expect &&
1150 echo baz >>expect &&
1151 echo bbb >>expect &&
1152 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1153 echo "YYY" >>actual &&
1154 git config --get-all remote.someremote.url >>actual &&
1155 cmp expect actual
1158 test_expect_success 'remote set-url --delete bbb' '
1159 git remote set-url --delete someremote bbb &&
1160 echo "YYY" >expect &&
1161 echo baz >>expect &&
1162 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1163 echo "YYY" >>actual &&
1164 git config --get-all remote.someremote.url >>actual &&
1165 cmp expect actual
1168 test_expect_success 'remote set-url --delete baz' '
1169 test_must_fail git remote set-url --delete someremote baz &&
1170 echo "YYY" >expect &&
1171 echo baz >>expect &&
1172 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1173 echo "YYY" >>actual &&
1174 git config --get-all remote.someremote.url >>actual &&
1175 cmp expect actual
1178 test_expect_success 'remote set-url --add ccc' '
1179 git remote set-url --add someremote ccc &&
1180 echo "YYY" >expect &&
1181 echo baz >>expect &&
1182 echo ccc >>expect &&
1183 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1184 echo "YYY" >>actual &&
1185 git config --get-all remote.someremote.url >>actual &&
1186 cmp expect actual
1189 test_expect_success 'remote set-url --delete baz' '
1190 git remote set-url --delete someremote baz &&
1191 echo "YYY" >expect &&
1192 echo ccc >>expect &&
1193 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1194 echo "YYY" >>actual &&
1195 git config --get-all remote.someremote.url >>actual &&
1196 cmp expect actual
1199 test_expect_success 'extra args: setup' '
1200 # add a dummy origin so that this does not trigger failure
1201 git remote add origin .
1204 test_extra_arg () {
1205 test_expect_success "extra args: $*" "
1206 test_must_fail git remote $* bogus_extra_arg 2>actual &&
1207 test_i18ngrep '^usage:' actual
1211 test_extra_arg add nick url
1212 test_extra_arg rename origin newname
1213 test_extra_arg remove origin
1214 test_extra_arg set-head origin master
1215 # set-branches takes any number of args
1216 test_extra_arg get-url origin newurl
1217 test_extra_arg set-url origin newurl oldurl
1218 # show takes any number of args
1219 # prune takes any number of args
1220 # update takes any number of args
1222 test_expect_success 'add remote matching the "insteadOf" URL' '
1223 git config url.xyz@example.com.insteadOf backup &&
1224 git remote add backup xyz@example.com
1227 test_done