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
'
45 setup_repository one &&
46 setup_repository two &&
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
'remote information for the origin' '
62 tokens_match origin "$(git remote)" &&
63 check_remote_track origin main side &&
64 check_tracking_branch origin HEAD main side
68 test_expect_success
'add another remote' '
71 git remote add -f second ../two &&
72 tokens_match "origin second" "$(git remote)" &&
73 check_tracking_branch second main 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 test_must_be_empty actual
81 test_expect_success
'check remote-tracking' '
84 check_remote_track origin main side &&
85 check_remote_track second main side another
89 test_expect_success
'remote forces tracking branches' '
92 case $(git config remote.second.fetch) in
99 test_expect_success
'remove remote' '
102 git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/main &&
107 test_expect_success
'remove remote' '
110 tokens_match origin "$(git remote)" &&
111 check_remote_track origin main side &&
112 git for-each-ref "--format=%(refname)" refs/remotes |
113 sed -e "/^refs\/remotes\/origin\//d" >actual &&
114 test_must_be_empty actual
118 test_expect_success
'remove remote protects local branches' '
121 cat >expect1 <<-\EOF &&
122 Note: A branch outside the refs/remotes/ hierarchy was not removed;
126 cat >expect2 <<-\EOF &&
127 Note: Some branches outside the refs/remotes/ hierarchy were not removed;
129 git branch -d foobranch
133 git config --add remote.oops.fetch "+refs/*:refs/*" &&
134 git remote remove oops 2>actual1 &&
135 git branch foobranch &&
136 git config --add remote.oops.fetch "+refs/*:refs/*" &&
137 git remote rm oops 2>actual2 &&
138 git branch -d foobranch &&
140 test_cmp expect1 actual1 &&
141 test_cmp expect2 actual2
145 test_expect_success
'remove errors out early when deleting non-existent branch' '
148 echo "error: No such remote: '\''foo'\''" >expect &&
149 test_expect_code 2 git remote rm foo 2>actual &&
150 test_cmp expect actual
154 test_expect_success
'remove remote with a branch without configured merge' '
155 test_when_finished "(
156 git -C test checkout main;
157 git -C test branch -D two;
158 git -C test config --remove-section remote.two;
159 git -C test config --remove-section branch.second;
164 git remote add two ../two &&
166 git checkout -b second two/main^0 &&
167 git config branch.second.remote two &&
173 test_expect_success
'rename errors out early when deleting non-existent branch' '
176 echo "error: No such remote: '\''foo'\''" >expect &&
177 test_expect_code 2 git remote rename foo bar 2>actual &&
178 test_cmp expect actual
182 test_expect_success
'rename errors out early when new name is invalid' '
183 test_config remote.foo.vcs bar &&
184 echo "fatal: '\''invalid...name'\'' is not a valid remote name" >expect &&
185 test_must_fail git remote rename foo invalid...name 2>actual &&
186 test_cmp expect actual
189 test_expect_success
'add existing foreign_vcs remote' '
190 test_config remote.foo.vcs bar &&
191 echo "error: remote foo already exists." >expect &&
192 test_expect_code 3 git remote add foo bar 2>actual &&
193 test_cmp expect actual
196 test_expect_success
'add existing foreign_vcs remote' '
197 test_config remote.foo.vcs bar &&
198 test_config remote.bar.vcs bar &&
199 echo "error: remote bar already exists." >expect &&
200 test_expect_code 3 git remote rename foo bar 2>actual &&
201 test_cmp expect actual
204 test_expect_success
'add invalid foreign_vcs remote' '
205 echo "fatal: '\''invalid...name'\'' is not a valid remote name" >expect &&
206 test_must_fail git remote add invalid...name bar 2>actual &&
207 test_cmp expect actual
210 cat >test
/expect
<<EOF
212 Fetch URL: $(pwd)/one
216 main new (next fetch will store in remotes/origin)
218 Local branches configured for 'git pull':
219 ahead merges with remote main
220 main merges with remote main
221 octopus merges with remote topic-a
222 and with remote topic-b
223 and with remote topic-c
224 rebase rebases onto remote main
225 Local refs configured for 'git push':
226 main pushes to main (local out of date)
227 main pushes to upstream (create)
232 Local refs configured for 'git push':
233 ahead forces to main (fast-forwardable)
234 main pushes to another (up to date)
237 test_expect_success
'show' '
240 git config --add remote.origin.fetch refs/heads/main:refs/heads/upstream &&
242 git checkout -b ahead origin/main &&
245 git commit -m update file &&
247 git branch --track octopus origin/main &&
248 git branch --track rebase origin/main &&
249 git branch -d -r origin/main &&
250 git config --add remote.two.url ../two &&
251 git config --add remote.two.pushurl ../three &&
252 git config branch.rebase.rebase true &&
253 git config branch.octopus.merge "topic-a topic-b topic-c" &&
258 git commit -m update file
260 git config --add remote.origin.push : &&
261 git config --add remote.origin.push refs/heads/main:refs/heads/upstream &&
262 git config --add remote.origin.push +refs/tags/lastbackup &&
263 git config --add remote.two.push +refs/heads/ahead:refs/heads/main &&
264 git config --add remote.two.push refs/heads/main:refs/heads/another &&
265 git remote show origin two >output &&
266 git branch -d rebase octopus &&
267 test_cmp expect output
271 cat >test
/expect
<<EOF
273 Fetch URL: $(pwd)/one
275 HEAD branch: (not queried)
276 Remote branches: (status not queried)
279 Local branches configured for 'git pull':
280 ahead merges with remote main
281 main merges with remote main
282 Local refs configured for 'git push' (status not queried):
283 (matching) pushes to (matching)
284 refs/heads/main pushes to refs/heads/upstream
285 refs/tags/lastbackup forces to refs/tags/lastbackup
288 test_expect_success
'show -n' '
289 mv one one.unreachable &&
292 git remote show -n origin >output &&
293 mv ../one.unreachable ../one &&
294 test_cmp expect output
298 test_expect_success
'prune' '
301 git branch -m side side2
306 git remote prune origin &&
307 git rev-parse refs/remotes/origin/side2 &&
308 test_must_fail git rev-parse refs/remotes/origin/side
312 test_expect_success
'set-head --delete' '
315 git symbolic-ref refs/remotes/origin/HEAD &&
316 git remote set-head --delete origin &&
317 test_must_fail git symbolic-ref refs/remotes/origin/HEAD
321 test_expect_success
'set-head --auto' '
324 git remote set-head --auto origin &&
325 echo refs/remotes/origin/main >expect &&
326 git symbolic-ref refs/remotes/origin/HEAD >output &&
327 test_cmp expect output
331 test_expect_success
'set-head --auto has no problem w/multiple HEADs' '
334 git fetch two "refs/heads/*:refs/remotes/two/*" &&
335 git remote set-head --auto two >output 2>&1 &&
336 echo "two/HEAD set to main" >expect &&
337 test_cmp expect output
341 cat >test
/expect
<<\EOF
342 refs
/remotes
/origin
/side2
345 test_expect_success
'set-head explicit' '
348 git remote set-head origin side2 &&
349 git symbolic-ref refs/remotes/origin/HEAD >output &&
350 git remote set-head origin main &&
351 test_cmp expect output
355 cat >test
/expect
<<EOF
358 * [would prune] origin/side2
361 test_expect_success
'prune --dry-run' '
362 git -C one branch -m side2 side &&
363 test_when_finished "git -C one branch -m side side2" &&
366 git remote prune --dry-run origin >output &&
367 git rev-parse refs/remotes/origin/side2 &&
368 test_must_fail git rev-parse refs/remotes/origin/side &&
369 test_cmp expect output
373 test_expect_success
'add --mirror && prune' '
378 git remote add --mirror -f origin ../one
382 git branch -m side2 side
386 git rev-parse --verify refs/heads/side2 &&
387 test_must_fail git rev-parse --verify refs/heads/side &&
389 git remote prune origin &&
390 test_must_fail git rev-parse --verify refs/heads/side2 &&
391 git rev-parse --verify refs/heads/side
395 test_expect_success
'add --mirror=fetch' '
396 mkdir mirror-fetch &&
397 git init -b main mirror-fetch/parent &&
399 cd mirror-fetch/parent &&
402 git init --bare mirror-fetch/child &&
404 cd mirror-fetch/child &&
405 git remote add --mirror=fetch -f parent ../parent
409 test_expect_success
'fetch mirrors act as mirrors during fetch' '
411 cd mirror-fetch/parent &&
413 git branch -m main renamed
416 cd mirror-fetch/child &&
418 git rev-parse --verify refs/heads/new &&
419 git rev-parse --verify refs/heads/renamed
423 test_expect_success
'fetch mirrors can prune' '
425 cd mirror-fetch/child &&
426 git remote prune parent &&
427 test_must_fail git rev-parse --verify refs/heads/main
431 test_expect_success
'fetch mirrors do not act as mirrors during push' '
433 cd mirror-fetch/parent &&
437 cd mirror-fetch/child &&
438 git branch -m renamed renamed2 &&
442 cd mirror-fetch/parent &&
443 git rev-parse --verify renamed &&
444 test_must_fail git rev-parse --verify refs/heads/renamed2
448 test_expect_success
'add fetch mirror with specific branches' '
449 git init --bare mirror-fetch/track &&
451 cd mirror-fetch/track &&
452 git remote add --mirror=fetch -t heads/new parent ../parent
456 test_expect_success
'fetch mirror respects specific branches' '
458 cd mirror-fetch/track &&
460 git rev-parse --verify refs/heads/new &&
461 test_must_fail git rev-parse --verify refs/heads/renamed
465 test_expect_success
'add --mirror=push' '
467 git init --bare mirror-push/public &&
468 git init -b main mirror-push/private &&
470 cd mirror-push/private &&
472 git remote add --mirror=push public ../public
476 test_expect_success
'push mirrors act as mirrors during push' '
478 cd mirror-push/private &&
480 git branch -m main renamed &&
484 cd mirror-push/private &&
485 git rev-parse --verify refs/heads/new &&
486 git rev-parse --verify refs/heads/renamed &&
487 test_must_fail git rev-parse --verify refs/heads/main
491 test_expect_success
'push mirrors do not act as mirrors during fetch' '
493 cd mirror-push/public &&
494 git branch -m renamed renamed2 &&
495 git symbolic-ref HEAD refs/heads/renamed2
498 cd mirror-push/private &&
500 git rev-parse --verify refs/heads/renamed &&
501 test_must_fail git rev-parse --verify refs/heads/renamed2
505 test_expect_success
'push mirrors do not allow you to specify refs' '
506 git init mirror-push/track &&
508 cd mirror-push/track &&
509 test_must_fail git remote add --mirror=push -t new public ../public
513 test_expect_success
'add alt && prune' '
518 git remote add -f origin ../one &&
519 git config remote.alt.url ../one &&
520 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*"
524 git branch -m side side2
528 git rev-parse --verify refs/remotes/origin/side &&
529 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
531 git remote prune alt &&
532 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
533 git rev-parse --verify refs/remotes/origin/side2
537 cat >test
/expect
<<\EOF
541 test_expect_success
'add with reachable tags (default)' '
546 git commit -m "Foobar" &&
547 git tag -a -m "Foobar tag" foobar-tag &&
548 git reset --hard HEAD~1 &&
549 git tag -a -m "Some tag" some-tag
555 git remote add -f origin ../one &&
556 git tag -l some-tag >../test/output &&
557 git tag -l foobar-tag >>../test/output &&
558 test_must_fail git config remote.origin.tagopt
560 test_cmp test/expect test/output
563 cat >test
/expect
<<\EOF
569 test_expect_success
'add --tags' '
575 git remote add -f --tags origin ../one &&
576 git tag -l some-tag >../test/output &&
577 git tag -l foobar-tag >>../test/output &&
578 git config remote.origin.tagopt >>../test/output
580 test_cmp test/expect test/output
583 cat >test
/expect
<<\EOF
587 test_expect_success
'add --no-tags' '
593 git remote add -f --no-tags origin ../one &&
594 grep tagOpt .git/config &&
595 git tag -l some-tag >../test/output &&
596 git tag -l foobar-tag >../test/output &&
597 git config remote.origin.tagopt >>../test/output
601 git tag -d some-tag foobar-tag
603 test_cmp test/expect test/output
606 test_expect_success
'reject --no-no-tags' '
609 test_must_fail git remote add -f --no-no-tags neworigin ../one
613 cat >one
/expect
<<\EOF
621 test_expect_success
'update' '
624 git remote add drosophila ../two &&
625 git remote add apis ../mirror &&
627 git branch -r >output &&
628 test_cmp expect output
632 cat >one
/expect
<<\EOF
642 test_expect_success
'update with arguments' '
645 for b in $(git branch -r)
647 git branch -r -d $b || exit 1
649 git remote add manduca ../mirror &&
650 git remote add megaloprepus ../mirror &&
651 git config remotes.phobaeticus "drosophila megaloprepus" &&
652 git config remotes.titanus manduca &&
653 git remote update phobaeticus titanus &&
654 git branch -r >output &&
655 test_cmp expect output
659 test_expect_success
'update --prune' '
662 git branch -m side2 side3
666 git remote update --prune &&
669 git branch -m side3 side2
671 git rev-parse refs/remotes/origin/side3 &&
672 test_must_fail git rev-parse refs/remotes/origin/side2
676 cat >one
/expect
<<-\EOF
685 test_expect_success 'update default' '
688 for b in $(git branch -r)
690 git branch -r -d $b || exit 1
692 git config remote.drosophila.skipDefaultUpdate true &&
693 git remote update default &&
694 git branch -r >output &&
695 test_cmp expect output
699 cat >one/expect <<\EOF
705 test_expect_success 'update default (overridden, with funny whitespace)' '
708 for b in $(git branch -r)
710 git branch -r -d $b || exit 1
712 git config remotes.default "$(printf "\t drosophila \n")" &&
713 git remote update default &&
714 git branch -r >output &&
715 test_cmp expect output
719 test_expect_success 'update (with remotes.default defined)' '
722 for b in $(git branch -r)
724 git branch -r -d $b || exit 1
726 git config remotes.default "drosophila" &&
728 git branch -r >output &&
729 test_cmp expect output
733 test_expect_success '"remote show" does not show symbolic refs' '
734 git clone one three &&
737 git remote show origin >output &&
738 ! grep "^ *HEAD$" < output &&
739 ! grep -i stale < output
743 test_expect_success 'reject adding remote with an invalid name' '
744 test_must_fail git remote add some:url desired-name
747 # The first three test if the tracking branches are properly renamed,
748 # the last two ones check if the config is updated.
750 test_expect_success 'rename a remote' '
751 test_config_global remote.pushDefault origin &&
752 git clone one four &&
755 git config branch.main.pushRemote origin &&
756 git remote rename origin upstream &&
757 grep "pushRemote" .git/config &&
758 test -z "$(git for-each-ref refs/remotes/origin)" &&
759 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/main" &&
760 test "$(git rev-parse upstream/main)" = "$(git rev-parse main)" &&
761 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
762 test "$(git config branch.main.remote)" = "upstream" &&
763 test "$(git config branch.main.pushRemote)" = "upstream" &&
764 test "$(git config --global remote.pushDefault)" = "origin"
768 test_expect_success 'rename a remote renames repo remote.pushDefault' '
769 git clone one four.1 &&
772 git config remote.pushDefault origin &&
773 git remote rename origin upstream &&
774 grep pushDefault .git/config &&
775 test "$(git config --local remote.pushDefault)" = "upstream"
779 test_expect_success 'rename a remote renames repo remote.pushDefault but ignores global' '
780 test_config_global remote.pushDefault other &&
781 git clone one four.2 &&
784 git config remote.pushDefault origin &&
785 git remote rename origin upstream &&
786 test "$(git config --global remote.pushDefault)" = "other" &&
787 test "$(git config --local remote.pushDefault)" = "upstream"
791 test_expect_success 'rename a remote renames repo remote.pushDefault but keeps global' '
792 test_config_global remote.pushDefault origin &&
793 git clone one four.3 &&
796 git config remote.pushDefault origin &&
797 git remote rename origin upstream &&
798 test "$(git config --global remote.pushDefault)" = "origin" &&
799 test "$(git config --local remote.pushDefault)" = "upstream"
803 test_expect_success 'rename does not update a non-default fetch refspec' '
804 git clone one four.one &&
807 git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
808 git remote rename origin upstream &&
809 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" &&
810 git rev-parse -q origin/main
814 test_expect_success 'rename a remote with name part of fetch spec' '
815 git clone one four.two &&
818 git remote rename origin remote &&
819 git remote rename remote upstream &&
820 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*"
824 test_expect_success 'rename a remote with name prefix of other remote' '
825 git clone one four.three &&
828 git remote add o git://example.com/repo.git &&
829 git remote rename o upstream &&
830 test "$(git rev-parse origin/main)" = "$(git rev-parse main)"
834 test_expect_success 'rename succeeds with existing remote.<target>.prune' '
835 git clone one four.four &&
836 test_when_finished git config --global --unset remote.upstream.prune &&
837 git config --global remote.upstream.prune true &&
838 git -C four.four remote rename origin upstream
841 test_expect_success 'remove a remote' '
842 test_config_global remote.pushDefault origin &&
843 git clone one four.five &&
846 git config branch.main.pushRemote origin &&
847 git remote remove origin &&
848 test -z "$(git for-each-ref refs/remotes/origin)" &&
849 test_must_fail git config branch.main.remote &&
850 test_must_fail git config branch.main.pushRemote &&
851 test "$(git config --global remote.pushDefault)" = "origin"
855 test_expect_success 'remove a remote removes repo remote.pushDefault' '
856 git clone one four.five.1 &&
859 git config remote.pushDefault origin &&
860 git remote remove origin &&
861 test_must_fail git config --local remote.pushDefault
865 test_expect_success 'remove a remote removes repo remote.pushDefault but ignores global' '
866 test_config_global remote.pushDefault other &&
867 git clone one four.five.2 &&
870 git config remote.pushDefault origin &&
871 git remote remove origin &&
872 test "$(git config --global remote.pushDefault)" = "other" &&
873 test_must_fail git config --local remote.pushDefault
877 test_expect_success 'remove a remote removes repo remote.pushDefault but keeps global' '
878 test_config_global remote.pushDefault origin &&
879 git clone one four.five.3 &&
882 git config remote.pushDefault origin &&
883 git remote remove origin &&
884 test "$(git config --global remote.pushDefault)" = "origin" &&
885 test_must_fail git config --local remote.pushDefault
889 cat >remotes_origin <<EOF
891 Push: refs/heads/main:refs/heads/upstream
892 Push: refs/heads/next:refs/heads/upstream2
893 Pull: refs/heads/main:refs/heads/origin
894 Pull: refs/heads/next:refs/heads/origin2
897 test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
898 git clone one five &&
899 origin_url=$(pwd)/one &&
902 git remote remove origin &&
903 mkdir -p .git/remotes &&
904 cat ../remotes_origin >.git/remotes/origin &&
905 git remote rename origin origin &&
906 test_path_is_missing .git/remotes/origin &&
907 test "$(git config remote.origin.url)" = "$origin_url" &&
908 cat >push_expected <<-\
EOF &&
909 refs/heads/main:refs/heads/upstream
910 refs/heads/next:refs/heads/upstream2
912 cat >fetch_expected <<-\EOF &&
913 refs/heads/main:refs/heads/origin
914 refs/heads/next:refs/heads/origin2
916 git config --get-all remote.origin.push >push_actual &&
917 git config --get-all remote.origin.fetch >fetch_actual &&
918 test_cmp push_expected push_actual &&
919 test_cmp fetch_expected fetch_actual
923 test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
925 origin_url=$(pwd)/one &&
928 git remote rm origin &&
929 echo "$origin_url#main" >.git/branches/origin &&
930 git remote rename origin origin &&
931 test_path_is_missing .git/branches/origin &&
932 test "$(git config remote.origin.url)" = "$origin_url" &&
933 test "$(git config remote.origin.fetch)" = "refs/heads/main:refs/heads/origin" &&
934 test "$(git config remote.origin.push)" = "HEAD:refs/heads/main"
938 test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' '
939 git clone one seven &&
942 git remote rm origin &&
943 echo "quux#foom" > .git/branches/origin &&
944 git remote rename origin origin &&
945 test_path_is_missing .git/branches/origin &&
946 test "$(git config remote.origin.url)" = "quux" &&
947 test "$(git config remote.origin.fetch)" = "refs/heads/foom:refs/heads/origin" &&
948 test "$(git config remote.origin.push)" = "HEAD:refs/heads/foom"
952 test_expect_success 'remote prune to cause a dangling symref' '
953 git clone one eight &&
956 git checkout side2 &&
961 git remote prune origin
963 test_i18ngrep "has become dangling" err &&
965 : And the dangling symref will not cause other annoying errors &&
970 ! grep "points nowhere" err &&
973 test_must_fail git branch nomore origin
975 test_i18ngrep "dangling symref" err
978 test_expect_success 'show empty remote' '
979 test_create_repo empty &&
980 git clone empty empty-clone &&
983 git remote show origin
987 test_expect_success 'remote set-branches requires a remote' '
988 test_must_fail git remote set-branches &&
989 test_must_fail git remote set-branches --add
992 test_expect_success 'remote set-branches' '
993 echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial &&
994 sort <<-\EOF >expect.add &&
995 +refs/heads/*:refs/remotes/scratch/*
996 +refs/heads/other:refs/remotes/scratch/other
998 sort <<-\EOF >expect.replace &&
999 +refs/heads/maint:refs/remotes/scratch/maint
1000 +refs/heads/main:refs/remotes/scratch/main
1001 +refs/heads/next:refs/remotes/scratch/next
1003 sort <<-\EOF >expect.add-two &&
1004 +refs/heads/maint:refs/remotes/scratch/maint
1005 +refs/heads/main:refs/remotes/scratch/main
1006 +refs/heads/next:refs/remotes/scratch/next
1007 +refs/heads/seen:refs/remotes/scratch/seen
1008 +refs/heads/t/topic:refs/remotes/scratch/t/topic
1010 sort <<-\EOF >expect.setup-ffonly &&
1011 refs/heads/main:refs/remotes/scratch/main
1012 +refs/heads/next:refs/remotes/scratch/next
1014 sort <<-\EOF >expect.respect-ffonly &&
1015 refs/heads/main:refs/remotes/scratch/main
1016 +refs/heads/next:refs/remotes/scratch/next
1017 +refs/heads/seen:refs/remotes/scratch/seen
1020 git clone .git/ setbranches &&
1023 git remote rename origin scratch &&
1024 git config --get-all remote.scratch.fetch >config-result &&
1025 sort <config-result >../actual.initial &&
1027 git remote set-branches scratch --add other &&
1028 git config --get-all remote.scratch.fetch >config-result &&
1029 sort <config-result >../actual.add &&
1031 git remote set-branches scratch maint main next &&
1032 git config --get-all remote.scratch.fetch >config-result &&
1033 sort <config-result >../actual.replace &&
1035 git remote set-branches --add scratch seen t/topic &&
1036 git config --get-all remote.scratch.fetch >config-result &&
1037 sort <config-result >../actual.add-two &&
1039 git config --unset-all remote.scratch.fetch &&
1040 git config remote.scratch.fetch \
1041 refs/heads/main:refs/remotes/scratch/main &&
1042 git config --add remote.scratch.fetch \
1043 +refs/heads/next:refs/remotes/scratch/next &&
1044 git config --get-all remote.scratch.fetch >config-result &&
1045 sort <config-result >../actual.setup-ffonly &&
1047 git remote set-branches --add scratch seen &&
1048 git config --get-all remote.scratch.fetch >config-result &&
1049 sort <config-result >../actual.respect-ffonly
1051 test_cmp expect.initial actual.initial &&
1052 test_cmp expect.add actual.add &&
1053 test_cmp expect.replace actual.replace &&
1054 test_cmp expect.add-two actual.add-two &&
1055 test_cmp expect.setup-ffonly actual.setup-ffonly &&
1056 test_cmp expect.respect-ffonly actual.respect-ffonly
1059 test_expect_success 'remote set-branches with --mirror' '
1060 echo "+refs/*:refs/*" >expect.initial &&
1061 echo "+refs/heads/main:refs/heads/main" >expect.replace &&
1062 git clone --mirror .git/ setbranches-mirror &&
1064 cd setbranches-mirror &&
1065 git remote rename origin scratch &&
1066 git config --get-all remote.scratch.fetch >../actual.initial &&
1068 git remote set-branches scratch heads/main &&
1069 git config --get-all remote.scratch.fetch >../actual.replace
1071 test_cmp expect.initial actual.initial &&
1072 test_cmp expect.replace actual.replace
1075 test_expect_success 'new remote' '
1076 git remote add someremote foo &&
1078 git config --get-all remote.someremote.url >actual &&
1084 git remote get-url "$@" >actual &&
1085 test_cmp expect actual
1088 test_expect_success 'get-url on new remote' '
1089 echo foo | get_url_test someremote &&
1090 echo foo | get_url_test --all someremote &&
1091 echo foo | get_url_test --push someremote &&
1092 echo foo | get_url_test --push --all someremote
1095 test_expect_success 'remote set-url with locked config' '
1096 test_when_finished "rm -f .git/config.lock" &&
1097 git config --get-all remote.someremote.url >expect &&
1098 >.git/config.lock &&
1099 test_must_fail git remote set-url someremote baz &&
1100 git config --get-all remote.someremote.url >actual &&
1104 test_expect_success 'remote set-url bar' '
1105 git remote set-url someremote bar &&
1107 git config --get-all remote.someremote.url >actual &&
1111 test_expect_success 'remote set-url baz bar' '
1112 git remote set-url someremote baz bar &&
1114 git config --get-all remote.someremote.url >actual &&
1118 test_expect_success 'remote set-url zot bar' '
1119 test_must_fail git remote set-url someremote zot bar &&
1121 git config --get-all remote.someremote.url >actual &&
1125 test_expect_success 'remote set-url --push zot baz' '
1126 test_must_fail git remote set-url --push someremote zot baz &&
1127 echo "YYY" >expect &&
1128 echo baz >>expect &&
1129 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1130 echo "YYY" >>actual &&
1131 git config --get-all remote.someremote.url >>actual &&
1135 test_expect_success 'remote set-url --push zot' '
1136 git remote set-url --push someremote zot &&
1138 echo "YYY" >>expect &&
1139 echo baz >>expect &&
1140 git config --get-all remote.someremote.pushurl >actual &&
1141 echo "YYY" >>actual &&
1142 git config --get-all remote.someremote.url >>actual &&
1146 test_expect_success 'get-url with different urls' '
1147 echo baz | get_url_test someremote &&
1148 echo baz | get_url_test --all someremote &&
1149 echo zot | get_url_test --push someremote &&
1150 echo zot | get_url_test --push --all someremote
1153 test_expect_success 'remote set-url --push qux zot' '
1154 git remote set-url --push someremote qux zot &&
1156 echo "YYY" >>expect &&
1157 echo baz >>expect &&
1158 git config --get-all remote.someremote.pushurl >actual &&
1159 echo "YYY" >>actual &&
1160 git config --get-all remote.someremote.url >>actual &&
1164 test_expect_success 'remote set-url --push foo qu+x' '
1165 git remote set-url --push someremote foo qu+x &&
1167 echo "YYY" >>expect &&
1168 echo baz >>expect &&
1169 git config --get-all remote.someremote.pushurl >actual &&
1170 echo "YYY" >>actual &&
1171 git config --get-all remote.someremote.url >>actual &&
1175 test_expect_success 'remote set-url --push --add aaa' '
1176 git remote set-url --push --add someremote aaa &&
1178 echo aaa >>expect &&
1179 echo "YYY" >>expect &&
1180 echo baz >>expect &&
1181 git config --get-all remote.someremote.pushurl >actual &&
1182 echo "YYY" >>actual &&
1183 git config --get-all remote.someremote.url >>actual &&
1187 test_expect_success 'get-url on multi push remote' '
1188 echo foo | get_url_test --push someremote &&
1189 get_url_test --push --all someremote <<-\EOF
1195 test_expect_success 'remote set-url --push bar aaa' '
1196 git remote set-url --push someremote bar aaa &&
1198 echo bar >>expect &&
1199 echo "YYY" >>expect &&
1200 echo baz >>expect &&
1201 git config --get-all remote.someremote.pushurl >actual &&
1202 echo "YYY" >>actual &&
1203 git config --get-all remote.someremote.url >>actual &&
1207 test_expect_success 'remote set-url --push --delete bar' '
1208 git remote set-url --push --delete someremote bar &&
1210 echo "YYY" >>expect &&
1211 echo baz >>expect &&
1212 git config --get-all remote.someremote.pushurl >actual &&
1213 echo "YYY" >>actual &&
1214 git config --get-all remote.someremote.url >>actual &&
1218 test_expect_success 'remote set-url --push --delete foo' '
1219 git remote set-url --push --delete someremote foo &&
1220 echo "YYY" >expect &&
1221 echo baz >>expect &&
1222 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1223 echo "YYY" >>actual &&
1224 git config --get-all remote.someremote.url >>actual &&
1228 test_expect_success 'remote set-url --add bbb' '
1229 git remote set-url --add someremote bbb &&
1230 echo "YYY" >expect &&
1231 echo baz >>expect &&
1232 echo bbb >>expect &&
1233 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1234 echo "YYY" >>actual &&
1235 git config --get-all remote.someremote.url >>actual &&
1239 test_expect_success 'get-url on multi fetch remote' '
1240 echo baz | get_url_test someremote &&
1241 get_url_test --all someremote <<-\EOF
1247 test_expect_success 'remote set-url --delete .*' '
1248 test_must_fail git remote set-url --delete someremote .\* &&
1249 echo "YYY" >expect &&
1250 echo baz >>expect &&
1251 echo bbb >>expect &&
1252 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1253 echo "YYY" >>actual &&
1254 git config --get-all remote.someremote.url >>actual &&
1258 test_expect_success 'remote set-url --delete bbb' '
1259 git remote set-url --delete someremote bbb &&
1260 echo "YYY" >expect &&
1261 echo baz >>expect &&
1262 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1263 echo "YYY" >>actual &&
1264 git config --get-all remote.someremote.url >>actual &&
1268 test_expect_success 'remote set-url --delete baz' '
1269 test_must_fail git remote set-url --delete someremote baz &&
1270 echo "YYY" >expect &&
1271 echo baz >>expect &&
1272 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1273 echo "YYY" >>actual &&
1274 git config --get-all remote.someremote.url >>actual &&
1278 test_expect_success 'remote set-url --add ccc' '
1279 git remote set-url --add someremote ccc &&
1280 echo "YYY" >expect &&
1281 echo baz >>expect &&
1282 echo ccc >>expect &&
1283 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1284 echo "YYY" >>actual &&
1285 git config --get-all remote.someremote.url >>actual &&
1289 test_expect_success 'remote set-url --delete baz' '
1290 git remote set-url --delete someremote baz &&
1291 echo "YYY" >expect &&
1292 echo ccc >>expect &&
1293 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1294 echo "YYY" >>actual &&
1295 git config --get-all remote.someremote.url >>actual &&
1299 test_expect_success 'extra args: setup' '
1300 # add a dummy origin so that this does not trigger failure
1301 git remote add origin .
1305 test_expect_success "extra args: $*" "
1306 test_must_fail git remote $* bogus_extra_arg 2>actual &&
1307 test_i18ngrep '^usage:' actual
1311 test_extra_arg add nick url
1312 test_extra_arg rename origin newname
1313 test_extra_arg remove origin
1314 test_extra_arg set-head origin main
1315 # set-branches takes any number of args
1316 test_extra_arg get-url origin newurl
1317 test_extra_arg set-url origin newurl oldurl
1318 # show takes any number of args
1319 # prune takes any number of args
1320 # update takes any number of args
1322 test_expect_success 'add remote matching the "insteadOf" URL' '
1323 git config url.xyz@example.com.insteadOf backup &&
1324 git remote add backup xyz@example.com
1327 test_expect_success 'unqualified <dst> refspec DWIM and advice' '
1328 test_when_finished "(cd test && git tag -d some-tag)" &&
1331 git tag -a -m "Some tag" some-tag main &&
1332 for type in commit tag tree blob
1334 if test "$type" = "blob"
1336 oid=$(git rev-parse some-tag:file)
1338 oid=$(git rev-parse some-tag^{$type})
1340 test_must_fail git push origin $oid:dst 2>err &&
1341 test_i18ngrep "error: The destination you" err &&
1342 test_i18ngrep "hint: Did you mean" err &&
1343 test_must_fail git -c advice.pushUnqualifiedRefName=false \
1344 push origin $oid:dst 2>err &&
1345 test_i18ngrep "error: The destination you" err &&
1346 test_i18ngrep ! "hint: Did you mean" err ||
1352 test_expect_success 'refs/remotes/* <src> refspec and unqualified <dst> DWIM and advice' '
1355 git tag -a -m "Some tag" my-tag main &&
1356 git update-ref refs/trees/my-head-tree HEAD^{tree} &&
1357 git update-ref refs/blobs/my-file-blob HEAD:file
1361 git config --add remote.two.fetch "+refs/tags/*:refs/remotes/tags-from-two/*" &&
1362 git config --add remote.two.fetch "+refs/trees/*:refs/remotes/trees-from-two/*" &&
1363 git config --add remote.two.fetch "+refs/blobs/*:refs/remotes/blobs-from-two/*" &&
1364 git fetch --no-tags two &&
1366 test_must_fail git push origin refs/remotes/two/another:dst 2>err &&
1367 test_i18ngrep "error: The destination you" err &&
1369 test_must_fail git push origin refs/remotes/tags-from-two/my-tag:dst-tag 2>err &&
1370 test_i18ngrep "error: The destination you" err &&
1372 test_must_fail git push origin refs/remotes/trees-from-two/my-head-tree:dst-tree 2>err &&
1373 test_i18ngrep "error: The destination you" err &&
1375 test_must_fail git push origin refs/remotes/blobs-from-two/my-file-blob:dst-blob 2>err &&
1376 test_i18ngrep "error: The destination you" err