blob: 7789ff12c4b8f80f8ad4385932c342c7c9ae7d00 [file] [log] [blame]
Junio C Hamano683b5672007-09-23 22:29:12 -07001#!/bin/sh
2
3test_description='git remote porcelain-ish'
4
Junio C Hamano683b5672007-09-23 22:29:12 -07005. ./test-lib.sh
6
Junio C Hamano683b5672007-09-23 22:29:12 -07007setup_repository () {
8 mkdir "$1" && (
9 cd "$1" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +000010 git init -b main &&
Junio C Hamano683b5672007-09-23 22:29:12 -070011 >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" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +000020 git checkout main
Junio C Hamano683b5672007-09-23 22:29:12 -070021 )
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
Ævar Arnfjörð Bjarmasona926c4b2021-02-11 02:53:51 +010059test_expect_success 'remote information for the origin' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053060 (
61 cd test &&
62 tokens_match origin "$(git remote)" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +000063 check_remote_track origin main side &&
64 check_tracking_branch origin HEAD main side
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053065 )
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)" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +000073 check_tracking_branch second main side another &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053074 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
Abhradeep Chakrabortyef6d15c2022-05-09 11:32:48 +000081test_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
Ævar Arnfjörð Bjarmasona926c4b2021-02-11 02:53:51 +0100115test_expect_success 'check remote-tracking' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530116 (
117 cd test &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000118 check_remote_track origin main side &&
119 check_remote_track second main side another
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530120 )
Jiang Xinf7dc6a92012-08-27 13:36:54 +0800121'
122
Jeff King1ce89cc2008-04-22 07:11:13 -0400123test_expect_success 'remote forces tracking branches' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530124 (
125 cd test &&
Elia Pintoc0097812015-12-23 14:45:53 +0100126 case $(git config remote.second.fetch) in
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530127 +*) true ;;
128 *) false ;;
129 esac
130 )
Jeff King1ce89cc2008-04-22 07:11:13 -0400131'
132
Junio C Hamano683b5672007-09-23 22:29:12 -0700133test_expect_success 'remove remote' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530134 (
135 cd test &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000136 git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/main &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530137 git remote rm second
138 )
Junio C Hamano683b5672007-09-23 22:29:12 -0700139'
140
Ævar Arnfjörð Bjarmasona926c4b2021-02-11 02:53:51 +0100141test_expect_success 'remove remote' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530142 (
143 cd test &&
144 tokens_match origin "$(git remote)" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000145 check_remote_track origin main side &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530146 git for-each-ref "--format=%(refname)" refs/remotes |
147 sed -e "/^refs\/remotes\/origin\//d" >actual &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +0000148 test_must_be_empty actual
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530149 )
Junio C Hamano683b5672007-09-23 22:29:12 -0700150'
151
Matthieu Moy13931232010-11-02 16:31:25 +0100152test_expect_success 'remove remote protects local branches' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530153 (
154 cd test &&
155 cat >expect1 <<-\EOF &&
156 Note: A branch outside the refs/remotes/ hierarchy was not removed;
157 to delete it, use:
Johannes Schindelin97b91362020-12-17 01:07:05 +0000158 git branch -d main
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530159 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
Johannes Schindelin97b91362020-12-17 01:07:05 +0000164 git branch -d main
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530165 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 &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100174 test_cmp expect1 actual1 &&
175 test_cmp expect2 actual2
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530176 )
Jay Soffian441adf02009-02-04 11:06:07 -0500177'
178
Thomas Gummerercc8e5382016-02-16 10:47:51 +0100179test_expect_success 'remove errors out early when deleting non-existent branch' '
180 (
181 cd test &&
Ævar Arnfjörð Bjarmason9144ba42020-10-27 10:41:36 +0100182 echo "error: No such remote: '\''foo'\''" >expect &&
183 test_expect_code 2 git remote rm foo 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100184 test_cmp expect actual
Thomas Gummerercc8e5382016-02-16 10:47:51 +0100185 )
186'
187
Ross Lagerwall20690b22017-02-18 00:23:41 +0000188test_expect_success 'remove remote with a branch without configured merge' '
189 test_when_finished "(
Johannes Schindelin97b91362020-12-17 01:07:05 +0000190 git -C test checkout main;
Ross Lagerwall20690b22017-02-18 00:23:41 +0000191 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 &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000200 git checkout -b second two/main^0 &&
Ross Lagerwall20690b22017-02-18 00:23:41 +0000201 git config branch.second.remote two &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000202 git checkout main &&
Ross Lagerwall20690b22017-02-18 00:23:41 +0000203 git remote rm two
204 )
205'
206
Thomas Gummerercc8e5382016-02-16 10:47:51 +0100207test_expect_success 'rename errors out early when deleting non-existent branch' '
208 (
209 cd test &&
Ævar Arnfjörð Bjarmason9144ba42020-10-27 10:41:36 +0100210 echo "error: No such remote: '\''foo'\''" >expect &&
211 test_expect_code 2 git remote rename foo bar 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100212 test_cmp expect actual
Thomas Gummerercc8e5382016-02-16 10:47:51 +0100213 )
214'
215
Andrei Rybakabcb66c2021-06-11 13:18:50 +0200216test_expect_success 'rename errors out early when new name is invalid' '
Sean Barag444825c2020-10-01 03:46:12 +0000217 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 &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100220 test_cmp expect actual
Sean Barag444825c2020-10-01 03:46:12 +0000221'
222
Thomas Gummerera31eeae2016-02-16 10:47:52 +0100223test_expect_success 'add existing foreign_vcs remote' '
224 test_config remote.foo.vcs bar &&
Ævar Arnfjörð Bjarmason9144ba42020-10-27 10:41:36 +0100225 echo "error: remote foo already exists." >expect &&
226 test_expect_code 3 git remote add foo bar 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100227 test_cmp expect actual
Thomas Gummerera31eeae2016-02-16 10:47:52 +0100228'
229
230test_expect_success 'add existing foreign_vcs remote' '
231 test_config remote.foo.vcs bar &&
232 test_config remote.bar.vcs bar &&
Ævar Arnfjörð Bjarmason9144ba42020-10-27 10:41:36 +0100233 echo "error: remote bar already exists." >expect &&
234 test_expect_code 3 git remote rename foo bar 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100235 test_cmp expect actual
Thomas Gummerera31eeae2016-02-16 10:47:52 +0100236'
237
Sean Barag444825c2020-10-01 03:46:12 +0000238test_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 &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100241 test_cmp expect actual
Sean Barag444825c2020-10-01 03:46:12 +0000242'
243
SZEDER Gábor31a66c12022-08-19 18:03:54 +0200244test_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 &&
SZEDER Gáborb26a4122022-08-19 18:04:08 +0200261 grep "^error: unknown subcommand:" err
SZEDER Gábor31a66c12022-08-19 18:03:54 +0200262'
263
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530264cat >test/expect <<EOF
Johannes Schindelin47046402008-02-29 01:45:24 +0000265* remote origin
Michael J Gruber857f8c32009-06-13 18:29:10 +0200266 Fetch URL: $(pwd)/one
267 Push URL: $(pwd)/one
Johannes Schindelin97b91362020-12-17 01:07:05 +0000268 HEAD branch: main
Jay Soffian7ecbbf82009-02-25 03:32:27 -0500269 Remote branches:
Johannes Schindelin66713e82020-10-23 14:00:05 +0000270 main new (next fetch will store in remotes/origin)
271 side tracked
Jay Soffian7ecbbf82009-02-25 03:32:27 -0500272 Local branches configured for 'git pull':
Johannes Schindelin66713e82020-10-23 14:00:05 +0000273 ahead merges with remote main
274 main merges with remote main
Jay Soffian7ecbbf82009-02-25 03:32:27 -0500275 octopus merges with remote topic-a
276 and with remote topic-b
277 and with remote topic-c
Johannes Schindelin97b91362020-12-17 01:07:05 +0000278 rebase rebases onto remote main
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500279 Local refs configured for 'git push':
Johannes Schindelin66713e82020-10-23 14:00:05 +0000280 main pushes to main (local out of date)
281 main pushes to upstream (create)
Jay Soffiane61e0cc2009-02-25 03:32:24 -0500282* remote two
Michael J Gruber857f8c32009-06-13 18:29:10 +0200283 Fetch URL: ../two
284 Push URL: ../three
Johannes Schindelin97b91362020-12-17 01:07:05 +0000285 HEAD branch: main
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500286 Local refs configured for 'git push':
Johannes Schindelin66713e82020-10-23 14:00:05 +0000287 ahead forces to main (fast-forwardable)
288 main pushes to another (up to date)
Johannes Schindelin47046402008-02-29 01:45:24 +0000289EOF
290
Johannes Schindelin97b91362020-12-17 01:07:05 +0000291test_expect_success 'show' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530292 (
293 cd test &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000294 git config --add remote.origin.fetch refs/heads/main:refs/heads/upstream &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530295 git fetch &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000296 git checkout -b ahead origin/main &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530297 echo 1 >>file &&
298 test_tick &&
299 git commit -m update file &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000300 git checkout main &&
301 git branch --track octopus origin/main &&
302 git branch --track rebase origin/main &&
303 git branch -d -r origin/main &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530304 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 : &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000315 git config --add remote.origin.push refs/heads/main:refs/heads/upstream &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530316 git config --add remote.origin.push +refs/tags/lastbackup &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000317 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 &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530319 git remote show origin two >output &&
320 git branch -d rebase octopus &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100321 test_cmp expect output
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530322 )
Johannes Schindelin47046402008-02-29 01:45:24 +0000323'
324
Jacob Keller2c80a822022-06-16 17:20:31 -0700325cat >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
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530371cat >test/expect <<EOF
Olivier Marin0ecfcb32008-06-10 16:51:08 +0200372* remote origin
Michael J Gruber857f8c32009-06-13 18:29:10 +0200373 Fetch URL: $(pwd)/one
374 Push URL: $(pwd)/one
Jay Soffiane61e0cc2009-02-25 03:32:24 -0500375 HEAD branch: (not queried)
Jay Soffian7ecbbf82009-02-25 03:32:27 -0500376 Remote branches: (status not queried)
Johannes Schindelin97b91362020-12-17 01:07:05 +0000377 main
Johannes Sixt20244ea2008-10-22 09:39:47 +0200378 side
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500379 Local branches configured for 'git pull':
Johannes Schindelin66713e82020-10-23 14:00:05 +0000380 ahead merges with remote main
381 main merges with remote main
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500382 Local refs configured for 'git push' (status not queried):
383 (matching) pushes to (matching)
Johannes Schindelin66713e82020-10-23 14:00:05 +0000384 refs/heads/main pushes to refs/heads/upstream
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500385 refs/tags/lastbackup forces to refs/tags/lastbackup
Olivier Marin0ecfcb32008-06-10 16:51:08 +0200386EOF
387
Johannes Schindelin97b91362020-12-17 01:07:05 +0000388test_expect_success 'show -n' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530389 mv one one.unreachable &&
390 (
391 cd test &&
392 git remote show -n origin >output &&
393 mv ../one.unreachable ../one &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100394 test_cmp expect output
Jay Soffianbc14fac2009-02-25 03:32:25 -0500395 )
396'
397
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530398test_expect_success 'prune' '
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 )
410'
411
412test_expect_success 'set-head --delete' '
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 )
419'
420
421test_expect_success 'set-head --auto' '
422 (
423 cd test &&
424 git remote set-head --auto origin &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000425 echo refs/remotes/origin/main >expect &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530426 git symbolic-ref refs/remotes/origin/HEAD >output &&
427 test_cmp expect output
428 )
429'
430
Johannes Schindelin97b91362020-12-17 01:07:05 +0000431test_expect_success 'set-head --auto has no problem w/multiple HEADs' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530432 (
433 cd test &&
Junio C Hamanoa4dfee02013-09-17 21:45:34 -0700434 git fetch two "refs/heads/*:refs/remotes/two/*" &&
Junio C Hamanoa45b5f02013-09-17 19:10:31 -0700435 git remote set-head --auto two >output 2>&1 &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000436 echo "two/HEAD set to main" >expect &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100437 test_cmp expect output
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530438 )
Jay Soffianbc14fac2009-02-25 03:32:25 -0500439'
440
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530441cat >test/expect <<\EOF
Jay Soffianbc14fac2009-02-25 03:32:25 -0500442refs/remotes/origin/side2
443EOF
444
445test_expect_success 'set-head explicit' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530446 (
447 cd test &&
448 git remote set-head origin side2 &&
449 git symbolic-ref refs/remotes/origin/HEAD >output &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000450 git remote set-head origin main &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530451 test_cmp expect output
452 )
Jay Soffianbc14fac2009-02-25 03:32:25 -0500453'
454
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530455cat >test/expect <<EOF
Olivier Marin8d767922008-06-10 16:51:35 +0200456Pruning origin
Johan Herland86521ac2008-09-01 21:07:33 +0200457URL: $(pwd)/one
Olivier Marin8d767922008-06-10 16:51:35 +0200458 * [would prune] origin/side2
459EOF
460
461test_expect_success 'prune --dry-run' '
Eric Sunshine431f4a22018-07-01 20:23:48 -0400462 git -C one branch -m side2 side &&
463 test_when_finished "git -C one branch -m side side2" &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530464 (
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 &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100469 test_cmp expect output
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530470 )
Olivier Marin8d767922008-06-10 16:51:35 +0200471'
472
Johannes Schindelin4ebc9142008-02-29 01:46:07 +0000473test_expect_success 'add --mirror && prune' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530474 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 )
Johannes Schindelin4ebc9142008-02-29 01:46:07 +0000493'
494
Jeff Kinga9f5a352011-03-30 15:53:19 -0400495test_expect_success 'add --mirror=fetch' '
496 mkdir mirror-fetch &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000497 git init -b main mirror-fetch/parent &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530498 (
499 cd mirror-fetch/parent &&
500 test_commit one
501 ) &&
Jeff Kinga9f5a352011-03-30 15:53:19 -0400502 git init --bare mirror-fetch/child &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530503 (
504 cd mirror-fetch/child &&
505 git remote add --mirror=fetch -f parent ../parent
506 )
Jeff Kinga9f5a352011-03-30 15:53:19 -0400507'
508
509test_expect_success 'fetch mirrors act as mirrors during fetch' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530510 (
511 cd mirror-fetch/parent &&
512 git branch new &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000513 git branch -m main renamed
Jeff Kinga9f5a352011-03-30 15:53:19 -0400514 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530515 (
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
Jeff Kinga9f5a352011-03-30 15:53:19 -0400520 )
521'
522
523test_expect_success 'fetch mirrors can prune' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530524 (
525 cd mirror-fetch/child &&
526 git remote prune parent &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000527 test_must_fail git rev-parse --verify refs/heads/main
Jeff Kinga9f5a352011-03-30 15:53:19 -0400528 )
529'
530
531test_expect_success 'fetch mirrors do not act as mirrors during push' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530532 (
533 cd mirror-fetch/parent &&
534 git checkout HEAD^0
Jeff Kinga9f5a352011-03-30 15:53:19 -0400535 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530536 (
537 cd mirror-fetch/child &&
538 git branch -m renamed renamed2 &&
539 git push parent :
Jeff Kinga9f5a352011-03-30 15:53:19 -0400540 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530541 (
542 cd mirror-fetch/parent &&
543 git rev-parse --verify renamed &&
544 test_must_fail git rev-parse --verify refs/heads/renamed2
Jeff Kinga9f5a352011-03-30 15:53:19 -0400545 )
546'
547
Jeff King3eafdc92011-05-26 11:11:00 -0400548test_expect_success 'add fetch mirror with specific branches' '
549 git init --bare mirror-fetch/track &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530550 (
551 cd mirror-fetch/track &&
552 git remote add --mirror=fetch -t heads/new parent ../parent
Jeff King3eafdc92011-05-26 11:11:00 -0400553 )
554'
555
556test_expect_success 'fetch mirror respects specific branches' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530557 (
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
Jeff King3eafdc92011-05-26 11:11:00 -0400562 )
563'
564
Jeff Kinga9f5a352011-03-30 15:53:19 -0400565test_expect_success 'add --mirror=push' '
566 mkdir mirror-push &&
567 git init --bare mirror-push/public &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000568 git init -b main mirror-push/private &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530569 (
570 cd mirror-push/private &&
571 test_commit one &&
572 git remote add --mirror=push public ../public
Jeff Kinga9f5a352011-03-30 15:53:19 -0400573 )
574'
575
576test_expect_success 'push mirrors act as mirrors during push' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530577 (
578 cd mirror-push/private &&
579 git branch new &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000580 git branch -m main renamed &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530581 git push public
Jeff Kinga9f5a352011-03-30 15:53:19 -0400582 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530583 (
584 cd mirror-push/private &&
585 git rev-parse --verify refs/heads/new &&
586 git rev-parse --verify refs/heads/renamed &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000587 test_must_fail git rev-parse --verify refs/heads/main
Jeff Kinga9f5a352011-03-30 15:53:19 -0400588 )
589'
590
591test_expect_success 'push mirrors do not act as mirrors during fetch' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530592 (
593 cd mirror-push/public &&
594 git branch -m renamed renamed2 &&
595 git symbolic-ref HEAD refs/heads/renamed2
Jeff Kinga9f5a352011-03-30 15:53:19 -0400596 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530597 (
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
Jeff Kinga9f5a352011-03-30 15:53:19 -0400602 )
603'
604
Jeff King3eafdc92011-05-26 11:11:00 -0400605test_expect_success 'push mirrors do not allow you to specify refs' '
606 git init mirror-push/track &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530607 (
608 cd mirror-push/track &&
609 test_must_fail git remote add --mirror=push -t new public ../public
Jeff King3eafdc92011-05-26 11:11:00 -0400610 )
611'
612
Shawn O. Pearcec175a7a2008-05-31 23:58:05 -0400613test_expect_success 'add alt && prune' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530614 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 )
Shawn O. Pearcec175a7a2008-05-31 23:58:05 -0400635'
636
Samuel Tardieu111fb852010-04-20 01:31:31 +0200637cat >test/expect <<\EOF
638some-tag
639EOF
640
641test_expect_success 'add with reachable tags (default)' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530642 (
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 ) &&
Samuel Tardieu111fb852010-04-20 01:31:31 +0200660 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' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530670 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 ) &&
Samuel Tardieu111fb852010-04-20 01:31:31 +0200680 test_cmp test/expect test/output
681'
682
683cat >test/expect <<\EOF
684--no-tags
685EOF
686
687test_expect_success 'add --no-tags' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530688 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 &&
Ævar Arnfjörð Bjarmasonbfa91482021-02-25 02:21:16 +0100694 grep tagOpt .git/config &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530695 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 ) &&
Samuel Tardieu111fb852010-04-20 01:31:31 +0200703 test_cmp test/expect test/output
704'
705
706test_expect_success 'reject --no-no-tags' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530707 (
708 cd add-no-tags &&
709 test_must_fail git remote add -f --no-no-tags neworigin ../one
710 )
Samuel Tardieu111fb852010-04-20 01:31:31 +0200711'
712
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530713cat >one/expect <<\EOF
Johannes Schindelin97b91362020-12-17 01:07:05 +0000714 apis/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000715 apis/side
716 drosophila/another
Johannes Schindelin97b91362020-12-17 01:07:05 +0000717 drosophila/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000718 drosophila/side
719EOF
720
721test_expect_success 'update' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530722 (
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 )
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000730'
731
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530732cat >one/expect <<\EOF
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000733 drosophila/another
Johannes Schindelin97b91362020-12-17 01:07:05 +0000734 drosophila/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000735 drosophila/side
Johannes Schindelin97b91362020-12-17 01:07:05 +0000736 manduca/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000737 manduca/side
Johannes Schindelin97b91362020-12-17 01:07:05 +0000738 megaloprepus/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000739 megaloprepus/side
740EOF
741
742test_expect_success 'update with arguments' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530743 (
744 cd one &&
745 for b in $(git branch -r)
746 do
Jeff Kinge6821d02015-03-25 01:29:52 -0400747 git branch -r -d $b || exit 1
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530748 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 )
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000757'
758
Björn Gustavssone2d41c62009-11-09 21:11:59 +0100759test_expect_success 'update --prune' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530760 (
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 )
Björn Gustavssone2d41c62009-11-09 21:11:59 +0100774'
775
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530776cat >one/expect <<-\EOF
Johannes Schindelin97b91362020-12-17 01:07:05 +0000777 apis/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000778 apis/side
Johannes Schindelin97b91362020-12-17 01:07:05 +0000779 manduca/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000780 manduca/side
Johannes Schindelin97b91362020-12-17 01:07:05 +0000781 megaloprepus/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000782 megaloprepus/side
783EOF
784
785test_expect_success 'update default' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530786 (
787 cd one &&
788 for b in $(git branch -r)
789 do
Jeff Kinge6821d02015-03-25 01:29:52 -0400790 git branch -r -d $b || exit 1
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530791 done &&
792 git config remote.drosophila.skipDefaultUpdate true &&
793 git remote update default &&
794 git branch -r >output &&
795 test_cmp expect output
796 )
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000797'
798
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530799cat >one/expect <<\EOF
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000800 drosophila/another
Johannes Schindelin97b91362020-12-17 01:07:05 +0000801 drosophila/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000802 drosophila/side
803EOF
804
805test_expect_success 'update default (overridden, with funny whitespace)' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530806 (
807 cd one &&
808 for b in $(git branch -r)
809 do
Jeff Kinge6821d02015-03-25 01:29:52 -0400810 git branch -r -d $b || exit 1
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530811 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 )
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000817'
818
Björn Gustavsson4f2e8422009-12-31 10:43:17 +0100819test_expect_success 'update (with remotes.default defined)' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530820 (
821 cd one &&
822 for b in $(git branch -r)
823 do
Jeff Kinge6821d02015-03-25 01:29:52 -0400824 git branch -r -d $b || exit 1
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530825 done &&
826 git config remotes.default "drosophila" &&
827 git remote update &&
828 git branch -r >output &&
829 test_cmp expect output
830 )
Björn Gustavsson4f2e8422009-12-31 10:43:17 +0100831'
832
Johannes Schindelin740fdd22008-03-19 00:27:42 +0000833test_expect_success '"remote show" does not show symbolic refs' '
Johannes Schindelin740fdd22008-03-19 00:27:42 +0000834 git clone one three &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530835 (
836 cd three &&
837 git remote show origin >output &&
838 ! grep "^ *HEAD$" < output &&
839 ! grep -i stale < output
840 )
Johannes Schindelin740fdd22008-03-19 00:27:42 +0000841'
842
Jonas Fonseca24b61772008-04-13 11:56:54 +0200843test_expect_success 'reject adding remote with an invalid name' '
Stephan Beyerd492b312008-07-12 17:47:52 +0200844 test_must_fail git remote add some:url desired-name
Jonas Fonseca24b61772008-04-13 11:56:54 +0200845'
846
Miklos Vajnabf984212008-11-03 19:26:18 +0100847# 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' '
Bert Wesargb3fd6cb2020-02-01 10:34:09 +0100851 test_config_global remote.pushDefault origin &&
Miklos Vajnabf984212008-11-03 19:26:18 +0100852 git clone one four &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530853 (
854 cd four &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000855 git config branch.main.pushRemote origin &&
Taylor Blau56710a72022-03-03 17:25:18 -0500856 GIT_TRACE2_EVENT=$(pwd)/trace \
857 git remote rename --progress origin upstream &&
858 test_region progress "Renaming remote references" trace &&
Ævar Arnfjörð Bjarmason0f1da602021-02-25 02:21:17 +0100859 grep "pushRemote" .git/config &&
Michael Haggerty2eb7a0e2017-01-06 17:22:23 +0100860 test -z "$(git for-each-ref refs/remotes/origin)" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000861 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/main" &&
862 test "$(git rev-parse upstream/main)" = "$(git rev-parse main)" &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530863 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000864 test "$(git config branch.main.remote)" = "upstream" &&
865 test "$(git config branch.main.pushRemote)" = "upstream" &&
Bert Wesargb3fd6cb2020-02-01 10:34:09 +0100866 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 &&
Ævar Arnfjörð Bjarmason0f1da602021-02-25 02:21:17 +0100876 grep pushDefault .git/config &&
Bert Wesargb3fd6cb2020-02-01 10:34:09 +0100877 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"
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530902 )
Miklos Vajnabf984212008-11-03 19:26:18 +0100903'
Miklos Vajna1dd12392008-11-10 21:43:01 +0100904
Jeff King5a97b382022-09-22 01:33:29 -0400905test_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
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400916test_expect_success 'rename does not update a non-default fetch refspec' '
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400917 git clone one four.one &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530918 (
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/*" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000923 git rev-parse -q origin/main
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530924 )
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400925'
926
927test_expect_success 'rename a remote with name part of fetch spec' '
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400928 git clone one four.two &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530929 (
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 )
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400935'
936
Martin von Zweigbergk60e5eee2011-09-01 20:50:34 -0400937test_expect_success 'rename a remote with name prefix of other remote' '
Martin von Zweigbergk60e5eee2011-09-01 20:50:34 -0400938 git clone one four.three &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530939 (
940 cd four.three &&
941 git remote add o git://example.com/repo.git &&
942 git remote rename o upstream &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000943 test "$(git rev-parse origin/main)" = "$(git rev-parse main)"
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530944 )
Martin von Zweigbergk60e5eee2011-09-01 20:50:34 -0400945'
946
Johannes Schindeline459b072017-01-19 22:20:02 +0100947test_expect_success 'rename succeeds with existing remote.<target>.prune' '
Johannes Schindelinaf5bacf2017-01-19 22:19:58 +0100948 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
Bert Wesarg923d4a52020-01-27 08:04:30 +0100954test_expect_success 'remove a remote' '
Bert Wesargb3fd6cb2020-02-01 10:34:09 +0100955 test_config_global remote.pushDefault origin &&
Bert Wesarg923d4a52020-01-27 08:04:30 +0100956 git clone one four.five &&
957 (
958 cd four.five &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000959 git config branch.main.pushRemote origin &&
Bert Wesarg923d4a52020-01-27 08:04:30 +0100960 git remote remove origin &&
961 test -z "$(git for-each-ref refs/remotes/origin)" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000962 test_must_fail git config branch.main.remote &&
963 test_must_fail git config branch.main.pushRemote &&
Bert Wesargb3fd6cb2020-02-01 10:34:09 +0100964 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
Bert Wesarg923d4a52020-01-27 08:04:30 +0100999 )
1000'
1001
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +05301002cat >remotes_origin <<EOF
Miklos Vajna1dd12392008-11-10 21:43:01 +01001003URL: $(pwd)/one
Johannes Schindelin97b91362020-12-17 01:07:05 +00001004Push: refs/heads/main:refs/heads/upstream
Ramkumar Ramachandraf0f249d2013-06-22 13:28:18 +05301005Push: refs/heads/next:refs/heads/upstream2
Johannes Schindelin97b91362020-12-17 01:07:05 +00001006Pull: refs/heads/main:refs/heads/origin
Ramkumar Ramachandraf0f249d2013-06-22 13:28:18 +05301007Pull: refs/heads/next:refs/heads/origin2
Miklos Vajna1dd12392008-11-10 21:43:01 +01001008EOF
1009
1010test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
1011 git clone one five &&
1012 origin_url=$(pwd)/one &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +05301013 (
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 &&
Ramkumar Ramachandrafe3c1952013-06-22 13:28:10 +05301019 test_path_is_missing .git/remotes/origin &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +05301020 test "$(git config remote.origin.url)" = "$origin_url" &&
Ramkumar Ramachandraf0f249d2013-06-22 13:28:18 +05301021 cat >push_expected <<-\EOF &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001022 refs/heads/main:refs/heads/upstream
Ramkumar Ramachandraf0f249d2013-06-22 13:28:18 +05301023 refs/heads/next:refs/heads/upstream2
1024 EOF
1025 cat >fetch_expected <<-\EOF &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001026 refs/heads/main:refs/heads/origin
Ramkumar Ramachandraf0f249d2013-06-22 13:28:18 +05301027 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
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +05301033 )
Miklos Vajna1dd12392008-11-10 21:43:01 +01001034'
1035
1036test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
Ævar Arnfjörð Bjarmasone9422922022-06-03 13:15:04 +02001037 git clone --template= one six &&
Miklos Vajna1dd12392008-11-10 21:43:01 +01001038 origin_url=$(pwd)/one &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +05301039 (
1040 cd six &&
1041 git remote rm origin &&
Ævar Arnfjörð Bjarmasone9422922022-06-03 13:15:04 +02001042 mkdir .git/branches &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001043 echo "$origin_url#main" >.git/branches/origin &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +05301044 git remote rename origin origin &&
Ramkumar Ramachandrafe3c1952013-06-22 13:28:10 +05301045 test_path_is_missing .git/branches/origin &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +05301046 test "$(git config remote.origin.url)" = "$origin_url" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001047 test "$(git config remote.origin.fetch)" = "refs/heads/main:refs/heads/origin" &&
1048 test "$(git config remote.origin.push)" = "HEAD:refs/heads/main"
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +05301049 )
Miklos Vajna1dd12392008-11-10 21:43:01 +01001050'
1051
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +05301052test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' '
Ævar Arnfjörð Bjarmasone9422922022-06-03 13:15:04 +02001053 git clone --template= one seven &&
Junio C Hamanof8948e22009-02-08 23:27:10 -08001054 (
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +05301055 cd seven &&
1056 git remote rm origin &&
Ævar Arnfjörð Bjarmasone9422922022-06-03 13:15:04 +02001057 mkdir .git/branches &&
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +05301058 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" &&
Eric Sunshine51b85472018-07-01 20:24:01 -04001062 test "$(git config remote.origin.fetch)" = "refs/heads/foom:refs/heads/origin" &&
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +05301063 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 &&
1069 (
Junio C Hamanof8948e22009-02-08 23:27:10 -08001070 cd one &&
1071 git checkout side2 &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001072 git branch -D main
Junio C Hamanof8948e22009-02-08 23:27:10 -08001073 ) &&
1074 (
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +05301075 cd eight &&
Junio C Hamanof8948e22009-02-08 23:27:10 -08001076 git remote prune origin
Junio C Hamanoe01de1c2010-03-15 22:12:55 -07001077 ) >err 2>&1 &&
Junio C Hamano67892752023-10-31 14:23:30 +09001078 test_grep "has become dangling" err &&
Junio C Hamanof8948e22009-02-08 23:27:10 -08001079
Junio C Hamanoe01de1c2010-03-15 22:12:55 -07001080 : And the dangling symref will not cause other annoying errors &&
Junio C Hamanof8948e22009-02-08 23:27:10 -08001081 (
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +05301082 cd eight &&
Junio C Hamanof8948e22009-02-08 23:27:10 -08001083 git branch -a
1084 ) 2>err &&
Junio C Hamanoe01de1c2010-03-15 22:12:55 -07001085 ! grep "points nowhere" err &&
Junio C Hamano057e7132009-02-08 23:52:01 -08001086 (
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +05301087 cd eight &&
Junio C Hamano057e7132009-02-08 23:52:01 -08001088 test_must_fail git branch nomore origin
1089 ) 2>err &&
Junio C Hamano67892752023-10-31 14:23:30 +09001090 test_grep "dangling symref" err
Junio C Hamanof8948e22009-02-08 23:27:10 -08001091'
1092
Clemens Buchacher6a015542009-05-27 22:13:43 +02001093test_expect_success 'show empty remote' '
Clemens Buchacher6a015542009-05-27 22:13:43 +02001094 test_create_repo empty &&
1095 git clone empty empty-clone &&
1096 (
1097 cd empty-clone &&
1098 git remote show origin
1099 )
1100'
1101
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001102test_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
Johannes Schindelin97b91362020-12-17 01:07:05 +00001115 +refs/heads/main:refs/remotes/scratch/main
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001116 +refs/heads/next:refs/remotes/scratch/next
1117 EOF
1118 sort <<-\EOF >expect.add-two &&
1119 +refs/heads/maint:refs/remotes/scratch/maint
Johannes Schindelin97b91362020-12-17 01:07:05 +00001120 +refs/heads/main:refs/remotes/scratch/main
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001121 +refs/heads/next:refs/remotes/scratch/next
Johannes Schindelin6dca5db2020-06-25 12:18:59 +00001122 +refs/heads/seen:refs/remotes/scratch/seen
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001123 +refs/heads/t/topic:refs/remotes/scratch/t/topic
1124 EOF
1125 sort <<-\EOF >expect.setup-ffonly &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001126 refs/heads/main:refs/remotes/scratch/main
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001127 +refs/heads/next:refs/remotes/scratch/next
1128 EOF
1129 sort <<-\EOF >expect.respect-ffonly &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001130 refs/heads/main:refs/remotes/scratch/main
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001131 +refs/heads/next:refs/remotes/scratch/next
Johannes Schindelin6dca5db2020-06-25 12:18:59 +00001132 +refs/heads/seen:refs/remotes/scratch/seen
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001133 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
Johannes Schindelin97b91362020-12-17 01:07:05 +00001146 git remote set-branches scratch maint main next &&
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001147 git config --get-all remote.scratch.fetch >config-result &&
1148 sort <config-result >../actual.replace &&
1149
Johannes Schindelin6dca5db2020-06-25 12:18:59 +00001150 git remote set-branches --add scratch seen t/topic &&
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001151 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 \
Johannes Schindelin97b91362020-12-17 01:07:05 +00001156 refs/heads/main:refs/remotes/scratch/main &&
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001157 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
Johannes Schindelin6dca5db2020-06-25 12:18:59 +00001162 git remote set-branches --add scratch seen &&
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001163 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 &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001176 echo "+refs/heads/main:refs/heads/main" >expect.replace &&
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001177 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
Johannes Schindelin97b91362020-12-17 01:07:05 +00001183 git remote set-branches scratch heads/main &&
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001184 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001190test_expect_success 'new remote' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001191 git remote add someremote foo &&
1192 echo foo >expect &&
1193 git config --get-all remote.someremote.url >actual &&
1194 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001195'
Junio C Hamano057e7132009-02-08 23:52:01 -08001196
Ben Boeckel96f78d32015-09-15 21:53:47 -04001197get_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
Patrick Steinhardt45ebdcc2016-02-22 12:23:28 +01001210test_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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001219test_expect_success 'remote set-url bar' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001220 git remote set-url someremote bar &&
1221 echo bar >expect &&
1222 git config --get-all remote.someremote.url >actual &&
1223 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001224'
1225
1226test_expect_success 'remote set-url baz bar' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001227 git remote set-url someremote baz bar &&
1228 echo baz >expect &&
1229 git config --get-all remote.someremote.url >actual &&
1230 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001231'
1232
1233test_expect_success 'remote set-url zot bar' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001234 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001238'
1239
1240test_expect_success 'remote set-url --push zot baz' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001241 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001248'
1249
1250test_expect_success 'remote set-url --push zot' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001251 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001259'
1260
Ben Boeckel96f78d32015-09-15 21:53:47 -04001261test_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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001268test_expect_success 'remote set-url --push qux zot' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001269 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001277'
1278
1279test_expect_success 'remote set-url --push foo qu+x' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001280 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001288'
1289
1290test_expect_success 'remote set-url --push --add aaa' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001291 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001300'
1301
Ben Boeckel96f78d32015-09-15 21:53:47 -04001302test_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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001310test_expect_success 'remote set-url --push bar aaa' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001311 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001320'
1321
1322test_expect_success 'remote set-url --push --delete bar' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001323 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001331'
1332
1333test_expect_success 'remote set-url --push --delete foo' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001334 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001341'
1342
1343test_expect_success 'remote set-url --add bbb' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001344 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001352'
1353
Ben Boeckel96f78d32015-09-15 21:53:47 -04001354test_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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001362test_expect_success 'remote set-url --delete .*' '
Brandon Casey49de47c2010-03-19 19:10:20 -05001363 test_must_fail git remote set-url --delete someremote .\* &&
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001364 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001371'
1372
1373test_expect_success 'remote set-url --delete bbb' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001374 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001381'
1382
1383test_expect_success 'remote set-url --delete baz' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001384 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001391'
1392
1393test_expect_success 'remote set-url --add ccc' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001394 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001402'
1403
1404test_expect_success 'remote set-url --delete baz' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001405 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
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001412'
1413
Thomas Rastabf5f872013-04-24 15:54:35 +02001414test_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 () {
Thomas Rastb17dd3f2013-04-24 15:54:37 +02001420 test_expect_success "extra args: $*" "
Thomas Rastabf5f872013-04-24 15:54:35 +02001421 test_must_fail git remote $* bogus_extra_arg 2>actual &&
Junio C Hamano67892752023-10-31 14:23:30 +09001422 test_grep '^usage:' actual
Thomas Rastabf5f872013-04-24 15:54:35 +02001423 "
1424}
1425
Thomas Rast2d2e3d22013-04-24 15:54:36 +02001426test_extra_arg add nick url
Thomas Rastabf5f872013-04-24 15:54:35 +02001427test_extra_arg rename origin newname
1428test_extra_arg remove origin
Johannes Schindelin97b91362020-12-17 01:07:05 +00001429test_extra_arg set-head origin main
Thomas Rastabf5f872013-04-24 15:54:35 +02001430# set-branches takes any number of args
Ben Boeckel96f78d32015-09-15 21:53:47 -04001431test_extra_arg get-url origin newurl
Thomas Rastabf5f872013-04-24 15:54:35 +02001432test_extra_arg set-url origin newurl oldurl
Thomas Rastb17dd3f2013-04-24 15:54:37 +02001433# show takes any number of args
1434# prune takes any number of args
Thomas Rastabf5f872013-04-24 15:54:35 +02001435# update takes any number of args
1436
Johannes Schindelinb90c95d2014-12-23 14:25:09 +01001437test_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
Ævar Arnfjörð Bjarmasondd8dd302018-11-13 19:52:43 +00001442test_expect_success 'unqualified <dst> refspec DWIM and advice' '
1443 test_when_finished "(cd test && git tag -d some-tag)" &&
1444 (
1445 cd test &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001446 git tag -a -m "Some tag" some-tag main &&
Ævar Arnfjörð Bjarmasondd8dd302018-11-13 19:52:43 +00001447 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 &&
Junio C Hamano67892752023-10-31 14:23:30 +09001456 test_grep "error: The destination you" err &&
1457 test_grep "hint: Did you mean" err &&
Ævar Arnfjörð Bjarmasondd8dd302018-11-13 19:52:43 +00001458 test_must_fail git -c advice.pushUnqualifiedRefName=false \
1459 push origin $oid:dst 2>err &&
Junio C Hamano67892752023-10-31 14:23:30 +09001460 test_grep "error: The destination you" err &&
1461 test_grep ! "hint: Did you mean" err ||
Eric Sunshine03949e32021-12-09 00:11:10 -05001462 exit 1
1463 done
Ævar Arnfjörð Bjarmasondd8dd302018-11-13 19:52:43 +00001464 )
1465'
1466
Johannes Schindelin97b91362020-12-17 01:07:05 +00001467test_expect_success 'refs/remotes/* <src> refspec and unqualified <dst> DWIM and advice' '
Ævar Arnfjörð Bjarmasonbf706362018-11-13 19:52:44 +00001468 (
1469 cd two &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001470 git tag -a -m "Some tag" my-tag main &&
Ævar Arnfjörð Bjarmasonbf706362018-11-13 19:52:44 +00001471 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 &&
Junio C Hamano67892752023-10-31 14:23:30 +09001482 test_grep "error: The destination you" err &&
Ævar Arnfjörð Bjarmasonbf706362018-11-13 19:52:44 +00001483
1484 test_must_fail git push origin refs/remotes/tags-from-two/my-tag:dst-tag 2>err &&
Junio C Hamano67892752023-10-31 14:23:30 +09001485 test_grep "error: The destination you" err &&
Ævar Arnfjörð Bjarmasonbf706362018-11-13 19:52:44 +00001486
1487 test_must_fail git push origin refs/remotes/trees-from-two/my-head-tree:dst-tree 2>err &&
Junio C Hamano67892752023-10-31 14:23:30 +09001488 test_grep "error: The destination you" err &&
Ævar Arnfjörð Bjarmasonbf706362018-11-13 19:52:44 +00001489
1490 test_must_fail git push origin refs/remotes/blobs-from-two/my-file-blob:dst-blob 2>err &&
Junio C Hamano67892752023-10-31 14:23:30 +09001491 test_grep "error: The destination you" err
Ævar Arnfjörð Bjarmasonbf706362018-11-13 19:52:44 +00001492 )
1493'
Ævar Arnfjörð Bjarmasondd8dd302018-11-13 19:52:43 +00001494
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001495test_done