]>
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" && | |
10 | git init && | |
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 JH |
19 | git commit -m "Second" && |
20 | git checkout master | |
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 ' | |
45 | ||
46 | setup_repository one && | |
47 | setup_repository two && | |
48 | ( | |
49 | cd two && git branch another | |
50 | ) && | |
51 | git clone one test | |
52 | ||
53 | ' | |
54 | ||
55 | test_expect_success 'remote information for the origin' ' | |
56 | ( | |
57 | cd test && | |
58 | tokens_match origin "$(git remote)" && | |
59 | check_remote_track origin master side && | |
60 | check_tracking_branch origin HEAD master side | |
61 | ) | |
62 | ' | |
63 | ||
64 | test_expect_success 'add another remote' ' | |
65 | ( | |
66 | cd test && | |
67 | git remote add -f second ../two && | |
68 | tokens_match "origin second" "$(git remote)" && | |
69 | check_remote_track origin master side && | |
70 | check_remote_track second master side another && | |
71 | check_tracking_branch second master side another && | |
72 | git for-each-ref "--format=%(refname)" refs/remotes | | |
73 | sed -e "/^refs\/remotes\/origin\//d" \ | |
74 | -e "/^refs\/remotes\/second\//d" >actual && | |
75 | >expect && | |
82ebb0b6 | 76 | test_cmp expect actual |
683b5679 JH |
77 | ) |
78 | ' | |
79 | ||
1ce89cc4 JK |
80 | test_expect_success 'remote forces tracking branches' ' |
81 | ( | |
82 | cd test && | |
83 | case `git config remote.second.fetch` in | |
84 | +*) true ;; | |
85 | *) false ;; | |
86 | esac | |
87 | ) | |
88 | ' | |
89 | ||
683b5679 JH |
90 | test_expect_success 'remove remote' ' |
91 | ( | |
92 | cd test && | |
3b9dcff5 | 93 | git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master && |
683b5679 JH |
94 | git remote rm second |
95 | ) | |
96 | ' | |
97 | ||
98 | test_expect_success 'remove remote' ' | |
99 | ( | |
100 | cd test && | |
101 | tokens_match origin "$(git remote)" && | |
102 | check_remote_track origin master side && | |
103 | git for-each-ref "--format=%(refname)" refs/remotes | | |
104 | sed -e "/^refs\/remotes\/origin\//d" >actual && | |
105 | >expect && | |
82ebb0b6 | 106 | test_cmp expect actual |
683b5679 JH |
107 | ) |
108 | ' | |
109 | ||
13931236 | 110 | test_expect_success 'remove remote protects local branches' ' |
441adf0c JS |
111 | ( |
112 | cd test && | |
65f83dc0 | 113 | { cat >expect1 <<EOF |
13931236 MM |
114 | Note: A branch outside the refs/remotes/ hierarchy was not removed; |
115 | to delete it, use: | |
441adf0c JS |
116 | git branch -d master |
117 | EOF | |
65f83dc0 BC |
118 | } && |
119 | { cat >expect2 <<EOF | |
13931236 MM |
120 | Note: Some branches outside the refs/remotes/ hierarchy were not removed; |
121 | to delete them, use: | |
441adf0c JS |
122 | git branch -d foobranch |
123 | git branch -d master | |
124 | EOF | |
65f83dc0 | 125 | } && |
f3b1fbf8 | 126 | git tag footag && |
441adf0c JS |
127 | git config --add remote.oops.fetch "+refs/*:refs/*" && |
128 | git remote rm oops 2>actual1 && | |
129 | git branch foobranch && | |
130 | git config --add remote.oops.fetch "+refs/*:refs/*" && | |
131 | git remote rm oops 2>actual2 && | |
132 | git branch -d foobranch && | |
133 | git tag -d footag && | |
134 | test_cmp expect1 actual1 && | |
135 | test_cmp expect2 actual2 | |
136 | ) | |
137 | ' | |
138 | ||
4704640b JS |
139 | cat > test/expect << EOF |
140 | * remote origin | |
857f8c30 MG |
141 | Fetch URL: $(pwd)/one |
142 | Push URL: $(pwd)/one | |
e61e0cc6 | 143 | HEAD branch: master |
7ecbbf87 JS |
144 | Remote branches: |
145 | master new (next fetch will store in remotes/origin) | |
146 | side tracked | |
147 | Local branches configured for 'git pull': | |
e5dcbfd9 | 148 | ahead merges with remote master |
7ecbbf87 JS |
149 | master merges with remote master |
150 | octopus merges with remote topic-a | |
151 | and with remote topic-b | |
152 | and with remote topic-c | |
153 | rebase rebases onto remote master | |
e5dcbfd9 JS |
154 | Local refs configured for 'git push': |
155 | master pushes to master (local out of date) | |
156 | master pushes to upstream (create) | |
e61e0cc6 | 157 | * remote two |
857f8c30 MG |
158 | Fetch URL: ../two |
159 | Push URL: ../three | |
e61e0cc6 JS |
160 | HEAD branch (remote HEAD is ambiguous, may be one of the following): |
161 | another | |
162 | master | |
e5dcbfd9 | 163 | Local refs configured for 'git push': |
a75d7b54 | 164 | ahead forces to master (fast-forwardable) |
e5dcbfd9 | 165 | master pushes to another (up to date) |
4704640b JS |
166 | EOF |
167 | ||
168 | test_expect_success 'show' ' | |
169 | (cd test && | |
7ecbbf87 | 170 | git config --add remote.origin.fetch refs/heads/master:refs/heads/upstream && |
4704640b | 171 | git fetch && |
e5dcbfd9 JS |
172 | git checkout -b ahead origin/master && |
173 | echo 1 >> file && | |
174 | test_tick && | |
175 | git commit -m update file && | |
176 | git checkout master && | |
7ecbbf87 JS |
177 | git branch --track octopus origin/master && |
178 | git branch --track rebase origin/master && | |
4704640b | 179 | git branch -d -r origin/master && |
e61e0cc6 | 180 | git config --add remote.two.url ../two && |
857f8c30 | 181 | git config --add remote.two.pushurl ../three && |
7ecbbf87 JS |
182 | git config branch.rebase.rebase true && |
183 | git config branch.octopus.merge "topic-a topic-b topic-c" && | |
4704640b JS |
184 | (cd ../one && |
185 | echo 1 > file && | |
84521ed6 | 186 | test_tick && |
4704640b | 187 | git commit -m update file) && |
e5dcbfd9 JS |
188 | git config --add remote.origin.push : && |
189 | git config --add remote.origin.push refs/heads/master:refs/heads/upstream && | |
7ecbbf87 | 190 | git config --add remote.origin.push +refs/tags/lastbackup && |
e5dcbfd9 JS |
191 | git config --add remote.two.push +refs/heads/ahead:refs/heads/master && |
192 | git config --add remote.two.push refs/heads/master:refs/heads/another && | |
e61e0cc6 | 193 | git remote show origin two > output && |
7ecbbf87 | 194 | git branch -d rebase octopus && |
3af82863 | 195 | test_cmp expect output) |
4704640b JS |
196 | ' |
197 | ||
0ecfcb3b OM |
198 | cat > test/expect << EOF |
199 | * remote origin | |
857f8c30 MG |
200 | Fetch URL: $(pwd)/one |
201 | Push URL: $(pwd)/one | |
e61e0cc6 | 202 | HEAD branch: (not queried) |
7ecbbf87 | 203 | Remote branches: (status not queried) |
20244ea2 JS |
204 | master |
205 | side | |
e5dcbfd9 JS |
206 | Local branches configured for 'git pull': |
207 | ahead merges with remote master | |
7ecbbf87 | 208 | master merges with remote master |
e5dcbfd9 JS |
209 | Local refs configured for 'git push' (status not queried): |
210 | (matching) pushes to (matching) | |
211 | refs/heads/master pushes to refs/heads/upstream | |
212 | refs/tags/lastbackup forces to refs/tags/lastbackup | |
0ecfcb3b OM |
213 | EOF |
214 | ||
215 | test_expect_success 'show -n' ' | |
216 | (mv one one.unreachable && | |
217 | cd test && | |
218 | git remote show -n origin > output && | |
219 | mv ../one.unreachable ../one && | |
220 | test_cmp expect output) | |
221 | ' | |
222 | ||
4704640b JS |
223 | test_expect_success 'prune' ' |
224 | (cd one && | |
225 | git branch -m side side2) && | |
226 | (cd test && | |
227 | git fetch origin && | |
228 | git remote prune origin && | |
229 | git rev-parse refs/remotes/origin/side2 && | |
d492b31c | 230 | test_must_fail git rev-parse refs/remotes/origin/side) |
4704640b JS |
231 | ' |
232 | ||
bc14fac8 JS |
233 | test_expect_success 'set-head --delete' ' |
234 | (cd test && | |
235 | git symbolic-ref refs/remotes/origin/HEAD && | |
236 | git remote set-head --delete origin && | |
237 | test_must_fail git symbolic-ref refs/remotes/origin/HEAD) | |
238 | ' | |
239 | ||
240 | test_expect_success 'set-head --auto' ' | |
241 | (cd test && | |
242 | git remote set-head --auto origin && | |
243 | echo refs/remotes/origin/master >expect && | |
244 | git symbolic-ref refs/remotes/origin/HEAD >output && | |
245 | test_cmp expect output | |
246 | ) | |
247 | ' | |
248 | ||
249 | cat >test/expect <<EOF | |
250 | error: Multiple remote HEAD branches. Please choose one explicitly with: | |
251 | git remote set-head two another | |
252 | git remote set-head two master | |
253 | EOF | |
254 | ||
255 | test_expect_success 'set-head --auto fails w/multiple HEADs' ' | |
256 | (cd test && | |
257 | test_must_fail git remote set-head --auto two >output 2>&1 && | |
258 | test_cmp expect output) | |
259 | ' | |
260 | ||
261 | cat >test/expect <<EOF | |
262 | refs/remotes/origin/side2 | |
263 | EOF | |
264 | ||
265 | test_expect_success 'set-head explicit' ' | |
266 | (cd test && | |
267 | git remote set-head origin side2 && | |
268 | git symbolic-ref refs/remotes/origin/HEAD >output && | |
269 | git remote set-head origin master && | |
270 | test_cmp expect output) | |
271 | ' | |
272 | ||
8d767927 OM |
273 | cat > test/expect << EOF |
274 | Pruning origin | |
86521aca | 275 | URL: $(pwd)/one |
8d767927 OM |
276 | * [would prune] origin/side2 |
277 | EOF | |
278 | ||
279 | test_expect_success 'prune --dry-run' ' | |
280 | (cd one && | |
281 | git branch -m side2 side) && | |
282 | (cd test && | |
283 | git remote prune --dry-run origin > output && | |
284 | git rev-parse refs/remotes/origin/side2 && | |
d492b31c | 285 | test_must_fail git rev-parse refs/remotes/origin/side && |
8d767927 OM |
286 | (cd ../one && |
287 | git branch -m side side2) && | |
288 | test_cmp expect output) | |
289 | ' | |
290 | ||
4ebc914c JS |
291 | test_expect_success 'add --mirror && prune' ' |
292 | (mkdir mirror && | |
293 | cd mirror && | |
8ee5d731 | 294 | git init --bare && |
4ebc914c JS |
295 | git remote add --mirror -f origin ../one) && |
296 | (cd one && | |
297 | git branch -m side2 side) && | |
298 | (cd mirror && | |
299 | git rev-parse --verify refs/heads/side2 && | |
d492b31c | 300 | test_must_fail git rev-parse --verify refs/heads/side && |
4ebc914c JS |
301 | git fetch origin && |
302 | git remote prune origin && | |
d492b31c | 303 | test_must_fail git rev-parse --verify refs/heads/side2 && |
4ebc914c JS |
304 | git rev-parse --verify refs/heads/side) |
305 | ' | |
306 | ||
a9f5a355 JK |
307 | test_expect_success 'add --mirror=fetch' ' |
308 | mkdir mirror-fetch && | |
309 | git init mirror-fetch/parent && | |
310 | (cd mirror-fetch/parent && | |
311 | test_commit one) && | |
312 | git init --bare mirror-fetch/child && | |
313 | (cd mirror-fetch/child && | |
314 | git remote add --mirror=fetch -f parent ../parent) | |
315 | ' | |
316 | ||
317 | test_expect_success 'fetch mirrors act as mirrors during fetch' ' | |
318 | (cd mirror-fetch/parent && | |
319 | git branch new && | |
320 | git branch -m master renamed | |
321 | ) && | |
322 | (cd mirror-fetch/child && | |
323 | git fetch parent && | |
324 | git rev-parse --verify refs/heads/new && | |
325 | git rev-parse --verify refs/heads/renamed | |
326 | ) | |
327 | ' | |
328 | ||
329 | test_expect_success 'fetch mirrors can prune' ' | |
330 | (cd mirror-fetch/child && | |
331 | git remote prune parent && | |
332 | test_must_fail git rev-parse --verify refs/heads/master | |
333 | ) | |
334 | ' | |
335 | ||
336 | test_expect_success 'fetch mirrors do not act as mirrors during push' ' | |
337 | (cd mirror-fetch/parent && | |
338 | git checkout HEAD^0 | |
339 | ) && | |
340 | (cd mirror-fetch/child && | |
341 | git branch -m renamed renamed2 && | |
342 | git push parent | |
343 | ) && | |
344 | (cd mirror-fetch/parent && | |
345 | git rev-parse --verify renamed && | |
346 | test_must_fail git rev-parse --verify refs/heads/renamed2 | |
347 | ) | |
348 | ' | |
349 | ||
350 | test_expect_success 'add --mirror=push' ' | |
351 | mkdir mirror-push && | |
352 | git init --bare mirror-push/public && | |
353 | git init mirror-push/private && | |
354 | (cd mirror-push/private && | |
355 | test_commit one && | |
356 | git remote add --mirror=push public ../public | |
357 | ) | |
358 | ' | |
359 | ||
360 | test_expect_success 'push mirrors act as mirrors during push' ' | |
361 | (cd mirror-push/private && | |
362 | git branch new && | |
363 | git branch -m master renamed && | |
364 | git push public | |
365 | ) && | |
366 | (cd mirror-push/private && | |
367 | git rev-parse --verify refs/heads/new && | |
368 | git rev-parse --verify refs/heads/renamed && | |
369 | test_must_fail git rev-parse --verify refs/heads/master | |
370 | ) | |
371 | ' | |
372 | ||
373 | test_expect_success 'push mirrors do not act as mirrors during fetch' ' | |
374 | (cd mirror-push/public && | |
375 | git branch -m renamed renamed2 && | |
376 | git symbolic-ref HEAD refs/heads/renamed2 | |
377 | ) && | |
378 | (cd mirror-push/private && | |
379 | git fetch public && | |
380 | git rev-parse --verify refs/heads/renamed && | |
381 | test_must_fail git rev-parse --verify refs/heads/renamed2 | |
382 | ) | |
383 | ' | |
384 | ||
c175a7ad SP |
385 | test_expect_success 'add alt && prune' ' |
386 | (mkdir alttst && | |
387 | cd alttst && | |
388 | git init && | |
389 | git remote add -f origin ../one && | |
390 | git config remote.alt.url ../one && | |
391 | git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") && | |
392 | (cd one && | |
393 | git branch -m side side2) && | |
394 | (cd alttst && | |
395 | git rev-parse --verify refs/remotes/origin/side && | |
d492b31c | 396 | test_must_fail git rev-parse --verify refs/remotes/origin/side2 && |
c175a7ad SP |
397 | git fetch alt && |
398 | git remote prune alt && | |
d492b31c | 399 | test_must_fail git rev-parse --verify refs/remotes/origin/side && |
c175a7ad SP |
400 | git rev-parse --verify refs/remotes/origin/side2) |
401 | ' | |
402 | ||
111fb858 ST |
403 | cat >test/expect <<\EOF |
404 | some-tag | |
405 | EOF | |
406 | ||
407 | test_expect_success 'add with reachable tags (default)' ' | |
408 | (cd one && | |
409 | >foobar && | |
410 | git add foobar && | |
411 | git commit -m "Foobar" && | |
412 | git tag -a -m "Foobar tag" foobar-tag && | |
413 | git reset --hard HEAD~1 && | |
414 | git tag -a -m "Some tag" some-tag) && | |
415 | (mkdir add-tags && | |
416 | cd add-tags && | |
417 | git init && | |
418 | git remote add -f origin ../one && | |
419 | git tag -l some-tag >../test/output && | |
420 | git tag -l foobar-tag >>../test/output && | |
421 | test_must_fail git config remote.origin.tagopt) && | |
422 | test_cmp test/expect test/output | |
423 | ' | |
424 | ||
425 | cat >test/expect <<\EOF | |
426 | some-tag | |
427 | foobar-tag | |
428 | --tags | |
429 | EOF | |
430 | ||
431 | test_expect_success 'add --tags' ' | |
432 | (rm -rf add-tags && | |
433 | mkdir add-tags && | |
434 | cd add-tags && | |
435 | git init && | |
436 | git remote add -f --tags origin ../one && | |
437 | git tag -l some-tag >../test/output && | |
438 | git tag -l foobar-tag >>../test/output && | |
439 | git config remote.origin.tagopt >>../test/output) && | |
440 | test_cmp test/expect test/output | |
441 | ' | |
442 | ||
443 | cat >test/expect <<\EOF | |
444 | --no-tags | |
445 | EOF | |
446 | ||
447 | test_expect_success 'add --no-tags' ' | |
448 | (rm -rf add-tags && | |
449 | mkdir add-no-tags && | |
450 | cd add-no-tags && | |
451 | git init && | |
452 | git remote add -f --no-tags origin ../one && | |
453 | git tag -l some-tag >../test/output && | |
454 | git tag -l foobar-tag >../test/output && | |
455 | git config remote.origin.tagopt >>../test/output) && | |
456 | (cd one && | |
457 | git tag -d some-tag foobar-tag) && | |
458 | test_cmp test/expect test/output | |
459 | ' | |
460 | ||
461 | test_expect_success 'reject --no-no-tags' ' | |
462 | (cd add-no-tags && | |
463 | test_must_fail git remote add -f --no-no-tags neworigin ../one) | |
464 | ' | |
465 | ||
84521ed6 JS |
466 | cat > one/expect << EOF |
467 | apis/master | |
468 | apis/side | |
469 | drosophila/another | |
470 | drosophila/master | |
471 | drosophila/side | |
472 | EOF | |
473 | ||
474 | test_expect_success 'update' ' | |
475 | ||
476 | (cd one && | |
477 | git remote add drosophila ../two && | |
478 | git remote add apis ../mirror && | |
479 | git remote update && | |
480 | git branch -r > output && | |
3af82863 | 481 | test_cmp expect output) |
84521ed6 JS |
482 | |
483 | ' | |
484 | ||
485 | cat > one/expect << EOF | |
486 | drosophila/another | |
487 | drosophila/master | |
488 | drosophila/side | |
489 | manduca/master | |
490 | manduca/side | |
491 | megaloprepus/master | |
492 | megaloprepus/side | |
493 | EOF | |
494 | ||
495 | test_expect_success 'update with arguments' ' | |
496 | ||
497 | (cd one && | |
498 | for b in $(git branch -r) | |
499 | do | |
500 | git branch -r -d $b || break | |
501 | done && | |
502 | git remote add manduca ../mirror && | |
503 | git remote add megaloprepus ../mirror && | |
504 | git config remotes.phobaeticus "drosophila megaloprepus" && | |
505 | git config remotes.titanus manduca && | |
506 | git remote update phobaeticus titanus && | |
507 | git branch -r > output && | |
3af82863 | 508 | test_cmp expect output) |
84521ed6 JS |
509 | |
510 | ' | |
511 | ||
e2d41c64 BG |
512 | test_expect_success 'update --prune' ' |
513 | ||
514 | (cd one && | |
515 | git branch -m side2 side3) && | |
516 | (cd test && | |
517 | git remote update --prune && | |
65b26eb4 | 518 | (cd ../one && git branch -m side3 side2) && |
e2d41c64 BG |
519 | git rev-parse refs/remotes/origin/side3 && |
520 | test_must_fail git rev-parse refs/remotes/origin/side2) | |
521 | ' | |
522 | ||
84521ed6 JS |
523 | cat > one/expect << EOF |
524 | apis/master | |
525 | apis/side | |
526 | manduca/master | |
527 | manduca/side | |
528 | megaloprepus/master | |
529 | megaloprepus/side | |
530 | EOF | |
531 | ||
532 | test_expect_success 'update default' ' | |
533 | ||
534 | (cd one && | |
535 | for b in $(git branch -r) | |
536 | do | |
537 | git branch -r -d $b || break | |
538 | done && | |
539 | git config remote.drosophila.skipDefaultUpdate true && | |
540 | git remote update default && | |
541 | git branch -r > output && | |
3af82863 | 542 | test_cmp expect output) |
84521ed6 JS |
543 | |
544 | ' | |
545 | ||
546 | cat > one/expect << EOF | |
547 | drosophila/another | |
548 | drosophila/master | |
549 | drosophila/side | |
550 | EOF | |
551 | ||
552 | test_expect_success 'update default (overridden, with funny whitespace)' ' | |
553 | ||
554 | (cd one && | |
555 | for b in $(git branch -r) | |
556 | do | |
557 | git branch -r -d $b || break | |
558 | done && | |
559 | git config remotes.default "$(printf "\t drosophila \n")" && | |
560 | git remote update default && | |
561 | git branch -r > output && | |
3af82863 | 562 | test_cmp expect output) |
84521ed6 JS |
563 | |
564 | ' | |
565 | ||
4f2e842d BG |
566 | test_expect_success 'update (with remotes.default defined)' ' |
567 | ||
568 | (cd one && | |
569 | for b in $(git branch -r) | |
570 | do | |
571 | git branch -r -d $b || break | |
572 | done && | |
573 | git config remotes.default "drosophila" && | |
574 | git remote update && | |
575 | git branch -r > output && | |
576 | test_cmp expect output) | |
577 | ||
578 | ' | |
579 | ||
740fdd27 JS |
580 | test_expect_success '"remote show" does not show symbolic refs' ' |
581 | ||
582 | git clone one three && | |
583 | (cd three && | |
584 | git remote show origin > output && | |
e61e0cc6 | 585 | ! grep "^ *HEAD$" < output && |
740fdd27 JS |
586 | ! grep -i stale < output) |
587 | ||
588 | ' | |
589 | ||
24b6177e JF |
590 | test_expect_success 'reject adding remote with an invalid name' ' |
591 | ||
d492b31c | 592 | test_must_fail git remote add some:url desired-name |
24b6177e JF |
593 | |
594 | ' | |
595 | ||
bf98421a MV |
596 | # The first three test if the tracking branches are properly renamed, |
597 | # the last two ones check if the config is updated. | |
598 | ||
599 | test_expect_success 'rename a remote' ' | |
600 | ||
601 | git clone one four && | |
602 | (cd four && | |
603 | git remote rename origin upstream && | |
604 | rmdir .git/refs/remotes/origin && | |
605 | test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" && | |
606 | test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" && | |
607 | test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" && | |
608 | test "$(git config branch.master.remote)" = "upstream") | |
609 | ||
610 | ' | |
1dd1239a MV |
611 | |
612 | cat > remotes_origin << EOF | |
613 | URL: $(pwd)/one | |
614 | Push: refs/heads/master:refs/heads/upstream | |
615 | Pull: refs/heads/master:refs/heads/origin | |
616 | EOF | |
617 | ||
618 | test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' ' | |
619 | git clone one five && | |
620 | origin_url=$(pwd)/one && | |
621 | (cd five && | |
622 | git remote rm origin && | |
623 | mkdir -p .git/remotes && | |
624 | cat ../remotes_origin > .git/remotes/origin && | |
625 | git remote rename origin origin && | |
626 | ! test -f .git/remotes/origin && | |
627 | test "$(git config remote.origin.url)" = "$origin_url" && | |
628 | test "$(git config remote.origin.push)" = "refs/heads/master:refs/heads/upstream" && | |
629 | test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin") | |
630 | ' | |
631 | ||
632 | test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' ' | |
633 | git clone one six && | |
634 | origin_url=$(pwd)/one && | |
635 | (cd six && | |
636 | git remote rm origin && | |
637 | echo "$origin_url" > .git/branches/origin && | |
638 | git remote rename origin origin && | |
639 | ! test -f .git/branches/origin && | |
640 | test "$(git config remote.origin.url)" = "$origin_url" && | |
641 | test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin") | |
642 | ' | |
643 | ||
f8948e2f JH |
644 | test_expect_success 'remote prune to cause a dangling symref' ' |
645 | git clone one seven && | |
646 | ( | |
647 | cd one && | |
648 | git checkout side2 && | |
649 | git branch -D master | |
650 | ) && | |
651 | ( | |
652 | cd seven && | |
653 | git remote prune origin | |
e01de1c9 | 654 | ) >err 2>&1 && |
f8948e2f JH |
655 | grep "has become dangling" err && |
656 | ||
e01de1c9 | 657 | : And the dangling symref will not cause other annoying errors && |
f8948e2f JH |
658 | ( |
659 | cd seven && | |
660 | git branch -a | |
661 | ) 2>err && | |
e01de1c9 | 662 | ! grep "points nowhere" err && |
057e7138 JH |
663 | ( |
664 | cd seven && | |
665 | test_must_fail git branch nomore origin | |
666 | ) 2>err && | |
667 | grep "dangling symref" err | |
f8948e2f JH |
668 | ' |
669 | ||
6a01554e CB |
670 | test_expect_success 'show empty remote' ' |
671 | ||
672 | test_create_repo empty && | |
673 | git clone empty empty-clone && | |
674 | ( | |
675 | cd empty-clone && | |
676 | git remote show origin | |
677 | ) | |
678 | ' | |
679 | ||
3d8b6949 JN |
680 | test_expect_success 'remote set-branches requires a remote' ' |
681 | test_must_fail git remote set-branches && | |
682 | test_must_fail git remote set-branches --add | |
683 | ' | |
684 | ||
685 | test_expect_success 'remote set-branches' ' | |
686 | echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial && | |
687 | sort <<-\EOF >expect.add && | |
688 | +refs/heads/*:refs/remotes/scratch/* | |
689 | +refs/heads/other:refs/remotes/scratch/other | |
690 | EOF | |
691 | sort <<-\EOF >expect.replace && | |
692 | +refs/heads/maint:refs/remotes/scratch/maint | |
693 | +refs/heads/master:refs/remotes/scratch/master | |
694 | +refs/heads/next:refs/remotes/scratch/next | |
695 | EOF | |
696 | sort <<-\EOF >expect.add-two && | |
697 | +refs/heads/maint:refs/remotes/scratch/maint | |
698 | +refs/heads/master:refs/remotes/scratch/master | |
699 | +refs/heads/next:refs/remotes/scratch/next | |
700 | +refs/heads/pu:refs/remotes/scratch/pu | |
701 | +refs/heads/t/topic:refs/remotes/scratch/t/topic | |
702 | EOF | |
703 | sort <<-\EOF >expect.setup-ffonly && | |
704 | refs/heads/master:refs/remotes/scratch/master | |
705 | +refs/heads/next:refs/remotes/scratch/next | |
706 | EOF | |
707 | sort <<-\EOF >expect.respect-ffonly && | |
708 | refs/heads/master:refs/remotes/scratch/master | |
709 | +refs/heads/next:refs/remotes/scratch/next | |
710 | +refs/heads/pu:refs/remotes/scratch/pu | |
711 | EOF | |
712 | ||
713 | git clone .git/ setbranches && | |
714 | ( | |
715 | cd setbranches && | |
716 | git remote rename origin scratch && | |
717 | git config --get-all remote.scratch.fetch >config-result && | |
718 | sort <config-result >../actual.initial && | |
719 | ||
720 | git remote set-branches scratch --add other && | |
721 | git config --get-all remote.scratch.fetch >config-result && | |
722 | sort <config-result >../actual.add && | |
723 | ||
724 | git remote set-branches scratch maint master next && | |
725 | git config --get-all remote.scratch.fetch >config-result && | |
726 | sort <config-result >../actual.replace && | |
727 | ||
728 | git remote set-branches --add scratch pu t/topic && | |
729 | git config --get-all remote.scratch.fetch >config-result && | |
730 | sort <config-result >../actual.add-two && | |
731 | ||
732 | git config --unset-all remote.scratch.fetch && | |
733 | git config remote.scratch.fetch \ | |
734 | refs/heads/master:refs/remotes/scratch/master && | |
735 | git config --add remote.scratch.fetch \ | |
736 | +refs/heads/next:refs/remotes/scratch/next && | |
737 | git config --get-all remote.scratch.fetch >config-result && | |
738 | sort <config-result >../actual.setup-ffonly && | |
739 | ||
740 | git remote set-branches --add scratch pu && | |
741 | git config --get-all remote.scratch.fetch >config-result && | |
742 | sort <config-result >../actual.respect-ffonly | |
743 | ) && | |
744 | test_cmp expect.initial actual.initial && | |
745 | test_cmp expect.add actual.add && | |
746 | test_cmp expect.replace actual.replace && | |
747 | test_cmp expect.add-two actual.add-two && | |
748 | test_cmp expect.setup-ffonly actual.setup-ffonly && | |
749 | test_cmp expect.respect-ffonly actual.respect-ffonly | |
750 | ' | |
751 | ||
752 | test_expect_success 'remote set-branches with --mirror' ' | |
753 | echo "+refs/*:refs/*" >expect.initial && | |
754 | echo "+refs/heads/master:refs/heads/master" >expect.replace && | |
755 | git clone --mirror .git/ setbranches-mirror && | |
756 | ( | |
757 | cd setbranches-mirror && | |
758 | git remote rename origin scratch && | |
759 | git config --get-all remote.scratch.fetch >../actual.initial && | |
760 | ||
761 | git remote set-branches scratch heads/master && | |
762 | git config --get-all remote.scratch.fetch >../actual.replace | |
763 | ) && | |
764 | test_cmp expect.initial actual.initial && | |
765 | test_cmp expect.replace actual.replace | |
766 | ' | |
767 | ||
433f2be1 | 768 | test_expect_success 'new remote' ' |
433f2be1 IL |
769 | git remote add someremote foo && |
770 | echo foo >expect && | |
771 | git config --get-all remote.someremote.url >actual && | |
772 | cmp expect actual | |
433f2be1 IL |
773 | ' |
774 | ||
775 | test_expect_success 'remote set-url bar' ' | |
433f2be1 IL |
776 | git remote set-url someremote bar && |
777 | echo bar >expect && | |
778 | git config --get-all remote.someremote.url >actual && | |
779 | cmp expect actual | |
433f2be1 | 780 | ' |
057e7138 | 781 | |
433f2be1 | 782 | test_expect_success 'remote set-url baz bar' ' |
433f2be1 IL |
783 | git remote set-url someremote baz bar && |
784 | echo baz >expect && | |
785 | git config --get-all remote.someremote.url >actual && | |
786 | cmp expect actual | |
433f2be1 IL |
787 | ' |
788 | ||
789 | test_expect_success 'remote set-url zot bar' ' | |
433f2be1 IL |
790 | test_must_fail git remote set-url someremote zot bar && |
791 | echo baz >expect && | |
792 | git config --get-all remote.someremote.url >actual && | |
793 | cmp expect actual | |
433f2be1 IL |
794 | ' |
795 | ||
796 | test_expect_success 'remote set-url --push zot baz' ' | |
433f2be1 IL |
797 | test_must_fail git remote set-url --push someremote zot baz && |
798 | echo "YYY" >expect && | |
799 | echo baz >>expect && | |
800 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
801 | echo "YYY" >>actual && | |
802 | git config --get-all remote.someremote.url >>actual && | |
803 | cmp expect actual | |
433f2be1 IL |
804 | ' |
805 | ||
806 | test_expect_success 'remote set-url --push zot' ' | |
433f2be1 IL |
807 | git remote set-url --push someremote zot && |
808 | echo zot >expect && | |
809 | echo "YYY" >>expect && | |
810 | echo baz >>expect && | |
811 | git config --get-all remote.someremote.pushurl >actual && | |
812 | echo "YYY" >>actual && | |
813 | git config --get-all remote.someremote.url >>actual && | |
814 | cmp expect actual | |
433f2be1 IL |
815 | ' |
816 | ||
817 | test_expect_success 'remote set-url --push qux zot' ' | |
433f2be1 IL |
818 | git remote set-url --push someremote qux zot && |
819 | echo qux >expect && | |
820 | echo "YYY" >>expect && | |
821 | echo baz >>expect && | |
822 | git config --get-all remote.someremote.pushurl >actual && | |
823 | echo "YYY" >>actual && | |
824 | git config --get-all remote.someremote.url >>actual && | |
825 | cmp expect actual | |
433f2be1 IL |
826 | ' |
827 | ||
828 | test_expect_success 'remote set-url --push foo qu+x' ' | |
433f2be1 IL |
829 | git remote set-url --push someremote foo qu+x && |
830 | echo foo >expect && | |
831 | echo "YYY" >>expect && | |
832 | echo baz >>expect && | |
833 | git config --get-all remote.someremote.pushurl >actual && | |
834 | echo "YYY" >>actual && | |
835 | git config --get-all remote.someremote.url >>actual && | |
836 | cmp expect actual | |
433f2be1 IL |
837 | ' |
838 | ||
839 | test_expect_success 'remote set-url --push --add aaa' ' | |
433f2be1 IL |
840 | git remote set-url --push --add someremote aaa && |
841 | echo foo >expect && | |
842 | echo aaa >>expect && | |
843 | echo "YYY" >>expect && | |
844 | echo baz >>expect && | |
845 | git config --get-all remote.someremote.pushurl >actual && | |
846 | echo "YYY" >>actual && | |
847 | git config --get-all remote.someremote.url >>actual && | |
848 | cmp expect actual | |
433f2be1 IL |
849 | ' |
850 | ||
851 | test_expect_success 'remote set-url --push bar aaa' ' | |
433f2be1 IL |
852 | git remote set-url --push someremote bar aaa && |
853 | echo foo >expect && | |
854 | echo bar >>expect && | |
855 | echo "YYY" >>expect && | |
856 | echo baz >>expect && | |
857 | git config --get-all remote.someremote.pushurl >actual && | |
858 | echo "YYY" >>actual && | |
859 | git config --get-all remote.someremote.url >>actual && | |
860 | cmp expect actual | |
433f2be1 IL |
861 | ' |
862 | ||
863 | test_expect_success 'remote set-url --push --delete bar' ' | |
433f2be1 IL |
864 | git remote set-url --push --delete someremote bar && |
865 | echo foo >expect && | |
866 | echo "YYY" >>expect && | |
867 | echo baz >>expect && | |
868 | git config --get-all remote.someremote.pushurl >actual && | |
869 | echo "YYY" >>actual && | |
870 | git config --get-all remote.someremote.url >>actual && | |
871 | cmp expect actual | |
433f2be1 IL |
872 | ' |
873 | ||
874 | test_expect_success 'remote set-url --push --delete foo' ' | |
433f2be1 IL |
875 | git remote set-url --push --delete someremote foo && |
876 | echo "YYY" >expect && | |
877 | echo baz >>expect && | |
878 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
879 | echo "YYY" >>actual && | |
880 | git config --get-all remote.someremote.url >>actual && | |
881 | cmp expect actual | |
433f2be1 IL |
882 | ' |
883 | ||
884 | test_expect_success 'remote set-url --add bbb' ' | |
433f2be1 IL |
885 | git remote set-url --add someremote bbb && |
886 | echo "YYY" >expect && | |
887 | echo baz >>expect && | |
888 | echo bbb >>expect && | |
889 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
890 | echo "YYY" >>actual && | |
891 | git config --get-all remote.someremote.url >>actual && | |
892 | cmp expect actual | |
433f2be1 IL |
893 | ' |
894 | ||
895 | test_expect_success 'remote set-url --delete .*' ' | |
49de47cf | 896 | test_must_fail git remote set-url --delete someremote .\* && |
433f2be1 IL |
897 | echo "YYY" >expect && |
898 | echo baz >>expect && | |
899 | echo bbb >>expect && | |
900 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
901 | echo "YYY" >>actual && | |
902 | git config --get-all remote.someremote.url >>actual && | |
903 | cmp expect actual | |
433f2be1 IL |
904 | ' |
905 | ||
906 | test_expect_success 'remote set-url --delete bbb' ' | |
433f2be1 IL |
907 | git remote set-url --delete someremote bbb && |
908 | echo "YYY" >expect && | |
909 | echo baz >>expect && | |
910 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
911 | echo "YYY" >>actual && | |
912 | git config --get-all remote.someremote.url >>actual && | |
913 | cmp expect actual | |
433f2be1 IL |
914 | ' |
915 | ||
916 | test_expect_success 'remote set-url --delete baz' ' | |
433f2be1 IL |
917 | test_must_fail git remote set-url --delete someremote baz && |
918 | echo "YYY" >expect && | |
919 | echo baz >>expect && | |
920 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
921 | echo "YYY" >>actual && | |
922 | git config --get-all remote.someremote.url >>actual && | |
923 | cmp expect actual | |
433f2be1 IL |
924 | ' |
925 | ||
926 | test_expect_success 'remote set-url --add ccc' ' | |
433f2be1 IL |
927 | git remote set-url --add someremote ccc && |
928 | echo "YYY" >expect && | |
929 | echo baz >>expect && | |
930 | echo ccc >>expect && | |
931 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
932 | echo "YYY" >>actual && | |
933 | git config --get-all remote.someremote.url >>actual && | |
934 | cmp expect actual | |
433f2be1 IL |
935 | ' |
936 | ||
937 | test_expect_success 'remote set-url --delete baz' ' | |
433f2be1 IL |
938 | git remote set-url --delete someremote baz && |
939 | echo "YYY" >expect && | |
940 | echo ccc >>expect && | |
941 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
942 | echo "YYY" >>actual && | |
943 | git config --get-all remote.someremote.url >>actual && | |
944 | cmp expect actual | |
433f2be1 IL |
945 | ' |
946 | ||
947 | test_done |