ident: don't consider '.' a crud
[git/gitster.git] / t / t5505-remote.sh
blob43b7bcd7159c252ff7a2e68dc28fc617649bb658
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 -b main &&
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 main
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 'remote information for the origin' '
61 cd test &&
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' '
70 cd test &&
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" &&
100 git clone one 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' '
117 cd test &&
118 check_remote_track origin main side &&
119 check_remote_track second main side another
123 test_expect_success 'remote forces tracking branches' '
125 cd test &&
126 case $(git config remote.second.fetch) in
127 +*) true ;;
128 *) false ;;
129 esac
133 test_expect_success 'remove remote' '
135 cd test &&
136 git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/main &&
137 git remote rm second
141 test_expect_success 'remove remote' '
143 cd test &&
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' '
154 cd test &&
155 cat >expect1 <<-\EOF &&
156 Note: A branch outside the refs/remotes/ hierarchy was not removed;
157 to delete it, use:
158 git branch -d main
160 cat >expect2 <<-\EOF &&
161 Note: Some branches outside the refs/remotes/ hierarchy were not removed;
162 to delete them, use:
163 git branch -d foobranch
164 git branch -d main
166 git tag footag &&
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 &&
173 git tag -d footag &&
174 test_cmp expect1 actual1 &&
175 test_cmp expect2 actual2
179 test_expect_success 'remove errors out early when deleting non-existent branch' '
181 cd test &&
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;
194 true
195 )" &&
197 cd test &&
198 git remote add two ../two &&
199 git fetch two &&
200 git checkout -b second two/main^0 &&
201 git config branch.second.remote two &&
202 git checkout main &&
203 git remote rm two
207 test_expect_success 'rename errors out early when deleting non-existent branch' '
209 cd test &&
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
265 * remote origin
266 Fetch URL: $(pwd)/one
267 Push URL: $(pwd)/one
268 HEAD branch: main
269 Remote branches:
270 main new (next fetch will store in remotes/origin)
271 side tracked
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)
282 * remote two
283 Fetch URL: ../two
284 Push URL: ../three
285 HEAD branch: main
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' '
293 cd test &&
294 git config --add remote.origin.fetch refs/heads/main:refs/heads/upstream &&
295 git fetch &&
296 git checkout -b ahead origin/main &&
297 echo 1 >>file &&
298 test_tick &&
299 git commit -m update file &&
300 git checkout main &&
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" &&
309 cd ../one &&
310 echo 1 >file &&
311 test_tick &&
312 git commit -m update file
313 ) &&
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
325 cat >expect <<EOF
326 * remote origin
327 Fetch URL: $(pwd)/one
328 Push URL: $(pwd)/one
329 HEAD branch: main
330 Remote branches:
331 main skipped
332 side tracked
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
348 cat >expect <<EOF
349 * remote origin
350 Fetch URL: $(pwd)/one
351 Push URL: $(pwd)/one
352 HEAD branch: main
353 Remote branches:
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
372 * remote origin
373 Fetch URL: $(pwd)/one
374 Push URL: $(pwd)/one
375 HEAD branch: (not queried)
376 Remote branches: (status not queried)
377 main
378 side
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 &&
391 cd test &&
392 git remote show -n origin >output &&
393 mv ../one.unreachable ../one &&
394 test_cmp expect output
398 test_expect_success 'prune' '
400 cd one &&
401 git branch -m side side2
402 ) &&
404 cd test &&
405 git fetch origin &&
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' '
414 cd test &&
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' '
423 cd test &&
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' '
433 cd test &&
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' '
447 cd test &&
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
456 Pruning origin
457 URL: $(pwd)/one
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" &&
465 cd test &&
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' '
474 mkdir mirror &&
476 cd mirror &&
477 git init --bare &&
478 git remote add --mirror -f origin ../one
479 ) &&
481 cd one &&
482 git branch -m side2 side
483 ) &&
485 cd mirror &&
486 git rev-parse --verify refs/heads/side2 &&
487 test_must_fail git rev-parse --verify refs/heads/side &&
488 git fetch origin &&
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 &&
500 test_commit one
501 ) &&
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 &&
512 git branch new &&
513 git branch -m main renamed
514 ) &&
516 cd mirror-fetch/child &&
517 git fetch parent &&
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 &&
534 git checkout HEAD^0
535 ) &&
537 cd mirror-fetch/child &&
538 git branch -m renamed renamed2 &&
539 git push parent :
540 ) &&
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 &&
559 git fetch parent &&
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' '
566 mkdir mirror-push &&
567 git init --bare mirror-push/public &&
568 git init -b main mirror-push/private &&
570 cd mirror-push/private &&
571 test_commit one &&
572 git remote add --mirror=push public ../public
576 test_expect_success 'push mirrors act as mirrors during push' '
578 cd mirror-push/private &&
579 git branch new &&
580 git branch -m main renamed &&
581 git push public
582 ) &&
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
596 ) &&
598 cd mirror-push/private &&
599 git fetch public &&
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' '
614 mkdir alttst &&
616 cd alttst &&
617 git init &&
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/*"
621 ) &&
623 cd one &&
624 git branch -m side side2
625 ) &&
627 cd alttst &&
628 git rev-parse --verify refs/remotes/origin/side &&
629 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
630 git fetch alt &&
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
638 some-tag
641 test_expect_success 'add with reachable tags (default)' '
643 cd one &&
644 >foobar &&
645 git add foobar &&
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
650 ) &&
651 mkdir add-tags &&
653 cd add-tags &&
654 git init &&
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
659 ) &&
660 test_cmp test/expect test/output
663 cat >test/expect <<\EOF
664 some-tag
665 foobar-tag
666 --tags
669 test_expect_success 'add --tags' '
670 rm -rf add-tags &&
672 mkdir add-tags &&
673 cd add-tags &&
674 git init &&
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
679 ) &&
680 test_cmp test/expect test/output
683 cat >test/expect <<\EOF
684 --no-tags
687 test_expect_success 'add --no-tags' '
688 rm -rf add-tags &&
690 mkdir add-no-tags &&
691 cd add-no-tags &&
692 git init &&
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
698 ) &&
700 cd one &&
701 git tag -d some-tag foobar-tag
702 ) &&
703 test_cmp test/expect test/output
706 test_expect_success 'reject --no-no-tags' '
708 cd add-no-tags &&
709 test_must_fail git remote add -f --no-no-tags neworigin ../one
713 cat >one/expect <<\EOF
714 apis/main
715 apis/side
716 drosophila/another
717 drosophila/main
718 drosophila/side
721 test_expect_success 'update' '
723 cd one &&
724 git remote add drosophila ../two &&
725 git remote add apis ../mirror &&
726 git remote update &&
727 git branch -r >output &&
728 test_cmp expect output
732 cat >one/expect <<\EOF
733 drosophila/another
734 drosophila/main
735 drosophila/side
736 manduca/main
737 manduca/side
738 megaloprepus/main
739 megaloprepus/side
742 test_expect_success 'update with arguments' '
744 cd one &&
745 for b in $(git branch -r)
747 git branch -r -d $b || exit 1
748 done &&
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' '
761 cd one &&
762 git branch -m side2 side3
763 ) &&
765 cd test &&
766 git remote update --prune &&
768 cd ../one &&
769 git branch -m side3 side2
770 ) &&
771 git rev-parse refs/remotes/origin/side3 &&
772 test_must_fail git rev-parse refs/remotes/origin/side2
776 cat >one/expect <<-\EOF
777 apis/main
778 apis/side
779 manduca/main
780 manduca/side
781 megaloprepus/main
782 megaloprepus/side
785 test_expect_success 'update default' '
787 cd one &&
788 for b in $(git branch -r)
790 git branch -r -d $b || exit 1
791 done &&
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
800 drosophila/another
801 drosophila/main
802 drosophila/side
805 test_expect_success 'update default (overridden, with funny whitespace)' '
807 cd one &&
808 for b in $(git branch -r)
810 git branch -r -d $b || exit 1
811 done &&
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)' '
821 cd one &&
822 for b in $(git branch -r)
824 git branch -r -d $b || exit 1
825 done &&
826 git config remotes.default "drosophila" &&
827 git remote update &&
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 &&
836 cd 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 &&
854 cd 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 &&
873 cd 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 &&
885 cd 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 &&
897 cd 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
908 test_expect_code 5 \
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 &&
919 cd 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 &&
930 cd 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 &&
940 cd 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 &&
958 cd 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 &&
971 cd 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 &&
982 cd 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 &&
994 cd 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
1003 URL: $(pwd)/one
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 &&
1014 cd five &&
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 &&
1040 cd six &&
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 &&
1055 cd 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 &&
1070 cd one &&
1071 git checkout side2 &&
1072 git branch -D main
1073 ) &&
1075 cd eight &&
1076 git remote prune origin
1077 ) >err 2>&1 &&
1078 test_i18ngrep "has become dangling" err &&
1080 : And the dangling symref will not cause other annoying errors &&
1082 cd eight &&
1083 git branch -a
1084 ) 2>err &&
1085 ! grep "points nowhere" err &&
1087 cd eight &&
1088 test_must_fail git branch nomore origin
1089 ) 2>err &&
1090 test_i18ngrep "dangling symref" err
1093 test_expect_success 'show empty remote' '
1094 test_create_repo empty &&
1095 git clone empty empty-clone &&
1097 cd 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 &&
1137 cd 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
1165 ) &&
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
1185 ) &&
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 &&
1192 echo foo >expect &&
1193 git config --get-all remote.someremote.url >actual &&
1194 cmp expect actual
1197 get_url_test () {
1198 cat >expect &&
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 &&
1216 cmp expect actual
1219 test_expect_success 'remote set-url bar' '
1220 git remote set-url someremote bar &&
1221 echo bar >expect &&
1222 git config --get-all remote.someremote.url >actual &&
1223 cmp expect actual
1226 test_expect_success 'remote set-url baz bar' '
1227 git remote set-url someremote baz bar &&
1228 echo baz >expect &&
1229 git config --get-all remote.someremote.url >actual &&
1230 cmp expect actual
1233 test_expect_success 'remote set-url zot bar' '
1234 test_must_fail git remote set-url someremote zot bar &&
1235 echo baz >expect &&
1236 git config --get-all remote.someremote.url >actual &&
1237 cmp expect 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 &&
1247 cmp expect actual
1250 test_expect_success 'remote set-url --push zot' '
1251 git remote set-url --push someremote zot &&
1252 echo zot >expect &&
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 &&
1258 cmp expect 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 &&
1270 echo qux >expect &&
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 &&
1276 cmp expect actual
1279 test_expect_success 'remote set-url --push foo qu+x' '
1280 git remote set-url --push someremote foo qu+x &&
1281 echo foo >expect &&
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 &&
1287 cmp expect actual
1290 test_expect_success 'remote set-url --push --add aaa' '
1291 git remote set-url --push --add someremote aaa &&
1292 echo foo >expect &&
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 &&
1299 cmp expect 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 &&
1312 echo foo >expect &&
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 &&
1319 cmp expect actual
1322 test_expect_success 'remote set-url --push --delete bar' '
1323 git remote set-url --push --delete someremote bar &&
1324 echo foo >expect &&
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 &&
1330 cmp expect 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 &&
1340 cmp expect 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 &&
1351 cmp expect 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 &&
1370 cmp expect 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 &&
1380 cmp expect 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 &&
1390 cmp expect 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 &&
1401 cmp expect 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 &&
1411 cmp expect 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 .
1419 test_extra_arg () {
1420 test_expect_success "extra args: $*" "
1421 test_must_fail git remote $* bogus_extra_arg 2>actual &&
1422 test_i18ngrep '^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)" &&
1445 cd test &&
1446 git tag -a -m "Some tag" some-tag main &&
1447 for type in commit tag tree blob
1449 if test "$type" = "blob"
1450 then
1451 oid=$(git rev-parse some-tag:file)
1452 else
1453 oid=$(git rev-parse some-tag^{$type})
1454 fi &&
1455 test_must_fail git push origin $oid:dst 2>err &&
1456 test_i18ngrep "error: The destination you" err &&
1457 test_i18ngrep "hint: Did you mean" err &&
1458 test_must_fail git -c advice.pushUnqualifiedRefName=false \
1459 push origin $oid:dst 2>err &&
1460 test_i18ngrep "error: The destination you" err &&
1461 test_i18ngrep ! "hint: Did you mean" err ||
1462 exit 1
1463 done
1467 test_expect_success 'refs/remotes/* <src> refspec and unqualified <dst> DWIM and advice' '
1469 cd two &&
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
1473 ) &&
1475 cd test &&
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_i18ngrep "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_i18ngrep "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_i18ngrep "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_i18ngrep "error: The destination you" err
1495 test_done