]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5505-remote.sh
The third batch
[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 &&
b26a412f 261 grep "^error: unknown subcommand:" err
31a66c19
SG
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
5a97b381
JK
905test_expect_success 'rename handles remote without fetch refspec' '
906 git clone --bare one no-refspec.git &&
907 # confirm assumption that bare clone does not create refspec
908 test_expect_code 5 \
909 git -C no-refspec.git config --unset-all remote.origin.fetch &&
910 git -C no-refspec.git config remote.origin.url >expect &&
911 git -C no-refspec.git remote rename origin foo &&
912 git -C no-refspec.git config remote.foo.url >actual &&
913 test_cmp expect actual
914'
915
28f555f6 916test_expect_success 'rename does not update a non-default fetch refspec' '
28f555f6 917 git clone one four.one &&
9b9439af
RR
918 (
919 cd four.one &&
920 git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
921 git remote rename origin upstream &&
922 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" &&
97b91368 923 git rev-parse -q origin/main
9b9439af 924 )
28f555f6
MZ
925'
926
927test_expect_success 'rename a remote with name part of fetch spec' '
28f555f6 928 git clone one four.two &&
9b9439af
RR
929 (
930 cd four.two &&
931 git remote rename origin remote &&
932 git remote rename remote upstream &&
933 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*"
934 )
28f555f6
MZ
935'
936
60e5eee0 937test_expect_success 'rename a remote with name prefix of other remote' '
60e5eee0 938 git clone one four.three &&
9b9439af
RR
939 (
940 cd four.three &&
941 git remote add o git://example.com/repo.git &&
942 git remote rename o upstream &&
97b91368 943 test "$(git rev-parse origin/main)" = "$(git rev-parse main)"
9b9439af 944 )
60e5eee0
MZ
945'
946
e459b073 947test_expect_success 'rename succeeds with existing remote.<target>.prune' '
af5bacf4
JS
948 git clone one four.four &&
949 test_when_finished git config --global --unset remote.upstream.prune &&
950 git config --global remote.upstream.prune true &&
951 git -C four.four remote rename origin upstream
952'
953
923d4a5c 954test_expect_success 'remove a remote' '
b3fd6cbf 955 test_config_global remote.pushDefault origin &&
923d4a5c
BW
956 git clone one four.five &&
957 (
958 cd four.five &&
97b91368 959 git config branch.main.pushRemote origin &&
923d4a5c
BW
960 git remote remove origin &&
961 test -z "$(git for-each-ref refs/remotes/origin)" &&
97b91368
JS
962 test_must_fail git config branch.main.remote &&
963 test_must_fail git config branch.main.pushRemote &&
b3fd6cbf
BW
964 test "$(git config --global remote.pushDefault)" = "origin"
965 )
966'
967
968test_expect_success 'remove a remote removes repo remote.pushDefault' '
969 git clone one four.five.1 &&
970 (
971 cd four.five.1 &&
972 git config remote.pushDefault origin &&
973 git remote remove origin &&
974 test_must_fail git config --local remote.pushDefault
975 )
976'
977
978test_expect_success 'remove a remote removes repo remote.pushDefault but ignores global' '
979 test_config_global remote.pushDefault other &&
980 git clone one four.five.2 &&
981 (
982 cd four.five.2 &&
983 git config remote.pushDefault origin &&
984 git remote remove origin &&
985 test "$(git config --global remote.pushDefault)" = "other" &&
986 test_must_fail git config --local remote.pushDefault
987 )
988'
989
990test_expect_success 'remove a remote removes repo remote.pushDefault but keeps global' '
991 test_config_global remote.pushDefault origin &&
992 git clone one four.five.3 &&
993 (
994 cd four.five.3 &&
995 git config remote.pushDefault origin &&
996 git remote remove origin &&
997 test "$(git config --global remote.pushDefault)" = "origin" &&
998 test_must_fail git config --local remote.pushDefault
923d4a5c
BW
999 )
1000'
1001
9b9439af 1002cat >remotes_origin <<EOF
1dd1239a 1003URL: $(pwd)/one
97b91368 1004Push: refs/heads/main:refs/heads/upstream
f0f249d1 1005Push: refs/heads/next:refs/heads/upstream2
97b91368 1006Pull: refs/heads/main:refs/heads/origin
f0f249d1 1007Pull: refs/heads/next:refs/heads/origin2
1dd1239a
MV
1008EOF
1009
1010test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
1011 git clone one five &&
1012 origin_url=$(pwd)/one &&
9b9439af
RR
1013 (
1014 cd five &&
1015 git remote remove origin &&
1016 mkdir -p .git/remotes &&
1017 cat ../remotes_origin >.git/remotes/origin &&
1018 git remote rename origin origin &&
fe3c1956 1019 test_path_is_missing .git/remotes/origin &&
9b9439af 1020 test "$(git config remote.origin.url)" = "$origin_url" &&
f0f249d1 1021 cat >push_expected <<-\EOF &&
97b91368 1022 refs/heads/main:refs/heads/upstream
f0f249d1
RR
1023 refs/heads/next:refs/heads/upstream2
1024 EOF
1025 cat >fetch_expected <<-\EOF &&
97b91368 1026 refs/heads/main:refs/heads/origin
f0f249d1
RR
1027 refs/heads/next:refs/heads/origin2
1028 EOF
1029 git config --get-all remote.origin.push >push_actual &&
1030 git config --get-all remote.origin.fetch >fetch_actual &&
1031 test_cmp push_expected push_actual &&
1032 test_cmp fetch_expected fetch_actual
9b9439af 1033 )
1dd1239a
MV
1034'
1035
1036test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
e942292a 1037 git clone --template= one six &&
1dd1239a 1038 origin_url=$(pwd)/one &&
9b9439af
RR
1039 (
1040 cd six &&
1041 git remote rm origin &&
e942292a 1042 mkdir .git/branches &&
97b91368 1043 echo "$origin_url#main" >.git/branches/origin &&
9b9439af 1044 git remote rename origin origin &&
fe3c1956 1045 test_path_is_missing .git/branches/origin &&
9b9439af 1046 test "$(git config remote.origin.url)" = "$origin_url" &&
97b91368
JS
1047 test "$(git config remote.origin.fetch)" = "refs/heads/main:refs/heads/origin" &&
1048 test "$(git config remote.origin.push)" = "HEAD:refs/heads/main"
9b9439af 1049 )
1dd1239a
MV
1050'
1051
1f9a5e90 1052test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' '
e942292a 1053 git clone --template= one seven &&
1f9a5e90
RR
1054 (
1055 cd seven &&
1056 git remote rm origin &&
e942292a 1057 mkdir .git/branches &&
1f9a5e90
RR
1058 echo "quux#foom" > .git/branches/origin &&
1059 git remote rename origin origin &&
1060 test_path_is_missing .git/branches/origin &&
1061 test "$(git config remote.origin.url)" = "quux" &&
51b85471 1062 test "$(git config remote.origin.fetch)" = "refs/heads/foom:refs/heads/origin" &&
1f9a5e90
RR
1063 test "$(git config remote.origin.push)" = "HEAD:refs/heads/foom"
1064 )
1065'
1066
1067test_expect_success 'remote prune to cause a dangling symref' '
1068 git clone one eight &&
f8948e2f
JH
1069 (
1070 cd one &&
1071 git checkout side2 &&
97b91368 1072 git branch -D main
f8948e2f
JH
1073 ) &&
1074 (
1f9a5e90 1075 cd eight &&
f8948e2f 1076 git remote prune origin
e01de1c9 1077 ) >err 2>&1 &&
6789275d 1078 test_grep "has become dangling" err &&
f8948e2f 1079
e01de1c9 1080 : And the dangling symref will not cause other annoying errors &&
f8948e2f 1081 (
1f9a5e90 1082 cd eight &&
f8948e2f
JH
1083 git branch -a
1084 ) 2>err &&
e01de1c9 1085 ! grep "points nowhere" err &&
057e7138 1086 (
1f9a5e90 1087 cd eight &&
057e7138
JH
1088 test_must_fail git branch nomore origin
1089 ) 2>err &&
6789275d 1090 test_grep "dangling symref" err
f8948e2f
JH
1091'
1092
6a01554e 1093test_expect_success 'show empty remote' '
6a01554e
CB
1094 test_create_repo empty &&
1095 git clone empty empty-clone &&
1096 (
1097 cd empty-clone &&
1098 git remote show origin
1099 )
1100'
1101
3d8b6949
JN
1102test_expect_success 'remote set-branches requires a remote' '
1103 test_must_fail git remote set-branches &&
1104 test_must_fail git remote set-branches --add
1105'
1106
1107test_expect_success 'remote set-branches' '
1108 echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial &&
1109 sort <<-\EOF >expect.add &&
1110 +refs/heads/*:refs/remotes/scratch/*
1111 +refs/heads/other:refs/remotes/scratch/other
1112 EOF
1113 sort <<-\EOF >expect.replace &&
1114 +refs/heads/maint:refs/remotes/scratch/maint
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.add-two &&
1119 +refs/heads/maint:refs/remotes/scratch/maint
97b91368 1120 +refs/heads/main:refs/remotes/scratch/main
3d8b6949 1121 +refs/heads/next:refs/remotes/scratch/next
6dca5dbf 1122 +refs/heads/seen:refs/remotes/scratch/seen
3d8b6949
JN
1123 +refs/heads/t/topic:refs/remotes/scratch/t/topic
1124 EOF
1125 sort <<-\EOF >expect.setup-ffonly &&
97b91368 1126 refs/heads/main:refs/remotes/scratch/main
3d8b6949
JN
1127 +refs/heads/next:refs/remotes/scratch/next
1128 EOF
1129 sort <<-\EOF >expect.respect-ffonly &&
97b91368 1130 refs/heads/main:refs/remotes/scratch/main
3d8b6949 1131 +refs/heads/next:refs/remotes/scratch/next
6dca5dbf 1132 +refs/heads/seen:refs/remotes/scratch/seen
3d8b6949
JN
1133 EOF
1134
1135 git clone .git/ setbranches &&
1136 (
1137 cd setbranches &&
1138 git remote rename origin scratch &&
1139 git config --get-all remote.scratch.fetch >config-result &&
1140 sort <config-result >../actual.initial &&
1141
1142 git remote set-branches scratch --add other &&
1143 git config --get-all remote.scratch.fetch >config-result &&
1144 sort <config-result >../actual.add &&
1145
97b91368 1146 git remote set-branches scratch maint main next &&
3d8b6949
JN
1147 git config --get-all remote.scratch.fetch >config-result &&
1148 sort <config-result >../actual.replace &&
1149
6dca5dbf 1150 git remote set-branches --add scratch seen t/topic &&
3d8b6949
JN
1151 git config --get-all remote.scratch.fetch >config-result &&
1152 sort <config-result >../actual.add-two &&
1153
1154 git config --unset-all remote.scratch.fetch &&
1155 git config remote.scratch.fetch \
97b91368 1156 refs/heads/main:refs/remotes/scratch/main &&
3d8b6949
JN
1157 git config --add remote.scratch.fetch \
1158 +refs/heads/next:refs/remotes/scratch/next &&
1159 git config --get-all remote.scratch.fetch >config-result &&
1160 sort <config-result >../actual.setup-ffonly &&
1161
6dca5dbf 1162 git remote set-branches --add scratch seen &&
3d8b6949
JN
1163 git config --get-all remote.scratch.fetch >config-result &&
1164 sort <config-result >../actual.respect-ffonly
1165 ) &&
1166 test_cmp expect.initial actual.initial &&
1167 test_cmp expect.add actual.add &&
1168 test_cmp expect.replace actual.replace &&
1169 test_cmp expect.add-two actual.add-two &&
1170 test_cmp expect.setup-ffonly actual.setup-ffonly &&
1171 test_cmp expect.respect-ffonly actual.respect-ffonly
1172'
1173
1174test_expect_success 'remote set-branches with --mirror' '
1175 echo "+refs/*:refs/*" >expect.initial &&
97b91368 1176 echo "+refs/heads/main:refs/heads/main" >expect.replace &&
3d8b6949
JN
1177 git clone --mirror .git/ setbranches-mirror &&
1178 (
1179 cd setbranches-mirror &&
1180 git remote rename origin scratch &&
1181 git config --get-all remote.scratch.fetch >../actual.initial &&
1182
97b91368 1183 git remote set-branches scratch heads/main &&
3d8b6949
JN
1184 git config --get-all remote.scratch.fetch >../actual.replace
1185 ) &&
1186 test_cmp expect.initial actual.initial &&
1187 test_cmp expect.replace actual.replace
1188'
1189
433f2be1 1190test_expect_success 'new remote' '
433f2be1
IL
1191 git remote add someremote foo &&
1192 echo foo >expect &&
1193 git config --get-all remote.someremote.url >actual &&
1194 cmp expect actual
433f2be1
IL
1195'
1196
96f78d39
BB
1197get_url_test () {
1198 cat >expect &&
1199 git remote get-url "$@" >actual &&
1200 test_cmp expect actual
1201}
1202
1203test_expect_success 'get-url on new remote' '
1204 echo foo | get_url_test someremote &&
1205 echo foo | get_url_test --all someremote &&
1206 echo foo | get_url_test --push someremote &&
1207 echo foo | get_url_test --push --all someremote
1208'
1209
45ebdcc9
PS
1210test_expect_success 'remote set-url with locked config' '
1211 test_when_finished "rm -f .git/config.lock" &&
1212 git config --get-all remote.someremote.url >expect &&
1213 >.git/config.lock &&
1214 test_must_fail git remote set-url someremote baz &&
1215 git config --get-all remote.someremote.url >actual &&
1216 cmp expect actual
1217'
1218
433f2be1 1219test_expect_success 'remote set-url bar' '
433f2be1
IL
1220 git remote set-url someremote bar &&
1221 echo bar >expect &&
1222 git config --get-all remote.someremote.url >actual &&
1223 cmp expect actual
433f2be1 1224'
057e7138 1225
433f2be1 1226test_expect_success 'remote set-url baz bar' '
433f2be1
IL
1227 git remote set-url someremote baz bar &&
1228 echo baz >expect &&
1229 git config --get-all remote.someremote.url >actual &&
1230 cmp expect actual
433f2be1
IL
1231'
1232
1233test_expect_success 'remote set-url zot bar' '
433f2be1
IL
1234 test_must_fail git remote set-url someremote zot bar &&
1235 echo baz >expect &&
1236 git config --get-all remote.someremote.url >actual &&
1237 cmp expect actual
433f2be1
IL
1238'
1239
1240test_expect_success 'remote set-url --push zot baz' '
433f2be1
IL
1241 test_must_fail git remote set-url --push someremote zot baz &&
1242 echo "YYY" >expect &&
1243 echo baz >>expect &&
1244 test_must_fail 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
1250test_expect_success 'remote set-url --push zot' '
433f2be1
IL
1251 git remote set-url --push someremote zot &&
1252 echo zot >expect &&
1253 echo "YYY" >>expect &&
1254 echo baz >>expect &&
1255 git config --get-all remote.someremote.pushurl >actual &&
1256 echo "YYY" >>actual &&
1257 git config --get-all remote.someremote.url >>actual &&
1258 cmp expect actual
433f2be1
IL
1259'
1260
96f78d39
BB
1261test_expect_success 'get-url with different urls' '
1262 echo baz | get_url_test someremote &&
1263 echo baz | get_url_test --all someremote &&
1264 echo zot | get_url_test --push someremote &&
1265 echo zot | get_url_test --push --all someremote
1266'
1267
433f2be1 1268test_expect_success 'remote set-url --push qux zot' '
433f2be1
IL
1269 git remote set-url --push someremote qux zot &&
1270 echo qux >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 foo qu+x' '
433f2be1
IL
1280 git remote set-url --push someremote foo qu+x &&
1281 echo foo >expect &&
1282 echo "YYY" >>expect &&
1283 echo baz >>expect &&
1284 git config --get-all remote.someremote.pushurl >actual &&
1285 echo "YYY" >>actual &&
1286 git config --get-all remote.someremote.url >>actual &&
1287 cmp expect actual
433f2be1
IL
1288'
1289
1290test_expect_success 'remote set-url --push --add aaa' '
433f2be1
IL
1291 git remote set-url --push --add someremote aaa &&
1292 echo foo >expect &&
1293 echo aaa >>expect &&
1294 echo "YYY" >>expect &&
1295 echo baz >>expect &&
1296 git config --get-all remote.someremote.pushurl >actual &&
1297 echo "YYY" >>actual &&
1298 git config --get-all remote.someremote.url >>actual &&
1299 cmp expect actual
433f2be1
IL
1300'
1301
96f78d39
BB
1302test_expect_success 'get-url on multi push remote' '
1303 echo foo | get_url_test --push someremote &&
1304 get_url_test --push --all someremote <<-\EOF
1305 foo
1306 aaa
1307 EOF
1308'
1309
433f2be1 1310test_expect_success 'remote set-url --push bar aaa' '
433f2be1
IL
1311 git remote set-url --push someremote bar aaa &&
1312 echo foo >expect &&
1313 echo bar >>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 bar' '
433f2be1
IL
1323 git remote set-url --push --delete someremote bar &&
1324 echo foo >expect &&
1325 echo "YYY" >>expect &&
1326 echo baz >>expect &&
1327 git config --get-all remote.someremote.pushurl >actual &&
1328 echo "YYY" >>actual &&
1329 git config --get-all remote.someremote.url >>actual &&
1330 cmp expect actual
433f2be1
IL
1331'
1332
1333test_expect_success 'remote set-url --push --delete foo' '
433f2be1
IL
1334 git remote set-url --push --delete someremote foo &&
1335 echo "YYY" >expect &&
1336 echo baz >>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
1343test_expect_success 'remote set-url --add bbb' '
433f2be1
IL
1344 git remote set-url --add someremote bbb &&
1345 echo "YYY" >expect &&
1346 echo baz >>expect &&
1347 echo bbb >>expect &&
1348 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1349 echo "YYY" >>actual &&
1350 git config --get-all remote.someremote.url >>actual &&
1351 cmp expect actual
433f2be1
IL
1352'
1353
96f78d39
BB
1354test_expect_success 'get-url on multi fetch remote' '
1355 echo baz | get_url_test someremote &&
1356 get_url_test --all someremote <<-\EOF
1357 baz
1358 bbb
1359 EOF
1360'
1361
433f2be1 1362test_expect_success 'remote set-url --delete .*' '
49de47cf 1363 test_must_fail git remote set-url --delete someremote .\* &&
433f2be1
IL
1364 echo "YYY" >expect &&
1365 echo baz >>expect &&
1366 echo bbb >>expect &&
1367 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1368 echo "YYY" >>actual &&
1369 git config --get-all remote.someremote.url >>actual &&
1370 cmp expect actual
433f2be1
IL
1371'
1372
1373test_expect_success 'remote set-url --delete bbb' '
433f2be1
IL
1374 git remote set-url --delete someremote bbb &&
1375 echo "YYY" >expect &&
1376 echo baz >>expect &&
1377 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1378 echo "YYY" >>actual &&
1379 git config --get-all remote.someremote.url >>actual &&
1380 cmp expect actual
433f2be1
IL
1381'
1382
1383test_expect_success 'remote set-url --delete baz' '
433f2be1
IL
1384 test_must_fail git remote set-url --delete someremote baz &&
1385 echo "YYY" >expect &&
1386 echo baz >>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 --add ccc' '
433f2be1
IL
1394 git remote set-url --add someremote ccc &&
1395 echo "YYY" >expect &&
1396 echo baz >>expect &&
1397 echo ccc >>expect &&
1398 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1399 echo "YYY" >>actual &&
1400 git config --get-all remote.someremote.url >>actual &&
1401 cmp expect actual
433f2be1
IL
1402'
1403
1404test_expect_success 'remote set-url --delete baz' '
433f2be1
IL
1405 git remote set-url --delete someremote baz &&
1406 echo "YYY" >expect &&
1407 echo ccc >>expect &&
1408 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1409 echo "YYY" >>actual &&
1410 git config --get-all remote.someremote.url >>actual &&
1411 cmp expect actual
433f2be1
IL
1412'
1413
abf5f872
TR
1414test_expect_success 'extra args: setup' '
1415 # add a dummy origin so that this does not trigger failure
1416 git remote add origin .
1417'
1418
1419test_extra_arg () {
b17dd3f9 1420 test_expect_success "extra args: $*" "
abf5f872 1421 test_must_fail git remote $* bogus_extra_arg 2>actual &&
6789275d 1422 test_grep '^usage:' actual
abf5f872
TR
1423 "
1424}
1425
2d2e3d25 1426test_extra_arg add nick url
abf5f872
TR
1427test_extra_arg rename origin newname
1428test_extra_arg remove origin
97b91368 1429test_extra_arg set-head origin main
abf5f872 1430# set-branches takes any number of args
96f78d39 1431test_extra_arg get-url origin newurl
abf5f872 1432test_extra_arg set-url origin newurl oldurl
b17dd3f9
TR
1433# show takes any number of args
1434# prune takes any number of args
abf5f872
TR
1435# update takes any number of args
1436
b90c95d9
JS
1437test_expect_success 'add remote matching the "insteadOf" URL' '
1438 git config url.xyz@example.com.insteadOf backup &&
1439 git remote add backup xyz@example.com
1440'
1441
dd8dd300
ÆAB
1442test_expect_success 'unqualified <dst> refspec DWIM and advice' '
1443 test_when_finished "(cd test && git tag -d some-tag)" &&
1444 (
1445 cd test &&
97b91368 1446 git tag -a -m "Some tag" some-tag main &&
dd8dd300
ÆAB
1447 for type in commit tag tree blob
1448 do
1449 if test "$type" = "blob"
1450 then
1451 oid=$(git rev-parse some-tag:file)
1452 else
1453 oid=$(git rev-parse some-tag^{$type})
1454 fi &&
1455 test_must_fail git push origin $oid:dst 2>err &&
6789275d
JH
1456 test_grep "error: The destination you" err &&
1457 test_grep "hint: Did you mean" err &&
dd8dd300
ÆAB
1458 test_must_fail git -c advice.pushUnqualifiedRefName=false \
1459 push origin $oid:dst 2>err &&
6789275d
JH
1460 test_grep "error: The destination you" err &&
1461 test_grep ! "hint: Did you mean" err ||
03949e33
ES
1462 exit 1
1463 done
dd8dd300
ÆAB
1464 )
1465'
1466
97b91368 1467test_expect_success 'refs/remotes/* <src> refspec and unqualified <dst> DWIM and advice' '
bf70636f
ÆAB
1468 (
1469 cd two &&
97b91368 1470 git tag -a -m "Some tag" my-tag main &&
bf70636f
ÆAB
1471 git update-ref refs/trees/my-head-tree HEAD^{tree} &&
1472 git update-ref refs/blobs/my-file-blob HEAD:file
1473 ) &&
1474 (
1475 cd test &&
1476 git config --add remote.two.fetch "+refs/tags/*:refs/remotes/tags-from-two/*" &&
1477 git config --add remote.two.fetch "+refs/trees/*:refs/remotes/trees-from-two/*" &&
1478 git config --add remote.two.fetch "+refs/blobs/*:refs/remotes/blobs-from-two/*" &&
1479 git fetch --no-tags two &&
1480
1481 test_must_fail git push origin refs/remotes/two/another:dst 2>err &&
6789275d 1482 test_grep "error: The destination you" err &&
bf70636f
ÆAB
1483
1484 test_must_fail git push origin refs/remotes/tags-from-two/my-tag:dst-tag 2>err &&
6789275d 1485 test_grep "error: The destination you" err &&
bf70636f
ÆAB
1486
1487 test_must_fail git push origin refs/remotes/trees-from-two/my-head-tree:dst-tree 2>err &&
6789275d 1488 test_grep "error: The destination you" err &&
bf70636f
ÆAB
1489
1490 test_must_fail git push origin refs/remotes/blobs-from-two/my-file-blob:dst-blob 2>err &&
6789275d 1491 test_grep "error: The destination you" err
bf70636f
ÆAB
1492 )
1493'
dd8dd300 1494
433f2be1 1495test_done