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