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