blob: e6e3c8f552cd66fedaccbadb49cb47facb3f3863 [file] [log] [blame]
Junio C Hamano683b5672007-09-23 22:29:12 -07001#!/bin/sh
2
3test_description='git remote porcelain-ish'
4
Johannes Schindelin3275f4e2020-11-18 23:44:31 +00005GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00006export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
Junio C Hamano683b5672007-09-23 22:29:12 -07008. ./test-lib.sh
9
Junio C Hamano683b5672007-09-23 22:29:12 -070010setup_repository () {
11 mkdir "$1" && (
12 cd "$1" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +000013 git init -b main &&
Junio C Hamano683b5672007-09-23 22:29:12 -070014 >file &&
15 git add file &&
Johannes Schindelin84521ed2008-03-04 11:23:53 +000016 test_tick &&
Junio C Hamano683b5672007-09-23 22:29:12 -070017 git commit -m "Initial" &&
18 git checkout -b side &&
19 >elif &&
20 git add elif &&
Johannes Schindelin84521ed2008-03-04 11:23:53 +000021 test_tick &&
Junio C Hamano683b5672007-09-23 22:29:12 -070022 git commit -m "Second" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +000023 git checkout main
Junio C Hamano683b5672007-09-23 22:29:12 -070024 )
25}
26
27tokens_match () {
28 echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect &&
29 echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual &&
Jeff King82ebb0b2008-03-12 17:36:36 -040030 test_cmp expect actual
Junio C Hamano683b5672007-09-23 22:29:12 -070031}
32
33check_remote_track () {
Jay Soffian7ecbbf82009-02-25 03:32:27 -050034 actual=$(git remote show "$1" | sed -ne 's|^ \(.*\) tracked$|\1|p')
Junio C Hamano683b5672007-09-23 22:29:12 -070035 shift &&
36 tokens_match "$*" "$actual"
37}
38
39check_tracking_branch () {
40 f="" &&
41 r=$(git for-each-ref "--format=%(refname)" |
42 sed -ne "s|^refs/remotes/$1/||p") &&
43 shift &&
44 tokens_match "$*" "$r"
45}
46
47test_expect_success setup '
Junio C Hamano683b5672007-09-23 22:29:12 -070048 setup_repository one &&
49 setup_repository two &&
50 (
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053051 cd two &&
52 git branch another
Junio C Hamano683b5672007-09-23 22:29:12 -070053 ) &&
54 git clone one test
Junio C Hamano683b5672007-09-23 22:29:12 -070055'
56
Johannes Schindelind8ff76c2016-02-17 17:20:47 +010057test_expect_success 'add remote whose URL agrees with url.<...>.insteadOf' '
58 test_config url.git@host.com:team/repo.git.insteadOf myremote &&
59 git remote add myremote git@host.com:team/repo.git
60'
61
Ævar Arnfjörð Bjarmasona926c4b2021-02-11 02:53:51 +010062test_expect_success 'remote information for the origin' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053063 (
64 cd test &&
65 tokens_match origin "$(git remote)" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +000066 check_remote_track origin main side &&
67 check_tracking_branch origin HEAD main side
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053068 )
Junio C Hamano683b5672007-09-23 22:29:12 -070069'
70
71test_expect_success 'add another remote' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053072 (
73 cd test &&
74 git remote add -f second ../two &&
75 tokens_match "origin second" "$(git remote)" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +000076 check_tracking_branch second main side another &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053077 git for-each-ref "--format=%(refname)" refs/remotes |
78 sed -e "/^refs\/remotes\/origin\//d" \
79 -e "/^refs\/remotes\/second\//d" >actual &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +000080 test_must_be_empty actual
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053081 )
Junio C Hamano683b5672007-09-23 22:29:12 -070082'
83
Ævar Arnfjörð Bjarmasona926c4b2021-02-11 02:53:51 +010084test_expect_success 'check remote-tracking' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053085 (
86 cd test &&
Johannes Schindelin97b91362020-12-17 01:07:05 +000087 check_remote_track origin main side &&
88 check_remote_track second main side another
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053089 )
Jiang Xinf7dc6a92012-08-27 13:36:54 +080090'
91
Jeff King1ce89cc2008-04-22 07:11:13 -040092test_expect_success 'remote forces tracking branches' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053093 (
94 cd test &&
Elia Pintoc0097812015-12-23 14:45:53 +010095 case $(git config remote.second.fetch) in
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +053096 +*) true ;;
97 *) false ;;
98 esac
99 )
Jeff King1ce89cc2008-04-22 07:11:13 -0400100'
101
Junio C Hamano683b5672007-09-23 22:29:12 -0700102test_expect_success 'remove remote' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530103 (
104 cd test &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000105 git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/main &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530106 git remote rm second
107 )
Junio C Hamano683b5672007-09-23 22:29:12 -0700108'
109
Ævar Arnfjörð Bjarmasona926c4b2021-02-11 02:53:51 +0100110test_expect_success 'remove remote' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530111 (
112 cd test &&
113 tokens_match origin "$(git remote)" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000114 check_remote_track origin main side &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530115 git for-each-ref "--format=%(refname)" refs/remotes |
116 sed -e "/^refs\/remotes\/origin\//d" >actual &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +0000117 test_must_be_empty actual
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530118 )
Junio C Hamano683b5672007-09-23 22:29:12 -0700119'
120
Matthieu Moy13931232010-11-02 16:31:25 +0100121test_expect_success 'remove remote protects local branches' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530122 (
123 cd test &&
124 cat >expect1 <<-\EOF &&
125 Note: A branch outside the refs/remotes/ hierarchy was not removed;
126 to delete it, use:
Johannes Schindelin97b91362020-12-17 01:07:05 +0000127 git branch -d main
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530128 EOF
129 cat >expect2 <<-\EOF &&
130 Note: Some branches outside the refs/remotes/ hierarchy were not removed;
131 to delete them, use:
132 git branch -d foobranch
Johannes Schindelin97b91362020-12-17 01:07:05 +0000133 git branch -d main
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530134 EOF
135 git tag footag &&
136 git config --add remote.oops.fetch "+refs/*:refs/*" &&
137 git remote remove oops 2>actual1 &&
138 git branch foobranch &&
139 git config --add remote.oops.fetch "+refs/*:refs/*" &&
140 git remote rm oops 2>actual2 &&
141 git branch -d foobranch &&
142 git tag -d footag &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100143 test_cmp expect1 actual1 &&
144 test_cmp expect2 actual2
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530145 )
Jay Soffian441adf02009-02-04 11:06:07 -0500146'
147
Thomas Gummerercc8e5382016-02-16 10:47:51 +0100148test_expect_success 'remove errors out early when deleting non-existent branch' '
149 (
150 cd test &&
Ævar Arnfjörð Bjarmason9144ba42020-10-27 10:41:36 +0100151 echo "error: No such remote: '\''foo'\''" >expect &&
152 test_expect_code 2 git remote rm foo 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100153 test_cmp expect actual
Thomas Gummerercc8e5382016-02-16 10:47:51 +0100154 )
155'
156
Ross Lagerwall20690b22017-02-18 00:23:41 +0000157test_expect_success 'remove remote with a branch without configured merge' '
158 test_when_finished "(
Johannes Schindelin97b91362020-12-17 01:07:05 +0000159 git -C test checkout main;
Ross Lagerwall20690b22017-02-18 00:23:41 +0000160 git -C test branch -D two;
161 git -C test config --remove-section remote.two;
162 git -C test config --remove-section branch.second;
163 true
164 )" &&
165 (
166 cd test &&
167 git remote add two ../two &&
168 git fetch two &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000169 git checkout -b second two/main^0 &&
Ross Lagerwall20690b22017-02-18 00:23:41 +0000170 git config branch.second.remote two &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000171 git checkout main &&
Ross Lagerwall20690b22017-02-18 00:23:41 +0000172 git remote rm two
173 )
174'
175
Thomas Gummerercc8e5382016-02-16 10:47:51 +0100176test_expect_success 'rename errors out early when deleting non-existent branch' '
177 (
178 cd test &&
Ævar Arnfjörð Bjarmason9144ba42020-10-27 10:41:36 +0100179 echo "error: No such remote: '\''foo'\''" >expect &&
180 test_expect_code 2 git remote rename foo bar 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100181 test_cmp expect actual
Thomas Gummerercc8e5382016-02-16 10:47:51 +0100182 )
183'
184
Andrei Rybakabcb66c2021-06-11 13:18:50 +0200185test_expect_success 'rename errors out early when new name is invalid' '
Sean Barag444825c2020-10-01 03:46:12 +0000186 test_config remote.foo.vcs bar &&
187 echo "fatal: '\''invalid...name'\'' is not a valid remote name" >expect &&
188 test_must_fail git remote rename foo invalid...name 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100189 test_cmp expect actual
Sean Barag444825c2020-10-01 03:46:12 +0000190'
191
Thomas Gummerera31eeae2016-02-16 10:47:52 +0100192test_expect_success 'add existing foreign_vcs remote' '
193 test_config remote.foo.vcs bar &&
Ævar Arnfjörð Bjarmason9144ba42020-10-27 10:41:36 +0100194 echo "error: remote foo already exists." >expect &&
195 test_expect_code 3 git remote add foo bar 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100196 test_cmp expect actual
Thomas Gummerera31eeae2016-02-16 10:47:52 +0100197'
198
199test_expect_success 'add existing foreign_vcs remote' '
200 test_config remote.foo.vcs bar &&
201 test_config remote.bar.vcs bar &&
Ævar Arnfjörð Bjarmason9144ba42020-10-27 10:41:36 +0100202 echo "error: remote bar already exists." >expect &&
203 test_expect_code 3 git remote rename foo bar 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100204 test_cmp expect actual
Thomas Gummerera31eeae2016-02-16 10:47:52 +0100205'
206
Sean Barag444825c2020-10-01 03:46:12 +0000207test_expect_success 'add invalid foreign_vcs remote' '
208 echo "fatal: '\''invalid...name'\'' is not a valid remote name" >expect &&
209 test_must_fail git remote add invalid...name bar 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100210 test_cmp expect actual
Sean Barag444825c2020-10-01 03:46:12 +0000211'
212
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530213cat >test/expect <<EOF
Johannes Schindelin47046402008-02-29 01:45:24 +0000214* remote origin
Michael J Gruber857f8c32009-06-13 18:29:10 +0200215 Fetch URL: $(pwd)/one
216 Push URL: $(pwd)/one
Johannes Schindelin97b91362020-12-17 01:07:05 +0000217 HEAD branch: main
Jay Soffian7ecbbf82009-02-25 03:32:27 -0500218 Remote branches:
Johannes Schindelin66713e82020-10-23 14:00:05 +0000219 main new (next fetch will store in remotes/origin)
220 side tracked
Jay Soffian7ecbbf82009-02-25 03:32:27 -0500221 Local branches configured for 'git pull':
Johannes Schindelin66713e82020-10-23 14:00:05 +0000222 ahead merges with remote main
223 main merges with remote main
Jay Soffian7ecbbf82009-02-25 03:32:27 -0500224 octopus merges with remote topic-a
225 and with remote topic-b
226 and with remote topic-c
Johannes Schindelin97b91362020-12-17 01:07:05 +0000227 rebase rebases onto remote main
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500228 Local refs configured for 'git push':
Johannes Schindelin66713e82020-10-23 14:00:05 +0000229 main pushes to main (local out of date)
230 main pushes to upstream (create)
Jay Soffiane61e0cc2009-02-25 03:32:24 -0500231* remote two
Michael J Gruber857f8c32009-06-13 18:29:10 +0200232 Fetch URL: ../two
233 Push URL: ../three
Johannes Schindelin97b91362020-12-17 01:07:05 +0000234 HEAD branch: main
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500235 Local refs configured for 'git push':
Johannes Schindelin66713e82020-10-23 14:00:05 +0000236 ahead forces to main (fast-forwardable)
237 main pushes to another (up to date)
Johannes Schindelin47046402008-02-29 01:45:24 +0000238EOF
239
Johannes Schindelin97b91362020-12-17 01:07:05 +0000240test_expect_success 'show' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530241 (
242 cd test &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000243 git config --add remote.origin.fetch refs/heads/main:refs/heads/upstream &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530244 git fetch &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000245 git checkout -b ahead origin/main &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530246 echo 1 >>file &&
247 test_tick &&
248 git commit -m update file &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000249 git checkout main &&
250 git branch --track octopus origin/main &&
251 git branch --track rebase origin/main &&
252 git branch -d -r origin/main &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530253 git config --add remote.two.url ../two &&
254 git config --add remote.two.pushurl ../three &&
255 git config branch.rebase.rebase true &&
256 git config branch.octopus.merge "topic-a topic-b topic-c" &&
257 (
258 cd ../one &&
259 echo 1 >file &&
260 test_tick &&
261 git commit -m update file
262 ) &&
263 git config --add remote.origin.push : &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000264 git config --add remote.origin.push refs/heads/main:refs/heads/upstream &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530265 git config --add remote.origin.push +refs/tags/lastbackup &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000266 git config --add remote.two.push +refs/heads/ahead:refs/heads/main &&
267 git config --add remote.two.push refs/heads/main:refs/heads/another &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530268 git remote show origin two >output &&
269 git branch -d rebase octopus &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100270 test_cmp expect output
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530271 )
Johannes Schindelin47046402008-02-29 01:45:24 +0000272'
273
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530274cat >test/expect <<EOF
Olivier Marin0ecfcb32008-06-10 16:51:08 +0200275* remote origin
Michael J Gruber857f8c32009-06-13 18:29:10 +0200276 Fetch URL: $(pwd)/one
277 Push URL: $(pwd)/one
Jay Soffiane61e0cc2009-02-25 03:32:24 -0500278 HEAD branch: (not queried)
Jay Soffian7ecbbf82009-02-25 03:32:27 -0500279 Remote branches: (status not queried)
Johannes Schindelin97b91362020-12-17 01:07:05 +0000280 main
Johannes Sixt20244ea2008-10-22 09:39:47 +0200281 side
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500282 Local branches configured for 'git pull':
Johannes Schindelin66713e82020-10-23 14:00:05 +0000283 ahead merges with remote main
284 main merges with remote main
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500285 Local refs configured for 'git push' (status not queried):
286 (matching) pushes to (matching)
Johannes Schindelin66713e82020-10-23 14:00:05 +0000287 refs/heads/main pushes to refs/heads/upstream
Jay Soffiane5dcbfd2009-02-25 03:32:28 -0500288 refs/tags/lastbackup forces to refs/tags/lastbackup
Olivier Marin0ecfcb32008-06-10 16:51:08 +0200289EOF
290
Johannes Schindelin97b91362020-12-17 01:07:05 +0000291test_expect_success 'show -n' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530292 mv one one.unreachable &&
293 (
294 cd test &&
295 git remote show -n origin >output &&
296 mv ../one.unreachable ../one &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100297 test_cmp expect output
Jay Soffianbc14fac2009-02-25 03:32:25 -0500298 )
299'
300
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530301test_expect_success 'prune' '
302 (
303 cd one &&
304 git branch -m side side2
305 ) &&
306 (
307 cd test &&
308 git fetch origin &&
309 git remote prune origin &&
310 git rev-parse refs/remotes/origin/side2 &&
311 test_must_fail git rev-parse refs/remotes/origin/side
312 )
313'
314
315test_expect_success 'set-head --delete' '
316 (
317 cd test &&
318 git symbolic-ref refs/remotes/origin/HEAD &&
319 git remote set-head --delete origin &&
320 test_must_fail git symbolic-ref refs/remotes/origin/HEAD
321 )
322'
323
324test_expect_success 'set-head --auto' '
325 (
326 cd test &&
327 git remote set-head --auto origin &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000328 echo refs/remotes/origin/main >expect &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530329 git symbolic-ref refs/remotes/origin/HEAD >output &&
330 test_cmp expect output
331 )
332'
333
Johannes Schindelin97b91362020-12-17 01:07:05 +0000334test_expect_success 'set-head --auto has no problem w/multiple HEADs' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530335 (
336 cd test &&
Junio C Hamanoa4dfee02013-09-17 21:45:34 -0700337 git fetch two "refs/heads/*:refs/remotes/two/*" &&
Junio C Hamanoa45b5f02013-09-17 19:10:31 -0700338 git remote set-head --auto two >output 2>&1 &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000339 echo "two/HEAD set to main" >expect &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100340 test_cmp expect output
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530341 )
Jay Soffianbc14fac2009-02-25 03:32:25 -0500342'
343
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530344cat >test/expect <<\EOF
Jay Soffianbc14fac2009-02-25 03:32:25 -0500345refs/remotes/origin/side2
346EOF
347
348test_expect_success 'set-head explicit' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530349 (
350 cd test &&
351 git remote set-head origin side2 &&
352 git symbolic-ref refs/remotes/origin/HEAD >output &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000353 git remote set-head origin main &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530354 test_cmp expect output
355 )
Jay Soffianbc14fac2009-02-25 03:32:25 -0500356'
357
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530358cat >test/expect <<EOF
Olivier Marin8d767922008-06-10 16:51:35 +0200359Pruning origin
Johan Herland86521ac2008-09-01 21:07:33 +0200360URL: $(pwd)/one
Olivier Marin8d767922008-06-10 16:51:35 +0200361 * [would prune] origin/side2
362EOF
363
364test_expect_success 'prune --dry-run' '
Eric Sunshine431f4a22018-07-01 20:23:48 -0400365 git -C one branch -m side2 side &&
366 test_when_finished "git -C one branch -m side side2" &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530367 (
368 cd test &&
369 git remote prune --dry-run origin >output &&
370 git rev-parse refs/remotes/origin/side2 &&
371 test_must_fail git rev-parse refs/remotes/origin/side &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100372 test_cmp expect output
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530373 )
Olivier Marin8d767922008-06-10 16:51:35 +0200374'
375
Johannes Schindelin4ebc9142008-02-29 01:46:07 +0000376test_expect_success 'add --mirror && prune' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530377 mkdir mirror &&
378 (
379 cd mirror &&
380 git init --bare &&
381 git remote add --mirror -f origin ../one
382 ) &&
383 (
384 cd one &&
385 git branch -m side2 side
386 ) &&
387 (
388 cd mirror &&
389 git rev-parse --verify refs/heads/side2 &&
390 test_must_fail git rev-parse --verify refs/heads/side &&
391 git fetch origin &&
392 git remote prune origin &&
393 test_must_fail git rev-parse --verify refs/heads/side2 &&
394 git rev-parse --verify refs/heads/side
395 )
Johannes Schindelin4ebc9142008-02-29 01:46:07 +0000396'
397
Jeff Kinga9f5a352011-03-30 15:53:19 -0400398test_expect_success 'add --mirror=fetch' '
399 mkdir mirror-fetch &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000400 git init -b main mirror-fetch/parent &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530401 (
402 cd mirror-fetch/parent &&
403 test_commit one
404 ) &&
Jeff Kinga9f5a352011-03-30 15:53:19 -0400405 git init --bare mirror-fetch/child &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530406 (
407 cd mirror-fetch/child &&
408 git remote add --mirror=fetch -f parent ../parent
409 )
Jeff Kinga9f5a352011-03-30 15:53:19 -0400410'
411
412test_expect_success 'fetch mirrors act as mirrors during fetch' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530413 (
414 cd mirror-fetch/parent &&
415 git branch new &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000416 git branch -m main renamed
Jeff Kinga9f5a352011-03-30 15:53:19 -0400417 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530418 (
419 cd mirror-fetch/child &&
420 git fetch parent &&
421 git rev-parse --verify refs/heads/new &&
422 git rev-parse --verify refs/heads/renamed
Jeff Kinga9f5a352011-03-30 15:53:19 -0400423 )
424'
425
426test_expect_success 'fetch mirrors can prune' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530427 (
428 cd mirror-fetch/child &&
429 git remote prune parent &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000430 test_must_fail git rev-parse --verify refs/heads/main
Jeff Kinga9f5a352011-03-30 15:53:19 -0400431 )
432'
433
434test_expect_success 'fetch mirrors do not act as mirrors during push' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530435 (
436 cd mirror-fetch/parent &&
437 git checkout HEAD^0
Jeff Kinga9f5a352011-03-30 15:53:19 -0400438 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530439 (
440 cd mirror-fetch/child &&
441 git branch -m renamed renamed2 &&
442 git push parent :
Jeff Kinga9f5a352011-03-30 15:53:19 -0400443 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530444 (
445 cd mirror-fetch/parent &&
446 git rev-parse --verify renamed &&
447 test_must_fail git rev-parse --verify refs/heads/renamed2
Jeff Kinga9f5a352011-03-30 15:53:19 -0400448 )
449'
450
Jeff King3eafdc92011-05-26 11:11:00 -0400451test_expect_success 'add fetch mirror with specific branches' '
452 git init --bare mirror-fetch/track &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530453 (
454 cd mirror-fetch/track &&
455 git remote add --mirror=fetch -t heads/new parent ../parent
Jeff King3eafdc92011-05-26 11:11:00 -0400456 )
457'
458
459test_expect_success 'fetch mirror respects specific branches' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530460 (
461 cd mirror-fetch/track &&
462 git fetch parent &&
463 git rev-parse --verify refs/heads/new &&
464 test_must_fail git rev-parse --verify refs/heads/renamed
Jeff King3eafdc92011-05-26 11:11:00 -0400465 )
466'
467
Jeff Kinga9f5a352011-03-30 15:53:19 -0400468test_expect_success 'add --mirror=push' '
469 mkdir mirror-push &&
470 git init --bare mirror-push/public &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000471 git init -b main mirror-push/private &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530472 (
473 cd mirror-push/private &&
474 test_commit one &&
475 git remote add --mirror=push public ../public
Jeff Kinga9f5a352011-03-30 15:53:19 -0400476 )
477'
478
479test_expect_success 'push mirrors act as mirrors during push' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530480 (
481 cd mirror-push/private &&
482 git branch new &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000483 git branch -m main renamed &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530484 git push public
Jeff Kinga9f5a352011-03-30 15:53:19 -0400485 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530486 (
487 cd mirror-push/private &&
488 git rev-parse --verify refs/heads/new &&
489 git rev-parse --verify refs/heads/renamed &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000490 test_must_fail git rev-parse --verify refs/heads/main
Jeff Kinga9f5a352011-03-30 15:53:19 -0400491 )
492'
493
494test_expect_success 'push mirrors do not act as mirrors during fetch' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530495 (
496 cd mirror-push/public &&
497 git branch -m renamed renamed2 &&
498 git symbolic-ref HEAD refs/heads/renamed2
Jeff Kinga9f5a352011-03-30 15:53:19 -0400499 ) &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530500 (
501 cd mirror-push/private &&
502 git fetch public &&
503 git rev-parse --verify refs/heads/renamed &&
504 test_must_fail git rev-parse --verify refs/heads/renamed2
Jeff Kinga9f5a352011-03-30 15:53:19 -0400505 )
506'
507
Jeff King3eafdc92011-05-26 11:11:00 -0400508test_expect_success 'push mirrors do not allow you to specify refs' '
509 git init mirror-push/track &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530510 (
511 cd mirror-push/track &&
512 test_must_fail git remote add --mirror=push -t new public ../public
Jeff King3eafdc92011-05-26 11:11:00 -0400513 )
514'
515
Shawn O. Pearcec175a7a2008-05-31 23:58:05 -0400516test_expect_success 'add alt && prune' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530517 mkdir alttst &&
518 (
519 cd alttst &&
520 git init &&
521 git remote add -f origin ../one &&
522 git config remote.alt.url ../one &&
523 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*"
524 ) &&
525 (
526 cd one &&
527 git branch -m side side2
528 ) &&
529 (
530 cd alttst &&
531 git rev-parse --verify refs/remotes/origin/side &&
532 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
533 git fetch alt &&
534 git remote prune alt &&
535 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
536 git rev-parse --verify refs/remotes/origin/side2
537 )
Shawn O. Pearcec175a7a2008-05-31 23:58:05 -0400538'
539
Samuel Tardieu111fb852010-04-20 01:31:31 +0200540cat >test/expect <<\EOF
541some-tag
542EOF
543
544test_expect_success 'add with reachable tags (default)' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530545 (
546 cd one &&
547 >foobar &&
548 git add foobar &&
549 git commit -m "Foobar" &&
550 git tag -a -m "Foobar tag" foobar-tag &&
551 git reset --hard HEAD~1 &&
552 git tag -a -m "Some tag" some-tag
553 ) &&
554 mkdir add-tags &&
555 (
556 cd add-tags &&
557 git init &&
558 git remote add -f origin ../one &&
559 git tag -l some-tag >../test/output &&
560 git tag -l foobar-tag >>../test/output &&
561 test_must_fail git config remote.origin.tagopt
562 ) &&
Samuel Tardieu111fb852010-04-20 01:31:31 +0200563 test_cmp test/expect test/output
564'
565
566cat >test/expect <<\EOF
567some-tag
568foobar-tag
569--tags
570EOF
571
572test_expect_success 'add --tags' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530573 rm -rf add-tags &&
574 (
575 mkdir add-tags &&
576 cd add-tags &&
577 git init &&
578 git remote add -f --tags origin ../one &&
579 git tag -l some-tag >../test/output &&
580 git tag -l foobar-tag >>../test/output &&
581 git config remote.origin.tagopt >>../test/output
582 ) &&
Samuel Tardieu111fb852010-04-20 01:31:31 +0200583 test_cmp test/expect test/output
584'
585
586cat >test/expect <<\EOF
587--no-tags
588EOF
589
590test_expect_success 'add --no-tags' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530591 rm -rf add-tags &&
592 (
593 mkdir add-no-tags &&
594 cd add-no-tags &&
595 git init &&
596 git remote add -f --no-tags origin ../one &&
Ævar Arnfjörð Bjarmasonbfa91482021-02-25 02:21:16 +0100597 grep tagOpt .git/config &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530598 git tag -l some-tag >../test/output &&
599 git tag -l foobar-tag >../test/output &&
600 git config remote.origin.tagopt >>../test/output
601 ) &&
602 (
603 cd one &&
604 git tag -d some-tag foobar-tag
605 ) &&
Samuel Tardieu111fb852010-04-20 01:31:31 +0200606 test_cmp test/expect test/output
607'
608
609test_expect_success 'reject --no-no-tags' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530610 (
611 cd add-no-tags &&
612 test_must_fail git remote add -f --no-no-tags neworigin ../one
613 )
Samuel Tardieu111fb852010-04-20 01:31:31 +0200614'
615
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530616cat >one/expect <<\EOF
Johannes Schindelin97b91362020-12-17 01:07:05 +0000617 apis/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000618 apis/side
619 drosophila/another
Johannes Schindelin97b91362020-12-17 01:07:05 +0000620 drosophila/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000621 drosophila/side
622EOF
623
624test_expect_success 'update' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530625 (
626 cd one &&
627 git remote add drosophila ../two &&
628 git remote add apis ../mirror &&
629 git remote update &&
630 git branch -r >output &&
631 test_cmp expect output
632 )
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000633'
634
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530635cat >one/expect <<\EOF
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000636 drosophila/another
Johannes Schindelin97b91362020-12-17 01:07:05 +0000637 drosophila/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000638 drosophila/side
Johannes Schindelin97b91362020-12-17 01:07:05 +0000639 manduca/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000640 manduca/side
Johannes Schindelin97b91362020-12-17 01:07:05 +0000641 megaloprepus/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000642 megaloprepus/side
643EOF
644
645test_expect_success 'update with arguments' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530646 (
647 cd one &&
648 for b in $(git branch -r)
649 do
Jeff Kinge6821d02015-03-25 01:29:52 -0400650 git branch -r -d $b || exit 1
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530651 done &&
652 git remote add manduca ../mirror &&
653 git remote add megaloprepus ../mirror &&
654 git config remotes.phobaeticus "drosophila megaloprepus" &&
655 git config remotes.titanus manduca &&
656 git remote update phobaeticus titanus &&
657 git branch -r >output &&
658 test_cmp expect output
659 )
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000660'
661
Björn Gustavssone2d41c62009-11-09 21:11:59 +0100662test_expect_success 'update --prune' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530663 (
664 cd one &&
665 git branch -m side2 side3
666 ) &&
667 (
668 cd test &&
669 git remote update --prune &&
670 (
671 cd ../one &&
672 git branch -m side3 side2
673 ) &&
674 git rev-parse refs/remotes/origin/side3 &&
675 test_must_fail git rev-parse refs/remotes/origin/side2
676 )
Björn Gustavssone2d41c62009-11-09 21:11:59 +0100677'
678
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530679cat >one/expect <<-\EOF
Johannes Schindelin97b91362020-12-17 01:07:05 +0000680 apis/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000681 apis/side
Johannes Schindelin97b91362020-12-17 01:07:05 +0000682 manduca/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000683 manduca/side
Johannes Schindelin97b91362020-12-17 01:07:05 +0000684 megaloprepus/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000685 megaloprepus/side
686EOF
687
688test_expect_success 'update default' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530689 (
690 cd one &&
691 for b in $(git branch -r)
692 do
Jeff Kinge6821d02015-03-25 01:29:52 -0400693 git branch -r -d $b || exit 1
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530694 done &&
695 git config remote.drosophila.skipDefaultUpdate true &&
696 git remote update default &&
697 git branch -r >output &&
698 test_cmp expect output
699 )
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000700'
701
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530702cat >one/expect <<\EOF
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000703 drosophila/another
Johannes Schindelin97b91362020-12-17 01:07:05 +0000704 drosophila/main
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000705 drosophila/side
706EOF
707
708test_expect_success 'update default (overridden, with funny whitespace)' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530709 (
710 cd one &&
711 for b in $(git branch -r)
712 do
Jeff Kinge6821d02015-03-25 01:29:52 -0400713 git branch -r -d $b || exit 1
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530714 done &&
715 git config remotes.default "$(printf "\t drosophila \n")" &&
716 git remote update default &&
717 git branch -r >output &&
718 test_cmp expect output
719 )
Johannes Schindelin84521ed2008-03-04 11:23:53 +0000720'
721
Björn Gustavsson4f2e8422009-12-31 10:43:17 +0100722test_expect_success 'update (with remotes.default defined)' '
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530723 (
724 cd one &&
725 for b in $(git branch -r)
726 do
Jeff Kinge6821d02015-03-25 01:29:52 -0400727 git branch -r -d $b || exit 1
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530728 done &&
729 git config remotes.default "drosophila" &&
730 git remote update &&
731 git branch -r >output &&
732 test_cmp expect output
733 )
Björn Gustavsson4f2e8422009-12-31 10:43:17 +0100734'
735
Johannes Schindelin740fdd22008-03-19 00:27:42 +0000736test_expect_success '"remote show" does not show symbolic refs' '
Johannes Schindelin740fdd22008-03-19 00:27:42 +0000737 git clone one three &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530738 (
739 cd three &&
740 git remote show origin >output &&
741 ! grep "^ *HEAD$" < output &&
742 ! grep -i stale < output
743 )
Johannes Schindelin740fdd22008-03-19 00:27:42 +0000744'
745
Jonas Fonseca24b61772008-04-13 11:56:54 +0200746test_expect_success 'reject adding remote with an invalid name' '
Stephan Beyerd492b312008-07-12 17:47:52 +0200747 test_must_fail git remote add some:url desired-name
Jonas Fonseca24b61772008-04-13 11:56:54 +0200748'
749
Miklos Vajnabf984212008-11-03 19:26:18 +0100750# The first three test if the tracking branches are properly renamed,
751# the last two ones check if the config is updated.
752
753test_expect_success 'rename a remote' '
Bert Wesargb3fd6cb2020-02-01 10:34:09 +0100754 test_config_global remote.pushDefault origin &&
Miklos Vajnabf984212008-11-03 19:26:18 +0100755 git clone one four &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530756 (
757 cd four &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000758 git config branch.main.pushRemote origin &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530759 git remote rename origin upstream &&
Ævar Arnfjörð Bjarmason0f1da602021-02-25 02:21:17 +0100760 grep "pushRemote" .git/config &&
Michael Haggerty2eb7a0e2017-01-06 17:22:23 +0100761 test -z "$(git for-each-ref refs/remotes/origin)" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000762 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/main" &&
763 test "$(git rev-parse upstream/main)" = "$(git rev-parse main)" &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530764 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000765 test "$(git config branch.main.remote)" = "upstream" &&
766 test "$(git config branch.main.pushRemote)" = "upstream" &&
Bert Wesargb3fd6cb2020-02-01 10:34:09 +0100767 test "$(git config --global remote.pushDefault)" = "origin"
768 )
769'
770
771test_expect_success 'rename a remote renames repo remote.pushDefault' '
772 git clone one four.1 &&
773 (
774 cd four.1 &&
775 git config remote.pushDefault origin &&
776 git remote rename origin upstream &&
Ævar Arnfjörð Bjarmason0f1da602021-02-25 02:21:17 +0100777 grep pushDefault .git/config &&
Bert Wesargb3fd6cb2020-02-01 10:34:09 +0100778 test "$(git config --local remote.pushDefault)" = "upstream"
779 )
780'
781
782test_expect_success 'rename a remote renames repo remote.pushDefault but ignores global' '
783 test_config_global remote.pushDefault other &&
784 git clone one four.2 &&
785 (
786 cd four.2 &&
787 git config remote.pushDefault origin &&
788 git remote rename origin upstream &&
789 test "$(git config --global remote.pushDefault)" = "other" &&
790 test "$(git config --local remote.pushDefault)" = "upstream"
791 )
792'
793
794test_expect_success 'rename a remote renames repo remote.pushDefault but keeps global' '
795 test_config_global remote.pushDefault origin &&
796 git clone one four.3 &&
797 (
798 cd four.3 &&
799 git config remote.pushDefault origin &&
800 git remote rename origin upstream &&
801 test "$(git config --global remote.pushDefault)" = "origin" &&
802 test "$(git config --local remote.pushDefault)" = "upstream"
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530803 )
Miklos Vajnabf984212008-11-03 19:26:18 +0100804'
Miklos Vajna1dd12392008-11-10 21:43:01 +0100805
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400806test_expect_success 'rename does not update a non-default fetch refspec' '
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400807 git clone one four.one &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530808 (
809 cd four.one &&
810 git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
811 git remote rename origin upstream &&
812 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000813 git rev-parse -q origin/main
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530814 )
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400815'
816
817test_expect_success 'rename a remote with name part of fetch spec' '
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400818 git clone one four.two &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530819 (
820 cd four.two &&
821 git remote rename origin remote &&
822 git remote rename remote upstream &&
823 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*"
824 )
Martin von Zweigbergk28f555f2011-09-01 20:50:33 -0400825'
826
Martin von Zweigbergk60e5eee2011-09-01 20:50:34 -0400827test_expect_success 'rename a remote with name prefix of other remote' '
Martin von Zweigbergk60e5eee2011-09-01 20:50:34 -0400828 git clone one four.three &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530829 (
830 cd four.three &&
831 git remote add o git://example.com/repo.git &&
832 git remote rename o upstream &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000833 test "$(git rev-parse origin/main)" = "$(git rev-parse main)"
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530834 )
Martin von Zweigbergk60e5eee2011-09-01 20:50:34 -0400835'
836
Johannes Schindeline459b072017-01-19 22:20:02 +0100837test_expect_success 'rename succeeds with existing remote.<target>.prune' '
Johannes Schindelinaf5bacf2017-01-19 22:19:58 +0100838 git clone one four.four &&
839 test_when_finished git config --global --unset remote.upstream.prune &&
840 git config --global remote.upstream.prune true &&
841 git -C four.four remote rename origin upstream
842'
843
Bert Wesarg923d4a52020-01-27 08:04:30 +0100844test_expect_success 'remove a remote' '
Bert Wesargb3fd6cb2020-02-01 10:34:09 +0100845 test_config_global remote.pushDefault origin &&
Bert Wesarg923d4a52020-01-27 08:04:30 +0100846 git clone one four.five &&
847 (
848 cd four.five &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000849 git config branch.main.pushRemote origin &&
Bert Wesarg923d4a52020-01-27 08:04:30 +0100850 git remote remove origin &&
851 test -z "$(git for-each-ref refs/remotes/origin)" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000852 test_must_fail git config branch.main.remote &&
853 test_must_fail git config branch.main.pushRemote &&
Bert Wesargb3fd6cb2020-02-01 10:34:09 +0100854 test "$(git config --global remote.pushDefault)" = "origin"
855 )
856'
857
858test_expect_success 'remove a remote removes repo remote.pushDefault' '
859 git clone one four.five.1 &&
860 (
861 cd four.five.1 &&
862 git config remote.pushDefault origin &&
863 git remote remove origin &&
864 test_must_fail git config --local remote.pushDefault
865 )
866'
867
868test_expect_success 'remove a remote removes repo remote.pushDefault but ignores global' '
869 test_config_global remote.pushDefault other &&
870 git clone one four.five.2 &&
871 (
872 cd four.five.2 &&
873 git config remote.pushDefault origin &&
874 git remote remove origin &&
875 test "$(git config --global remote.pushDefault)" = "other" &&
876 test_must_fail git config --local remote.pushDefault
877 )
878'
879
880test_expect_success 'remove a remote removes repo remote.pushDefault but keeps global' '
881 test_config_global remote.pushDefault origin &&
882 git clone one four.five.3 &&
883 (
884 cd four.five.3 &&
885 git config remote.pushDefault origin &&
886 git remote remove origin &&
887 test "$(git config --global remote.pushDefault)" = "origin" &&
888 test_must_fail git config --local remote.pushDefault
Bert Wesarg923d4a52020-01-27 08:04:30 +0100889 )
890'
891
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530892cat >remotes_origin <<EOF
Miklos Vajna1dd12392008-11-10 21:43:01 +0100893URL: $(pwd)/one
Johannes Schindelin97b91362020-12-17 01:07:05 +0000894Push: refs/heads/main:refs/heads/upstream
Ramkumar Ramachandraf0f249d2013-06-22 13:28:18 +0530895Push: refs/heads/next:refs/heads/upstream2
Johannes Schindelin97b91362020-12-17 01:07:05 +0000896Pull: refs/heads/main:refs/heads/origin
Ramkumar Ramachandraf0f249d2013-06-22 13:28:18 +0530897Pull: refs/heads/next:refs/heads/origin2
Miklos Vajna1dd12392008-11-10 21:43:01 +0100898EOF
899
900test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
901 git clone one five &&
902 origin_url=$(pwd)/one &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530903 (
904 cd five &&
905 git remote remove origin &&
906 mkdir -p .git/remotes &&
907 cat ../remotes_origin >.git/remotes/origin &&
908 git remote rename origin origin &&
Ramkumar Ramachandrafe3c1952013-06-22 13:28:10 +0530909 test_path_is_missing .git/remotes/origin &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530910 test "$(git config remote.origin.url)" = "$origin_url" &&
Ramkumar Ramachandraf0f249d2013-06-22 13:28:18 +0530911 cat >push_expected <<-\EOF &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000912 refs/heads/main:refs/heads/upstream
Ramkumar Ramachandraf0f249d2013-06-22 13:28:18 +0530913 refs/heads/next:refs/heads/upstream2
914 EOF
915 cat >fetch_expected <<-\EOF &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000916 refs/heads/main:refs/heads/origin
Ramkumar Ramachandraf0f249d2013-06-22 13:28:18 +0530917 refs/heads/next:refs/heads/origin2
918 EOF
919 git config --get-all remote.origin.push >push_actual &&
920 git config --get-all remote.origin.fetch >fetch_actual &&
921 test_cmp push_expected push_actual &&
922 test_cmp fetch_expected fetch_actual
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530923 )
Miklos Vajna1dd12392008-11-10 21:43:01 +0100924'
925
926test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
927 git clone one six &&
928 origin_url=$(pwd)/one &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530929 (
930 cd six &&
931 git remote rm origin &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000932 echo "$origin_url#main" >.git/branches/origin &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530933 git remote rename origin origin &&
Ramkumar Ramachandrafe3c1952013-06-22 13:28:10 +0530934 test_path_is_missing .git/branches/origin &&
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530935 test "$(git config remote.origin.url)" = "$origin_url" &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000936 test "$(git config remote.origin.fetch)" = "refs/heads/main:refs/heads/origin" &&
937 test "$(git config remote.origin.push)" = "HEAD:refs/heads/main"
Ramkumar Ramachandra9b9439a2013-06-22 13:28:08 +0530938 )
Miklos Vajna1dd12392008-11-10 21:43:01 +0100939'
940
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +0530941test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' '
Junio C Hamanof8948e22009-02-08 23:27:10 -0800942 git clone one seven &&
943 (
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +0530944 cd seven &&
945 git remote rm origin &&
946 echo "quux#foom" > .git/branches/origin &&
947 git remote rename origin origin &&
948 test_path_is_missing .git/branches/origin &&
949 test "$(git config remote.origin.url)" = "quux" &&
Eric Sunshine51b85472018-07-01 20:24:01 -0400950 test "$(git config remote.origin.fetch)" = "refs/heads/foom:refs/heads/origin" &&
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +0530951 test "$(git config remote.origin.push)" = "HEAD:refs/heads/foom"
952 )
953'
954
955test_expect_success 'remote prune to cause a dangling symref' '
956 git clone one eight &&
957 (
Junio C Hamanof8948e22009-02-08 23:27:10 -0800958 cd one &&
959 git checkout side2 &&
Johannes Schindelin97b91362020-12-17 01:07:05 +0000960 git branch -D main
Junio C Hamanof8948e22009-02-08 23:27:10 -0800961 ) &&
962 (
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +0530963 cd eight &&
Junio C Hamanof8948e22009-02-08 23:27:10 -0800964 git remote prune origin
Junio C Hamanoe01de1c2010-03-15 22:12:55 -0700965 ) >err 2>&1 &&
Jiang Xinf7dc6a92012-08-27 13:36:54 +0800966 test_i18ngrep "has become dangling" err &&
Junio C Hamanof8948e22009-02-08 23:27:10 -0800967
Junio C Hamanoe01de1c2010-03-15 22:12:55 -0700968 : And the dangling symref will not cause other annoying errors &&
Junio C Hamanof8948e22009-02-08 23:27:10 -0800969 (
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +0530970 cd eight &&
Junio C Hamanof8948e22009-02-08 23:27:10 -0800971 git branch -a
972 ) 2>err &&
Junio C Hamanoe01de1c2010-03-15 22:12:55 -0700973 ! grep "points nowhere" err &&
Junio C Hamano057e7132009-02-08 23:52:01 -0800974 (
Ramkumar Ramachandra1f9a5e92013-06-22 13:28:13 +0530975 cd eight &&
Junio C Hamano057e7132009-02-08 23:52:01 -0800976 test_must_fail git branch nomore origin
977 ) 2>err &&
Nguyễn Thái Ngọc Duy661558f2018-07-21 09:49:35 +0200978 test_i18ngrep "dangling symref" err
Junio C Hamanof8948e22009-02-08 23:27:10 -0800979'
980
Clemens Buchacher6a015542009-05-27 22:13:43 +0200981test_expect_success 'show empty remote' '
Clemens Buchacher6a015542009-05-27 22:13:43 +0200982 test_create_repo empty &&
983 git clone empty empty-clone &&
984 (
985 cd empty-clone &&
986 git remote show origin
987 )
988'
989
Jonathan Nieder3d8b6942010-05-19 13:38:50 -0500990test_expect_success 'remote set-branches requires a remote' '
991 test_must_fail git remote set-branches &&
992 test_must_fail git remote set-branches --add
993'
994
995test_expect_success 'remote set-branches' '
996 echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial &&
997 sort <<-\EOF >expect.add &&
998 +refs/heads/*:refs/remotes/scratch/*
999 +refs/heads/other:refs/remotes/scratch/other
1000 EOF
1001 sort <<-\EOF >expect.replace &&
1002 +refs/heads/maint:refs/remotes/scratch/maint
Johannes Schindelin97b91362020-12-17 01:07:05 +00001003 +refs/heads/main:refs/remotes/scratch/main
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001004 +refs/heads/next:refs/remotes/scratch/next
1005 EOF
1006 sort <<-\EOF >expect.add-two &&
1007 +refs/heads/maint:refs/remotes/scratch/maint
Johannes Schindelin97b91362020-12-17 01:07:05 +00001008 +refs/heads/main:refs/remotes/scratch/main
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001009 +refs/heads/next:refs/remotes/scratch/next
Johannes Schindelin6dca5db2020-06-25 12:18:59 +00001010 +refs/heads/seen:refs/remotes/scratch/seen
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001011 +refs/heads/t/topic:refs/remotes/scratch/t/topic
1012 EOF
1013 sort <<-\EOF >expect.setup-ffonly &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001014 refs/heads/main:refs/remotes/scratch/main
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001015 +refs/heads/next:refs/remotes/scratch/next
1016 EOF
1017 sort <<-\EOF >expect.respect-ffonly &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001018 refs/heads/main:refs/remotes/scratch/main
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001019 +refs/heads/next:refs/remotes/scratch/next
Johannes Schindelin6dca5db2020-06-25 12:18:59 +00001020 +refs/heads/seen:refs/remotes/scratch/seen
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001021 EOF
1022
1023 git clone .git/ setbranches &&
1024 (
1025 cd setbranches &&
1026 git remote rename origin scratch &&
1027 git config --get-all remote.scratch.fetch >config-result &&
1028 sort <config-result >../actual.initial &&
1029
1030 git remote set-branches scratch --add other &&
1031 git config --get-all remote.scratch.fetch >config-result &&
1032 sort <config-result >../actual.add &&
1033
Johannes Schindelin97b91362020-12-17 01:07:05 +00001034 git remote set-branches scratch maint main next &&
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001035 git config --get-all remote.scratch.fetch >config-result &&
1036 sort <config-result >../actual.replace &&
1037
Johannes Schindelin6dca5db2020-06-25 12:18:59 +00001038 git remote set-branches --add scratch seen t/topic &&
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001039 git config --get-all remote.scratch.fetch >config-result &&
1040 sort <config-result >../actual.add-two &&
1041
1042 git config --unset-all remote.scratch.fetch &&
1043 git config remote.scratch.fetch \
Johannes Schindelin97b91362020-12-17 01:07:05 +00001044 refs/heads/main:refs/remotes/scratch/main &&
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001045 git config --add remote.scratch.fetch \
1046 +refs/heads/next:refs/remotes/scratch/next &&
1047 git config --get-all remote.scratch.fetch >config-result &&
1048 sort <config-result >../actual.setup-ffonly &&
1049
Johannes Schindelin6dca5db2020-06-25 12:18:59 +00001050 git remote set-branches --add scratch seen &&
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001051 git config --get-all remote.scratch.fetch >config-result &&
1052 sort <config-result >../actual.respect-ffonly
1053 ) &&
1054 test_cmp expect.initial actual.initial &&
1055 test_cmp expect.add actual.add &&
1056 test_cmp expect.replace actual.replace &&
1057 test_cmp expect.add-two actual.add-two &&
1058 test_cmp expect.setup-ffonly actual.setup-ffonly &&
1059 test_cmp expect.respect-ffonly actual.respect-ffonly
1060'
1061
1062test_expect_success 'remote set-branches with --mirror' '
1063 echo "+refs/*:refs/*" >expect.initial &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001064 echo "+refs/heads/main:refs/heads/main" >expect.replace &&
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001065 git clone --mirror .git/ setbranches-mirror &&
1066 (
1067 cd setbranches-mirror &&
1068 git remote rename origin scratch &&
1069 git config --get-all remote.scratch.fetch >../actual.initial &&
1070
Johannes Schindelin97b91362020-12-17 01:07:05 +00001071 git remote set-branches scratch heads/main &&
Jonathan Nieder3d8b6942010-05-19 13:38:50 -05001072 git config --get-all remote.scratch.fetch >../actual.replace
1073 ) &&
1074 test_cmp expect.initial actual.initial &&
1075 test_cmp expect.replace actual.replace
1076'
1077
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001078test_expect_success 'new remote' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001079 git remote add someremote foo &&
1080 echo foo >expect &&
1081 git config --get-all remote.someremote.url >actual &&
1082 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001083'
Junio C Hamano057e7132009-02-08 23:52:01 -08001084
Ben Boeckel96f78d32015-09-15 21:53:47 -04001085get_url_test () {
1086 cat >expect &&
1087 git remote get-url "$@" >actual &&
1088 test_cmp expect actual
1089}
1090
1091test_expect_success 'get-url on new remote' '
1092 echo foo | get_url_test someremote &&
1093 echo foo | get_url_test --all someremote &&
1094 echo foo | get_url_test --push someremote &&
1095 echo foo | get_url_test --push --all someremote
1096'
1097
Patrick Steinhardt45ebdcc2016-02-22 12:23:28 +01001098test_expect_success 'remote set-url with locked config' '
1099 test_when_finished "rm -f .git/config.lock" &&
1100 git config --get-all remote.someremote.url >expect &&
1101 >.git/config.lock &&
1102 test_must_fail git remote set-url someremote baz &&
1103 git config --get-all remote.someremote.url >actual &&
1104 cmp expect actual
1105'
1106
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001107test_expect_success 'remote set-url bar' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001108 git remote set-url someremote bar &&
1109 echo bar >expect &&
1110 git config --get-all remote.someremote.url >actual &&
1111 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001112'
1113
1114test_expect_success 'remote set-url baz bar' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001115 git remote set-url someremote baz bar &&
1116 echo baz >expect &&
1117 git config --get-all remote.someremote.url >actual &&
1118 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001119'
1120
1121test_expect_success 'remote set-url zot bar' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001122 test_must_fail git remote set-url someremote zot bar &&
1123 echo baz >expect &&
1124 git config --get-all remote.someremote.url >actual &&
1125 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001126'
1127
1128test_expect_success 'remote set-url --push zot baz' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001129 test_must_fail git remote set-url --push someremote zot baz &&
1130 echo "YYY" >expect &&
1131 echo baz >>expect &&
1132 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1133 echo "YYY" >>actual &&
1134 git config --get-all remote.someremote.url >>actual &&
1135 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001136'
1137
1138test_expect_success 'remote set-url --push zot' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001139 git remote set-url --push someremote zot &&
1140 echo zot >expect &&
1141 echo "YYY" >>expect &&
1142 echo baz >>expect &&
1143 git config --get-all remote.someremote.pushurl >actual &&
1144 echo "YYY" >>actual &&
1145 git config --get-all remote.someremote.url >>actual &&
1146 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001147'
1148
Ben Boeckel96f78d32015-09-15 21:53:47 -04001149test_expect_success 'get-url with different urls' '
1150 echo baz | get_url_test someremote &&
1151 echo baz | get_url_test --all someremote &&
1152 echo zot | get_url_test --push someremote &&
1153 echo zot | get_url_test --push --all someremote
1154'
1155
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001156test_expect_success 'remote set-url --push qux zot' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001157 git remote set-url --push someremote qux zot &&
1158 echo qux >expect &&
1159 echo "YYY" >>expect &&
1160 echo baz >>expect &&
1161 git config --get-all remote.someremote.pushurl >actual &&
1162 echo "YYY" >>actual &&
1163 git config --get-all remote.someremote.url >>actual &&
1164 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001165'
1166
1167test_expect_success 'remote set-url --push foo qu+x' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001168 git remote set-url --push someremote foo qu+x &&
1169 echo foo >expect &&
1170 echo "YYY" >>expect &&
1171 echo baz >>expect &&
1172 git config --get-all remote.someremote.pushurl >actual &&
1173 echo "YYY" >>actual &&
1174 git config --get-all remote.someremote.url >>actual &&
1175 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001176'
1177
1178test_expect_success 'remote set-url --push --add aaa' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001179 git remote set-url --push --add someremote aaa &&
1180 echo foo >expect &&
1181 echo aaa >>expect &&
1182 echo "YYY" >>expect &&
1183 echo baz >>expect &&
1184 git config --get-all remote.someremote.pushurl >actual &&
1185 echo "YYY" >>actual &&
1186 git config --get-all remote.someremote.url >>actual &&
1187 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001188'
1189
Ben Boeckel96f78d32015-09-15 21:53:47 -04001190test_expect_success 'get-url on multi push remote' '
1191 echo foo | get_url_test --push someremote &&
1192 get_url_test --push --all someremote <<-\EOF
1193 foo
1194 aaa
1195 EOF
1196'
1197
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001198test_expect_success 'remote set-url --push bar aaa' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001199 git remote set-url --push someremote bar aaa &&
1200 echo foo >expect &&
1201 echo bar >>expect &&
1202 echo "YYY" >>expect &&
1203 echo baz >>expect &&
1204 git config --get-all remote.someremote.pushurl >actual &&
1205 echo "YYY" >>actual &&
1206 git config --get-all remote.someremote.url >>actual &&
1207 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001208'
1209
1210test_expect_success 'remote set-url --push --delete bar' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001211 git remote set-url --push --delete someremote bar &&
1212 echo foo >expect &&
1213 echo "YYY" >>expect &&
1214 echo baz >>expect &&
1215 git config --get-all remote.someremote.pushurl >actual &&
1216 echo "YYY" >>actual &&
1217 git config --get-all remote.someremote.url >>actual &&
1218 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001219'
1220
1221test_expect_success 'remote set-url --push --delete foo' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001222 git remote set-url --push --delete someremote foo &&
1223 echo "YYY" >expect &&
1224 echo baz >>expect &&
1225 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1226 echo "YYY" >>actual &&
1227 git config --get-all remote.someremote.url >>actual &&
1228 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001229'
1230
1231test_expect_success 'remote set-url --add bbb' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001232 git remote set-url --add someremote bbb &&
1233 echo "YYY" >expect &&
1234 echo baz >>expect &&
1235 echo bbb >>expect &&
1236 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1237 echo "YYY" >>actual &&
1238 git config --get-all remote.someremote.url >>actual &&
1239 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001240'
1241
Ben Boeckel96f78d32015-09-15 21:53:47 -04001242test_expect_success 'get-url on multi fetch remote' '
1243 echo baz | get_url_test someremote &&
1244 get_url_test --all someremote <<-\EOF
1245 baz
1246 bbb
1247 EOF
1248'
1249
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001250test_expect_success 'remote set-url --delete .*' '
Brandon Casey49de47c2010-03-19 19:10:20 -05001251 test_must_fail git remote set-url --delete someremote .\* &&
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001252 echo "YYY" >expect &&
1253 echo baz >>expect &&
1254 echo bbb >>expect &&
1255 test_must_fail 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
1261test_expect_success 'remote set-url --delete bbb' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001262 git remote set-url --delete someremote bbb &&
1263 echo "YYY" >expect &&
1264 echo baz >>expect &&
1265 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1266 echo "YYY" >>actual &&
1267 git config --get-all remote.someremote.url >>actual &&
1268 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001269'
1270
1271test_expect_success 'remote set-url --delete baz' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001272 test_must_fail git remote set-url --delete someremote baz &&
1273 echo "YYY" >expect &&
1274 echo baz >>expect &&
1275 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1276 echo "YYY" >>actual &&
1277 git config --get-all remote.someremote.url >>actual &&
1278 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001279'
1280
1281test_expect_success 'remote set-url --add ccc' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001282 git remote set-url --add someremote ccc &&
1283 echo "YYY" >expect &&
1284 echo baz >>expect &&
1285 echo ccc >>expect &&
1286 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1287 echo "YYY" >>actual &&
1288 git config --get-all remote.someremote.url >>actual &&
1289 cmp expect actual
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001290'
1291
1292test_expect_success 'remote set-url --delete baz' '
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001293 git remote set-url --delete someremote baz &&
1294 echo "YYY" >expect &&
1295 echo ccc >>expect &&
1296 test_must_fail 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
Thomas Rastabf5f872013-04-24 15:54:35 +02001302test_expect_success 'extra args: setup' '
1303 # add a dummy origin so that this does not trigger failure
1304 git remote add origin .
1305'
1306
1307test_extra_arg () {
Thomas Rastb17dd3f2013-04-24 15:54:37 +02001308 test_expect_success "extra args: $*" "
Thomas Rastabf5f872013-04-24 15:54:35 +02001309 test_must_fail git remote $* bogus_extra_arg 2>actual &&
Vasco Almeida1edbaac2016-06-17 20:21:07 +00001310 test_i18ngrep '^usage:' actual
Thomas Rastabf5f872013-04-24 15:54:35 +02001311 "
1312}
1313
Thomas Rast2d2e3d22013-04-24 15:54:36 +02001314test_extra_arg add nick url
Thomas Rastabf5f872013-04-24 15:54:35 +02001315test_extra_arg rename origin newname
1316test_extra_arg remove origin
Johannes Schindelin97b91362020-12-17 01:07:05 +00001317test_extra_arg set-head origin main
Thomas Rastabf5f872013-04-24 15:54:35 +02001318# set-branches takes any number of args
Ben Boeckel96f78d32015-09-15 21:53:47 -04001319test_extra_arg get-url origin newurl
Thomas Rastabf5f872013-04-24 15:54:35 +02001320test_extra_arg set-url origin newurl oldurl
Thomas Rastb17dd3f2013-04-24 15:54:37 +02001321# show takes any number of args
1322# prune takes any number of args
Thomas Rastabf5f872013-04-24 15:54:35 +02001323# update takes any number of args
1324
Johannes Schindelinb90c95d2014-12-23 14:25:09 +01001325test_expect_success 'add remote matching the "insteadOf" URL' '
1326 git config url.xyz@example.com.insteadOf backup &&
1327 git remote add backup xyz@example.com
1328'
1329
Ævar Arnfjörð Bjarmasondd8dd302018-11-13 19:52:43 +00001330test_expect_success 'unqualified <dst> refspec DWIM and advice' '
1331 test_when_finished "(cd test && git tag -d some-tag)" &&
1332 (
1333 cd test &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001334 git tag -a -m "Some tag" some-tag main &&
Ævar Arnfjörð Bjarmasondd8dd302018-11-13 19:52:43 +00001335 exit_with=true &&
1336 for type in commit tag tree blob
1337 do
1338 if test "$type" = "blob"
1339 then
1340 oid=$(git rev-parse some-tag:file)
1341 else
1342 oid=$(git rev-parse some-tag^{$type})
1343 fi &&
1344 test_must_fail git push origin $oid:dst 2>err &&
1345 test_i18ngrep "error: The destination you" err &&
1346 test_i18ngrep "hint: Did you mean" err &&
1347 test_must_fail git -c advice.pushUnqualifiedRefName=false \
1348 push origin $oid:dst 2>err &&
1349 test_i18ngrep "error: The destination you" err &&
1350 test_i18ngrep ! "hint: Did you mean" err ||
1351 exit_with=false
1352 done &&
1353 $exit_with
1354 )
1355'
1356
Johannes Schindelin97b91362020-12-17 01:07:05 +00001357test_expect_success 'refs/remotes/* <src> refspec and unqualified <dst> DWIM and advice' '
Ævar Arnfjörð Bjarmasonbf706362018-11-13 19:52:44 +00001358 (
1359 cd two &&
Johannes Schindelin97b91362020-12-17 01:07:05 +00001360 git tag -a -m "Some tag" my-tag main &&
Ævar Arnfjörð Bjarmasonbf706362018-11-13 19:52:44 +00001361 git update-ref refs/trees/my-head-tree HEAD^{tree} &&
1362 git update-ref refs/blobs/my-file-blob HEAD:file
1363 ) &&
1364 (
1365 cd test &&
1366 git config --add remote.two.fetch "+refs/tags/*:refs/remotes/tags-from-two/*" &&
1367 git config --add remote.two.fetch "+refs/trees/*:refs/remotes/trees-from-two/*" &&
1368 git config --add remote.two.fetch "+refs/blobs/*:refs/remotes/blobs-from-two/*" &&
1369 git fetch --no-tags two &&
1370
1371 test_must_fail git push origin refs/remotes/two/another:dst 2>err &&
1372 test_i18ngrep "error: The destination you" err &&
1373
1374 test_must_fail git push origin refs/remotes/tags-from-two/my-tag:dst-tag 2>err &&
1375 test_i18ngrep "error: The destination you" err &&
1376
1377 test_must_fail git push origin refs/remotes/trees-from-two/my-head-tree:dst-tree 2>err &&
1378 test_i18ngrep "error: The destination you" err &&
1379
1380 test_must_fail git push origin refs/remotes/blobs-from-two/my-file-blob:dst-blob 2>err &&
1381 test_i18ngrep "error: The destination you" err
1382 )
1383'
Ævar Arnfjörð Bjarmasondd8dd302018-11-13 19:52:43 +00001384
Ilari Liusvaara433f2be2010-01-18 19:18:02 +02001385test_done