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