]> git.ipfire.org Git - thirdparty/git.git/blame_incremental - t/t5505-remote.sh
remote: actually check if remote exits
[thirdparty/git.git] / t / t5505-remote.sh
... / ...
CommitLineData
1#!/bin/sh
2
3test_description='git remote porcelain-ish'
4
5. ./test-lib.sh
6
7setup_repository () {
8 mkdir "$1" && (
9 cd "$1" &&
10 git init &&
11 >file &&
12 git add file &&
13 test_tick &&
14 git commit -m "Initial" &&
15 git checkout -b side &&
16 >elif &&
17 git add elif &&
18 test_tick &&
19 git commit -m "Second" &&
20 git checkout master
21 )
22}
23
24tokens_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
28}
29
30check_remote_track () {
31 actual=$(git remote show "$1" | sed -ne 's|^ \(.*\) tracked$|\1|p')
32 shift &&
33 tokens_match "$*" "$actual"
34}
35
36check_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"
42}
43
44test_expect_success setup '
45 setup_repository one &&
46 setup_repository two &&
47 (
48 cd two &&
49 git branch another
50 ) &&
51 git clone one test
52'
53
54test_expect_success C_LOCALE_OUTPUT 'remote information for the origin' '
55 (
56 cd test &&
57 tokens_match origin "$(git remote)" &&
58 check_remote_track origin master side &&
59 check_tracking_branch origin HEAD master side
60 )
61'
62
63test_expect_success 'add another remote' '
64 (
65 cd test &&
66 git remote add -f second ../two &&
67 tokens_match "origin second" "$(git remote)" &&
68 check_tracking_branch second master side another &&
69 git for-each-ref "--format=%(refname)" refs/remotes |
70 sed -e "/^refs\/remotes\/origin\//d" \
71 -e "/^refs\/remotes\/second\//d" >actual &&
72 >expect &&
73 test_cmp expect actual
74 )
75'
76
77test_expect_success C_LOCALE_OUTPUT 'check remote-tracking' '
78 (
79 cd test &&
80 check_remote_track origin master side &&
81 check_remote_track second master side another
82 )
83'
84
85test_expect_success 'remote forces tracking branches' '
86 (
87 cd test &&
88 case $(git config remote.second.fetch) in
89 +*) true ;;
90 *) false ;;
91 esac
92 )
93'
94
95test_expect_success 'remove remote' '
96 (
97 cd test &&
98 git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master &&
99 git remote rm second
100 )
101'
102
103test_expect_success C_LOCALE_OUTPUT 'remove remote' '
104 (
105 cd test &&
106 tokens_match origin "$(git remote)" &&
107 check_remote_track origin master side &&
108 git for-each-ref "--format=%(refname)" refs/remotes |
109 sed -e "/^refs\/remotes\/origin\//d" >actual &&
110 >expect &&
111 test_cmp expect actual
112 )
113'
114
115test_expect_success 'remove remote protects local branches' '
116 (
117 cd test &&
118 cat >expect1 <<-\EOF &&
119 Note: A branch outside the refs/remotes/ hierarchy was not removed;
120 to delete it, use:
121 git branch -d master
122 EOF
123 cat >expect2 <<-\EOF &&
124 Note: Some branches outside the refs/remotes/ hierarchy were not removed;
125 to delete them, use:
126 git branch -d foobranch
127 git branch -d master
128 EOF
129 git tag footag &&
130 git config --add remote.oops.fetch "+refs/*:refs/*" &&
131 git remote remove oops 2>actual1 &&
132 git branch foobranch &&
133 git config --add remote.oops.fetch "+refs/*:refs/*" &&
134 git remote rm oops 2>actual2 &&
135 git branch -d foobranch &&
136 git tag -d footag &&
137 test_i18ncmp expect1 actual1 &&
138 test_i18ncmp expect2 actual2
139 )
140'
141
142test_expect_success 'remove errors out early when deleting non-existent branch' '
143 (
144 cd test &&
145 echo "fatal: No such remote: foo" >expect &&
146 test_must_fail git remote rm foo 2>actual &&
147 test_i18ncmp expect actual
148 )
149'
150
151test_expect_success 'rename errors out early when deleting non-existent branch' '
152 (
153 cd test &&
154 echo "fatal: No such remote: foo" >expect &&
155 test_must_fail git remote rename foo bar 2>actual &&
156 test_i18ncmp expect actual
157 )
158'
159
160cat >test/expect <<EOF
161* remote origin
162 Fetch URL: $(pwd)/one
163 Push URL: $(pwd)/one
164 HEAD branch: master
165 Remote branches:
166 master new (next fetch will store in remotes/origin)
167 side tracked
168 Local branches configured for 'git pull':
169 ahead merges with remote master
170 master merges with remote master
171 octopus merges with remote topic-a
172 and with remote topic-b
173 and with remote topic-c
174 rebase rebases onto remote master
175 Local refs configured for 'git push':
176 master pushes to master (local out of date)
177 master pushes to upstream (create)
178* remote two
179 Fetch URL: ../two
180 Push URL: ../three
181 HEAD branch: master
182 Local refs configured for 'git push':
183 ahead forces to master (fast-forwardable)
184 master pushes to another (up to date)
185EOF
186
187test_expect_success 'show' '
188 (
189 cd test &&
190 git config --add remote.origin.fetch refs/heads/master:refs/heads/upstream &&
191 git fetch &&
192 git checkout -b ahead origin/master &&
193 echo 1 >>file &&
194 test_tick &&
195 git commit -m update file &&
196 git checkout master &&
197 git branch --track octopus origin/master &&
198 git branch --track rebase origin/master &&
199 git branch -d -r origin/master &&
200 git config --add remote.two.url ../two &&
201 git config --add remote.two.pushurl ../three &&
202 git config branch.rebase.rebase true &&
203 git config branch.octopus.merge "topic-a topic-b topic-c" &&
204 (
205 cd ../one &&
206 echo 1 >file &&
207 test_tick &&
208 git commit -m update file
209 ) &&
210 git config --add remote.origin.push : &&
211 git config --add remote.origin.push refs/heads/master:refs/heads/upstream &&
212 git config --add remote.origin.push +refs/tags/lastbackup &&
213 git config --add remote.two.push +refs/heads/ahead:refs/heads/master &&
214 git config --add remote.two.push refs/heads/master:refs/heads/another &&
215 git remote show origin two >output &&
216 git branch -d rebase octopus &&
217 test_i18ncmp expect output
218 )
219'
220
221cat >test/expect <<EOF
222* remote origin
223 Fetch URL: $(pwd)/one
224 Push URL: $(pwd)/one
225 HEAD branch: (not queried)
226 Remote branches: (status not queried)
227 master
228 side
229 Local branches configured for 'git pull':
230 ahead merges with remote master
231 master merges with remote master
232 Local refs configured for 'git push' (status not queried):
233 (matching) pushes to (matching)
234 refs/heads/master pushes to refs/heads/upstream
235 refs/tags/lastbackup forces to refs/tags/lastbackup
236EOF
237
238test_expect_success 'show -n' '
239 mv one one.unreachable &&
240 (
241 cd test &&
242 git remote show -n origin >output &&
243 mv ../one.unreachable ../one &&
244 test_i18ncmp expect output
245 )
246'
247
248test_expect_success 'prune' '
249 (
250 cd one &&
251 git branch -m side side2
252 ) &&
253 (
254 cd test &&
255 git fetch origin &&
256 git remote prune origin &&
257 git rev-parse refs/remotes/origin/side2 &&
258 test_must_fail git rev-parse refs/remotes/origin/side
259 )
260'
261
262test_expect_success 'set-head --delete' '
263 (
264 cd test &&
265 git symbolic-ref refs/remotes/origin/HEAD &&
266 git remote set-head --delete origin &&
267 test_must_fail git symbolic-ref refs/remotes/origin/HEAD
268 )
269'
270
271test_expect_success 'set-head --auto' '
272 (
273 cd test &&
274 git remote set-head --auto origin &&
275 echo refs/remotes/origin/master >expect &&
276 git symbolic-ref refs/remotes/origin/HEAD >output &&
277 test_cmp expect output
278 )
279'
280
281test_expect_success 'set-head --auto has no problem w/multiple HEADs' '
282 (
283 cd test &&
284 git fetch two "refs/heads/*:refs/remotes/two/*" &&
285 git remote set-head --auto two >output 2>&1 &&
286 echo "two/HEAD set to master" >expect &&
287 test_i18ncmp expect output
288 )
289'
290
291cat >test/expect <<\EOF
292refs/remotes/origin/side2
293EOF
294
295test_expect_success 'set-head explicit' '
296 (
297 cd test &&
298 git remote set-head origin side2 &&
299 git symbolic-ref refs/remotes/origin/HEAD >output &&
300 git remote set-head origin master &&
301 test_cmp expect output
302 )
303'
304
305cat >test/expect <<EOF
306Pruning origin
307URL: $(pwd)/one
308 * [would prune] origin/side2
309EOF
310
311test_expect_success 'prune --dry-run' '
312 (
313 cd one &&
314 git branch -m side2 side) &&
315 (
316 cd test &&
317 git remote prune --dry-run origin >output &&
318 git rev-parse refs/remotes/origin/side2 &&
319 test_must_fail git rev-parse refs/remotes/origin/side &&
320 (
321 cd ../one &&
322 git branch -m side side2) &&
323 test_i18ncmp expect output
324 )
325'
326
327test_expect_success 'add --mirror && prune' '
328 mkdir mirror &&
329 (
330 cd mirror &&
331 git init --bare &&
332 git remote add --mirror -f origin ../one
333 ) &&
334 (
335 cd one &&
336 git branch -m side2 side
337 ) &&
338 (
339 cd mirror &&
340 git rev-parse --verify refs/heads/side2 &&
341 test_must_fail git rev-parse --verify refs/heads/side &&
342 git fetch origin &&
343 git remote prune origin &&
344 test_must_fail git rev-parse --verify refs/heads/side2 &&
345 git rev-parse --verify refs/heads/side
346 )
347'
348
349test_expect_success 'add --mirror=fetch' '
350 mkdir mirror-fetch &&
351 git init mirror-fetch/parent &&
352 (
353 cd mirror-fetch/parent &&
354 test_commit one
355 ) &&
356 git init --bare mirror-fetch/child &&
357 (
358 cd mirror-fetch/child &&
359 git remote add --mirror=fetch -f parent ../parent
360 )
361'
362
363test_expect_success 'fetch mirrors act as mirrors during fetch' '
364 (
365 cd mirror-fetch/parent &&
366 git branch new &&
367 git branch -m master renamed
368 ) &&
369 (
370 cd mirror-fetch/child &&
371 git fetch parent &&
372 git rev-parse --verify refs/heads/new &&
373 git rev-parse --verify refs/heads/renamed
374 )
375'
376
377test_expect_success 'fetch mirrors can prune' '
378 (
379 cd mirror-fetch/child &&
380 git remote prune parent &&
381 test_must_fail git rev-parse --verify refs/heads/master
382 )
383'
384
385test_expect_success 'fetch mirrors do not act as mirrors during push' '
386 (
387 cd mirror-fetch/parent &&
388 git checkout HEAD^0
389 ) &&
390 (
391 cd mirror-fetch/child &&
392 git branch -m renamed renamed2 &&
393 git push parent :
394 ) &&
395 (
396 cd mirror-fetch/parent &&
397 git rev-parse --verify renamed &&
398 test_must_fail git rev-parse --verify refs/heads/renamed2
399 )
400'
401
402test_expect_success 'add fetch mirror with specific branches' '
403 git init --bare mirror-fetch/track &&
404 (
405 cd mirror-fetch/track &&
406 git remote add --mirror=fetch -t heads/new parent ../parent
407 )
408'
409
410test_expect_success 'fetch mirror respects specific branches' '
411 (
412 cd mirror-fetch/track &&
413 git fetch parent &&
414 git rev-parse --verify refs/heads/new &&
415 test_must_fail git rev-parse --verify refs/heads/renamed
416 )
417'
418
419test_expect_success 'add --mirror=push' '
420 mkdir mirror-push &&
421 git init --bare mirror-push/public &&
422 git init mirror-push/private &&
423 (
424 cd mirror-push/private &&
425 test_commit one &&
426 git remote add --mirror=push public ../public
427 )
428'
429
430test_expect_success 'push mirrors act as mirrors during push' '
431 (
432 cd mirror-push/private &&
433 git branch new &&
434 git branch -m master renamed &&
435 git push public
436 ) &&
437 (
438 cd mirror-push/private &&
439 git rev-parse --verify refs/heads/new &&
440 git rev-parse --verify refs/heads/renamed &&
441 test_must_fail git rev-parse --verify refs/heads/master
442 )
443'
444
445test_expect_success 'push mirrors do not act as mirrors during fetch' '
446 (
447 cd mirror-push/public &&
448 git branch -m renamed renamed2 &&
449 git symbolic-ref HEAD refs/heads/renamed2
450 ) &&
451 (
452 cd mirror-push/private &&
453 git fetch public &&
454 git rev-parse --verify refs/heads/renamed &&
455 test_must_fail git rev-parse --verify refs/heads/renamed2
456 )
457'
458
459test_expect_success 'push mirrors do not allow you to specify refs' '
460 git init mirror-push/track &&
461 (
462 cd mirror-push/track &&
463 test_must_fail git remote add --mirror=push -t new public ../public
464 )
465'
466
467test_expect_success 'add alt && prune' '
468 mkdir alttst &&
469 (
470 cd alttst &&
471 git init &&
472 git remote add -f origin ../one &&
473 git config remote.alt.url ../one &&
474 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*"
475 ) &&
476 (
477 cd one &&
478 git branch -m side side2
479 ) &&
480 (
481 cd alttst &&
482 git rev-parse --verify refs/remotes/origin/side &&
483 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
484 git fetch alt &&
485 git remote prune alt &&
486 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
487 git rev-parse --verify refs/remotes/origin/side2
488 )
489'
490
491cat >test/expect <<\EOF
492some-tag
493EOF
494
495test_expect_success 'add with reachable tags (default)' '
496 (
497 cd one &&
498 >foobar &&
499 git add foobar &&
500 git commit -m "Foobar" &&
501 git tag -a -m "Foobar tag" foobar-tag &&
502 git reset --hard HEAD~1 &&
503 git tag -a -m "Some tag" some-tag
504 ) &&
505 mkdir add-tags &&
506 (
507 cd add-tags &&
508 git init &&
509 git remote add -f origin ../one &&
510 git tag -l some-tag >../test/output &&
511 git tag -l foobar-tag >>../test/output &&
512 test_must_fail git config remote.origin.tagopt
513 ) &&
514 test_cmp test/expect test/output
515'
516
517cat >test/expect <<\EOF
518some-tag
519foobar-tag
520--tags
521EOF
522
523test_expect_success 'add --tags' '
524 rm -rf add-tags &&
525 (
526 mkdir add-tags &&
527 cd add-tags &&
528 git init &&
529 git remote add -f --tags origin ../one &&
530 git tag -l some-tag >../test/output &&
531 git tag -l foobar-tag >>../test/output &&
532 git config remote.origin.tagopt >>../test/output
533 ) &&
534 test_cmp test/expect test/output
535'
536
537cat >test/expect <<\EOF
538--no-tags
539EOF
540
541test_expect_success 'add --no-tags' '
542 rm -rf add-tags &&
543 (
544 mkdir add-no-tags &&
545 cd add-no-tags &&
546 git init &&
547 git remote add -f --no-tags origin ../one &&
548 git tag -l some-tag >../test/output &&
549 git tag -l foobar-tag >../test/output &&
550 git config remote.origin.tagopt >>../test/output
551 ) &&
552 (
553 cd one &&
554 git tag -d some-tag foobar-tag
555 ) &&
556 test_cmp test/expect test/output
557'
558
559test_expect_success 'reject --no-no-tags' '
560 (
561 cd add-no-tags &&
562 test_must_fail git remote add -f --no-no-tags neworigin ../one
563 )
564'
565
566cat >one/expect <<\EOF
567 apis/master
568 apis/side
569 drosophila/another
570 drosophila/master
571 drosophila/side
572EOF
573
574test_expect_success 'update' '
575 (
576 cd one &&
577 git remote add drosophila ../two &&
578 git remote add apis ../mirror &&
579 git remote update &&
580 git branch -r >output &&
581 test_cmp expect output
582 )
583'
584
585cat >one/expect <<\EOF
586 drosophila/another
587 drosophila/master
588 drosophila/side
589 manduca/master
590 manduca/side
591 megaloprepus/master
592 megaloprepus/side
593EOF
594
595test_expect_success 'update with arguments' '
596 (
597 cd one &&
598 for b in $(git branch -r)
599 do
600 git branch -r -d $b || exit 1
601 done &&
602 git remote add manduca ../mirror &&
603 git remote add megaloprepus ../mirror &&
604 git config remotes.phobaeticus "drosophila megaloprepus" &&
605 git config remotes.titanus manduca &&
606 git remote update phobaeticus titanus &&
607 git branch -r >output &&
608 test_cmp expect output
609 )
610'
611
612test_expect_success 'update --prune' '
613 (
614 cd one &&
615 git branch -m side2 side3
616 ) &&
617 (
618 cd test &&
619 git remote update --prune &&
620 (
621 cd ../one &&
622 git branch -m side3 side2
623 ) &&
624 git rev-parse refs/remotes/origin/side3 &&
625 test_must_fail git rev-parse refs/remotes/origin/side2
626 )
627'
628
629cat >one/expect <<-\EOF
630 apis/master
631 apis/side
632 manduca/master
633 manduca/side
634 megaloprepus/master
635 megaloprepus/side
636EOF
637
638test_expect_success 'update default' '
639 (
640 cd one &&
641 for b in $(git branch -r)
642 do
643 git branch -r -d $b || exit 1
644 done &&
645 git config remote.drosophila.skipDefaultUpdate true &&
646 git remote update default &&
647 git branch -r >output &&
648 test_cmp expect output
649 )
650'
651
652cat >one/expect <<\EOF
653 drosophila/another
654 drosophila/master
655 drosophila/side
656EOF
657
658test_expect_success 'update default (overridden, with funny whitespace)' '
659 (
660 cd one &&
661 for b in $(git branch -r)
662 do
663 git branch -r -d $b || exit 1
664 done &&
665 git config remotes.default "$(printf "\t drosophila \n")" &&
666 git remote update default &&
667 git branch -r >output &&
668 test_cmp expect output
669 )
670'
671
672test_expect_success 'update (with remotes.default defined)' '
673 (
674 cd one &&
675 for b in $(git branch -r)
676 do
677 git branch -r -d $b || exit 1
678 done &&
679 git config remotes.default "drosophila" &&
680 git remote update &&
681 git branch -r >output &&
682 test_cmp expect output
683 )
684'
685
686test_expect_success '"remote show" does not show symbolic refs' '
687 git clone one three &&
688 (
689 cd three &&
690 git remote show origin >output &&
691 ! grep "^ *HEAD$" < output &&
692 ! grep -i stale < output
693 )
694'
695
696test_expect_success 'reject adding remote with an invalid name' '
697 test_must_fail git remote add some:url desired-name
698'
699
700# The first three test if the tracking branches are properly renamed,
701# the last two ones check if the config is updated.
702
703test_expect_success 'rename a remote' '
704 git clone one four &&
705 (
706 cd four &&
707 git remote rename origin upstream &&
708 rmdir .git/refs/remotes/origin &&
709 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
710 test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
711 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
712 test "$(git config branch.master.remote)" = "upstream"
713 )
714'
715
716test_expect_success 'rename does not update a non-default fetch refspec' '
717 git clone one four.one &&
718 (
719 cd four.one &&
720 git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
721 git remote rename origin upstream &&
722 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" &&
723 git rev-parse -q origin/master
724 )
725'
726
727test_expect_success 'rename a remote with name part of fetch spec' '
728 git clone one four.two &&
729 (
730 cd four.two &&
731 git remote rename origin remote &&
732 git remote rename remote upstream &&
733 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*"
734 )
735'
736
737test_expect_success 'rename a remote with name prefix of other remote' '
738 git clone one four.three &&
739 (
740 cd four.three &&
741 git remote add o git://example.com/repo.git &&
742 git remote rename o upstream &&
743 test "$(git rev-parse origin/master)" = "$(git rev-parse master)"
744 )
745'
746
747cat >remotes_origin <<EOF
748URL: $(pwd)/one
749Push: refs/heads/master:refs/heads/upstream
750Push: refs/heads/next:refs/heads/upstream2
751Pull: refs/heads/master:refs/heads/origin
752Pull: refs/heads/next:refs/heads/origin2
753EOF
754
755test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
756 git clone one five &&
757 origin_url=$(pwd)/one &&
758 (
759 cd five &&
760 git remote remove origin &&
761 mkdir -p .git/remotes &&
762 cat ../remotes_origin >.git/remotes/origin &&
763 git remote rename origin origin &&
764 test_path_is_missing .git/remotes/origin &&
765 test "$(git config remote.origin.url)" = "$origin_url" &&
766 cat >push_expected <<-\EOF &&
767 refs/heads/master:refs/heads/upstream
768 refs/heads/next:refs/heads/upstream2
769 EOF
770 cat >fetch_expected <<-\EOF &&
771 refs/heads/master:refs/heads/origin
772 refs/heads/next:refs/heads/origin2
773 EOF
774 git config --get-all remote.origin.push >push_actual &&
775 git config --get-all remote.origin.fetch >fetch_actual &&
776 test_cmp push_expected push_actual &&
777 test_cmp fetch_expected fetch_actual
778 )
779'
780
781test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
782 git clone one six &&
783 origin_url=$(pwd)/one &&
784 (
785 cd six &&
786 git remote rm origin &&
787 echo "$origin_url" >.git/branches/origin &&
788 git remote rename origin origin &&
789 test_path_is_missing .git/branches/origin &&
790 test "$(git config remote.origin.url)" = "$origin_url" &&
791 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin" &&
792 test "$(git config remote.origin.push)" = "HEAD:refs/heads/master"
793 )
794'
795
796test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' '
797 git clone one seven &&
798 (
799 cd seven &&
800 git remote rm origin &&
801 echo "quux#foom" > .git/branches/origin &&
802 git remote rename origin origin &&
803 test_path_is_missing .git/branches/origin &&
804 test "$(git config remote.origin.url)" = "quux" &&
805 test "$(git config remote.origin.fetch)" = "refs/heads/foom:refs/heads/origin"
806 test "$(git config remote.origin.push)" = "HEAD:refs/heads/foom"
807 )
808'
809
810test_expect_success 'remote prune to cause a dangling symref' '
811 git clone one eight &&
812 (
813 cd one &&
814 git checkout side2 &&
815 git branch -D master
816 ) &&
817 (
818 cd eight &&
819 git remote prune origin
820 ) >err 2>&1 &&
821 test_i18ngrep "has become dangling" err &&
822
823 : And the dangling symref will not cause other annoying errors &&
824 (
825 cd eight &&
826 git branch -a
827 ) 2>err &&
828 ! grep "points nowhere" err &&
829 (
830 cd eight &&
831 test_must_fail git branch nomore origin
832 ) 2>err &&
833 grep "dangling symref" err
834'
835
836test_expect_success 'show empty remote' '
837 test_create_repo empty &&
838 git clone empty empty-clone &&
839 (
840 cd empty-clone &&
841 git remote show origin
842 )
843'
844
845test_expect_success 'remote set-branches requires a remote' '
846 test_must_fail git remote set-branches &&
847 test_must_fail git remote set-branches --add
848'
849
850test_expect_success 'remote set-branches' '
851 echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial &&
852 sort <<-\EOF >expect.add &&
853 +refs/heads/*:refs/remotes/scratch/*
854 +refs/heads/other:refs/remotes/scratch/other
855 EOF
856 sort <<-\EOF >expect.replace &&
857 +refs/heads/maint:refs/remotes/scratch/maint
858 +refs/heads/master:refs/remotes/scratch/master
859 +refs/heads/next:refs/remotes/scratch/next
860 EOF
861 sort <<-\EOF >expect.add-two &&
862 +refs/heads/maint:refs/remotes/scratch/maint
863 +refs/heads/master:refs/remotes/scratch/master
864 +refs/heads/next:refs/remotes/scratch/next
865 +refs/heads/pu:refs/remotes/scratch/pu
866 +refs/heads/t/topic:refs/remotes/scratch/t/topic
867 EOF
868 sort <<-\EOF >expect.setup-ffonly &&
869 refs/heads/master:refs/remotes/scratch/master
870 +refs/heads/next:refs/remotes/scratch/next
871 EOF
872 sort <<-\EOF >expect.respect-ffonly &&
873 refs/heads/master:refs/remotes/scratch/master
874 +refs/heads/next:refs/remotes/scratch/next
875 +refs/heads/pu:refs/remotes/scratch/pu
876 EOF
877
878 git clone .git/ setbranches &&
879 (
880 cd setbranches &&
881 git remote rename origin scratch &&
882 git config --get-all remote.scratch.fetch >config-result &&
883 sort <config-result >../actual.initial &&
884
885 git remote set-branches scratch --add other &&
886 git config --get-all remote.scratch.fetch >config-result &&
887 sort <config-result >../actual.add &&
888
889 git remote set-branches scratch maint master next &&
890 git config --get-all remote.scratch.fetch >config-result &&
891 sort <config-result >../actual.replace &&
892
893 git remote set-branches --add scratch pu t/topic &&
894 git config --get-all remote.scratch.fetch >config-result &&
895 sort <config-result >../actual.add-two &&
896
897 git config --unset-all remote.scratch.fetch &&
898 git config remote.scratch.fetch \
899 refs/heads/master:refs/remotes/scratch/master &&
900 git config --add remote.scratch.fetch \
901 +refs/heads/next:refs/remotes/scratch/next &&
902 git config --get-all remote.scratch.fetch >config-result &&
903 sort <config-result >../actual.setup-ffonly &&
904
905 git remote set-branches --add scratch pu &&
906 git config --get-all remote.scratch.fetch >config-result &&
907 sort <config-result >../actual.respect-ffonly
908 ) &&
909 test_cmp expect.initial actual.initial &&
910 test_cmp expect.add actual.add &&
911 test_cmp expect.replace actual.replace &&
912 test_cmp expect.add-two actual.add-two &&
913 test_cmp expect.setup-ffonly actual.setup-ffonly &&
914 test_cmp expect.respect-ffonly actual.respect-ffonly
915'
916
917test_expect_success 'remote set-branches with --mirror' '
918 echo "+refs/*:refs/*" >expect.initial &&
919 echo "+refs/heads/master:refs/heads/master" >expect.replace &&
920 git clone --mirror .git/ setbranches-mirror &&
921 (
922 cd setbranches-mirror &&
923 git remote rename origin scratch &&
924 git config --get-all remote.scratch.fetch >../actual.initial &&
925
926 git remote set-branches scratch heads/master &&
927 git config --get-all remote.scratch.fetch >../actual.replace
928 ) &&
929 test_cmp expect.initial actual.initial &&
930 test_cmp expect.replace actual.replace
931'
932
933test_expect_success 'new remote' '
934 git remote add someremote foo &&
935 echo foo >expect &&
936 git config --get-all remote.someremote.url >actual &&
937 cmp expect actual
938'
939
940get_url_test () {
941 cat >expect &&
942 git remote get-url "$@" >actual &&
943 test_cmp expect actual
944}
945
946test_expect_success 'get-url on new remote' '
947 echo foo | get_url_test someremote &&
948 echo foo | get_url_test --all someremote &&
949 echo foo | get_url_test --push someremote &&
950 echo foo | get_url_test --push --all someremote
951'
952
953test_expect_success 'remote set-url bar' '
954 git remote set-url someremote bar &&
955 echo bar >expect &&
956 git config --get-all remote.someremote.url >actual &&
957 cmp expect actual
958'
959
960test_expect_success 'remote set-url baz bar' '
961 git remote set-url someremote baz bar &&
962 echo baz >expect &&
963 git config --get-all remote.someremote.url >actual &&
964 cmp expect actual
965'
966
967test_expect_success 'remote set-url zot bar' '
968 test_must_fail git remote set-url someremote zot bar &&
969 echo baz >expect &&
970 git config --get-all remote.someremote.url >actual &&
971 cmp expect actual
972'
973
974test_expect_success 'remote set-url --push zot baz' '
975 test_must_fail git remote set-url --push someremote zot baz &&
976 echo "YYY" >expect &&
977 echo baz >>expect &&
978 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
979 echo "YYY" >>actual &&
980 git config --get-all remote.someremote.url >>actual &&
981 cmp expect actual
982'
983
984test_expect_success 'remote set-url --push zot' '
985 git remote set-url --push someremote zot &&
986 echo zot >expect &&
987 echo "YYY" >>expect &&
988 echo baz >>expect &&
989 git config --get-all remote.someremote.pushurl >actual &&
990 echo "YYY" >>actual &&
991 git config --get-all remote.someremote.url >>actual &&
992 cmp expect actual
993'
994
995test_expect_success 'get-url with different urls' '
996 echo baz | get_url_test someremote &&
997 echo baz | get_url_test --all someremote &&
998 echo zot | get_url_test --push someremote &&
999 echo zot | get_url_test --push --all someremote
1000'
1001
1002test_expect_success 'remote set-url --push qux zot' '
1003 git remote set-url --push someremote qux zot &&
1004 echo qux >expect &&
1005 echo "YYY" >>expect &&
1006 echo baz >>expect &&
1007 git config --get-all remote.someremote.pushurl >actual &&
1008 echo "YYY" >>actual &&
1009 git config --get-all remote.someremote.url >>actual &&
1010 cmp expect actual
1011'
1012
1013test_expect_success 'remote set-url --push foo qu+x' '
1014 git remote set-url --push someremote foo qu+x &&
1015 echo foo >expect &&
1016 echo "YYY" >>expect &&
1017 echo baz >>expect &&
1018 git config --get-all remote.someremote.pushurl >actual &&
1019 echo "YYY" >>actual &&
1020 git config --get-all remote.someremote.url >>actual &&
1021 cmp expect actual
1022'
1023
1024test_expect_success 'remote set-url --push --add aaa' '
1025 git remote set-url --push --add someremote aaa &&
1026 echo foo >expect &&
1027 echo aaa >>expect &&
1028 echo "YYY" >>expect &&
1029 echo baz >>expect &&
1030 git config --get-all remote.someremote.pushurl >actual &&
1031 echo "YYY" >>actual &&
1032 git config --get-all remote.someremote.url >>actual &&
1033 cmp expect actual
1034'
1035
1036test_expect_success 'get-url on multi push remote' '
1037 echo foo | get_url_test --push someremote &&
1038 get_url_test --push --all someremote <<-\EOF
1039 foo
1040 aaa
1041 EOF
1042'
1043
1044test_expect_success 'remote set-url --push bar aaa' '
1045 git remote set-url --push someremote bar aaa &&
1046 echo foo >expect &&
1047 echo bar >>expect &&
1048 echo "YYY" >>expect &&
1049 echo baz >>expect &&
1050 git config --get-all remote.someremote.pushurl >actual &&
1051 echo "YYY" >>actual &&
1052 git config --get-all remote.someremote.url >>actual &&
1053 cmp expect actual
1054'
1055
1056test_expect_success 'remote set-url --push --delete bar' '
1057 git remote set-url --push --delete someremote bar &&
1058 echo foo >expect &&
1059 echo "YYY" >>expect &&
1060 echo baz >>expect &&
1061 git config --get-all remote.someremote.pushurl >actual &&
1062 echo "YYY" >>actual &&
1063 git config --get-all remote.someremote.url >>actual &&
1064 cmp expect actual
1065'
1066
1067test_expect_success 'remote set-url --push --delete foo' '
1068 git remote set-url --push --delete someremote foo &&
1069 echo "YYY" >expect &&
1070 echo baz >>expect &&
1071 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1072 echo "YYY" >>actual &&
1073 git config --get-all remote.someremote.url >>actual &&
1074 cmp expect actual
1075'
1076
1077test_expect_success 'remote set-url --add bbb' '
1078 git remote set-url --add someremote bbb &&
1079 echo "YYY" >expect &&
1080 echo baz >>expect &&
1081 echo bbb >>expect &&
1082 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1083 echo "YYY" >>actual &&
1084 git config --get-all remote.someremote.url >>actual &&
1085 cmp expect actual
1086'
1087
1088test_expect_success 'get-url on multi fetch remote' '
1089 echo baz | get_url_test someremote &&
1090 get_url_test --all someremote <<-\EOF
1091 baz
1092 bbb
1093 EOF
1094'
1095
1096test_expect_success 'remote set-url --delete .*' '
1097 test_must_fail git remote set-url --delete someremote .\* &&
1098 echo "YYY" >expect &&
1099 echo baz >>expect &&
1100 echo bbb >>expect &&
1101 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1102 echo "YYY" >>actual &&
1103 git config --get-all remote.someremote.url >>actual &&
1104 cmp expect actual
1105'
1106
1107test_expect_success 'remote set-url --delete bbb' '
1108 git remote set-url --delete someremote bbb &&
1109 echo "YYY" >expect &&
1110 echo baz >>expect &&
1111 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1112 echo "YYY" >>actual &&
1113 git config --get-all remote.someremote.url >>actual &&
1114 cmp expect actual
1115'
1116
1117test_expect_success 'remote set-url --delete baz' '
1118 test_must_fail git remote set-url --delete someremote baz &&
1119 echo "YYY" >expect &&
1120 echo baz >>expect &&
1121 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1122 echo "YYY" >>actual &&
1123 git config --get-all remote.someremote.url >>actual &&
1124 cmp expect actual
1125'
1126
1127test_expect_success 'remote set-url --add ccc' '
1128 git remote set-url --add someremote ccc &&
1129 echo "YYY" >expect &&
1130 echo baz >>expect &&
1131 echo ccc >>expect &&
1132 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1133 echo "YYY" >>actual &&
1134 git config --get-all remote.someremote.url >>actual &&
1135 cmp expect actual
1136'
1137
1138test_expect_success 'remote set-url --delete baz' '
1139 git remote set-url --delete someremote baz &&
1140 echo "YYY" >expect &&
1141 echo ccc >>expect &&
1142 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1143 echo "YYY" >>actual &&
1144 git config --get-all remote.someremote.url >>actual &&
1145 cmp expect actual
1146'
1147
1148test_expect_success 'extra args: setup' '
1149 # add a dummy origin so that this does not trigger failure
1150 git remote add origin .
1151'
1152
1153test_extra_arg () {
1154 test_expect_success "extra args: $*" "
1155 test_must_fail git remote $* bogus_extra_arg 2>actual &&
1156 grep '^usage:' actual
1157 "
1158}
1159
1160test_extra_arg add nick url
1161test_extra_arg rename origin newname
1162test_extra_arg remove origin
1163test_extra_arg set-head origin master
1164# set-branches takes any number of args
1165test_extra_arg get-url origin newurl
1166test_extra_arg set-url origin newurl oldurl
1167# show takes any number of args
1168# prune takes any number of args
1169# update takes any number of args
1170
1171test_expect_success 'add remote matching the "insteadOf" URL' '
1172 git config url.xyz@example.com.insteadOf backup &&
1173 git remote add backup xyz@example.com
1174'
1175
1176test_done