]>
Commit | Line | Data |
---|---|---|
683b5679 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='git remote porcelain-ish' | |
4 | ||
3275f4e8 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
683b5679 JH |
8 | . ./test-lib.sh |
9 | ||
683b5679 JH |
10 | setup_repository () { |
11 | mkdir "$1" && ( | |
12 | cd "$1" && | |
97b91368 | 13 | git init -b main && |
683b5679 JH |
14 | >file && |
15 | git add file && | |
84521ed6 | 16 | test_tick && |
683b5679 JH |
17 | git commit -m "Initial" && |
18 | git checkout -b side && | |
19 | >elif && | |
20 | git add elif && | |
84521ed6 | 21 | test_tick && |
683b5679 | 22 | git commit -m "Second" && |
97b91368 | 23 | git checkout main |
683b5679 JH |
24 | ) |
25 | } | |
26 | ||
27 | tokens_match () { | |
28 | echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect && | |
29 | echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual && | |
82ebb0b6 | 30 | test_cmp expect actual |
683b5679 JH |
31 | } |
32 | ||
33 | check_remote_track () { | |
7ecbbf87 | 34 | actual=$(git remote show "$1" | sed -ne 's|^ \(.*\) tracked$|\1|p') |
683b5679 JH |
35 | shift && |
36 | tokens_match "$*" "$actual" | |
37 | } | |
38 | ||
39 | check_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 | ||
47 | test_expect_success setup ' | |
683b5679 JH |
48 | setup_repository one && |
49 | setup_repository two && | |
50 | ( | |
9b9439af RR |
51 | cd two && |
52 | git branch another | |
683b5679 JH |
53 | ) && |
54 | git clone one test | |
683b5679 JH |
55 | ' |
56 | ||
d8ff76cf JS |
57 | test_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 | ||
a926c4b9 | 62 | test_expect_success 'remote information for the origin' ' |
9b9439af RR |
63 | ( |
64 | cd test && | |
65 | tokens_match origin "$(git remote)" && | |
97b91368 JS |
66 | check_remote_track origin main side && |
67 | check_tracking_branch origin HEAD main side | |
9b9439af | 68 | ) |
683b5679 JH |
69 | ' |
70 | ||
71 | test_expect_success 'add another remote' ' | |
9b9439af RR |
72 | ( |
73 | cd test && | |
74 | git remote add -f second ../two && | |
75 | tokens_match "origin second" "$(git remote)" && | |
97b91368 | 76 | check_tracking_branch second main side another && |
9b9439af RR |
77 | git for-each-ref "--format=%(refname)" refs/remotes | |
78 | sed -e "/^refs\/remotes\/origin\//d" \ | |
79 | -e "/^refs\/remotes\/second\//d" >actual && | |
d3c6751b | 80 | test_must_be_empty actual |
9b9439af | 81 | ) |
683b5679 JH |
82 | ' |
83 | ||
a926c4b9 | 84 | test_expect_success 'check remote-tracking' ' |
9b9439af RR |
85 | ( |
86 | cd test && | |
97b91368 JS |
87 | check_remote_track origin main side && |
88 | check_remote_track second main side another | |
9b9439af | 89 | ) |
f7dc6a96 JX |
90 | ' |
91 | ||
1ce89cc4 | 92 | test_expect_success 'remote forces tracking branches' ' |
9b9439af RR |
93 | ( |
94 | cd test && | |
c0097814 | 95 | case $(git config remote.second.fetch) in |
9b9439af RR |
96 | +*) true ;; |
97 | *) false ;; | |
98 | esac | |
99 | ) | |
1ce89cc4 JK |
100 | ' |
101 | ||
683b5679 | 102 | test_expect_success 'remove remote' ' |
9b9439af RR |
103 | ( |
104 | cd test && | |
97b91368 | 105 | git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/main && |
9b9439af RR |
106 | git remote rm second |
107 | ) | |
683b5679 JH |
108 | ' |
109 | ||
a926c4b9 | 110 | test_expect_success 'remove remote' ' |
9b9439af RR |
111 | ( |
112 | cd test && | |
113 | tokens_match origin "$(git remote)" && | |
97b91368 | 114 | check_remote_track origin main side && |
9b9439af RR |
115 | git for-each-ref "--format=%(refname)" refs/remotes | |
116 | sed -e "/^refs\/remotes\/origin\//d" >actual && | |
d3c6751b | 117 | test_must_be_empty actual |
9b9439af | 118 | ) |
683b5679 JH |
119 | ' |
120 | ||
13931236 | 121 | test_expect_success 'remove remote protects local branches' ' |
9b9439af RR |
122 | ( |
123 | cd test && | |
124 | cat >expect1 <<-\EOF && | |
125 | Note: A branch outside the refs/remotes/ hierarchy was not removed; | |
126 | to delete it, use: | |
97b91368 | 127 | git branch -d main |
9b9439af RR |
128 | 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 | |
97b91368 | 133 | git branch -d main |
9b9439af RR |
134 | 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 && | |
1108cea7 ÆAB |
143 | test_cmp expect1 actual1 && |
144 | test_cmp expect2 actual2 | |
9b9439af RR |
145 | ) |
146 | ' | |
147 | ||
cc8e538d TG |
148 | test_expect_success 'remove errors out early when deleting non-existent branch' ' |
149 | ( | |
150 | cd test && | |
9144ba4c ÆAB |
151 | echo "error: No such remote: '\''foo'\''" >expect && |
152 | test_expect_code 2 git remote rm foo 2>actual && | |
1108cea7 | 153 | test_cmp expect actual |
cc8e538d TG |
154 | ) |
155 | ' | |
156 | ||
20690b21 RL |
157 | test_expect_success 'remove remote with a branch without configured merge' ' |
158 | test_when_finished "( | |
97b91368 | 159 | git -C test checkout main; |
20690b21 RL |
160 | 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 && | |
97b91368 | 169 | git checkout -b second two/main^0 && |
20690b21 | 170 | git config branch.second.remote two && |
97b91368 | 171 | git checkout main && |
20690b21 RL |
172 | git remote rm two |
173 | ) | |
174 | ' | |
175 | ||
cc8e538d TG |
176 | test_expect_success 'rename errors out early when deleting non-existent branch' ' |
177 | ( | |
178 | cd test && | |
9144ba4c ÆAB |
179 | echo "error: No such remote: '\''foo'\''" >expect && |
180 | test_expect_code 2 git remote rename foo bar 2>actual && | |
1108cea7 | 181 | test_cmp expect actual |
cc8e538d TG |
182 | ) |
183 | ' | |
184 | ||
444825c7 SB |
185 | test_expect_success 'rename errors out early when when new name is invalid' ' |
186 | 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 && | |
1108cea7 | 189 | test_cmp expect actual |
444825c7 SB |
190 | ' |
191 | ||
a31eeae2 TG |
192 | test_expect_success 'add existing foreign_vcs remote' ' |
193 | test_config remote.foo.vcs bar && | |
9144ba4c ÆAB |
194 | echo "error: remote foo already exists." >expect && |
195 | test_expect_code 3 git remote add foo bar 2>actual && | |
1108cea7 | 196 | test_cmp expect actual |
a31eeae2 TG |
197 | ' |
198 | ||
199 | test_expect_success 'add existing foreign_vcs remote' ' | |
200 | test_config remote.foo.vcs bar && | |
201 | test_config remote.bar.vcs bar && | |
9144ba4c ÆAB |
202 | echo "error: remote bar already exists." >expect && |
203 | test_expect_code 3 git remote rename foo bar 2>actual && | |
1108cea7 | 204 | test_cmp expect actual |
a31eeae2 TG |
205 | ' |
206 | ||
444825c7 SB |
207 | test_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 && | |
1108cea7 | 210 | test_cmp expect actual |
444825c7 SB |
211 | ' |
212 | ||
9b9439af | 213 | cat >test/expect <<EOF |
4704640b | 214 | * remote origin |
857f8c30 MG |
215 | Fetch URL: $(pwd)/one |
216 | Push URL: $(pwd)/one | |
97b91368 | 217 | HEAD branch: main |
7ecbbf87 | 218 | Remote branches: |
66713e84 JS |
219 | main new (next fetch will store in remotes/origin) |
220 | side tracked | |
7ecbbf87 | 221 | Local branches configured for 'git pull': |
66713e84 JS |
222 | ahead merges with remote main |
223 | main merges with remote main | |
7ecbbf87 JS |
224 | octopus merges with remote topic-a |
225 | and with remote topic-b | |
226 | and with remote topic-c | |
97b91368 | 227 | rebase rebases onto remote main |
e5dcbfd9 | 228 | Local refs configured for 'git push': |
66713e84 JS |
229 | main pushes to main (local out of date) |
230 | main pushes to upstream (create) | |
e61e0cc6 | 231 | * remote two |
857f8c30 MG |
232 | Fetch URL: ../two |
233 | Push URL: ../three | |
97b91368 | 234 | HEAD branch: main |
e5dcbfd9 | 235 | Local refs configured for 'git push': |
66713e84 JS |
236 | ahead forces to main (fast-forwardable) |
237 | main pushes to another (up to date) | |
4704640b JS |
238 | EOF |
239 | ||
97b91368 | 240 | test_expect_success 'show' ' |
9b9439af RR |
241 | ( |
242 | cd test && | |
97b91368 | 243 | git config --add remote.origin.fetch refs/heads/main:refs/heads/upstream && |
9b9439af | 244 | git fetch && |
97b91368 | 245 | git checkout -b ahead origin/main && |
9b9439af RR |
246 | echo 1 >>file && |
247 | test_tick && | |
248 | git commit -m update file && | |
97b91368 JS |
249 | git checkout main && |
250 | git branch --track octopus origin/main && | |
251 | git branch --track rebase origin/main && | |
252 | git branch -d -r origin/main && | |
9b9439af RR |
253 | 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 : && | |
97b91368 | 264 | git config --add remote.origin.push refs/heads/main:refs/heads/upstream && |
9b9439af | 265 | git config --add remote.origin.push +refs/tags/lastbackup && |
97b91368 JS |
266 | 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 && | |
9b9439af RR |
268 | git remote show origin two >output && |
269 | git branch -d rebase octopus && | |
1108cea7 | 270 | test_cmp expect output |
9b9439af RR |
271 | ) |
272 | ' | |
273 | ||
274 | cat >test/expect <<EOF | |
0ecfcb3b | 275 | * remote origin |
857f8c30 MG |
276 | Fetch URL: $(pwd)/one |
277 | Push URL: $(pwd)/one | |
e61e0cc6 | 278 | HEAD branch: (not queried) |
7ecbbf87 | 279 | Remote branches: (status not queried) |
97b91368 | 280 | main |
20244ea2 | 281 | side |
e5dcbfd9 | 282 | Local branches configured for 'git pull': |
66713e84 JS |
283 | ahead merges with remote main |
284 | main merges with remote main | |
e5dcbfd9 JS |
285 | Local refs configured for 'git push' (status not queried): |
286 | (matching) pushes to (matching) | |
66713e84 | 287 | refs/heads/main pushes to refs/heads/upstream |
e5dcbfd9 | 288 | refs/tags/lastbackup forces to refs/tags/lastbackup |
0ecfcb3b OM |
289 | EOF |
290 | ||
97b91368 | 291 | test_expect_success 'show -n' ' |
9b9439af RR |
292 | mv one one.unreachable && |
293 | ( | |
294 | cd test && | |
295 | git remote show -n origin >output && | |
296 | mv ../one.unreachable ../one && | |
1108cea7 | 297 | test_cmp expect output |
9b9439af | 298 | ) |
0ecfcb3b OM |
299 | ' |
300 | ||
4704640b | 301 | test_expect_success 'prune' ' |
9b9439af RR |
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 | ) | |
4704640b JS |
313 | ' |
314 | ||
bc14fac8 | 315 | test_expect_success 'set-head --delete' ' |
9b9439af RR |
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 | ) | |
bc14fac8 JS |
322 | ' |
323 | ||
324 | test_expect_success 'set-head --auto' ' | |
9b9439af RR |
325 | ( |
326 | cd test && | |
327 | git remote set-head --auto origin && | |
97b91368 | 328 | echo refs/remotes/origin/main >expect && |
9b9439af RR |
329 | git symbolic-ref refs/remotes/origin/HEAD >output && |
330 | test_cmp expect output | |
bc14fac8 JS |
331 | ) |
332 | ' | |
333 | ||
97b91368 | 334 | test_expect_success 'set-head --auto has no problem w/multiple HEADs' ' |
9b9439af RR |
335 | ( |
336 | cd test && | |
a4dfee06 | 337 | git fetch two "refs/heads/*:refs/remotes/two/*" && |
a45b5f05 | 338 | git remote set-head --auto two >output 2>&1 && |
97b91368 | 339 | echo "two/HEAD set to main" >expect && |
1108cea7 | 340 | test_cmp expect output |
9b9439af | 341 | ) |
bc14fac8 JS |
342 | ' |
343 | ||
9b9439af | 344 | cat >test/expect <<\EOF |
bc14fac8 JS |
345 | refs/remotes/origin/side2 |
346 | EOF | |
347 | ||
348 | test_expect_success 'set-head explicit' ' | |
9b9439af RR |
349 | ( |
350 | cd test && | |
351 | git remote set-head origin side2 && | |
352 | git symbolic-ref refs/remotes/origin/HEAD >output && | |
97b91368 | 353 | git remote set-head origin main && |
9b9439af RR |
354 | test_cmp expect output |
355 | ) | |
bc14fac8 JS |
356 | ' |
357 | ||
9b9439af | 358 | cat >test/expect <<EOF |
8d767927 | 359 | Pruning origin |
86521aca | 360 | URL: $(pwd)/one |
8d767927 OM |
361 | * [would prune] origin/side2 |
362 | EOF | |
363 | ||
364 | test_expect_success 'prune --dry-run' ' | |
431f4a26 ES |
365 | git -C one branch -m side2 side && |
366 | test_when_finished "git -C one branch -m side side2" && | |
9b9439af RR |
367 | ( |
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 && | |
1108cea7 | 372 | test_cmp expect output |
9b9439af | 373 | ) |
8d767927 OM |
374 | ' |
375 | ||
4ebc914c | 376 | test_expect_success 'add --mirror && prune' ' |
9b9439af RR |
377 | 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 | ) | |
4ebc914c JS |
396 | ' |
397 | ||
a9f5a355 JK |
398 | test_expect_success 'add --mirror=fetch' ' |
399 | mkdir mirror-fetch && | |
97b91368 | 400 | git init -b main mirror-fetch/parent && |
9b9439af RR |
401 | ( |
402 | cd mirror-fetch/parent && | |
403 | test_commit one | |
404 | ) && | |
a9f5a355 | 405 | git init --bare mirror-fetch/child && |
9b9439af RR |
406 | ( |
407 | cd mirror-fetch/child && | |
408 | git remote add --mirror=fetch -f parent ../parent | |
409 | ) | |
a9f5a355 JK |
410 | ' |
411 | ||
412 | test_expect_success 'fetch mirrors act as mirrors during fetch' ' | |
9b9439af RR |
413 | ( |
414 | cd mirror-fetch/parent && | |
415 | git branch new && | |
97b91368 | 416 | git branch -m main renamed |
a9f5a355 | 417 | ) && |
9b9439af RR |
418 | ( |
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 | |
a9f5a355 JK |
423 | ) |
424 | ' | |
425 | ||
426 | test_expect_success 'fetch mirrors can prune' ' | |
9b9439af RR |
427 | ( |
428 | cd mirror-fetch/child && | |
429 | git remote prune parent && | |
97b91368 | 430 | test_must_fail git rev-parse --verify refs/heads/main |
a9f5a355 JK |
431 | ) |
432 | ' | |
433 | ||
434 | test_expect_success 'fetch mirrors do not act as mirrors during push' ' | |
9b9439af RR |
435 | ( |
436 | cd mirror-fetch/parent && | |
437 | git checkout HEAD^0 | |
a9f5a355 | 438 | ) && |
9b9439af RR |
439 | ( |
440 | cd mirror-fetch/child && | |
441 | git branch -m renamed renamed2 && | |
442 | git push parent : | |
a9f5a355 | 443 | ) && |
9b9439af RR |
444 | ( |
445 | cd mirror-fetch/parent && | |
446 | git rev-parse --verify renamed && | |
447 | test_must_fail git rev-parse --verify refs/heads/renamed2 | |
a9f5a355 JK |
448 | ) |
449 | ' | |
450 | ||
3eafdc96 JK |
451 | test_expect_success 'add fetch mirror with specific branches' ' |
452 | git init --bare mirror-fetch/track && | |
9b9439af RR |
453 | ( |
454 | cd mirror-fetch/track && | |
455 | git remote add --mirror=fetch -t heads/new parent ../parent | |
3eafdc96 JK |
456 | ) |
457 | ' | |
458 | ||
459 | test_expect_success 'fetch mirror respects specific branches' ' | |
9b9439af RR |
460 | ( |
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 | |
3eafdc96 JK |
465 | ) |
466 | ' | |
467 | ||
a9f5a355 JK |
468 | test_expect_success 'add --mirror=push' ' |
469 | mkdir mirror-push && | |
470 | git init --bare mirror-push/public && | |
97b91368 | 471 | git init -b main mirror-push/private && |
9b9439af RR |
472 | ( |
473 | cd mirror-push/private && | |
474 | test_commit one && | |
475 | git remote add --mirror=push public ../public | |
a9f5a355 JK |
476 | ) |
477 | ' | |
478 | ||
479 | test_expect_success 'push mirrors act as mirrors during push' ' | |
9b9439af RR |
480 | ( |
481 | cd mirror-push/private && | |
482 | git branch new && | |
97b91368 | 483 | git branch -m main renamed && |
9b9439af | 484 | git push public |
a9f5a355 | 485 | ) && |
9b9439af RR |
486 | ( |
487 | cd mirror-push/private && | |
488 | git rev-parse --verify refs/heads/new && | |
489 | git rev-parse --verify refs/heads/renamed && | |
97b91368 | 490 | test_must_fail git rev-parse --verify refs/heads/main |
a9f5a355 JK |
491 | ) |
492 | ' | |
493 | ||
494 | test_expect_success 'push mirrors do not act as mirrors during fetch' ' | |
9b9439af RR |
495 | ( |
496 | cd mirror-push/public && | |
497 | git branch -m renamed renamed2 && | |
498 | git symbolic-ref HEAD refs/heads/renamed2 | |
a9f5a355 | 499 | ) && |
9b9439af RR |
500 | ( |
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 | |
a9f5a355 JK |
505 | ) |
506 | ' | |
507 | ||
3eafdc96 JK |
508 | test_expect_success 'push mirrors do not allow you to specify refs' ' |
509 | git init mirror-push/track && | |
9b9439af RR |
510 | ( |
511 | cd mirror-push/track && | |
512 | test_must_fail git remote add --mirror=push -t new public ../public | |
3eafdc96 JK |
513 | ) |
514 | ' | |
515 | ||
c175a7ad | 516 | test_expect_success 'add alt && prune' ' |
9b9439af RR |
517 | 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 | ) | |
c175a7ad SP |
538 | ' |
539 | ||
111fb858 ST |
540 | cat >test/expect <<\EOF |
541 | some-tag | |
542 | EOF | |
543 | ||
544 | test_expect_success 'add with reachable tags (default)' ' | |
9b9439af RR |
545 | ( |
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 | ) && | |
111fb858 ST |
563 | test_cmp test/expect test/output |
564 | ' | |
565 | ||
566 | cat >test/expect <<\EOF | |
567 | some-tag | |
568 | foobar-tag | |
569 | --tags | |
570 | EOF | |
571 | ||
572 | test_expect_success 'add --tags' ' | |
9b9439af RR |
573 | 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 | ) && | |
111fb858 ST |
583 | test_cmp test/expect test/output |
584 | ' | |
585 | ||
586 | cat >test/expect <<\EOF | |
587 | --no-tags | |
588 | EOF | |
589 | ||
590 | test_expect_success 'add --no-tags' ' | |
9b9439af RR |
591 | 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 && | |
bfa9148f | 597 | grep tagOpt .git/config && |
9b9439af RR |
598 | 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 | ) && | |
111fb858 ST |
606 | test_cmp test/expect test/output |
607 | ' | |
608 | ||
609 | test_expect_success 'reject --no-no-tags' ' | |
9b9439af RR |
610 | ( |
611 | cd add-no-tags && | |
612 | test_must_fail git remote add -f --no-no-tags neworigin ../one | |
613 | ) | |
111fb858 ST |
614 | ' |
615 | ||
9b9439af | 616 | cat >one/expect <<\EOF |
97b91368 | 617 | apis/main |
84521ed6 JS |
618 | apis/side |
619 | drosophila/another | |
97b91368 | 620 | drosophila/main |
84521ed6 JS |
621 | drosophila/side |
622 | EOF | |
623 | ||
624 | test_expect_success 'update' ' | |
9b9439af RR |
625 | ( |
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 | ) | |
84521ed6 JS |
633 | ' |
634 | ||
9b9439af | 635 | cat >one/expect <<\EOF |
84521ed6 | 636 | drosophila/another |
97b91368 | 637 | drosophila/main |
84521ed6 | 638 | drosophila/side |
97b91368 | 639 | manduca/main |
84521ed6 | 640 | manduca/side |
97b91368 | 641 | megaloprepus/main |
84521ed6 JS |
642 | megaloprepus/side |
643 | EOF | |
644 | ||
645 | test_expect_success 'update with arguments' ' | |
9b9439af RR |
646 | ( |
647 | cd one && | |
648 | for b in $(git branch -r) | |
649 | do | |
e6821d09 | 650 | git branch -r -d $b || exit 1 |
9b9439af RR |
651 | 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 | ) | |
84521ed6 JS |
660 | ' |
661 | ||
e2d41c64 | 662 | test_expect_success 'update --prune' ' |
9b9439af RR |
663 | ( |
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 | ) | |
e2d41c64 BG |
677 | ' |
678 | ||
9b9439af | 679 | cat >one/expect <<-\EOF |
97b91368 | 680 | apis/main |
84521ed6 | 681 | apis/side |
97b91368 | 682 | manduca/main |
84521ed6 | 683 | manduca/side |
97b91368 | 684 | megaloprepus/main |
84521ed6 JS |
685 | megaloprepus/side |
686 | EOF | |
687 | ||
688 | test_expect_success 'update default' ' | |
9b9439af RR |
689 | ( |
690 | cd one && | |
691 | for b in $(git branch -r) | |
692 | do | |
e6821d09 | 693 | git branch -r -d $b || exit 1 |
9b9439af RR |
694 | done && |
695 | git config remote.drosophila.skipDefaultUpdate true && | |
696 | git remote update default && | |
697 | git branch -r >output && | |
698 | test_cmp expect output | |
699 | ) | |
84521ed6 JS |
700 | ' |
701 | ||
9b9439af | 702 | cat >one/expect <<\EOF |
84521ed6 | 703 | drosophila/another |
97b91368 | 704 | drosophila/main |
84521ed6 JS |
705 | drosophila/side |
706 | EOF | |
707 | ||
708 | test_expect_success 'update default (overridden, with funny whitespace)' ' | |
9b9439af RR |
709 | ( |
710 | cd one && | |
711 | for b in $(git branch -r) | |
712 | do | |
e6821d09 | 713 | git branch -r -d $b || exit 1 |
9b9439af RR |
714 | 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 | ) | |
84521ed6 JS |
720 | ' |
721 | ||
4f2e842d | 722 | test_expect_success 'update (with remotes.default defined)' ' |
9b9439af RR |
723 | ( |
724 | cd one && | |
725 | for b in $(git branch -r) | |
726 | do | |
e6821d09 | 727 | git branch -r -d $b || exit 1 |
9b9439af RR |
728 | done && |
729 | git config remotes.default "drosophila" && | |
730 | git remote update && | |
731 | git branch -r >output && | |
732 | test_cmp expect output | |
733 | ) | |
4f2e842d BG |
734 | ' |
735 | ||
740fdd27 | 736 | test_expect_success '"remote show" does not show symbolic refs' ' |
740fdd27 | 737 | git clone one three && |
9b9439af RR |
738 | ( |
739 | cd three && | |
740 | git remote show origin >output && | |
741 | ! grep "^ *HEAD$" < output && | |
742 | ! grep -i stale < output | |
743 | ) | |
740fdd27 JS |
744 | ' |
745 | ||
24b6177e | 746 | test_expect_success 'reject adding remote with an invalid name' ' |
d492b31c | 747 | test_must_fail git remote add some:url desired-name |
24b6177e JF |
748 | ' |
749 | ||
bf98421a MV |
750 | # The first three test if the tracking branches are properly renamed, |
751 | # the last two ones check if the config is updated. | |
752 | ||
753 | test_expect_success 'rename a remote' ' | |
b3fd6cbf | 754 | test_config_global remote.pushDefault origin && |
bf98421a | 755 | git clone one four && |
9b9439af RR |
756 | ( |
757 | cd four && | |
97b91368 | 758 | git config branch.main.pushRemote origin && |
9b9439af | 759 | git remote rename origin upstream && |
0f1da600 | 760 | grep "pushRemote" .git/config && |
2eb7a0e5 | 761 | test -z "$(git for-each-ref refs/remotes/origin)" && |
97b91368 JS |
762 | test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/main" && |
763 | test "$(git rev-parse upstream/main)" = "$(git rev-parse main)" && | |
9b9439af | 764 | test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" && |
97b91368 JS |
765 | test "$(git config branch.main.remote)" = "upstream" && |
766 | test "$(git config branch.main.pushRemote)" = "upstream" && | |
b3fd6cbf BW |
767 | test "$(git config --global remote.pushDefault)" = "origin" |
768 | ) | |
769 | ' | |
770 | ||
771 | test_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 && | |
0f1da600 | 777 | grep pushDefault .git/config && |
b3fd6cbf BW |
778 | test "$(git config --local remote.pushDefault)" = "upstream" |
779 | ) | |
780 | ' | |
781 | ||
782 | test_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 | ||
794 | test_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" | |
9b9439af | 803 | ) |
bf98421a | 804 | ' |
1dd1239a | 805 | |
28f555f6 | 806 | test_expect_success 'rename does not update a non-default fetch refspec' ' |
28f555f6 | 807 | git clone one four.one && |
9b9439af RR |
808 | ( |
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/*" && | |
97b91368 | 813 | git rev-parse -q origin/main |
9b9439af | 814 | ) |
28f555f6 MZ |
815 | ' |
816 | ||
817 | test_expect_success 'rename a remote with name part of fetch spec' ' | |
28f555f6 | 818 | git clone one four.two && |
9b9439af RR |
819 | ( |
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 | ) | |
28f555f6 MZ |
825 | ' |
826 | ||
60e5eee0 | 827 | test_expect_success 'rename a remote with name prefix of other remote' ' |
60e5eee0 | 828 | git clone one four.three && |
9b9439af RR |
829 | ( |
830 | cd four.three && | |
831 | git remote add o git://example.com/repo.git && | |
832 | git remote rename o upstream && | |
97b91368 | 833 | test "$(git rev-parse origin/main)" = "$(git rev-parse main)" |
9b9439af | 834 | ) |
60e5eee0 MZ |
835 | ' |
836 | ||
e459b073 | 837 | test_expect_success 'rename succeeds with existing remote.<target>.prune' ' |
af5bacf4 JS |
838 | 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 | ||
923d4a5c | 844 | test_expect_success 'remove a remote' ' |
b3fd6cbf | 845 | test_config_global remote.pushDefault origin && |
923d4a5c BW |
846 | git clone one four.five && |
847 | ( | |
848 | cd four.five && | |
97b91368 | 849 | git config branch.main.pushRemote origin && |
923d4a5c BW |
850 | git remote remove origin && |
851 | test -z "$(git for-each-ref refs/remotes/origin)" && | |
97b91368 JS |
852 | test_must_fail git config branch.main.remote && |
853 | test_must_fail git config branch.main.pushRemote && | |
b3fd6cbf BW |
854 | test "$(git config --global remote.pushDefault)" = "origin" |
855 | ) | |
856 | ' | |
857 | ||
858 | test_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 | ||
868 | test_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 | ||
880 | test_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 | |
923d4a5c BW |
889 | ) |
890 | ' | |
891 | ||
9b9439af | 892 | cat >remotes_origin <<EOF |
1dd1239a | 893 | URL: $(pwd)/one |
97b91368 | 894 | Push: refs/heads/main:refs/heads/upstream |
f0f249d1 | 895 | Push: refs/heads/next:refs/heads/upstream2 |
97b91368 | 896 | Pull: refs/heads/main:refs/heads/origin |
f0f249d1 | 897 | Pull: refs/heads/next:refs/heads/origin2 |
1dd1239a MV |
898 | EOF |
899 | ||
900 | test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' ' | |
901 | git clone one five && | |
902 | origin_url=$(pwd)/one && | |
9b9439af RR |
903 | ( |
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 && | |
fe3c1956 | 909 | test_path_is_missing .git/remotes/origin && |
9b9439af | 910 | test "$(git config remote.origin.url)" = "$origin_url" && |
f0f249d1 | 911 | cat >push_expected <<-\EOF && |
97b91368 | 912 | refs/heads/main:refs/heads/upstream |
f0f249d1 RR |
913 | refs/heads/next:refs/heads/upstream2 |
914 | EOF | |
915 | cat >fetch_expected <<-\EOF && | |
97b91368 | 916 | refs/heads/main:refs/heads/origin |
f0f249d1 RR |
917 | 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 | |
9b9439af | 923 | ) |
1dd1239a MV |
924 | ' |
925 | ||
926 | test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' ' | |
927 | git clone one six && | |
928 | origin_url=$(pwd)/one && | |
9b9439af RR |
929 | ( |
930 | cd six && | |
931 | git remote rm origin && | |
97b91368 | 932 | echo "$origin_url#main" >.git/branches/origin && |
9b9439af | 933 | git remote rename origin origin && |
fe3c1956 | 934 | test_path_is_missing .git/branches/origin && |
9b9439af | 935 | test "$(git config remote.origin.url)" = "$origin_url" && |
97b91368 JS |
936 | test "$(git config remote.origin.fetch)" = "refs/heads/main:refs/heads/origin" && |
937 | test "$(git config remote.origin.push)" = "HEAD:refs/heads/main" | |
9b9439af | 938 | ) |
1dd1239a MV |
939 | ' |
940 | ||
1f9a5e90 | 941 | test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' ' |
f8948e2f | 942 | git clone one seven && |
1f9a5e90 RR |
943 | ( |
944 | 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" && | |
51b85471 | 950 | test "$(git config remote.origin.fetch)" = "refs/heads/foom:refs/heads/origin" && |
1f9a5e90 RR |
951 | test "$(git config remote.origin.push)" = "HEAD:refs/heads/foom" |
952 | ) | |
953 | ' | |
954 | ||
955 | test_expect_success 'remote prune to cause a dangling symref' ' | |
956 | git clone one eight && | |
f8948e2f JH |
957 | ( |
958 | cd one && | |
959 | git checkout side2 && | |
97b91368 | 960 | git branch -D main |
f8948e2f JH |
961 | ) && |
962 | ( | |
1f9a5e90 | 963 | cd eight && |
f8948e2f | 964 | git remote prune origin |
e01de1c9 | 965 | ) >err 2>&1 && |
f7dc6a96 | 966 | test_i18ngrep "has become dangling" err && |
f8948e2f | 967 | |
e01de1c9 | 968 | : And the dangling symref will not cause other annoying errors && |
f8948e2f | 969 | ( |
1f9a5e90 | 970 | cd eight && |
f8948e2f JH |
971 | git branch -a |
972 | ) 2>err && | |
e01de1c9 | 973 | ! grep "points nowhere" err && |
057e7138 | 974 | ( |
1f9a5e90 | 975 | cd eight && |
057e7138 JH |
976 | test_must_fail git branch nomore origin |
977 | ) 2>err && | |
661558f0 | 978 | test_i18ngrep "dangling symref" err |
f8948e2f JH |
979 | ' |
980 | ||
6a01554e | 981 | test_expect_success 'show empty remote' ' |
6a01554e CB |
982 | test_create_repo empty && |
983 | git clone empty empty-clone && | |
984 | ( | |
985 | cd empty-clone && | |
986 | git remote show origin | |
987 | ) | |
988 | ' | |
989 | ||
3d8b6949 JN |
990 | test_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 | ||
995 | test_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 | |
97b91368 | 1003 | +refs/heads/main:refs/remotes/scratch/main |
3d8b6949 JN |
1004 | +refs/heads/next:refs/remotes/scratch/next |
1005 | EOF | |
1006 | sort <<-\EOF >expect.add-two && | |
1007 | +refs/heads/maint:refs/remotes/scratch/maint | |
97b91368 | 1008 | +refs/heads/main:refs/remotes/scratch/main |
3d8b6949 | 1009 | +refs/heads/next:refs/remotes/scratch/next |
6dca5dbf | 1010 | +refs/heads/seen:refs/remotes/scratch/seen |
3d8b6949 JN |
1011 | +refs/heads/t/topic:refs/remotes/scratch/t/topic |
1012 | EOF | |
1013 | sort <<-\EOF >expect.setup-ffonly && | |
97b91368 | 1014 | refs/heads/main:refs/remotes/scratch/main |
3d8b6949 JN |
1015 | +refs/heads/next:refs/remotes/scratch/next |
1016 | EOF | |
1017 | sort <<-\EOF >expect.respect-ffonly && | |
97b91368 | 1018 | refs/heads/main:refs/remotes/scratch/main |
3d8b6949 | 1019 | +refs/heads/next:refs/remotes/scratch/next |
6dca5dbf | 1020 | +refs/heads/seen:refs/remotes/scratch/seen |
3d8b6949 JN |
1021 | 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 | ||
97b91368 | 1034 | git remote set-branches scratch maint main next && |
3d8b6949 JN |
1035 | git config --get-all remote.scratch.fetch >config-result && |
1036 | sort <config-result >../actual.replace && | |
1037 | ||
6dca5dbf | 1038 | git remote set-branches --add scratch seen t/topic && |
3d8b6949 JN |
1039 | 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 \ | |
97b91368 | 1044 | refs/heads/main:refs/remotes/scratch/main && |
3d8b6949 JN |
1045 | 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 | ||
6dca5dbf | 1050 | git remote set-branches --add scratch seen && |
3d8b6949 JN |
1051 | 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 | ||
1062 | test_expect_success 'remote set-branches with --mirror' ' | |
1063 | echo "+refs/*:refs/*" >expect.initial && | |
97b91368 | 1064 | echo "+refs/heads/main:refs/heads/main" >expect.replace && |
3d8b6949 JN |
1065 | 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 | ||
97b91368 | 1071 | git remote set-branches scratch heads/main && |
3d8b6949 JN |
1072 | 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 | ||
433f2be1 | 1078 | test_expect_success 'new remote' ' |
433f2be1 IL |
1079 | git remote add someremote foo && |
1080 | echo foo >expect && | |
1081 | git config --get-all remote.someremote.url >actual && | |
1082 | cmp expect actual | |
433f2be1 IL |
1083 | ' |
1084 | ||
96f78d39 BB |
1085 | get_url_test () { |
1086 | cat >expect && | |
1087 | git remote get-url "$@" >actual && | |
1088 | test_cmp expect actual | |
1089 | } | |
1090 | ||
1091 | test_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 | ||
45ebdcc9 PS |
1098 | test_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 | ||
433f2be1 | 1107 | test_expect_success 'remote set-url bar' ' |
433f2be1 IL |
1108 | git remote set-url someremote bar && |
1109 | echo bar >expect && | |
1110 | git config --get-all remote.someremote.url >actual && | |
1111 | cmp expect actual | |
433f2be1 | 1112 | ' |
057e7138 | 1113 | |
433f2be1 | 1114 | test_expect_success 'remote set-url baz bar' ' |
433f2be1 IL |
1115 | git remote set-url someremote baz bar && |
1116 | echo baz >expect && | |
1117 | git config --get-all remote.someremote.url >actual && | |
1118 | cmp expect actual | |
433f2be1 IL |
1119 | ' |
1120 | ||
1121 | test_expect_success 'remote set-url zot bar' ' | |
433f2be1 IL |
1122 | 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 | |
433f2be1 IL |
1126 | ' |
1127 | ||
1128 | test_expect_success 'remote set-url --push zot baz' ' | |
433f2be1 IL |
1129 | 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 | |
433f2be1 IL |
1136 | ' |
1137 | ||
1138 | test_expect_success 'remote set-url --push zot' ' | |
433f2be1 IL |
1139 | 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 | |
433f2be1 IL |
1147 | ' |
1148 | ||
96f78d39 BB |
1149 | test_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 | ||
433f2be1 | 1156 | test_expect_success 'remote set-url --push qux zot' ' |
433f2be1 IL |
1157 | 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 | |
433f2be1 IL |
1165 | ' |
1166 | ||
1167 | test_expect_success 'remote set-url --push foo qu+x' ' | |
433f2be1 IL |
1168 | 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 | |
433f2be1 IL |
1176 | ' |
1177 | ||
1178 | test_expect_success 'remote set-url --push --add aaa' ' | |
433f2be1 IL |
1179 | 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 | |
433f2be1 IL |
1188 | ' |
1189 | ||
96f78d39 BB |
1190 | test_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 | ||
433f2be1 | 1198 | test_expect_success 'remote set-url --push bar aaa' ' |
433f2be1 IL |
1199 | 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 | |
433f2be1 IL |
1208 | ' |
1209 | ||
1210 | test_expect_success 'remote set-url --push --delete bar' ' | |
433f2be1 IL |
1211 | 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 | |
433f2be1 IL |
1219 | ' |
1220 | ||
1221 | test_expect_success 'remote set-url --push --delete foo' ' | |
433f2be1 IL |
1222 | 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 | |
433f2be1 IL |
1229 | ' |
1230 | ||
1231 | test_expect_success 'remote set-url --add bbb' ' | |
433f2be1 IL |
1232 | 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 | |
433f2be1 IL |
1240 | ' |
1241 | ||
96f78d39 BB |
1242 | test_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 | ||
433f2be1 | 1250 | test_expect_success 'remote set-url --delete .*' ' |
49de47cf | 1251 | test_must_fail git remote set-url --delete someremote .\* && |
433f2be1 IL |
1252 | 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 | |
433f2be1 IL |
1259 | ' |
1260 | ||
1261 | test_expect_success 'remote set-url --delete bbb' ' | |
433f2be1 IL |
1262 | 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 | |
433f2be1 IL |
1269 | ' |
1270 | ||
1271 | test_expect_success 'remote set-url --delete baz' ' | |
433f2be1 IL |
1272 | 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 | |
433f2be1 IL |
1279 | ' |
1280 | ||
1281 | test_expect_success 'remote set-url --add ccc' ' | |
433f2be1 IL |
1282 | 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 | |
433f2be1 IL |
1290 | ' |
1291 | ||
1292 | test_expect_success 'remote set-url --delete baz' ' | |
433f2be1 IL |
1293 | 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 | |
433f2be1 IL |
1300 | ' |
1301 | ||
abf5f872 TR |
1302 | test_expect_success 'extra args: setup' ' |
1303 | # add a dummy origin so that this does not trigger failure | |
1304 | git remote add origin . | |
1305 | ' | |
1306 | ||
1307 | test_extra_arg () { | |
b17dd3f9 | 1308 | test_expect_success "extra args: $*" " |
abf5f872 | 1309 | test_must_fail git remote $* bogus_extra_arg 2>actual && |
1edbaac3 | 1310 | test_i18ngrep '^usage:' actual |
abf5f872 TR |
1311 | " |
1312 | } | |
1313 | ||
2d2e3d25 | 1314 | test_extra_arg add nick url |
abf5f872 TR |
1315 | test_extra_arg rename origin newname |
1316 | test_extra_arg remove origin | |
97b91368 | 1317 | test_extra_arg set-head origin main |
abf5f872 | 1318 | # set-branches takes any number of args |
96f78d39 | 1319 | test_extra_arg get-url origin newurl |
abf5f872 | 1320 | test_extra_arg set-url origin newurl oldurl |
b17dd3f9 TR |
1321 | # show takes any number of args |
1322 | # prune takes any number of args | |
abf5f872 TR |
1323 | # update takes any number of args |
1324 | ||
b90c95d9 JS |
1325 | test_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 | ||
dd8dd300 ÆAB |
1330 | test_expect_success 'unqualified <dst> refspec DWIM and advice' ' |
1331 | test_when_finished "(cd test && git tag -d some-tag)" && | |
1332 | ( | |
1333 | cd test && | |
97b91368 | 1334 | git tag -a -m "Some tag" some-tag main && |
dd8dd300 ÆAB |
1335 | 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 | ||
97b91368 | 1357 | test_expect_success 'refs/remotes/* <src> refspec and unqualified <dst> DWIM and advice' ' |
bf70636f ÆAB |
1358 | ( |
1359 | cd two && | |
97b91368 | 1360 | git tag -a -m "Some tag" my-tag main && |
bf70636f ÆAB |
1361 | 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 | ' | |
dd8dd300 | 1384 | |
433f2be1 | 1385 | test_done |