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