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