blob: d2a2cdd453396b1dba5525f32b6325ac8a10d95d [file] [log] [blame]
Junio C Hamano683b5672007-09-23 22:29:12 -07001#!/bin/sh
2
3test_description='git remote porcelain-ish'
4
5. ./test-lib.sh
6
Junio C Hamano683b5672007-09-23 22:29:12 -07007setup_repository () {
8 mkdir "$1" && (
9 cd "$1" &&
10 git init &&
11 >file &&
12 git add file &&
Johannes Schindelin84521ed2008-03-04 11:23:53 +000013 test_tick &&
Junio C Hamano683b5672007-09-23 22:29:12 -070014 git commit -m "Initial" &&
15 git checkout -b side &&
16 >elif &&
17 git add elif &&
Johannes Schindelin84521ed2008-03-04 11:23:53 +000018 test_tick &&
Junio C Hamano683b5672007-09-23 22:29:12 -070019 git commit -m "Second" &&
20 git checkout master
21 )
22}
23
24tokens_match () {
25 echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect &&
26 echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual &&
Jeff King82ebb0b2008-03-12 17:36:36 -040027 test_cmp expect actual
Junio C Hamano683b5672007-09-23 22:29:12 -070028}
29
30check_remote_track () {
Jay Soffian7ecbbf82009-02-25 03:32:27 -050031 actual=$(git remote show "$1" | sed -ne 's|^ \(.*\) tracked$|\1|p')
Junio C Hamano683b5672007-09-23 22:29:12 -070032 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 '
Junio C Hamano683b5672007-09-23 22:29:12 -070045 setup_repository one &&
46 setup_repository two &&
47 (
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053048 cd two &&
49 git branch another
Junio C Hamano683b5672007-09-23 22:29:12 -070050 ) &&
51 git clone one test
Junio C Hamano683b5672007-09-23 22:29:12 -070052'
53
Johannes Schindelind8ff76c2016-02-17 17:20:47 +010054test_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
Jiang Xinf7dc6a92012-08-27 13:36:54 +080059test_expect_success C_LOCALE_OUTPUT 'remote information for the origin' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053060 (
61 cd test &&
62 tokens_match origin "$(git remote)" &&
63 check_remote_track origin master side &&
64 check_tracking_branch origin HEAD master side
65 )
Junio C Hamano683b5672007-09-23 22:29:12 -070066'
67
68test_expect_success 'add another remote' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053069 (
70 cd test &&
71 git remote add -f second ../two &&
72 tokens_match "origin second" "$(git remote)" &&
73 check_tracking_branch second master side another &&
74 git for-each-ref "--format=%(refname)" refs/remotes |
75 sed -e "/^refs\/remotes\/origin\//d" \
76 -e "/^refs\/remotes\/second\//d" >actual &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +000077 test_must_be_empty actual
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053078 )
Junio C Hamano683b5672007-09-23 22:29:12 -070079'
80
Michael Schubertd6ac1d22013-07-03 11:12:34 +020081test_expect_success C_LOCALE_OUTPUT 'check remote-tracking' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053082 (
83 cd test &&
84 check_remote_track origin master side &&
85 check_remote_track second master side another
86 )
Jiang Xinf7dc6a92012-08-27 13:36:54 +080087'
88
Jeff King1ce89cc2008-04-22 07:11:13 -040089test_expect_success 'remote forces tracking branches' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053090 (
91 cd test &&
Elia Pintoc0097812015-12-23 14:45:53 +010092 case $(git config remote.second.fetch) in
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053093 +*) true ;;
94 *) false ;;
95 esac
96 )
Jeff King1ce89cc2008-04-22 07:11:13 -040097'
98
Junio C Hamano683b5672007-09-23 22:29:12 -070099test_expect_success 'remove remote' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530100 (
101 cd test &&
102 git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master &&
103 git remote rm second
104 )
Junio C Hamano683b5672007-09-23 22:29:12 -0700105'
106
Jiang Xinf7dc6a92012-08-27 13:36:54 +0800107test_expect_success C_LOCALE_OUTPUT 'remove remote' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530108 (
109 cd test &&
110 tokens_match origin "$(git remote)" &&
111 check_remote_track origin master side &&
112 git for-each-ref "--format=%(refname)" refs/remotes |
113 sed -e "/^refs\/remotes\/origin\//d" >actual &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +0000114 test_must_be_empty actual
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530115 )
Junio C Hamano683b5672007-09-23 22:29:12 -0700116'
117
Matthieu Moy13931232010-11-02 16:31:25 +0100118test_expect_success 'remove remote protects local branches' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530119 (
120 cd test &&
121 cat >expect1 <<-\EOF &&
122 Note: A branch outside the refs/remotes/ hierarchy was not removed;
123 to delete it, use:
124 git branch -d master
125 EOF
126 cat >expect2 <<-\EOF &&
127 Note: Some branches outside the refs/remotes/ hierarchy were not removed;
128 to delete them, use:
129 git branch -d foobranch
130 git branch -d master
131 EOF
132 git tag footag &&
133 git config --add remote.oops.fetch "+refs/*:refs/*" &&
134 git remote remove oops 2>actual1 &&
135 git branch foobranch &&
136 git config --add remote.oops.fetch "+refs/*:refs/*" &&
137 git remote rm oops 2>actual2 &&
138 git branch -d foobranch &&
139 git tag -d footag &&
140 test_i18ncmp expect1 actual1 &&
141 test_i18ncmp expect2 actual2
142 )
Jay Soffian441adf02009-02-04 11:06:07 -0500143'
144
Thomas Gummerercc8e5382016-02-16 10:47:51 +0100145test_expect_success 'remove errors out early when deleting non-existent branch' '
146 (
147 cd test &&
Shulhan50254252018-09-13 20:18:33 +0700148 echo "fatal: No such remote: '\''foo'\''" >expect &&
Thomas Gummerercc8e5382016-02-16 10:47:51 +0100149 test_must_fail git remote rm foo 2>actual &&
150 test_i18ncmp expect actual
151 )
152'
153
Ross Lagerwall20690b22017-02-18 00:23:41 +0000154test_expect_success 'remove remote with a branch without configured merge' '
155 test_when_finished "(
156 git -C test checkout master;
157 git -C test branch -D two;
158 git -C test config --remove-section remote.two;
159 git -C test config --remove-section branch.second;
160 true
161 )" &&
162 (
163 cd test &&
164 git remote add two ../two &&
165 git fetch two &&
166 git checkout -b second two/master^0 &&
167 git config branch.second.remote two &&
168 git checkout master &&
169 git remote rm two
170 )
171'
172
Thomas Gummerercc8e5382016-02-16 10:47:51 +0100173test_expect_success 'rename errors out early when deleting non-existent branch' '
174 (
175 cd test &&
Shulhan50254252018-09-13 20:18:33 +0700176 echo "fatal: No such remote: '\''foo'\''" >expect &&
Thomas Gummerercc8e5382016-02-16 10:47:51 +0100177 test_must_fail git remote rename foo bar 2>actual &&
178 test_i18ncmp expect actual
179 )
180'
181
Thomas Gummerera31eeae2016-02-16 10:47:52 +0100182test_expect_success 'add existing foreign_vcs remote' '
183 test_config remote.foo.vcs bar &&
184 echo "fatal: remote foo already exists." >expect &&
185 test_must_fail git remote add foo bar 2>actual &&
186 test_i18ncmp expect actual
187'
188
189test_expect_success 'add existing foreign_vcs remote' '
190 test_config remote.foo.vcs bar &&
191 test_config remote.bar.vcs bar &&
192 echo "fatal: remote bar already exists." >expect &&
193 test_must_fail git remote rename foo bar 2>actual &&
194 test_i18ncmp expect actual
195'
196
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530197cat >test/expect <<EOF
Johannes Schindelin47046402008-02-29 01:45:24 +0000198* remote origin
Michael J Gruber857f8c32009-06-13 18:29:10 +0200199 Fetch URL: $(pwd)/one
200 Push URL: $(pwd)/one
Jay Soffiane61e0cc2009-02-25 03:32:24 -0500201 HEAD branch: master
Jay Soffian7ecbbf82009-02-25 03:32:27 -0500202 Remote branches:
203 master new (next fetch will store in remotes/origin)
204 side tracked
205 Local branches configured for 'git pull':
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500206 ahead merges with remote master
Jay Soffian7ecbbf82009-02-25 03:32:27 -0500207 master merges with remote master
208 octopus merges with remote topic-a
209 and with remote topic-b
210 and with remote topic-c
211 rebase rebases onto remote master
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500212 Local refs configured for 'git push':
213 master pushes to master (local out of date)
214 master pushes to upstream (create)
Jay Soffiane61e0cc2009-02-25 03:32:24 -0500215* remote two
Michael J Gruber857f8c32009-06-13 18:29:10 +0200216 Fetch URL: ../two
217 Push URL: ../three
Junio C Hamanoa45b5f02013-09-17 19:10:31 -0700218 HEAD branch: master
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500219 Local refs configured for 'git push':
Felipe Contrerasa75d7b52009-10-24 11:31:32 +0300220 ahead forces to master (fast-forwardable)
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500221 master pushes to another (up to date)
Johannes Schindelin47046402008-02-29 01:45:24 +0000222EOF
223
224test_expect_success 'show' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530225 (
226 cd test &&
227 git config --add remote.origin.fetch refs/heads/master:refs/heads/upstream &&
228 git fetch &&
229 git checkout -b ahead origin/master &&
230 echo 1 >>file &&
231 test_tick &&
232 git commit -m update file &&
233 git checkout master &&
234 git branch --track octopus origin/master &&
235 git branch --track rebase origin/master &&
236 git branch -d -r origin/master &&
237 git config --add remote.two.url ../two &&
238 git config --add remote.two.pushurl ../three &&
239 git config branch.rebase.rebase true &&
240 git config branch.octopus.merge "topic-a topic-b topic-c" &&
241 (
242 cd ../one &&
243 echo 1 >file &&
244 test_tick &&
245 git commit -m update file
246 ) &&
247 git config --add remote.origin.push : &&
248 git config --add remote.origin.push refs/heads/master:refs/heads/upstream &&
249 git config --add remote.origin.push +refs/tags/lastbackup &&
250 git config --add remote.two.push +refs/heads/ahead:refs/heads/master &&
251 git config --add remote.two.push refs/heads/master:refs/heads/another &&
252 git remote show origin two >output &&
253 git branch -d rebase octopus &&
254 test_i18ncmp expect output
255 )
Johannes Schindelin47046402008-02-29 01:45:24 +0000256'
257
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530258cat >test/expect <<EOF
Olivier Marin0ecfcb32008-06-10 16:51:08 +0200259* remote origin
Michael J Gruber857f8c32009-06-13 18:29:10 +0200260 Fetch URL: $(pwd)/one
261 Push URL: $(pwd)/one
Jay Soffiane61e0cc2009-02-25 03:32:24 -0500262 HEAD branch: (not queried)
Jay Soffian7ecbbf82009-02-25 03:32:27 -0500263 Remote branches: (status not queried)
Johannes Sixt20244ea2008-10-22 09:39:47 +0200264 master
265 side
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500266 Local branches configured for 'git pull':
267 ahead merges with remote master
Jay Soffian7ecbbf82009-02-25 03:32:27 -0500268 master merges with remote master
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500269 Local refs configured for 'git push' (status not queried):
270 (matching) pushes to (matching)
271 refs/heads/master pushes to refs/heads/upstream
272 refs/tags/lastbackup forces to refs/tags/lastbackup
Olivier Marin0ecfcb32008-06-10 16:51:08 +0200273EOF
274
275test_expect_success 'show -n' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530276 mv one one.unreachable &&
277 (
278 cd test &&
279 git remote show -n origin >output &&
280 mv ../one.unreachable ../one &&
281 test_i18ncmp expect output
Jay Soffianbc14fac2009-02-25 03:32:25 -0500282 )
283'
284
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530285test_expect_success 'prune' '
286 (
287 cd one &&
288 git branch -m side side2
289 ) &&
290 (
291 cd test &&
292 git fetch origin &&
293 git remote prune origin &&
294 git rev-parse refs/remotes/origin/side2 &&
295 test_must_fail git rev-parse refs/remotes/origin/side
296 )
297'
298
299test_expect_success 'set-head --delete' '
300 (
301 cd test &&
302 git symbolic-ref refs/remotes/origin/HEAD &&
303 git remote set-head --delete origin &&
304 test_must_fail git symbolic-ref refs/remotes/origin/HEAD
305 )
306'
307
308test_expect_success 'set-head --auto' '
309 (
310 cd test &&
311 git remote set-head --auto origin &&
312 echo refs/remotes/origin/master >expect &&
313 git symbolic-ref refs/remotes/origin/HEAD >output &&
314 test_cmp expect output
315 )
316'
317
Junio C Hamanoa45b5f02013-09-17 19:10:31 -0700318test_expect_success 'set-head --auto has no problem w/multiple HEADs' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530319 (
320 cd test &&
Junio C Hamanoa4dfee02013-09-17 21:45:34 -0700321 git fetch two "refs/heads/*:refs/remotes/two/*" &&
Junio C Hamanoa45b5f02013-09-17 19:10:31 -0700322 git remote set-head --auto two >output 2>&1 &&
323 echo "two/HEAD set to master" >expect &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530324 test_i18ncmp expect output
325 )
Jay Soffianbc14fac2009-02-25 03:32:25 -0500326'
327
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530328cat >test/expect <<\EOF
Jay Soffianbc14fac2009-02-25 03:32:25 -0500329refs/remotes/origin/side2
330EOF
331
332test_expect_success 'set-head explicit' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530333 (
334 cd test &&
335 git remote set-head origin side2 &&
336 git symbolic-ref refs/remotes/origin/HEAD >output &&
337 git remote set-head origin master &&
338 test_cmp expect output
339 )
Jay Soffianbc14fac2009-02-25 03:32:25 -0500340'
341
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530342cat >test/expect <<EOF
Olivier Marin8d767922008-06-10 16:51:35 +0200343Pruning origin
Johan Herland86521ac2008-09-01 21:07:33 +0200344URL: $(pwd)/one
Olivier Marin8d767922008-06-10 16:51:35 +0200345 * [would prune] origin/side2
346EOF
347
348test_expect_success 'prune --dry-run' '
Eric Sunshine431f4a22018-07-01 20:23:48 -0400349 git -C one branch -m side2 side &&
350 test_when_finished "git -C one branch -m side side2" &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530351 (
352 cd test &&
353 git remote prune --dry-run origin >output &&
354 git rev-parse refs/remotes/origin/side2 &&
355 test_must_fail git rev-parse refs/remotes/origin/side &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530356 test_i18ncmp expect output
357 )
Olivier Marin8d767922008-06-10 16:51:35 +0200358'
359
Johannes Schindelin4ebc9142008-02-29 01:46:07 +0000360test_expect_success 'add --mirror && prune' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530361 mkdir mirror &&
362 (
363 cd mirror &&
364 git init --bare &&
365 git remote add --mirror -f origin ../one
366 ) &&
367 (
368 cd one &&
369 git branch -m side2 side
370 ) &&
371 (
372 cd mirror &&
373 git rev-parse --verify refs/heads/side2 &&
374 test_must_fail git rev-parse --verify refs/heads/side &&
375 git fetch origin &&
376 git remote prune origin &&
377 test_must_fail git rev-parse --verify refs/heads/side2 &&
378 git rev-parse --verify refs/heads/side
379 )
Johannes Schindelin4ebc9142008-02-29 01:46:07 +0000380'
381
Jeff Kinga9f5a352011-03-30 15:53:19 -0400382test_expect_success 'add --mirror=fetch' '
383 mkdir mirror-fetch &&
384 git init mirror-fetch/parent &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530385 (
386 cd mirror-fetch/parent &&
387 test_commit one
388 ) &&
Jeff Kinga9f5a352011-03-30 15:53:19 -0400389 git init --bare mirror-fetch/child &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530390 (
391 cd mirror-fetch/child &&
392 git remote add --mirror=fetch -f parent ../parent
393 )
Jeff Kinga9f5a352011-03-30 15:53:19 -0400394'
395
396test_expect_success 'fetch mirrors act as mirrors during fetch' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530397 (
398 cd mirror-fetch/parent &&
399 git branch new &&
400 git branch -m master renamed
Jeff Kinga9f5a352011-03-30 15:53:19 -0400401 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530402 (
403 cd mirror-fetch/child &&
404 git fetch parent &&
405 git rev-parse --verify refs/heads/new &&
406 git rev-parse --verify refs/heads/renamed
Jeff Kinga9f5a352011-03-30 15:53:19 -0400407 )
408'
409
410test_expect_success 'fetch mirrors can prune' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530411 (
412 cd mirror-fetch/child &&
413 git remote prune parent &&
414 test_must_fail git rev-parse --verify refs/heads/master
Jeff Kinga9f5a352011-03-30 15:53:19 -0400415 )
416'
417
418test_expect_success 'fetch mirrors do not act as mirrors during push' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530419 (
420 cd mirror-fetch/parent &&
421 git checkout HEAD^0
Jeff Kinga9f5a352011-03-30 15:53:19 -0400422 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530423 (
424 cd mirror-fetch/child &&
425 git branch -m renamed renamed2 &&
426 git push parent :
Jeff Kinga9f5a352011-03-30 15:53:19 -0400427 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530428 (
429 cd mirror-fetch/parent &&
430 git rev-parse --verify renamed &&
431 test_must_fail git rev-parse --verify refs/heads/renamed2
Jeff Kinga9f5a352011-03-30 15:53:19 -0400432 )
433'
434
Jeff King3eafdc92011-05-26 11:11:00 -0400435test_expect_success 'add fetch mirror with specific branches' '
436 git init --bare mirror-fetch/track &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530437 (
438 cd mirror-fetch/track &&
439 git remote add --mirror=fetch -t heads/new parent ../parent
Jeff King3eafdc92011-05-26 11:11:00 -0400440 )
441'
442
443test_expect_success 'fetch mirror respects specific branches' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530444 (
445 cd mirror-fetch/track &&
446 git fetch parent &&
447 git rev-parse --verify refs/heads/new &&
448 test_must_fail git rev-parse --verify refs/heads/renamed
Jeff King3eafdc92011-05-26 11:11:00 -0400449 )
450'
451
Jeff Kinga9f5a352011-03-30 15:53:19 -0400452test_expect_success 'add --mirror=push' '
453 mkdir mirror-push &&
454 git init --bare mirror-push/public &&
455 git init mirror-push/private &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530456 (
457 cd mirror-push/private &&
458 test_commit one &&
459 git remote add --mirror=push public ../public
Jeff Kinga9f5a352011-03-30 15:53:19 -0400460 )
461'
462
463test_expect_success 'push mirrors act as mirrors during push' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530464 (
465 cd mirror-push/private &&
466 git branch new &&
467 git branch -m master renamed &&
468 git push public
Jeff Kinga9f5a352011-03-30 15:53:19 -0400469 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530470 (
471 cd mirror-push/private &&
472 git rev-parse --verify refs/heads/new &&
473 git rev-parse --verify refs/heads/renamed &&
474 test_must_fail git rev-parse --verify refs/heads/master
Jeff Kinga9f5a352011-03-30 15:53:19 -0400475 )
476'
477
478test_expect_success 'push mirrors do not act as mirrors during fetch' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530479 (
480 cd mirror-push/public &&
481 git branch -m renamed renamed2 &&
482 git symbolic-ref HEAD refs/heads/renamed2
Jeff Kinga9f5a352011-03-30 15:53:19 -0400483 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530484 (
485 cd mirror-push/private &&
486 git fetch public &&
487 git rev-parse --verify refs/heads/renamed &&
488 test_must_fail git rev-parse --verify refs/heads/renamed2
Jeff Kinga9f5a352011-03-30 15:53:19 -0400489 )
490'
491
Jeff King3eafdc92011-05-26 11:11:00 -0400492test_expect_success 'push mirrors do not allow you to specify refs' '
493 git init mirror-push/track &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530494 (
495 cd mirror-push/track &&
496 test_must_fail git remote add --mirror=push -t new public ../public
Jeff King3eafdc92011-05-26 11:11:00 -0400497 )
498'
499
Shawn O. Pearcec175a7a2008-05-31 23:58:05 -0400500test_expect_success 'add alt && prune' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530501 mkdir alttst &&
502 (
503 cd alttst &&
504 git init &&
505 git remote add -f origin ../one &&
506 git config remote.alt.url ../one &&
507 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*"
508 ) &&
509 (
510 cd one &&
511 git branch -m side side2
512 ) &&
513 (
514 cd alttst &&
515 git rev-parse --verify refs/remotes/origin/side &&
516 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
517 git fetch alt &&
518 git remote prune alt &&
519 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
520 git rev-parse --verify refs/remotes/origin/side2
521 )
Shawn O. Pearcec175a7a2008-05-31 23:58:05 -0400522'
523
Samuel Tardieu111fb852010-04-20 01:31:31 +0200524cat >test/expect <<\EOF
525some-tag
526EOF
527
528test_expect_success 'add with reachable tags (default)' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530529 (
530 cd one &&
531 >foobar &&
532 git add foobar &&
533 git commit -m "Foobar" &&
534 git tag -a -m "Foobar tag" foobar-tag &&
535 git reset --hard HEAD~1 &&
536 git tag -a -m "Some tag" some-tag
537 ) &&
538 mkdir add-tags &&
539 (
540 cd add-tags &&
541 git init &&
542 git remote add -f origin ../one &&
543 git tag -l some-tag >../test/output &&
544 git tag -l foobar-tag >>../test/output &&
545 test_must_fail git config remote.origin.tagopt
546 ) &&
Samuel Tardieu111fb852010-04-20 01:31:31 +0200547 test_cmp test/expect test/output
548'
549
550cat >test/expect <<\EOF
551some-tag
552foobar-tag
553--tags
554EOF
555
556test_expect_success 'add --tags' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530557 rm -rf add-tags &&
558 (
559 mkdir add-tags &&
560 cd add-tags &&
561 git init &&
562 git remote add -f --tags origin ../one &&
563 git tag -l some-tag >../test/output &&
564 git tag -l foobar-tag >>../test/output &&
565 git config remote.origin.tagopt >>../test/output
566 ) &&
Samuel Tardieu111fb852010-04-20 01:31:31 +0200567 test_cmp test/expect test/output
568'
569
570cat >test/expect <<\EOF
571--no-tags
572EOF
573
574test_expect_success 'add --no-tags' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530575 rm -rf add-tags &&
576 (
577 mkdir add-no-tags &&
578 cd add-no-tags &&
579 git init &&
580 git remote add -f --no-tags origin ../one &&
581 git tag -l some-tag >../test/output &&
582 git tag -l foobar-tag >../test/output &&
583 git config remote.origin.tagopt >>../test/output
584 ) &&
585 (
586 cd one &&
587 git tag -d some-tag foobar-tag
588 ) &&
Samuel Tardieu111fb852010-04-20 01:31:31 +0200589 test_cmp test/expect test/output
590'
591
592test_expect_success 'reject --no-no-tags' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530593 (
594 cd add-no-tags &&
595 test_must_fail git remote add -f --no-no-tags neworigin ../one
596 )
Samuel Tardieu111fb852010-04-20 01:31:31 +0200597'
598
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530599cat >one/expect <<\EOF
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000600 apis/master
601 apis/side
602 drosophila/another
603 drosophila/master
604 drosophila/side
605EOF
606
607test_expect_success 'update' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530608 (
609 cd one &&
610 git remote add drosophila ../two &&
611 git remote add apis ../mirror &&
612 git remote update &&
613 git branch -r >output &&
614 test_cmp expect output
615 )
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000616'
617
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530618cat >one/expect <<\EOF
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000619 drosophila/another
620 drosophila/master
621 drosophila/side
622 manduca/master
623 manduca/side
624 megaloprepus/master
625 megaloprepus/side
626EOF
627
628test_expect_success 'update with arguments' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530629 (
630 cd one &&
631 for b in $(git branch -r)
632 do
Jeff Kinge6821d02015-03-25 01:29:52 -0400633 git branch -r -d $b || exit 1
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530634 done &&
635 git remote add manduca ../mirror &&
636 git remote add megaloprepus ../mirror &&
637 git config remotes.phobaeticus "drosophila megaloprepus" &&
638 git config remotes.titanus manduca &&
639 git remote update phobaeticus titanus &&
640 git branch -r >output &&
641 test_cmp expect output
642 )
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000643'
644
Björn Gustavssone2d41c62009-11-09 21:11:59 +0100645test_expect_success 'update --prune' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530646 (
647 cd one &&
648 git branch -m side2 side3
649 ) &&
650 (
651 cd test &&
652 git remote update --prune &&
653 (
654 cd ../one &&
655 git branch -m side3 side2
656 ) &&
657 git rev-parse refs/remotes/origin/side3 &&
658 test_must_fail git rev-parse refs/remotes/origin/side2
659 )
Björn Gustavssone2d41c62009-11-09 21:11:59 +0100660'
661
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530662cat >one/expect <<-\EOF
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000663 apis/master
664 apis/side
665 manduca/master
666 manduca/side
667 megaloprepus/master
668 megaloprepus/side
669EOF
670
671test_expect_success 'update default' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530672 (
673 cd one &&
674 for b in $(git branch -r)
675 do
Jeff Kinge6821d02015-03-25 01:29:52 -0400676 git branch -r -d $b || exit 1
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530677 done &&
678 git config remote.drosophila.skipDefaultUpdate true &&
679 git remote update default &&
680 git branch -r >output &&
681 test_cmp expect output
682 )
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000683'
684
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530685cat >one/expect <<\EOF
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000686 drosophila/another
687 drosophila/master
688 drosophila/side
689EOF
690
691test_expect_success 'update default (overridden, with funny whitespace)' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530692 (
693 cd one &&
694 for b in $(git branch -r)
695 do
Jeff Kinge6821d02015-03-25 01:29:52 -0400696 git branch -r -d $b || exit 1
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530697 done &&
698 git config remotes.default "$(printf "\t drosophila \n")" &&
699 git remote update default &&
700 git branch -r >output &&
701 test_cmp expect output
702 )
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000703'
704
Björn Gustavsson4f2e8422009-12-31 10:43:17 +0100705test_expect_success 'update (with remotes.default defined)' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530706 (
707 cd one &&
708 for b in $(git branch -r)
709 do
Jeff Kinge6821d02015-03-25 01:29:52 -0400710 git branch -r -d $b || exit 1
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530711 done &&
712 git config remotes.default "drosophila" &&
713 git remote update &&
714 git branch -r >output &&
715 test_cmp expect output
716 )
Björn Gustavsson4f2e8422009-12-31 10:43:17 +0100717'
718
Johannes Schindelin740fdd22008-03-19 00:27:42 +0000719test_expect_success '"remote show" does not show symbolic refs' '
Johannes Schindelin740fdd22008-03-19 00:27:42 +0000720 git clone one three &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530721 (
722 cd three &&
723 git remote show origin >output &&
724 ! grep "^ *HEAD$" < output &&
725 ! grep -i stale < output
726 )
Johannes Schindelin740fdd22008-03-19 00:27:42 +0000727'
728
Jonas Fonseca24b61772008-04-13 11:56:54 +0200729test_expect_success 'reject adding remote with an invalid name' '
Stephan Beyerd492b312008-07-12 17:47:52 +0200730 test_must_fail git remote add some:url desired-name
Jonas Fonseca24b61772008-04-13 11:56:54 +0200731'
732
Miklos Vajnabf984212008-11-03 19:26:18 +0100733# The first three test if the tracking branches are properly renamed,
734# the last two ones check if the config is updated.
735
736test_expect_success 'rename a remote' '
Miklos Vajnabf984212008-11-03 19:26:18 +0100737 git clone one four &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530738 (
739 cd four &&
740 git remote rename origin upstream &&
Michael Haggerty2eb7a0e2017-01-06 17:22:23 +0100741 test -z "$(git for-each-ref refs/remotes/origin)" &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530742 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
743 test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
744 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
745 test "$(git config branch.master.remote)" = "upstream"
746 )
Miklos Vajnabf984212008-11-03 19:26:18 +0100747'
Miklos Vajna1dd12392008-11-10 21:43:01 +0100748
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400749test_expect_success 'rename does not update a non-default fetch refspec' '
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400750 git clone one four.one &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530751 (
752 cd four.one &&
753 git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
754 git remote rename origin upstream &&
755 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" &&
756 git rev-parse -q origin/master
757 )
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400758'
759
760test_expect_success 'rename a remote with name part of fetch spec' '
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400761 git clone one four.two &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530762 (
763 cd four.two &&
764 git remote rename origin remote &&
765 git remote rename remote upstream &&
766 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*"
767 )
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400768'
769
Martin von Zweigbergk60e5eee2011-09-01 20:50:34 -0400770test_expect_success 'rename a remote with name prefix of other remote' '
Martin von Zweigbergk60e5eee2011-09-01 20:50:34 -0400771 git clone one four.three &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530772 (
773 cd four.three &&
774 git remote add o git://example.com/repo.git &&
775 git remote rename o upstream &&
776 test "$(git rev-parse origin/master)" = "$(git rev-parse master)"
777 )
Martin von Zweigbergk60e5eee2011-09-01 20:50:34 -0400778'
779
Johannes Schindeline459b072017-01-19 22:20:02 +0100780test_expect_success 'rename succeeds with existing remote.<target>.prune' '
Johannes Schindelinaf5bacf2017-01-19 22:19:58 +0100781 git clone one four.four &&
782 test_when_finished git config --global --unset remote.upstream.prune &&
783 git config --global remote.upstream.prune true &&
784 git -C four.four remote rename origin upstream
785'
786
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530787cat >remotes_origin <<EOF
Miklos Vajna1dd12392008-11-10 21:43:01 +0100788URL: $(pwd)/one
789Push: refs/heads/master:refs/heads/upstream
Ramkumar Ramachandraf0f249d2013-06-22 13:28:18 +0530790Push: refs/heads/next:refs/heads/upstream2
Miklos Vajna1dd12392008-11-10 21:43:01 +0100791Pull: refs/heads/master:refs/heads/origin
Ramkumar Ramachandraf0f249d2013-06-22 13:28:18 +0530792Pull: refs/heads/next:refs/heads/origin2
Miklos Vajna1dd12392008-11-10 21:43:01 +0100793EOF
794
795test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
796 git clone one five &&
797 origin_url=$(pwd)/one &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530798 (
799 cd five &&
800 git remote remove origin &&
801 mkdir -p .git/remotes &&
802 cat ../remotes_origin >.git/remotes/origin &&
803 git remote rename origin origin &&
Ramkumar Ramachandrafe3c1952013-06-22 13:28:10 +0530804 test_path_is_missing .git/remotes/origin &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530805 test "$(git config remote.origin.url)" = "$origin_url" &&
Ramkumar Ramachandraf0f249d2013-06-22 13:28:18 +0530806 cat >push_expected <<-\EOF &&
807 refs/heads/master:refs/heads/upstream
808 refs/heads/next:refs/heads/upstream2
809 EOF
810 cat >fetch_expected <<-\EOF &&
811 refs/heads/master:refs/heads/origin
812 refs/heads/next:refs/heads/origin2
813 EOF
814 git config --get-all remote.origin.push >push_actual &&
815 git config --get-all remote.origin.fetch >fetch_actual &&
816 test_cmp push_expected push_actual &&
817 test_cmp fetch_expected fetch_actual
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530818 )
Miklos Vajna1dd12392008-11-10 21:43:01 +0100819'
820
821test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
822 git clone one six &&
823 origin_url=$(pwd)/one &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530824 (
825 cd six &&
826 git remote rm origin &&
827 echo "$origin_url" >.git/branches/origin &&
828 git remote rename origin origin &&
Ramkumar Ramachandrafe3c1952013-06-22 13:28:10 +0530829 test_path_is_missing .git/branches/origin &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530830 test "$(git config remote.origin.url)" = "$origin_url" &&
Ramkumar Ramachandra294547f2013-06-22 13:28:09 +0530831 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin" &&
832 test "$(git config remote.origin.push)" = "HEAD:refs/heads/master"
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530833 )
Miklos Vajna1dd12392008-11-10 21:43:01 +0100834'
835
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +0530836test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' '
Junio C Hamanof8948e22009-02-08 23:27:10 -0800837 git clone one seven &&
838 (
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +0530839 cd seven &&
840 git remote rm origin &&
841 echo "quux#foom" > .git/branches/origin &&
842 git remote rename origin origin &&
843 test_path_is_missing .git/branches/origin &&
844 test "$(git config remote.origin.url)" = "quux" &&
Eric Sunshine51b85472018-07-01 20:24:01 -0400845 test "$(git config remote.origin.fetch)" = "refs/heads/foom:refs/heads/origin" &&
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +0530846 test "$(git config remote.origin.push)" = "HEAD:refs/heads/foom"
847 )
848'
849
850test_expect_success 'remote prune to cause a dangling symref' '
851 git clone one eight &&
852 (
Junio C Hamanof8948e22009-02-08 23:27:10 -0800853 cd one &&
854 git checkout side2 &&
855 git branch -D master
856 ) &&
857 (
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +0530858 cd eight &&
Junio C Hamanof8948e22009-02-08 23:27:10 -0800859 git remote prune origin
Junio C Hamanoe01de1c2010-03-15 22:12:55 -0700860 ) >err 2>&1 &&
Jiang Xinf7dc6a92012-08-27 13:36:54 +0800861 test_i18ngrep "has become dangling" err &&
Junio C Hamanof8948e22009-02-08 23:27:10 -0800862
Junio C Hamanoe01de1c2010-03-15 22:12:55 -0700863 : And the dangling symref will not cause other annoying errors &&
Junio C Hamanof8948e22009-02-08 23:27:10 -0800864 (
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +0530865 cd eight &&
Junio C Hamanof8948e22009-02-08 23:27:10 -0800866 git branch -a
867 ) 2>err &&
Junio C Hamanoe01de1c2010-03-15 22:12:55 -0700868 ! grep "points nowhere" err &&
Junio C Hamano057e7132009-02-08 23:52:01 -0800869 (
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +0530870 cd eight &&
Junio C Hamano057e7132009-02-08 23:52:01 -0800871 test_must_fail git branch nomore origin
872 ) 2>err &&
Nguyễn Thái Ngọc Duy661558f2018-07-21 09:49:35 +0200873 test_i18ngrep "dangling symref" err
Junio C Hamanof8948e22009-02-08 23:27:10 -0800874'
875
Clemens Buchacher6a015542009-05-27 22:13:43 +0200876test_expect_success 'show empty remote' '
Clemens Buchacher6a015542009-05-27 22:13:43 +0200877 test_create_repo empty &&
878 git clone empty empty-clone &&
879 (
880 cd empty-clone &&
881 git remote show origin
882 )
883'
884
Jonathan Nieder3d8b6942010-05-19 13:38:50 -0500885test_expect_success 'remote set-branches requires a remote' '
886 test_must_fail git remote set-branches &&
887 test_must_fail git remote set-branches --add
888'
889
890test_expect_success 'remote set-branches' '
891 echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial &&
892 sort <<-\EOF >expect.add &&
893 +refs/heads/*:refs/remotes/scratch/*
894 +refs/heads/other:refs/remotes/scratch/other
895 EOF
896 sort <<-\EOF >expect.replace &&
897 +refs/heads/maint:refs/remotes/scratch/maint
898 +refs/heads/master:refs/remotes/scratch/master
899 +refs/heads/next:refs/remotes/scratch/next
900 EOF
901 sort <<-\EOF >expect.add-two &&
902 +refs/heads/maint:refs/remotes/scratch/maint
903 +refs/heads/master:refs/remotes/scratch/master
904 +refs/heads/next:refs/remotes/scratch/next
905 +refs/heads/pu:refs/remotes/scratch/pu
906 +refs/heads/t/topic:refs/remotes/scratch/t/topic
907 EOF
908 sort <<-\EOF >expect.setup-ffonly &&
909 refs/heads/master:refs/remotes/scratch/master
910 +refs/heads/next:refs/remotes/scratch/next
911 EOF
912 sort <<-\EOF >expect.respect-ffonly &&
913 refs/heads/master:refs/remotes/scratch/master
914 +refs/heads/next:refs/remotes/scratch/next
915 +refs/heads/pu:refs/remotes/scratch/pu
916 EOF
917
918 git clone .git/ setbranches &&
919 (
920 cd setbranches &&
921 git remote rename origin scratch &&
922 git config --get-all remote.scratch.fetch >config-result &&
923 sort <config-result >../actual.initial &&
924
925 git remote set-branches scratch --add other &&
926 git config --get-all remote.scratch.fetch >config-result &&
927 sort <config-result >../actual.add &&
928
929 git remote set-branches scratch maint master next &&
930 git config --get-all remote.scratch.fetch >config-result &&
931 sort <config-result >../actual.replace &&
932
933 git remote set-branches --add scratch pu t/topic &&
934 git config --get-all remote.scratch.fetch >config-result &&
935 sort <config-result >../actual.add-two &&
936
937 git config --unset-all remote.scratch.fetch &&
938 git config remote.scratch.fetch \
939 refs/heads/master:refs/remotes/scratch/master &&
940 git config --add remote.scratch.fetch \
941 +refs/heads/next:refs/remotes/scratch/next &&
942 git config --get-all remote.scratch.fetch >config-result &&
943 sort <config-result >../actual.setup-ffonly &&
944
945 git remote set-branches --add scratch pu &&
946 git config --get-all remote.scratch.fetch >config-result &&
947 sort <config-result >../actual.respect-ffonly
948 ) &&
949 test_cmp expect.initial actual.initial &&
950 test_cmp expect.add actual.add &&
951 test_cmp expect.replace actual.replace &&
952 test_cmp expect.add-two actual.add-two &&
953 test_cmp expect.setup-ffonly actual.setup-ffonly &&
954 test_cmp expect.respect-ffonly actual.respect-ffonly
955'
956
957test_expect_success 'remote set-branches with --mirror' '
958 echo "+refs/*:refs/*" >expect.initial &&
959 echo "+refs/heads/master:refs/heads/master" >expect.replace &&
960 git clone --mirror .git/ setbranches-mirror &&
961 (
962 cd setbranches-mirror &&
963 git remote rename origin scratch &&
964 git config --get-all remote.scratch.fetch >../actual.initial &&
965
966 git remote set-branches scratch heads/master &&
967 git config --get-all remote.scratch.fetch >../actual.replace
968 ) &&
969 test_cmp expect.initial actual.initial &&
970 test_cmp expect.replace actual.replace
971'
972
Ilari Liusvaara433f2be2010-01-18 19:18:02 +0200973test_expect_success 'new remote' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +0200974 git remote add someremote foo &&
975 echo foo >expect &&
976 git config --get-all remote.someremote.url >actual &&
977 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +0200978'
Junio C Hamano057e7132009-02-08 23:52:01 -0800979
Ben Boeckel96f78d32015-09-15 21:53:47 -0400980get_url_test () {
981 cat >expect &&
982 git remote get-url "$@" >actual &&
983 test_cmp expect actual
984}
985
986test_expect_success 'get-url on new remote' '
987 echo foo | get_url_test someremote &&
988 echo foo | get_url_test --all someremote &&
989 echo foo | get_url_test --push someremote &&
990 echo foo | get_url_test --push --all someremote
991'
992
Patrick Steinhardt45ebdcc2016-02-22 12:23:28 +0100993test_expect_success 'remote set-url with locked config' '
994 test_when_finished "rm -f .git/config.lock" &&
995 git config --get-all remote.someremote.url >expect &&
996 >.git/config.lock &&
997 test_must_fail git remote set-url someremote baz &&
998 git config --get-all remote.someremote.url >actual &&
999 cmp expect actual
1000'
1001
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001002test_expect_success 'remote set-url bar' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001003 git remote set-url someremote bar &&
1004 echo bar >expect &&
1005 git config --get-all remote.someremote.url >actual &&
1006 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001007'
1008
1009test_expect_success 'remote set-url baz bar' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001010 git remote set-url someremote baz bar &&
1011 echo baz >expect &&
1012 git config --get-all remote.someremote.url >actual &&
1013 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001014'
1015
1016test_expect_success 'remote set-url zot bar' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001017 test_must_fail git remote set-url someremote zot bar &&
1018 echo baz >expect &&
1019 git config --get-all remote.someremote.url >actual &&
1020 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001021'
1022
1023test_expect_success 'remote set-url --push zot baz' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001024 test_must_fail git remote set-url --push someremote zot baz &&
1025 echo "YYY" >expect &&
1026 echo baz >>expect &&
1027 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1028 echo "YYY" >>actual &&
1029 git config --get-all remote.someremote.url >>actual &&
1030 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001031'
1032
1033test_expect_success 'remote set-url --push zot' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001034 git remote set-url --push someremote zot &&
1035 echo zot >expect &&
1036 echo "YYY" >>expect &&
1037 echo baz >>expect &&
1038 git config --get-all remote.someremote.pushurl >actual &&
1039 echo "YYY" >>actual &&
1040 git config --get-all remote.someremote.url >>actual &&
1041 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001042'
1043
Ben Boeckel96f78d32015-09-15 21:53:47 -04001044test_expect_success 'get-url with different urls' '
1045 echo baz | get_url_test someremote &&
1046 echo baz | get_url_test --all someremote &&
1047 echo zot | get_url_test --push someremote &&
1048 echo zot | get_url_test --push --all someremote
1049'
1050
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001051test_expect_success 'remote set-url --push qux zot' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001052 git remote set-url --push someremote qux zot &&
1053 echo qux >expect &&
1054 echo "YYY" >>expect &&
1055 echo baz >>expect &&
1056 git config --get-all remote.someremote.pushurl >actual &&
1057 echo "YYY" >>actual &&
1058 git config --get-all remote.someremote.url >>actual &&
1059 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001060'
1061
1062test_expect_success 'remote set-url --push foo qu+x' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001063 git remote set-url --push someremote foo qu+x &&
1064 echo foo >expect &&
1065 echo "YYY" >>expect &&
1066 echo baz >>expect &&
1067 git config --get-all remote.someremote.pushurl >actual &&
1068 echo "YYY" >>actual &&
1069 git config --get-all remote.someremote.url >>actual &&
1070 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001071'
1072
1073test_expect_success 'remote set-url --push --add aaa' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001074 git remote set-url --push --add someremote aaa &&
1075 echo foo >expect &&
1076 echo aaa >>expect &&
1077 echo "YYY" >>expect &&
1078 echo baz >>expect &&
1079 git config --get-all remote.someremote.pushurl >actual &&
1080 echo "YYY" >>actual &&
1081 git config --get-all remote.someremote.url >>actual &&
1082 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001083'
1084
Ben Boeckel96f78d32015-09-15 21:53:47 -04001085test_expect_success 'get-url on multi push remote' '
1086 echo foo | get_url_test --push someremote &&
1087 get_url_test --push --all someremote <<-\EOF
1088 foo
1089 aaa
1090 EOF
1091'
1092
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001093test_expect_success 'remote set-url --push bar aaa' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001094 git remote set-url --push someremote bar aaa &&
1095 echo foo >expect &&
1096 echo bar >>expect &&
1097 echo "YYY" >>expect &&
1098 echo baz >>expect &&
1099 git config --get-all remote.someremote.pushurl >actual &&
1100 echo "YYY" >>actual &&
1101 git config --get-all remote.someremote.url >>actual &&
1102 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001103'
1104
1105test_expect_success 'remote set-url --push --delete bar' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001106 git remote set-url --push --delete someremote bar &&
1107 echo foo >expect &&
1108 echo "YYY" >>expect &&
1109 echo baz >>expect &&
1110 git config --get-all remote.someremote.pushurl >actual &&
1111 echo "YYY" >>actual &&
1112 git config --get-all remote.someremote.url >>actual &&
1113 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001114'
1115
1116test_expect_success 'remote set-url --push --delete foo' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001117 git remote set-url --push --delete someremote foo &&
1118 echo "YYY" >expect &&
1119 echo baz >>expect &&
1120 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1121 echo "YYY" >>actual &&
1122 git config --get-all remote.someremote.url >>actual &&
1123 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001124'
1125
1126test_expect_success 'remote set-url --add bbb' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001127 git remote set-url --add someremote bbb &&
1128 echo "YYY" >expect &&
1129 echo baz >>expect &&
1130 echo bbb >>expect &&
1131 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1132 echo "YYY" >>actual &&
1133 git config --get-all remote.someremote.url >>actual &&
1134 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001135'
1136
Ben Boeckel96f78d32015-09-15 21:53:47 -04001137test_expect_success 'get-url on multi fetch remote' '
1138 echo baz | get_url_test someremote &&
1139 get_url_test --all someremote <<-\EOF
1140 baz
1141 bbb
1142 EOF
1143'
1144
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001145test_expect_success 'remote set-url --delete .*' '
Brandon Casey49de47c2010-03-19 19:10:20 -05001146 test_must_fail git remote set-url --delete someremote .\* &&
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001147 echo "YYY" >expect &&
1148 echo baz >>expect &&
1149 echo bbb >>expect &&
1150 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1151 echo "YYY" >>actual &&
1152 git config --get-all remote.someremote.url >>actual &&
1153 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001154'
1155
1156test_expect_success 'remote set-url --delete bbb' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001157 git remote set-url --delete someremote bbb &&
1158 echo "YYY" >expect &&
1159 echo baz >>expect &&
1160 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1161 echo "YYY" >>actual &&
1162 git config --get-all remote.someremote.url >>actual &&
1163 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001164'
1165
1166test_expect_success 'remote set-url --delete baz' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001167 test_must_fail git remote set-url --delete someremote baz &&
1168 echo "YYY" >expect &&
1169 echo baz >>expect &&
1170 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1171 echo "YYY" >>actual &&
1172 git config --get-all remote.someremote.url >>actual &&
1173 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001174'
1175
1176test_expect_success 'remote set-url --add ccc' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001177 git remote set-url --add someremote ccc &&
1178 echo "YYY" >expect &&
1179 echo baz >>expect &&
1180 echo ccc >>expect &&
1181 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1182 echo "YYY" >>actual &&
1183 git config --get-all remote.someremote.url >>actual &&
1184 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001185'
1186
1187test_expect_success 'remote set-url --delete baz' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001188 git remote set-url --delete someremote baz &&
1189 echo "YYY" >expect &&
1190 echo ccc >>expect &&
1191 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1192 echo "YYY" >>actual &&
1193 git config --get-all remote.someremote.url >>actual &&
1194 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001195'
1196
Thomas Rastabf5f872013-04-24 15:54:35 +02001197test_expect_success 'extra args: setup' '
1198 # add a dummy origin so that this does not trigger failure
1199 git remote add origin .
1200'
1201
1202test_extra_arg () {
Thomas Rastb17dd3f2013-04-24 15:54:37 +02001203 test_expect_success "extra args: $*" "
Thomas Rastabf5f872013-04-24 15:54:35 +02001204 test_must_fail git remote $* bogus_extra_arg 2>actual &&
Vasco Almeida1edbaac2016-06-17 20:21:07 +00001205 test_i18ngrep '^usage:' actual
Thomas Rastabf5f872013-04-24 15:54:35 +02001206 "
1207}
1208
Thomas Rast2d2e3d22013-04-24 15:54:36 +02001209test_extra_arg add nick url
Thomas Rastabf5f872013-04-24 15:54:35 +02001210test_extra_arg rename origin newname
1211test_extra_arg remove origin
1212test_extra_arg set-head origin master
1213# set-branches takes any number of args
Ben Boeckel96f78d32015-09-15 21:53:47 -04001214test_extra_arg get-url origin newurl
Thomas Rastabf5f872013-04-24 15:54:35 +02001215test_extra_arg set-url origin newurl oldurl
Thomas Rastb17dd3f2013-04-24 15:54:37 +02001216# show takes any number of args
1217# prune takes any number of args
Thomas Rastabf5f872013-04-24 15:54:35 +02001218# update takes any number of args
1219
Johannes Schindelinb90c95d2014-12-23 14:25:09 +01001220test_expect_success 'add remote matching the "insteadOf" URL' '
1221 git config url.xyz@example.com.insteadOf backup &&
1222 git remote add backup xyz@example.com
1223'
1224
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001225test_done