]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5505-remote.sh
remote: actually check if remote exits
[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
f7dc6a96 54test_expect_success C_LOCALE_OUTPUT 'remote information for the origin' '
9b9439af
RR
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 )
683b5679
JH
61'
62
63test_expect_success 'add another remote' '
9b9439af
RR
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 )
683b5679
JH
75'
76
d6ac1d21 77test_expect_success C_LOCALE_OUTPUT 'check remote-tracking' '
9b9439af
RR
78 (
79 cd test &&
80 check_remote_track origin master side &&
81 check_remote_track second master side another
82 )
f7dc6a96
JX
83'
84
1ce89cc4 85test_expect_success 'remote forces tracking branches' '
9b9439af
RR
86 (
87 cd test &&
c0097814 88 case $(git config remote.second.fetch) in
9b9439af
RR
89 +*) true ;;
90 *) false ;;
91 esac
92 )
1ce89cc4
JK
93'
94
683b5679 95test_expect_success 'remove remote' '
9b9439af
RR
96 (
97 cd test &&
98 git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master &&
99 git remote rm second
100 )
683b5679
JH
101'
102
f7dc6a96 103test_expect_success C_LOCALE_OUTPUT 'remove remote' '
9b9439af
RR
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 )
683b5679
JH
113'
114
13931236 115test_expect_success 'remove remote protects local branches' '
9b9439af
RR
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
cc8e538d
TG
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
9b9439af 160cat >test/expect <<EOF
4704640b 161* remote origin
857f8c30
MG
162 Fetch URL: $(pwd)/one
163 Push URL: $(pwd)/one
e61e0cc6 164 HEAD branch: master
7ecbbf87
JS
165 Remote branches:
166 master new (next fetch will store in remotes/origin)
167 side tracked
168 Local branches configured for 'git pull':
e5dcbfd9 169 ahead merges with remote master
7ecbbf87
JS
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
e5dcbfd9
JS
175 Local refs configured for 'git push':
176 master pushes to master (local out of date)
177 master pushes to upstream (create)
e61e0cc6 178* remote two
857f8c30
MG
179 Fetch URL: ../two
180 Push URL: ../three
a45b5f05 181 HEAD branch: master
e5dcbfd9 182 Local refs configured for 'git push':
a75d7b54 183 ahead forces to master (fast-forwardable)
e5dcbfd9 184 master pushes to another (up to date)
4704640b
JS
185EOF
186
187test_expect_success 'show' '
9b9439af
RR
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
0ecfcb3b 222* remote origin
857f8c30
MG
223 Fetch URL: $(pwd)/one
224 Push URL: $(pwd)/one
e61e0cc6 225 HEAD branch: (not queried)
7ecbbf87 226 Remote branches: (status not queried)
20244ea2
JS
227 master
228 side
e5dcbfd9
JS
229 Local branches configured for 'git pull':
230 ahead merges with remote master
7ecbbf87 231 master merges with remote master
e5dcbfd9
JS
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
0ecfcb3b
OM
236EOF
237
238test_expect_success 'show -n' '
9b9439af
RR
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 )
0ecfcb3b
OM
246'
247
4704640b 248test_expect_success 'prune' '
9b9439af
RR
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 )
4704640b
JS
260'
261
bc14fac8 262test_expect_success 'set-head --delete' '
9b9439af
RR
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 )
bc14fac8
JS
269'
270
271test_expect_success 'set-head --auto' '
9b9439af
RR
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
bc14fac8
JS
278 )
279'
280
a45b5f05 281test_expect_success 'set-head --auto has no problem w/multiple HEADs' '
9b9439af
RR
282 (
283 cd test &&
a4dfee06 284 git fetch two "refs/heads/*:refs/remotes/two/*" &&
a45b5f05
JH
285 git remote set-head --auto two >output 2>&1 &&
286 echo "two/HEAD set to master" >expect &&
9b9439af
RR
287 test_i18ncmp expect output
288 )
bc14fac8
JS
289'
290
9b9439af 291cat >test/expect <<\EOF
bc14fac8
JS
292refs/remotes/origin/side2
293EOF
294
295test_expect_success 'set-head explicit' '
9b9439af
RR
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 )
bc14fac8
JS
303'
304
9b9439af 305cat >test/expect <<EOF
8d767927 306Pruning origin
86521aca 307URL: $(pwd)/one
8d767927
OM
308 * [would prune] origin/side2
309EOF
310
311test_expect_success 'prune --dry-run' '
9b9439af
RR
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 )
8d767927
OM
325'
326
4ebc914c 327test_expect_success 'add --mirror && prune' '
9b9439af
RR
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 )
4ebc914c
JS
347'
348
a9f5a355
JK
349test_expect_success 'add --mirror=fetch' '
350 mkdir mirror-fetch &&
351 git init mirror-fetch/parent &&
9b9439af
RR
352 (
353 cd mirror-fetch/parent &&
354 test_commit one
355 ) &&
a9f5a355 356 git init --bare mirror-fetch/child &&
9b9439af
RR
357 (
358 cd mirror-fetch/child &&
359 git remote add --mirror=fetch -f parent ../parent
360 )
a9f5a355
JK
361'
362
363test_expect_success 'fetch mirrors act as mirrors during fetch' '
9b9439af
RR
364 (
365 cd mirror-fetch/parent &&
366 git branch new &&
367 git branch -m master renamed
a9f5a355 368 ) &&
9b9439af
RR
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
a9f5a355
JK
374 )
375'
376
377test_expect_success 'fetch mirrors can prune' '
9b9439af
RR
378 (
379 cd mirror-fetch/child &&
380 git remote prune parent &&
381 test_must_fail git rev-parse --verify refs/heads/master
a9f5a355
JK
382 )
383'
384
385test_expect_success 'fetch mirrors do not act as mirrors during push' '
9b9439af
RR
386 (
387 cd mirror-fetch/parent &&
388 git checkout HEAD^0
a9f5a355 389 ) &&
9b9439af
RR
390 (
391 cd mirror-fetch/child &&
392 git branch -m renamed renamed2 &&
393 git push parent :
a9f5a355 394 ) &&
9b9439af
RR
395 (
396 cd mirror-fetch/parent &&
397 git rev-parse --verify renamed &&
398 test_must_fail git rev-parse --verify refs/heads/renamed2
a9f5a355
JK
399 )
400'
401
3eafdc96
JK
402test_expect_success 'add fetch mirror with specific branches' '
403 git init --bare mirror-fetch/track &&
9b9439af
RR
404 (
405 cd mirror-fetch/track &&
406 git remote add --mirror=fetch -t heads/new parent ../parent
3eafdc96
JK
407 )
408'
409
410test_expect_success 'fetch mirror respects specific branches' '
9b9439af
RR
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
3eafdc96
JK
416 )
417'
418
a9f5a355
JK
419test_expect_success 'add --mirror=push' '
420 mkdir mirror-push &&
421 git init --bare mirror-push/public &&
422 git init mirror-push/private &&
9b9439af
RR
423 (
424 cd mirror-push/private &&
425 test_commit one &&
426 git remote add --mirror=push public ../public
a9f5a355
JK
427 )
428'
429
430test_expect_success 'push mirrors act as mirrors during push' '
9b9439af
RR
431 (
432 cd mirror-push/private &&
433 git branch new &&
434 git branch -m master renamed &&
435 git push public
a9f5a355 436 ) &&
9b9439af
RR
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
a9f5a355
JK
442 )
443'
444
445test_expect_success 'push mirrors do not act as mirrors during fetch' '
9b9439af
RR
446 (
447 cd mirror-push/public &&
448 git branch -m renamed renamed2 &&
449 git symbolic-ref HEAD refs/heads/renamed2
a9f5a355 450 ) &&
9b9439af
RR
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
a9f5a355
JK
456 )
457'
458
3eafdc96
JK
459test_expect_success 'push mirrors do not allow you to specify refs' '
460 git init mirror-push/track &&
9b9439af
RR
461 (
462 cd mirror-push/track &&
463 test_must_fail git remote add --mirror=push -t new public ../public
3eafdc96
JK
464 )
465'
466
c175a7ad 467test_expect_success 'add alt && prune' '
9b9439af
RR
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 )
c175a7ad
SP
489'
490
111fb858
ST
491cat >test/expect <<\EOF
492some-tag
493EOF
494
495test_expect_success 'add with reachable tags (default)' '
9b9439af
RR
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 ) &&
111fb858
ST
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' '
9b9439af
RR
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 ) &&
111fb858
ST
534 test_cmp test/expect test/output
535'
536
537cat >test/expect <<\EOF
538--no-tags
539EOF
540
541test_expect_success 'add --no-tags' '
9b9439af
RR
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 ) &&
111fb858
ST
556 test_cmp test/expect test/output
557'
558
559test_expect_success 'reject --no-no-tags' '
9b9439af
RR
560 (
561 cd add-no-tags &&
562 test_must_fail git remote add -f --no-no-tags neworigin ../one
563 )
111fb858
ST
564'
565
9b9439af 566cat >one/expect <<\EOF
84521ed6
JS
567 apis/master
568 apis/side
569 drosophila/another
570 drosophila/master
571 drosophila/side
572EOF
573
574test_expect_success 'update' '
9b9439af
RR
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 )
84521ed6
JS
583'
584
9b9439af 585cat >one/expect <<\EOF
84521ed6
JS
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' '
9b9439af
RR
596 (
597 cd one &&
598 for b in $(git branch -r)
599 do
e6821d09 600 git branch -r -d $b || exit 1
9b9439af
RR
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 )
84521ed6
JS
610'
611
e2d41c64 612test_expect_success 'update --prune' '
9b9439af
RR
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 )
e2d41c64
BG
627'
628
9b9439af 629cat >one/expect <<-\EOF
84521ed6
JS
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' '
9b9439af
RR
639 (
640 cd one &&
641 for b in $(git branch -r)
642 do
e6821d09 643 git branch -r -d $b || exit 1
9b9439af
RR
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 )
84521ed6
JS
650'
651
9b9439af 652cat >one/expect <<\EOF
84521ed6
JS
653 drosophila/another
654 drosophila/master
655 drosophila/side
656EOF
657
658test_expect_success 'update default (overridden, with funny whitespace)' '
9b9439af
RR
659 (
660 cd one &&
661 for b in $(git branch -r)
662 do
e6821d09 663 git branch -r -d $b || exit 1
9b9439af
RR
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 )
84521ed6
JS
670'
671
4f2e842d 672test_expect_success 'update (with remotes.default defined)' '
9b9439af
RR
673 (
674 cd one &&
675 for b in $(git branch -r)
676 do
e6821d09 677 git branch -r -d $b || exit 1
9b9439af
RR
678 done &&
679 git config remotes.default "drosophila" &&
680 git remote update &&
681 git branch -r >output &&
682 test_cmp expect output
683 )
4f2e842d
BG
684'
685
740fdd27 686test_expect_success '"remote show" does not show symbolic refs' '
740fdd27 687 git clone one three &&
9b9439af
RR
688 (
689 cd three &&
690 git remote show origin >output &&
691 ! grep "^ *HEAD$" < output &&
692 ! grep -i stale < output
693 )
740fdd27
JS
694'
695
24b6177e 696test_expect_success 'reject adding remote with an invalid name' '
d492b31c 697 test_must_fail git remote add some:url desired-name
24b6177e
JF
698'
699
bf98421a
MV
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' '
bf98421a 704 git clone one four &&
9b9439af
RR
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 )
bf98421a 714'
1dd1239a 715
28f555f6 716test_expect_success 'rename does not update a non-default fetch refspec' '
28f555f6 717 git clone one four.one &&
9b9439af
RR
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 )
28f555f6
MZ
725'
726
727test_expect_success 'rename a remote with name part of fetch spec' '
28f555f6 728 git clone one four.two &&
9b9439af
RR
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 )
28f555f6
MZ
735'
736
60e5eee0 737test_expect_success 'rename a remote with name prefix of other remote' '
60e5eee0 738 git clone one four.three &&
9b9439af
RR
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 )
60e5eee0
MZ
745'
746
9b9439af 747cat >remotes_origin <<EOF
1dd1239a
MV
748URL: $(pwd)/one
749Push: refs/heads/master:refs/heads/upstream
f0f249d1 750Push: refs/heads/next:refs/heads/upstream2
1dd1239a 751Pull: refs/heads/master:refs/heads/origin
f0f249d1 752Pull: refs/heads/next:refs/heads/origin2
1dd1239a
MV
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 &&
9b9439af
RR
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 &&
fe3c1956 764 test_path_is_missing .git/remotes/origin &&
9b9439af 765 test "$(git config remote.origin.url)" = "$origin_url" &&
f0f249d1
RR
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
9b9439af 778 )
1dd1239a
MV
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 &&
9b9439af
RR
784 (
785 cd six &&
786 git remote rm origin &&
787 echo "$origin_url" >.git/branches/origin &&
788 git remote rename origin origin &&
fe3c1956 789 test_path_is_missing .git/branches/origin &&
9b9439af 790 test "$(git config remote.origin.url)" = "$origin_url" &&
294547f5
RR
791 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin" &&
792 test "$(git config remote.origin.push)" = "HEAD:refs/heads/master"
9b9439af 793 )
1dd1239a
MV
794'
795
1f9a5e90 796test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' '
f8948e2f 797 git clone one seven &&
1f9a5e90
RR
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 &&
f8948e2f
JH
812 (
813 cd one &&
814 git checkout side2 &&
815 git branch -D master
816 ) &&
817 (
1f9a5e90 818 cd eight &&
f8948e2f 819 git remote prune origin
e01de1c9 820 ) >err 2>&1 &&
f7dc6a96 821 test_i18ngrep "has become dangling" err &&
f8948e2f 822
e01de1c9 823 : And the dangling symref will not cause other annoying errors &&
f8948e2f 824 (
1f9a5e90 825 cd eight &&
f8948e2f
JH
826 git branch -a
827 ) 2>err &&
e01de1c9 828 ! grep "points nowhere" err &&
057e7138 829 (
1f9a5e90 830 cd eight &&
057e7138
JH
831 test_must_fail git branch nomore origin
832 ) 2>err &&
833 grep "dangling symref" err
f8948e2f
JH
834'
835
6a01554e 836test_expect_success 'show empty remote' '
6a01554e
CB
837 test_create_repo empty &&
838 git clone empty empty-clone &&
839 (
840 cd empty-clone &&
841 git remote show origin
842 )
843'
844
3d8b6949
JN
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
433f2be1 933test_expect_success 'new remote' '
433f2be1
IL
934 git remote add someremote foo &&
935 echo foo >expect &&
936 git config --get-all remote.someremote.url >actual &&
937 cmp expect actual
433f2be1
IL
938'
939
96f78d39
BB
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
433f2be1 953test_expect_success 'remote set-url bar' '
433f2be1
IL
954 git remote set-url someremote bar &&
955 echo bar >expect &&
956 git config --get-all remote.someremote.url >actual &&
957 cmp expect actual
433f2be1 958'
057e7138 959
433f2be1 960test_expect_success 'remote set-url baz bar' '
433f2be1
IL
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
433f2be1
IL
965'
966
967test_expect_success 'remote set-url zot bar' '
433f2be1
IL
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
433f2be1
IL
972'
973
974test_expect_success 'remote set-url --push zot baz' '
433f2be1
IL
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
433f2be1
IL
982'
983
984test_expect_success 'remote set-url --push zot' '
433f2be1
IL
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
433f2be1
IL
993'
994
96f78d39
BB
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
433f2be1 1002test_expect_success 'remote set-url --push qux zot' '
433f2be1
IL
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
433f2be1
IL
1011'
1012
1013test_expect_success 'remote set-url --push foo qu+x' '
433f2be1
IL
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
433f2be1
IL
1022'
1023
1024test_expect_success 'remote set-url --push --add aaa' '
433f2be1
IL
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
433f2be1
IL
1034'
1035
96f78d39
BB
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
433f2be1 1044test_expect_success 'remote set-url --push bar aaa' '
433f2be1
IL
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
433f2be1
IL
1054'
1055
1056test_expect_success 'remote set-url --push --delete bar' '
433f2be1
IL
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
433f2be1
IL
1065'
1066
1067test_expect_success 'remote set-url --push --delete foo' '
433f2be1
IL
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
433f2be1
IL
1075'
1076
1077test_expect_success 'remote set-url --add bbb' '
433f2be1
IL
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
433f2be1
IL
1086'
1087
96f78d39
BB
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
433f2be1 1096test_expect_success 'remote set-url --delete .*' '
49de47cf 1097 test_must_fail git remote set-url --delete someremote .\* &&
433f2be1
IL
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
433f2be1
IL
1105'
1106
1107test_expect_success 'remote set-url --delete bbb' '
433f2be1
IL
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
433f2be1
IL
1115'
1116
1117test_expect_success 'remote set-url --delete baz' '
433f2be1
IL
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
433f2be1
IL
1125'
1126
1127test_expect_success 'remote set-url --add ccc' '
433f2be1
IL
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
433f2be1
IL
1136'
1137
1138test_expect_success 'remote set-url --delete baz' '
433f2be1
IL
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
433f2be1
IL
1146'
1147
abf5f872
TR
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 () {
b17dd3f9 1154 test_expect_success "extra args: $*" "
abf5f872
TR
1155 test_must_fail git remote $* bogus_extra_arg 2>actual &&
1156 grep '^usage:' actual
1157 "
1158}
1159
2d2e3d25 1160test_extra_arg add nick url
abf5f872
TR
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
96f78d39 1165test_extra_arg get-url origin newurl
abf5f872 1166test_extra_arg set-url origin newurl oldurl
b17dd3f9
TR
1167# show takes any number of args
1168# prune takes any number of args
abf5f872
TR
1169# update takes any number of args
1170
b90c95d9
JS
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
433f2be1 1176test_done