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
'setup bare clone for server' '
82 git clone --bare "file://$(pwd)/one" srv.bare &&
83 git -C srv.bare config --local uploadpack.allowfilter 1 &&
84 git -C srv.bare config --local uploadpack.allowanysha1inwant 1
87 test_expect_success
'filters for promisor remotes are listed by git remote -v' '
88 test_when_finished "rm -rf pc" &&
89 git clone --filter=blob:none "file://$(pwd)/srv.bare" pc &&
90 git -C pc remote -v >out &&
91 grep "srv.bare (fetch) \[blob:none\]" out &&
93 git -C pc config remote.origin.partialCloneFilter object:type=commit &&
94 git -C pc remote -v >out &&
95 grep "srv.bare (fetch) \[object:type=commit\]" out
98 test_expect_success
'filters should not be listed for non promisor remotes (remote -v)' '
99 test_when_finished "rm -rf pc" &&
101 git -C pc remote -v >out &&
102 ! grep "(fetch) \[.*\]" out
105 test_expect_success
'filters are listed by git remote -v only' '
106 test_when_finished "rm -rf pc" &&
107 git clone --filter=blob:none "file://$(pwd)/srv.bare" pc &&
108 git -C pc remote >out &&
109 ! grep "\[blob:none\]" out &&
111 git -C pc remote show >out &&
112 ! grep "\[blob:none\]" out
115 test_expect_success
'check remote-tracking' '
118 check_remote_track origin main side &&
119 check_remote_track second main side another
123 test_expect_success
'remote forces tracking branches' '
126 case $(git config remote.second.fetch) in
133 test_expect_success
'remove remote' '
136 git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/main &&
141 test_expect_success
'remove remote' '
144 tokens_match origin "$(git remote)" &&
145 check_remote_track origin main side &&
146 git for-each-ref "--format=%(refname)" refs/remotes |
147 sed -e "/^refs\/remotes\/origin\//d" >actual &&
148 test_must_be_empty actual
152 test_expect_success
'remove remote protects local branches' '
155 cat >expect1 <<-\EOF &&
156 Note: A branch outside the refs/remotes/ hierarchy was not removed;
160 cat >expect2 <<-\EOF &&
161 Note: Some branches outside the refs/remotes/ hierarchy were not removed;
163 git branch -d foobranch
167 git config --add remote.oops.fetch "+refs/*:refs/*" &&
168 git remote remove oops 2>actual1 &&
169 git branch foobranch &&
170 git config --add remote.oops.fetch "+refs/*:refs/*" &&
171 git remote rm oops 2>actual2 &&
172 git branch -d foobranch &&
174 test_cmp expect1 actual1 &&
175 test_cmp expect2 actual2
179 test_expect_success
'remove errors out early when deleting non-existent branch' '
182 echo "error: No such remote: '\''foo'\''" >expect &&
183 test_expect_code 2 git remote rm foo 2>actual &&
184 test_cmp expect actual
188 test_expect_success
'remove remote with a branch without configured merge' '
189 test_when_finished "(
190 git -C test checkout main;
191 git -C test branch -D two;
192 git -C test config --remove-section remote.two;
193 git -C test config --remove-section branch.second;
198 git remote add two ../two &&
200 git checkout -b second two/main^0 &&
201 git config branch.second.remote two &&
207 test_expect_success
'rename errors out early when deleting non-existent branch' '
210 echo "error: No such remote: '\''foo'\''" >expect &&
211 test_expect_code 2 git remote rename foo bar 2>actual &&
212 test_cmp expect actual
216 test_expect_success
'rename errors out early when new name is invalid' '
217 test_config remote.foo.vcs bar &&
218 echo "fatal: '\''invalid...name'\'' is not a valid remote name" >expect &&
219 test_must_fail git remote rename foo invalid...name 2>actual &&
220 test_cmp expect actual
223 test_expect_success
'add existing foreign_vcs remote' '
224 test_config remote.foo.vcs bar &&
225 echo "error: remote foo already exists." >expect &&
226 test_expect_code 3 git remote add foo bar 2>actual &&
227 test_cmp expect actual
230 test_expect_success
'add existing foreign_vcs remote' '
231 test_config remote.foo.vcs bar &&
232 test_config remote.bar.vcs bar &&
233 echo "error: remote bar already exists." >expect &&
234 test_expect_code 3 git remote rename foo bar 2>actual &&
235 test_cmp expect actual
238 test_expect_success
'add invalid foreign_vcs remote' '
239 echo "fatal: '\''invalid...name'\'' is not a valid remote name" >expect &&
240 test_must_fail git remote add invalid...name bar 2>actual &&
241 test_cmp expect actual
244 test_expect_success
'without subcommand' '
245 echo origin >expect &&
246 git -C test remote >actual &&
247 test_cmp expect actual
250 test_expect_success
'without subcommand accepts -v' '
251 cat >expect <<-EOF &&
252 origin $(pwd)/one (fetch)
253 origin $(pwd)/one (push)
255 git -C test remote -v >actual &&
256 test_cmp expect actual
259 test_expect_success
'without subcommand does not take arguments' '
260 test_expect_code 129 git -C test remote origin 2>err &&
261 grep "^error: unknown subcommand:" err
264 cat >test
/expect
<<EOF
266 Fetch URL: $(pwd)/one
270 main new (next fetch will store in remotes/origin)
272 Local branches configured for 'git pull':
273 ahead merges with remote main
274 main merges with remote main
275 octopus merges with remote topic-a
276 and with remote topic-b
277 and with remote topic-c
278 rebase rebases onto remote main
279 Local refs configured for 'git push':
280 main pushes to main (local out of date)
281 main pushes to upstream (create)
286 Local refs configured for 'git push':
287 ahead forces to main (fast-forwardable)
288 main pushes to another (up to date)
291 test_expect_success
'show' '
294 git config --add remote.origin.fetch refs/heads/main:refs/heads/upstream &&
296 git checkout -b ahead origin/main &&
299 git commit -m update file &&
301 git branch --track octopus origin/main &&
302 git branch --track rebase origin/main &&
303 git branch -d -r origin/main &&
304 git config --add remote.two.url ../two &&
305 git config --add remote.two.pushurl ../three &&
306 git config branch.rebase.rebase true &&
307 git config branch.octopus.merge "topic-a topic-b topic-c" &&
312 git commit -m update file
314 git config --add remote.origin.push : &&
315 git config --add remote.origin.push refs/heads/main:refs/heads/upstream &&
316 git config --add remote.origin.push +refs/tags/lastbackup &&
317 git config --add remote.two.push +refs/heads/ahead:refs/heads/main &&
318 git config --add remote.two.push refs/heads/main:refs/heads/another &&
319 git remote show origin two >output &&
320 git branch -d rebase octopus &&
321 test_cmp expect output
327 Fetch URL: $(pwd)/one
333 Local branches configured for 'git pull':
334 ahead merges with remote main
335 main merges with remote main
336 Local refs configured for 'git push':
337 main pushes to main (local out of date)
338 main pushes to upstream (create)
341 test_expect_success
'show with negative refspecs' '
342 test_when_finished "git -C test config --unset-all --fixed-value remote.origin.fetch ^refs/heads/main" &&
343 git -C test config --add remote.origin.fetch ^refs/heads/main &&
344 git -C test remote show origin >output &&
345 test_cmp expect output
350 Fetch URL: $(pwd)/one
354 main new (next fetch will store in remotes/origin)
355 side stale (use 'git remote prune' to remove)
356 Local branches configured for 'git pull':
357 ahead merges with remote main
358 main merges with remote main
359 Local refs configured for 'git push':
360 main pushes to main (local out of date)
361 main pushes to upstream (create)
364 test_expect_failure
'show stale with negative refspecs' '
365 test_when_finished "git -C test config --unset-all --fixed-value remote.origin.fetch ^refs/heads/side" &&
366 git -C test config --add remote.origin.fetch ^refs/heads/side &&
367 git -C test remote show origin >output &&
368 test_cmp expect output
371 cat >test
/expect
<<EOF
373 Fetch URL: $(pwd)/one
375 HEAD branch: (not queried)
376 Remote branches: (status not queried)
379 Local branches configured for 'git pull':
380 ahead merges with remote main
381 main merges with remote main
382 Local refs configured for 'git push' (status not queried):
383 (matching) pushes to (matching)
384 refs/heads/main pushes to refs/heads/upstream
385 refs/tags/lastbackup forces to refs/tags/lastbackup
388 test_expect_success
'show -n' '
389 mv one one.unreachable &&
392 git remote show -n origin >output &&
393 mv ../one.unreachable ../one &&
394 test_cmp expect output
398 test_expect_success
'prune' '
401 git branch -m side side2
406 git remote prune origin &&
407 git rev-parse refs/remotes/origin/side2 &&
408 test_must_fail git rev-parse refs/remotes/origin/side
412 test_expect_success
'set-head --delete' '
415 git symbolic-ref refs/remotes/origin/HEAD &&
416 git remote set-head --delete origin &&
417 test_must_fail git symbolic-ref refs/remotes/origin/HEAD
421 test_expect_success
'set-head --auto' '
424 git remote set-head --auto origin &&
425 echo refs/remotes/origin/main >expect &&
426 git symbolic-ref refs/remotes/origin/HEAD >output &&
427 test_cmp expect output
431 test_expect_success
'set-head --auto has no problem w/multiple HEADs' '
434 git fetch two "refs/heads/*:refs/remotes/two/*" &&
435 git remote set-head --auto two >output 2>&1 &&
436 echo "two/HEAD set to main" >expect &&
437 test_cmp expect output
441 cat >test
/expect
<<\EOF
442 refs
/remotes
/origin
/side2
445 test_expect_success
'set-head explicit' '
448 git remote set-head origin side2 &&
449 git symbolic-ref refs/remotes/origin/HEAD >output &&
450 git remote set-head origin main &&
451 test_cmp expect output
455 cat >test
/expect
<<EOF
458 * [would prune] origin/side2
461 test_expect_success
'prune --dry-run' '
462 git -C one branch -m side2 side &&
463 test_when_finished "git -C one branch -m side side2" &&
466 git remote prune --dry-run origin >output &&
467 git rev-parse refs/remotes/origin/side2 &&
468 test_must_fail git rev-parse refs/remotes/origin/side &&
469 test_cmp expect output
473 test_expect_success
'add --mirror && prune' '
478 git remote add --mirror -f origin ../one
482 git branch -m side2 side
486 git rev-parse --verify refs/heads/side2 &&
487 test_must_fail git rev-parse --verify refs/heads/side &&
489 git remote prune origin &&
490 test_must_fail git rev-parse --verify refs/heads/side2 &&
491 git rev-parse --verify refs/heads/side
495 test_expect_success
'add --mirror=fetch' '
496 mkdir mirror-fetch &&
497 git init -b main mirror-fetch/parent &&
499 cd mirror-fetch/parent &&
502 git init --bare mirror-fetch/child &&
504 cd mirror-fetch/child &&
505 git remote add --mirror=fetch -f parent ../parent
509 test_expect_success
'fetch mirrors act as mirrors during fetch' '
511 cd mirror-fetch/parent &&
513 git branch -m main renamed
516 cd mirror-fetch/child &&
518 git rev-parse --verify refs/heads/new &&
519 git rev-parse --verify refs/heads/renamed
523 test_expect_success
'fetch mirrors can prune' '
525 cd mirror-fetch/child &&
526 git remote prune parent &&
527 test_must_fail git rev-parse --verify refs/heads/main
531 test_expect_success
'fetch mirrors do not act as mirrors during push' '
533 cd mirror-fetch/parent &&
537 cd mirror-fetch/child &&
538 git branch -m renamed renamed2 &&
542 cd mirror-fetch/parent &&
543 git rev-parse --verify renamed &&
544 test_must_fail git rev-parse --verify refs/heads/renamed2
548 test_expect_success
'add fetch mirror with specific branches' '
549 git init --bare mirror-fetch/track &&
551 cd mirror-fetch/track &&
552 git remote add --mirror=fetch -t heads/new parent ../parent
556 test_expect_success
'fetch mirror respects specific branches' '
558 cd mirror-fetch/track &&
560 git rev-parse --verify refs/heads/new &&
561 test_must_fail git rev-parse --verify refs/heads/renamed
565 test_expect_success
'add --mirror=push' '
567 git init --bare mirror-push/public &&
568 git init -b main mirror-push/private &&
570 cd mirror-push/private &&
572 git remote add --mirror=push public ../public
576 test_expect_success
'push mirrors act as mirrors during push' '
578 cd mirror-push/private &&
580 git branch -m main renamed &&
584 cd mirror-push/private &&
585 git rev-parse --verify refs/heads/new &&
586 git rev-parse --verify refs/heads/renamed &&
587 test_must_fail git rev-parse --verify refs/heads/main
591 test_expect_success
'push mirrors do not act as mirrors during fetch' '
593 cd mirror-push/public &&
594 git branch -m renamed renamed2 &&
595 git symbolic-ref HEAD refs/heads/renamed2
598 cd mirror-push/private &&
600 git rev-parse --verify refs/heads/renamed &&
601 test_must_fail git rev-parse --verify refs/heads/renamed2
605 test_expect_success
'push mirrors do not allow you to specify refs' '
606 git init mirror-push/track &&
608 cd mirror-push/track &&
609 test_must_fail git remote add --mirror=push -t new public ../public
613 test_expect_success
'add alt && prune' '
618 git remote add -f origin ../one &&
619 git config remote.alt.url ../one &&
620 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*"
624 git branch -m side side2
628 git rev-parse --verify refs/remotes/origin/side &&
629 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
631 git remote prune alt &&
632 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
633 git rev-parse --verify refs/remotes/origin/side2
637 cat >test
/expect
<<\EOF
641 test_expect_success
'add with reachable tags (default)' '
646 git commit -m "Foobar" &&
647 git tag -a -m "Foobar tag" foobar-tag &&
648 git reset --hard HEAD~1 &&
649 git tag -a -m "Some tag" some-tag
655 git remote add -f origin ../one &&
656 git tag -l some-tag >../test/output &&
657 git tag -l foobar-tag >>../test/output &&
658 test_must_fail git config remote.origin.tagopt
660 test_cmp test/expect test/output
663 cat >test
/expect
<<\EOF
669 test_expect_success
'add --tags' '
675 git remote add -f --tags origin ../one &&
676 git tag -l some-tag >../test/output &&
677 git tag -l foobar-tag >>../test/output &&
678 git config remote.origin.tagopt >>../test/output
680 test_cmp test/expect test/output
683 cat >test
/expect
<<\EOF
687 test_expect_success
'add --no-tags' '
693 git remote add -f --no-tags origin ../one &&
694 grep tagOpt .git/config &&
695 git tag -l some-tag >../test/output &&
696 git tag -l foobar-tag >../test/output &&
697 git config remote.origin.tagopt >>../test/output
701 git tag -d some-tag foobar-tag
703 test_cmp test/expect test/output
706 test_expect_success
'reject --no-no-tags' '
709 test_must_fail git remote add -f --no-no-tags neworigin ../one
713 cat >one
/expect
<<\EOF
721 test_expect_success
'update' '
724 git remote add drosophila ../two &&
725 git remote add apis ../mirror &&
727 git branch -r >output &&
728 test_cmp expect output
732 cat >one
/expect
<<\EOF
742 test_expect_success
'update with arguments' '
745 for b in $(git branch -r)
747 git branch -r -d $b || exit 1
749 git remote add manduca ../mirror &&
750 git remote add megaloprepus ../mirror &&
751 git config remotes.phobaeticus "drosophila megaloprepus" &&
752 git config remotes.titanus manduca &&
753 git remote update phobaeticus titanus &&
754 git branch -r >output &&
755 test_cmp expect output
759 test_expect_success
'update --prune' '
762 git branch -m side2 side3
766 git remote update --prune &&
769 git branch -m side3 side2
771 git rev-parse refs/remotes/origin/side3 &&
772 test_must_fail git rev-parse refs/remotes/origin/side2
776 cat >one
/expect
<<-\EOF
785 test_expect_success 'update default' '
788 for b in $(git branch -r)
790 git branch -r -d $b || exit 1
792 git config remote.drosophila.skipDefaultUpdate true &&
793 git remote update default &&
794 git branch -r >output &&
795 test_cmp expect output
799 cat >one/expect <<\EOF
805 test_expect_success 'update default (overridden, with funny whitespace)' '
808 for b in $(git branch -r)
810 git branch -r -d $b || exit 1
812 git config remotes.default "$(printf "\t drosophila \n")" &&
813 git remote update default &&
814 git branch -r >output &&
815 test_cmp expect output
819 test_expect_success 'update (with remotes.default defined)' '
822 for b in $(git branch -r)
824 git branch -r -d $b || exit 1
826 git config remotes.default "drosophila" &&
828 git branch -r >output &&
829 test_cmp expect output
833 test_expect_success '"remote show" does not show symbolic refs' '
834 git clone one three &&
837 git remote show origin >output &&
838 ! grep "^ *HEAD$" < output &&
839 ! grep -i stale < output
843 test_expect_success 'reject adding remote with an invalid name' '
844 test_must_fail git remote add some:url desired-name
847 # The first three test if the tracking branches are properly renamed,
848 # the last two ones check if the config is updated.
850 test_expect_success 'rename a remote' '
851 test_config_global remote.pushDefault origin &&
852 git clone one four &&
855 git config branch.main.pushRemote origin &&
856 GIT_TRACE2_EVENT=$(pwd)/trace \
857 git remote rename --progress origin upstream &&
858 test_region progress "Renaming remote references" trace &&
859 grep "pushRemote" .git/config &&
860 test -z "$(git for-each-ref refs/remotes/origin)" &&
861 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/main" &&
862 test "$(git rev-parse upstream/main)" = "$(git rev-parse main)" &&
863 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
864 test "$(git config branch.main.remote)" = "upstream" &&
865 test "$(git config branch.main.pushRemote)" = "upstream" &&
866 test "$(git config --global remote.pushDefault)" = "origin"
870 test_expect_success 'rename a remote renames repo remote.pushDefault' '
871 git clone one four.1 &&
874 git config remote.pushDefault origin &&
875 git remote rename origin upstream &&
876 grep pushDefault .git/config &&
877 test "$(git config --local remote.pushDefault)" = "upstream"
881 test_expect_success 'rename a remote renames repo remote.pushDefault but ignores global' '
882 test_config_global remote.pushDefault other &&
883 git clone one four.2 &&
886 git config remote.pushDefault origin &&
887 git remote rename origin upstream &&
888 test "$(git config --global remote.pushDefault)" = "other" &&
889 test "$(git config --local remote.pushDefault)" = "upstream"
893 test_expect_success 'rename a remote renames repo remote.pushDefault but keeps global' '
894 test_config_global remote.pushDefault origin &&
895 git clone one four.3 &&
898 git config remote.pushDefault origin &&
899 git remote rename origin upstream &&
900 test "$(git config --global remote.pushDefault)" = "origin" &&
901 test "$(git config --local remote.pushDefault)" = "upstream"
905 test_expect_success 'rename handles remote without fetch refspec' '
906 git clone --bare one no-refspec.git &&
907 # confirm assumption that bare clone does not create refspec
909 git -C no-refspec.git config --unset-all remote.origin.fetch &&
910 git -C no-refspec.git config remote.origin.url >expect &&
911 git -C no-refspec.git remote rename origin foo &&
912 git -C no-refspec.git config remote.foo.url >actual &&
913 test_cmp expect actual
916 test_expect_success 'rename does not update a non-default fetch refspec' '
917 git clone one four.one &&
920 git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
921 git remote rename origin upstream &&
922 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" &&
923 git rev-parse -q origin/main
927 test_expect_success 'rename a remote with name part of fetch spec' '
928 git clone one four.two &&
931 git remote rename origin remote &&
932 git remote rename remote upstream &&
933 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*"
937 test_expect_success 'rename a remote with name prefix of other remote' '
938 git clone one four.three &&
941 git remote add o git://example.com/repo.git &&
942 git remote rename o upstream &&
943 test "$(git rev-parse origin/main)" = "$(git rev-parse main)"
947 test_expect_success 'rename succeeds with existing remote.<target>.prune' '
948 git clone one four.four &&
949 test_when_finished git config --global --unset remote.upstream.prune &&
950 git config --global remote.upstream.prune true &&
951 git -C four.four remote rename origin upstream
954 test_expect_success 'remove a remote' '
955 test_config_global remote.pushDefault origin &&
956 git clone one four.five &&
959 git config branch.main.pushRemote origin &&
960 git remote remove origin &&
961 test -z "$(git for-each-ref refs/remotes/origin)" &&
962 test_must_fail git config branch.main.remote &&
963 test_must_fail git config branch.main.pushRemote &&
964 test "$(git config --global remote.pushDefault)" = "origin"
968 test_expect_success 'remove a remote removes repo remote.pushDefault' '
969 git clone one four.five.1 &&
972 git config remote.pushDefault origin &&
973 git remote remove origin &&
974 test_must_fail git config --local remote.pushDefault
978 test_expect_success 'remove a remote removes repo remote.pushDefault but ignores global' '
979 test_config_global remote.pushDefault other &&
980 git clone one four.five.2 &&
983 git config remote.pushDefault origin &&
984 git remote remove origin &&
985 test "$(git config --global remote.pushDefault)" = "other" &&
986 test_must_fail git config --local remote.pushDefault
990 test_expect_success 'remove a remote removes repo remote.pushDefault but keeps global' '
991 test_config_global remote.pushDefault origin &&
992 git clone one four.five.3 &&
995 git config remote.pushDefault origin &&
996 git remote remove origin &&
997 test "$(git config --global remote.pushDefault)" = "origin" &&
998 test_must_fail git config --local remote.pushDefault
1002 cat >remotes_origin <<EOF
1004 Push: refs/heads/main:refs/heads/upstream
1005 Push: refs/heads/next:refs/heads/upstream2
1006 Pull: refs/heads/main:refs/heads/origin
1007 Pull: refs/heads/next:refs/heads/origin2
1010 test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
1011 git clone one five &&
1012 origin_url=$(pwd)/one &&
1015 git remote remove origin &&
1016 mkdir -p .git/remotes &&
1017 cat ../remotes_origin >.git/remotes/origin &&
1018 git remote rename origin origin &&
1019 test_path_is_missing .git/remotes/origin &&
1020 test "$(git config remote.origin.url)" = "$origin_url" &&
1021 cat >push_expected <<-\
EOF &&
1022 refs/heads/main:refs/heads/upstream
1023 refs/heads/next:refs/heads/upstream2
1025 cat >fetch_expected <<-\EOF &&
1026 refs/heads/main:refs/heads/origin
1027 refs/heads/next:refs/heads/origin2
1029 git config --get-all remote.origin.push >push_actual &&
1030 git config --get-all remote.origin.fetch >fetch_actual &&
1031 test_cmp push_expected push_actual &&
1032 test_cmp fetch_expected fetch_actual
1036 test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
1037 git clone --template= one six &&
1038 origin_url=$(pwd)/one &&
1041 git remote rm origin &&
1042 mkdir .git/branches &&
1043 echo "$origin_url#main" >.git/branches/origin &&
1044 git remote rename origin origin &&
1045 test_path_is_missing .git/branches/origin &&
1046 test "$(git config remote.origin.url)" = "$origin_url" &&
1047 test "$(git config remote.origin.fetch)" = "refs/heads/main:refs/heads/origin" &&
1048 test "$(git config remote.origin.push)" = "HEAD:refs/heads/main"
1052 test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' '
1053 git clone --template= one seven &&
1056 git remote rm origin &&
1057 mkdir .git/branches &&
1058 echo "quux#foom" > .git/branches/origin &&
1059 git remote rename origin origin &&
1060 test_path_is_missing .git/branches/origin &&
1061 test "$(git config remote.origin.url)" = "quux" &&
1062 test "$(git config remote.origin.fetch)" = "refs/heads/foom:refs/heads/origin" &&
1063 test "$(git config remote.origin.push)" = "HEAD:refs/heads/foom"
1067 test_expect_success 'remote prune to cause a dangling symref' '
1068 git clone one eight &&
1071 git checkout side2 &&
1076 git remote prune origin
1078 test_grep "has become dangling" err &&
1080 : And the dangling symref will not cause other annoying errors &&
1085 ! grep "points nowhere" err &&
1088 test_must_fail git branch nomore origin
1090 test_grep "dangling symref" err
1093 test_expect_success 'show empty remote' '
1094 test_create_repo empty &&
1095 git clone empty empty-clone &&
1098 git remote show origin
1102 test_expect_success 'remote set-branches requires a remote' '
1103 test_must_fail git remote set-branches &&
1104 test_must_fail git remote set-branches --add
1107 test_expect_success 'remote set-branches' '
1108 echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial &&
1109 sort <<-\EOF >expect.add &&
1110 +refs/heads/*:refs/remotes/scratch/*
1111 +refs/heads/other:refs/remotes/scratch/other
1113 sort <<-\EOF >expect.replace &&
1114 +refs/heads/maint:refs/remotes/scratch/maint
1115 +refs/heads/main:refs/remotes/scratch/main
1116 +refs/heads/next:refs/remotes/scratch/next
1118 sort <<-\EOF >expect.add-two &&
1119 +refs/heads/maint:refs/remotes/scratch/maint
1120 +refs/heads/main:refs/remotes/scratch/main
1121 +refs/heads/next:refs/remotes/scratch/next
1122 +refs/heads/seen:refs/remotes/scratch/seen
1123 +refs/heads/t/topic:refs/remotes/scratch/t/topic
1125 sort <<-\EOF >expect.setup-ffonly &&
1126 refs/heads/main:refs/remotes/scratch/main
1127 +refs/heads/next:refs/remotes/scratch/next
1129 sort <<-\EOF >expect.respect-ffonly &&
1130 refs/heads/main:refs/remotes/scratch/main
1131 +refs/heads/next:refs/remotes/scratch/next
1132 +refs/heads/seen:refs/remotes/scratch/seen
1135 git clone .git/ setbranches &&
1138 git remote rename origin scratch &&
1139 git config --get-all remote.scratch.fetch >config-result &&
1140 sort <config-result >../actual.initial &&
1142 git remote set-branches scratch --add other &&
1143 git config --get-all remote.scratch.fetch >config-result &&
1144 sort <config-result >../actual.add &&
1146 git remote set-branches scratch maint main next &&
1147 git config --get-all remote.scratch.fetch >config-result &&
1148 sort <config-result >../actual.replace &&
1150 git remote set-branches --add scratch seen t/topic &&
1151 git config --get-all remote.scratch.fetch >config-result &&
1152 sort <config-result >../actual.add-two &&
1154 git config --unset-all remote.scratch.fetch &&
1155 git config remote.scratch.fetch \
1156 refs/heads/main:refs/remotes/scratch/main &&
1157 git config --add remote.scratch.fetch \
1158 +refs/heads/next:refs/remotes/scratch/next &&
1159 git config --get-all remote.scratch.fetch >config-result &&
1160 sort <config-result >../actual.setup-ffonly &&
1162 git remote set-branches --add scratch seen &&
1163 git config --get-all remote.scratch.fetch >config-result &&
1164 sort <config-result >../actual.respect-ffonly
1166 test_cmp expect.initial actual.initial &&
1167 test_cmp expect.add actual.add &&
1168 test_cmp expect.replace actual.replace &&
1169 test_cmp expect.add-two actual.add-two &&
1170 test_cmp expect.setup-ffonly actual.setup-ffonly &&
1171 test_cmp expect.respect-ffonly actual.respect-ffonly
1174 test_expect_success 'remote set-branches with --mirror' '
1175 echo "+refs/*:refs/*" >expect.initial &&
1176 echo "+refs/heads/main:refs/heads/main" >expect.replace &&
1177 git clone --mirror .git/ setbranches-mirror &&
1179 cd setbranches-mirror &&
1180 git remote rename origin scratch &&
1181 git config --get-all remote.scratch.fetch >../actual.initial &&
1183 git remote set-branches scratch heads/main &&
1184 git config --get-all remote.scratch.fetch >../actual.replace
1186 test_cmp expect.initial actual.initial &&
1187 test_cmp expect.replace actual.replace
1190 test_expect_success 'new remote' '
1191 git remote add someremote foo &&
1193 git config --get-all remote.someremote.url >actual &&
1199 git remote get-url "$@" >actual &&
1200 test_cmp expect actual
1203 test_expect_success 'get-url on new remote' '
1204 echo foo | get_url_test someremote &&
1205 echo foo | get_url_test --all someremote &&
1206 echo foo | get_url_test --push someremote &&
1207 echo foo | get_url_test --push --all someremote
1210 test_expect_success 'remote set-url with locked config' '
1211 test_when_finished "rm -f .git/config.lock" &&
1212 git config --get-all remote.someremote.url >expect &&
1213 >.git/config.lock &&
1214 test_must_fail git remote set-url someremote baz &&
1215 git config --get-all remote.someremote.url >actual &&
1219 test_expect_success 'remote set-url bar' '
1220 git remote set-url someremote bar &&
1222 git config --get-all remote.someremote.url >actual &&
1226 test_expect_success 'remote set-url baz bar' '
1227 git remote set-url someremote baz bar &&
1229 git config --get-all remote.someremote.url >actual &&
1233 test_expect_success 'remote set-url zot bar' '
1234 test_must_fail git remote set-url someremote zot bar &&
1236 git config --get-all remote.someremote.url >actual &&
1240 test_expect_success 'remote set-url --push zot baz' '
1241 test_must_fail git remote set-url --push someremote zot baz &&
1242 echo "YYY" >expect &&
1243 echo baz >>expect &&
1244 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1245 echo "YYY" >>actual &&
1246 git config --get-all remote.someremote.url >>actual &&
1250 test_expect_success 'remote set-url --push zot' '
1251 git remote set-url --push someremote zot &&
1253 echo "YYY" >>expect &&
1254 echo baz >>expect &&
1255 git config --get-all remote.someremote.pushurl >actual &&
1256 echo "YYY" >>actual &&
1257 git config --get-all remote.someremote.url >>actual &&
1261 test_expect_success 'get-url with different urls' '
1262 echo baz | get_url_test someremote &&
1263 echo baz | get_url_test --all someremote &&
1264 echo zot | get_url_test --push someremote &&
1265 echo zot | get_url_test --push --all someremote
1268 test_expect_success 'remote set-url --push qux zot' '
1269 git remote set-url --push someremote qux zot &&
1271 echo "YYY" >>expect &&
1272 echo baz >>expect &&
1273 git config --get-all remote.someremote.pushurl >actual &&
1274 echo "YYY" >>actual &&
1275 git config --get-all remote.someremote.url >>actual &&
1279 test_expect_success 'remote set-url --push foo qu+x' '
1280 git remote set-url --push someremote foo qu+x &&
1282 echo "YYY" >>expect &&
1283 echo baz >>expect &&
1284 git config --get-all remote.someremote.pushurl >actual &&
1285 echo "YYY" >>actual &&
1286 git config --get-all remote.someremote.url >>actual &&
1290 test_expect_success 'remote set-url --push --add aaa' '
1291 git remote set-url --push --add someremote aaa &&
1293 echo aaa >>expect &&
1294 echo "YYY" >>expect &&
1295 echo baz >>expect &&
1296 git config --get-all remote.someremote.pushurl >actual &&
1297 echo "YYY" >>actual &&
1298 git config --get-all remote.someremote.url >>actual &&
1302 test_expect_success 'get-url on multi push remote' '
1303 echo foo | get_url_test --push someremote &&
1304 get_url_test --push --all someremote <<-\EOF
1310 test_expect_success 'remote set-url --push bar aaa' '
1311 git remote set-url --push someremote bar aaa &&
1313 echo bar >>expect &&
1314 echo "YYY" >>expect &&
1315 echo baz >>expect &&
1316 git config --get-all remote.someremote.pushurl >actual &&
1317 echo "YYY" >>actual &&
1318 git config --get-all remote.someremote.url >>actual &&
1322 test_expect_success 'remote set-url --push --delete bar' '
1323 git remote set-url --push --delete someremote bar &&
1325 echo "YYY" >>expect &&
1326 echo baz >>expect &&
1327 git config --get-all remote.someremote.pushurl >actual &&
1328 echo "YYY" >>actual &&
1329 git config --get-all remote.someremote.url >>actual &&
1333 test_expect_success 'remote set-url --push --delete foo' '
1334 git remote set-url --push --delete someremote foo &&
1335 echo "YYY" >expect &&
1336 echo baz >>expect &&
1337 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1338 echo "YYY" >>actual &&
1339 git config --get-all remote.someremote.url >>actual &&
1343 test_expect_success 'remote set-url --add bbb' '
1344 git remote set-url --add someremote bbb &&
1345 echo "YYY" >expect &&
1346 echo baz >>expect &&
1347 echo bbb >>expect &&
1348 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1349 echo "YYY" >>actual &&
1350 git config --get-all remote.someremote.url >>actual &&
1354 test_expect_success 'get-url on multi fetch remote' '
1355 echo baz | get_url_test someremote &&
1356 get_url_test --all someremote <<-\EOF
1362 test_expect_success 'remote set-url --delete .*' '
1363 test_must_fail git remote set-url --delete someremote .\* &&
1364 echo "YYY" >expect &&
1365 echo baz >>expect &&
1366 echo bbb >>expect &&
1367 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1368 echo "YYY" >>actual &&
1369 git config --get-all remote.someremote.url >>actual &&
1373 test_expect_success 'remote set-url --delete bbb' '
1374 git remote set-url --delete someremote bbb &&
1375 echo "YYY" >expect &&
1376 echo baz >>expect &&
1377 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1378 echo "YYY" >>actual &&
1379 git config --get-all remote.someremote.url >>actual &&
1383 test_expect_success 'remote set-url --delete baz' '
1384 test_must_fail git remote set-url --delete someremote baz &&
1385 echo "YYY" >expect &&
1386 echo baz >>expect &&
1387 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1388 echo "YYY" >>actual &&
1389 git config --get-all remote.someremote.url >>actual &&
1393 test_expect_success 'remote set-url --add ccc' '
1394 git remote set-url --add someremote ccc &&
1395 echo "YYY" >expect &&
1396 echo baz >>expect &&
1397 echo ccc >>expect &&
1398 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1399 echo "YYY" >>actual &&
1400 git config --get-all remote.someremote.url >>actual &&
1404 test_expect_success 'remote set-url --delete baz' '
1405 git remote set-url --delete someremote baz &&
1406 echo "YYY" >expect &&
1407 echo ccc >>expect &&
1408 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1409 echo "YYY" >>actual &&
1410 git config --get-all remote.someremote.url >>actual &&
1414 test_expect_success 'extra args: setup' '
1415 # add a dummy origin so that this does not trigger failure
1416 git remote add origin .
1420 test_expect_success "extra args: $*" "
1421 test_must_fail git remote $* bogus_extra_arg 2>actual &&
1422 test_grep '^usage:' actual
1426 test_extra_arg add nick url
1427 test_extra_arg rename origin newname
1428 test_extra_arg remove origin
1429 test_extra_arg set-head origin main
1430 # set-branches takes any number of args
1431 test_extra_arg get-url origin newurl
1432 test_extra_arg set-url origin newurl oldurl
1433 # show takes any number of args
1434 # prune takes any number of args
1435 # update takes any number of args
1437 test_expect_success 'add remote matching the "insteadOf" URL' '
1438 git config url.xyz@example.com.insteadOf backup &&
1439 git remote add backup xyz@example.com
1442 test_expect_success 'unqualified <dst> refspec DWIM and advice' '
1443 test_when_finished "(cd test && git tag -d some-tag)" &&
1446 git tag -a -m "Some tag" some-tag main &&
1447 for type in commit tag tree blob
1449 if test "$type" = "blob"
1451 oid=$(git rev-parse some-tag:file)
1453 oid=$(git rev-parse some-tag^{$type})
1455 test_must_fail git push origin $oid:dst 2>err &&
1456 test_grep "error: The destination you" err &&
1457 test_grep "hint: Did you mean" err &&
1458 test_must_fail git -c advice.pushUnqualifiedRefName=false \
1459 push origin $oid:dst 2>err &&
1460 test_grep "error: The destination you" err &&
1461 test_grep ! "hint: Did you mean" err ||
1467 test_expect_success 'refs/remotes/* <src> refspec and unqualified <dst> DWIM and advice' '
1470 git tag -a -m "Some tag" my-tag main &&
1471 git update-ref refs/trees/my-head-tree HEAD^{tree} &&
1472 git update-ref refs/blobs/my-file-blob HEAD:file
1476 git config --add remote.two.fetch "+refs/tags/*:refs/remotes/tags-from-two/*" &&
1477 git config --add remote.two.fetch "+refs/trees/*:refs/remotes/trees-from-two/*" &&
1478 git config --add remote.two.fetch "+refs/blobs/*:refs/remotes/blobs-from-two/*" &&
1479 git fetch --no-tags two &&
1481 test_must_fail git push origin refs/remotes/two/another:dst 2>err &&
1482 test_grep "error: The destination you" err &&
1484 test_must_fail git push origin refs/remotes/tags-from-two/my-tag:dst-tag 2>err &&
1485 test_grep "error: The destination you" err &&
1487 test_must_fail git push origin refs/remotes/trees-from-two/my-head-tree:dst-tree 2>err &&
1488 test_grep "error: The destination you" err &&
1490 test_must_fail git push origin refs/remotes/blobs-from-two/my-file-blob:dst-blob 2>err &&
1491 test_grep "error: The destination you" err