]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | ||
3 | test_description='git remote porcelain-ish' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | setup_repository () { | |
8 | mkdir "$1" && ( | |
9 | cd "$1" && | |
10 | git init && | |
11 | >file && | |
12 | git add file && | |
13 | test_tick && | |
14 | git commit -m "Initial" && | |
15 | git checkout -b side && | |
16 | >elif && | |
17 | git add elif && | |
18 | test_tick && | |
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 && | |
27 | test_cmp expect actual | |
28 | } | |
29 | ||
30 | check_remote_track () { | |
31 | actual=$(git remote show "$1" | sed -ne 's|^ \(.*\) tracked$|\1|p') | |
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 && | |
76 | test_cmp expect actual | |
77 | ) | |
78 | ' | |
79 | ||
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 | ||
90 | test_expect_success 'remove remote' ' | |
91 | ( | |
92 | cd test && | |
93 | git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master && | |
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 && | |
106 | test_cmp expect actual | |
107 | ) | |
108 | ' | |
109 | ||
110 | test_expect_success 'remove remote protects local branches' ' | |
111 | ( | |
112 | cd test && | |
113 | { cat >expect1 <<EOF | |
114 | Note: A branch outside the refs/remotes/ hierarchy was not removed; | |
115 | to delete it, use: | |
116 | git branch -d master | |
117 | EOF | |
118 | } && | |
119 | { cat >expect2 <<EOF | |
120 | Note: Some branches outside the refs/remotes/ hierarchy were not removed; | |
121 | to delete them, use: | |
122 | git branch -d foobranch | |
123 | git branch -d master | |
124 | EOF | |
125 | } && | |
126 | git tag footag && | |
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 | ||
139 | cat > test/expect << EOF | |
140 | * remote origin | |
141 | Fetch URL: $(pwd)/one | |
142 | Push URL: $(pwd)/one | |
143 | HEAD branch: master | |
144 | Remote branches: | |
145 | master new (next fetch will store in remotes/origin) | |
146 | side tracked | |
147 | Local branches configured for 'git pull': | |
148 | ahead merges with remote master | |
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 | |
154 | Local refs configured for 'git push': | |
155 | master pushes to master (local out of date) | |
156 | master pushes to upstream (create) | |
157 | * remote two | |
158 | Fetch URL: ../two | |
159 | Push URL: ../three | |
160 | HEAD branch (remote HEAD is ambiguous, may be one of the following): | |
161 | another | |
162 | master | |
163 | Local refs configured for 'git push': | |
164 | ahead forces to master (fast-forwardable) | |
165 | master pushes to another (up to date) | |
166 | EOF | |
167 | ||
168 | test_expect_success 'show' ' | |
169 | (cd test && | |
170 | git config --add remote.origin.fetch refs/heads/master:refs/heads/upstream && | |
171 | git fetch && | |
172 | git checkout -b ahead origin/master && | |
173 | echo 1 >> file && | |
174 | test_tick && | |
175 | git commit -m update file && | |
176 | git checkout master && | |
177 | git branch --track octopus origin/master && | |
178 | git branch --track rebase origin/master && | |
179 | git branch -d -r origin/master && | |
180 | git config --add remote.two.url ../two && | |
181 | git config --add remote.two.pushurl ../three && | |
182 | git config branch.rebase.rebase true && | |
183 | git config branch.octopus.merge "topic-a topic-b topic-c" && | |
184 | (cd ../one && | |
185 | echo 1 > file && | |
186 | test_tick && | |
187 | git commit -m update file) && | |
188 | git config --add remote.origin.push : && | |
189 | git config --add remote.origin.push refs/heads/master:refs/heads/upstream && | |
190 | git config --add remote.origin.push +refs/tags/lastbackup && | |
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 && | |
193 | git remote show origin two > output && | |
194 | git branch -d rebase octopus && | |
195 | test_cmp expect output) | |
196 | ' | |
197 | ||
198 | cat > test/expect << EOF | |
199 | * remote origin | |
200 | Fetch URL: $(pwd)/one | |
201 | Push URL: $(pwd)/one | |
202 | HEAD branch: (not queried) | |
203 | Remote branches: (status not queried) | |
204 | master | |
205 | side | |
206 | Local branches configured for 'git pull': | |
207 | ahead merges with remote master | |
208 | master merges with remote master | |
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 | |
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 | ||
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 && | |
230 | test_must_fail git rev-parse refs/remotes/origin/side) | |
231 | ' | |
232 | ||
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 | ||
273 | cat > test/expect << EOF | |
274 | Pruning origin | |
275 | URL: $(pwd)/one | |
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 && | |
285 | test_must_fail git rev-parse refs/remotes/origin/side && | |
286 | (cd ../one && | |
287 | git branch -m side side2) && | |
288 | test_cmp expect output) | |
289 | ' | |
290 | ||
291 | test_expect_success 'add --mirror && prune' ' | |
292 | (mkdir mirror && | |
293 | cd mirror && | |
294 | git init --bare && | |
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 && | |
300 | test_must_fail git rev-parse --verify refs/heads/side && | |
301 | git fetch origin && | |
302 | git remote prune origin && | |
303 | test_must_fail git rev-parse --verify refs/heads/side2 && | |
304 | git rev-parse --verify refs/heads/side) | |
305 | ' | |
306 | ||
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 fetch mirror with specific branches' ' | |
351 | git init --bare mirror-fetch/track && | |
352 | (cd mirror-fetch/track && | |
353 | git remote add --mirror=fetch -t heads/new parent ../parent | |
354 | ) | |
355 | ' | |
356 | ||
357 | test_expect_success 'fetch mirror respects specific branches' ' | |
358 | (cd mirror-fetch/track && | |
359 | git fetch parent && | |
360 | git rev-parse --verify refs/heads/new && | |
361 | test_must_fail git rev-parse --verify refs/heads/renamed | |
362 | ) | |
363 | ' | |
364 | ||
365 | test_expect_success 'add --mirror=push' ' | |
366 | mkdir mirror-push && | |
367 | git init --bare mirror-push/public && | |
368 | git init mirror-push/private && | |
369 | (cd mirror-push/private && | |
370 | test_commit one && | |
371 | git remote add --mirror=push public ../public | |
372 | ) | |
373 | ' | |
374 | ||
375 | test_expect_success 'push mirrors act as mirrors during push' ' | |
376 | (cd mirror-push/private && | |
377 | git branch new && | |
378 | git branch -m master renamed && | |
379 | git push public | |
380 | ) && | |
381 | (cd mirror-push/private && | |
382 | git rev-parse --verify refs/heads/new && | |
383 | git rev-parse --verify refs/heads/renamed && | |
384 | test_must_fail git rev-parse --verify refs/heads/master | |
385 | ) | |
386 | ' | |
387 | ||
388 | test_expect_success 'push mirrors do not act as mirrors during fetch' ' | |
389 | (cd mirror-push/public && | |
390 | git branch -m renamed renamed2 && | |
391 | git symbolic-ref HEAD refs/heads/renamed2 | |
392 | ) && | |
393 | (cd mirror-push/private && | |
394 | git fetch public && | |
395 | git rev-parse --verify refs/heads/renamed && | |
396 | test_must_fail git rev-parse --verify refs/heads/renamed2 | |
397 | ) | |
398 | ' | |
399 | ||
400 | test_expect_success 'push mirrors do not allow you to specify refs' ' | |
401 | git init mirror-push/track && | |
402 | (cd mirror-push/track && | |
403 | test_must_fail git remote add --mirror=push -t new public ../public | |
404 | ) | |
405 | ' | |
406 | ||
407 | test_expect_success 'add alt && prune' ' | |
408 | (mkdir alttst && | |
409 | cd alttst && | |
410 | git init && | |
411 | git remote add -f origin ../one && | |
412 | git config remote.alt.url ../one && | |
413 | git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") && | |
414 | (cd one && | |
415 | git branch -m side side2) && | |
416 | (cd alttst && | |
417 | git rev-parse --verify refs/remotes/origin/side && | |
418 | test_must_fail git rev-parse --verify refs/remotes/origin/side2 && | |
419 | git fetch alt && | |
420 | git remote prune alt && | |
421 | test_must_fail git rev-parse --verify refs/remotes/origin/side && | |
422 | git rev-parse --verify refs/remotes/origin/side2) | |
423 | ' | |
424 | ||
425 | cat >test/expect <<\EOF | |
426 | some-tag | |
427 | EOF | |
428 | ||
429 | test_expect_success 'add with reachable tags (default)' ' | |
430 | (cd one && | |
431 | >foobar && | |
432 | git add foobar && | |
433 | git commit -m "Foobar" && | |
434 | git tag -a -m "Foobar tag" foobar-tag && | |
435 | git reset --hard HEAD~1 && | |
436 | git tag -a -m "Some tag" some-tag) && | |
437 | (mkdir add-tags && | |
438 | cd add-tags && | |
439 | git init && | |
440 | git remote add -f origin ../one && | |
441 | git tag -l some-tag >../test/output && | |
442 | git tag -l foobar-tag >>../test/output && | |
443 | test_must_fail git config remote.origin.tagopt) && | |
444 | test_cmp test/expect test/output | |
445 | ' | |
446 | ||
447 | cat >test/expect <<\EOF | |
448 | some-tag | |
449 | foobar-tag | |
450 | --tags | |
451 | EOF | |
452 | ||
453 | test_expect_success 'add --tags' ' | |
454 | (rm -rf add-tags && | |
455 | mkdir add-tags && | |
456 | cd add-tags && | |
457 | git init && | |
458 | git remote add -f --tags origin ../one && | |
459 | git tag -l some-tag >../test/output && | |
460 | git tag -l foobar-tag >>../test/output && | |
461 | git config remote.origin.tagopt >>../test/output) && | |
462 | test_cmp test/expect test/output | |
463 | ' | |
464 | ||
465 | cat >test/expect <<\EOF | |
466 | --no-tags | |
467 | EOF | |
468 | ||
469 | test_expect_success 'add --no-tags' ' | |
470 | (rm -rf add-tags && | |
471 | mkdir add-no-tags && | |
472 | cd add-no-tags && | |
473 | git init && | |
474 | git remote add -f --no-tags origin ../one && | |
475 | git tag -l some-tag >../test/output && | |
476 | git tag -l foobar-tag >../test/output && | |
477 | git config remote.origin.tagopt >>../test/output) && | |
478 | (cd one && | |
479 | git tag -d some-tag foobar-tag) && | |
480 | test_cmp test/expect test/output | |
481 | ' | |
482 | ||
483 | test_expect_success 'reject --no-no-tags' ' | |
484 | (cd add-no-tags && | |
485 | test_must_fail git remote add -f --no-no-tags neworigin ../one) | |
486 | ' | |
487 | ||
488 | cat > one/expect << EOF | |
489 | apis/master | |
490 | apis/side | |
491 | drosophila/another | |
492 | drosophila/master | |
493 | drosophila/side | |
494 | EOF | |
495 | ||
496 | test_expect_success 'update' ' | |
497 | ||
498 | (cd one && | |
499 | git remote add drosophila ../two && | |
500 | git remote add apis ../mirror && | |
501 | git remote update && | |
502 | git branch -r > output && | |
503 | test_cmp expect output) | |
504 | ||
505 | ' | |
506 | ||
507 | cat > one/expect << EOF | |
508 | drosophila/another | |
509 | drosophila/master | |
510 | drosophila/side | |
511 | manduca/master | |
512 | manduca/side | |
513 | megaloprepus/master | |
514 | megaloprepus/side | |
515 | EOF | |
516 | ||
517 | test_expect_success 'update with arguments' ' | |
518 | ||
519 | (cd one && | |
520 | for b in $(git branch -r) | |
521 | do | |
522 | git branch -r -d $b || break | |
523 | done && | |
524 | git remote add manduca ../mirror && | |
525 | git remote add megaloprepus ../mirror && | |
526 | git config remotes.phobaeticus "drosophila megaloprepus" && | |
527 | git config remotes.titanus manduca && | |
528 | git remote update phobaeticus titanus && | |
529 | git branch -r > output && | |
530 | test_cmp expect output) | |
531 | ||
532 | ' | |
533 | ||
534 | test_expect_success 'update --prune' ' | |
535 | ||
536 | (cd one && | |
537 | git branch -m side2 side3) && | |
538 | (cd test && | |
539 | git remote update --prune && | |
540 | (cd ../one && git branch -m side3 side2) && | |
541 | git rev-parse refs/remotes/origin/side3 && | |
542 | test_must_fail git rev-parse refs/remotes/origin/side2) | |
543 | ' | |
544 | ||
545 | cat > one/expect << EOF | |
546 | apis/master | |
547 | apis/side | |
548 | manduca/master | |
549 | manduca/side | |
550 | megaloprepus/master | |
551 | megaloprepus/side | |
552 | EOF | |
553 | ||
554 | test_expect_success 'update default' ' | |
555 | ||
556 | (cd one && | |
557 | for b in $(git branch -r) | |
558 | do | |
559 | git branch -r -d $b || break | |
560 | done && | |
561 | git config remote.drosophila.skipDefaultUpdate true && | |
562 | git remote update default && | |
563 | git branch -r > output && | |
564 | test_cmp expect output) | |
565 | ||
566 | ' | |
567 | ||
568 | cat > one/expect << EOF | |
569 | drosophila/another | |
570 | drosophila/master | |
571 | drosophila/side | |
572 | EOF | |
573 | ||
574 | test_expect_success 'update default (overridden, with funny whitespace)' ' | |
575 | ||
576 | (cd one && | |
577 | for b in $(git branch -r) | |
578 | do | |
579 | git branch -r -d $b || break | |
580 | done && | |
581 | git config remotes.default "$(printf "\t drosophila \n")" && | |
582 | git remote update default && | |
583 | git branch -r > output && | |
584 | test_cmp expect output) | |
585 | ||
586 | ' | |
587 | ||
588 | test_expect_success 'update (with remotes.default defined)' ' | |
589 | ||
590 | (cd one && | |
591 | for b in $(git branch -r) | |
592 | do | |
593 | git branch -r -d $b || break | |
594 | done && | |
595 | git config remotes.default "drosophila" && | |
596 | git remote update && | |
597 | git branch -r > output && | |
598 | test_cmp expect output) | |
599 | ||
600 | ' | |
601 | ||
602 | test_expect_success '"remote show" does not show symbolic refs' ' | |
603 | ||
604 | git clone one three && | |
605 | (cd three && | |
606 | git remote show origin > output && | |
607 | ! grep "^ *HEAD$" < output && | |
608 | ! grep -i stale < output) | |
609 | ||
610 | ' | |
611 | ||
612 | test_expect_success 'reject adding remote with an invalid name' ' | |
613 | ||
614 | test_must_fail git remote add some:url desired-name | |
615 | ||
616 | ' | |
617 | ||
618 | # The first three test if the tracking branches are properly renamed, | |
619 | # the last two ones check if the config is updated. | |
620 | ||
621 | test_expect_success 'rename a remote' ' | |
622 | ||
623 | git clone one four && | |
624 | (cd four && | |
625 | git remote rename origin upstream && | |
626 | rmdir .git/refs/remotes/origin && | |
627 | test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" && | |
628 | test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" && | |
629 | test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" && | |
630 | test "$(git config branch.master.remote)" = "upstream") | |
631 | ||
632 | ' | |
633 | ||
634 | cat > remotes_origin << EOF | |
635 | URL: $(pwd)/one | |
636 | Push: refs/heads/master:refs/heads/upstream | |
637 | Pull: refs/heads/master:refs/heads/origin | |
638 | EOF | |
639 | ||
640 | test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' ' | |
641 | git clone one five && | |
642 | origin_url=$(pwd)/one && | |
643 | (cd five && | |
644 | git remote rm origin && | |
645 | mkdir -p .git/remotes && | |
646 | cat ../remotes_origin > .git/remotes/origin && | |
647 | git remote rename origin origin && | |
648 | ! test -f .git/remotes/origin && | |
649 | test "$(git config remote.origin.url)" = "$origin_url" && | |
650 | test "$(git config remote.origin.push)" = "refs/heads/master:refs/heads/upstream" && | |
651 | test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin") | |
652 | ' | |
653 | ||
654 | test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' ' | |
655 | git clone one six && | |
656 | origin_url=$(pwd)/one && | |
657 | (cd six && | |
658 | git remote rm origin && | |
659 | echo "$origin_url" > .git/branches/origin && | |
660 | git remote rename origin origin && | |
661 | ! test -f .git/branches/origin && | |
662 | test "$(git config remote.origin.url)" = "$origin_url" && | |
663 | test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin") | |
664 | ' | |
665 | ||
666 | test_expect_success 'remote prune to cause a dangling symref' ' | |
667 | git clone one seven && | |
668 | ( | |
669 | cd one && | |
670 | git checkout side2 && | |
671 | git branch -D master | |
672 | ) && | |
673 | ( | |
674 | cd seven && | |
675 | git remote prune origin | |
676 | ) >err 2>&1 && | |
677 | grep "has become dangling" err && | |
678 | ||
679 | : And the dangling symref will not cause other annoying errors && | |
680 | ( | |
681 | cd seven && | |
682 | git branch -a | |
683 | ) 2>err && | |
684 | ! grep "points nowhere" err && | |
685 | ( | |
686 | cd seven && | |
687 | test_must_fail git branch nomore origin | |
688 | ) 2>err && | |
689 | grep "dangling symref" err | |
690 | ' | |
691 | ||
692 | test_expect_success 'show empty remote' ' | |
693 | ||
694 | test_create_repo empty && | |
695 | git clone empty empty-clone && | |
696 | ( | |
697 | cd empty-clone && | |
698 | git remote show origin | |
699 | ) | |
700 | ' | |
701 | ||
702 | test_expect_success 'remote set-branches requires a remote' ' | |
703 | test_must_fail git remote set-branches && | |
704 | test_must_fail git remote set-branches --add | |
705 | ' | |
706 | ||
707 | test_expect_success 'remote set-branches' ' | |
708 | echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial && | |
709 | sort <<-\EOF >expect.add && | |
710 | +refs/heads/*:refs/remotes/scratch/* | |
711 | +refs/heads/other:refs/remotes/scratch/other | |
712 | EOF | |
713 | sort <<-\EOF >expect.replace && | |
714 | +refs/heads/maint:refs/remotes/scratch/maint | |
715 | +refs/heads/master:refs/remotes/scratch/master | |
716 | +refs/heads/next:refs/remotes/scratch/next | |
717 | EOF | |
718 | sort <<-\EOF >expect.add-two && | |
719 | +refs/heads/maint:refs/remotes/scratch/maint | |
720 | +refs/heads/master:refs/remotes/scratch/master | |
721 | +refs/heads/next:refs/remotes/scratch/next | |
722 | +refs/heads/pu:refs/remotes/scratch/pu | |
723 | +refs/heads/t/topic:refs/remotes/scratch/t/topic | |
724 | EOF | |
725 | sort <<-\EOF >expect.setup-ffonly && | |
726 | refs/heads/master:refs/remotes/scratch/master | |
727 | +refs/heads/next:refs/remotes/scratch/next | |
728 | EOF | |
729 | sort <<-\EOF >expect.respect-ffonly && | |
730 | refs/heads/master:refs/remotes/scratch/master | |
731 | +refs/heads/next:refs/remotes/scratch/next | |
732 | +refs/heads/pu:refs/remotes/scratch/pu | |
733 | EOF | |
734 | ||
735 | git clone .git/ setbranches && | |
736 | ( | |
737 | cd setbranches && | |
738 | git remote rename origin scratch && | |
739 | git config --get-all remote.scratch.fetch >config-result && | |
740 | sort <config-result >../actual.initial && | |
741 | ||
742 | git remote set-branches scratch --add other && | |
743 | git config --get-all remote.scratch.fetch >config-result && | |
744 | sort <config-result >../actual.add && | |
745 | ||
746 | git remote set-branches scratch maint master next && | |
747 | git config --get-all remote.scratch.fetch >config-result && | |
748 | sort <config-result >../actual.replace && | |
749 | ||
750 | git remote set-branches --add scratch pu t/topic && | |
751 | git config --get-all remote.scratch.fetch >config-result && | |
752 | sort <config-result >../actual.add-two && | |
753 | ||
754 | git config --unset-all remote.scratch.fetch && | |
755 | git config remote.scratch.fetch \ | |
756 | refs/heads/master:refs/remotes/scratch/master && | |
757 | git config --add remote.scratch.fetch \ | |
758 | +refs/heads/next:refs/remotes/scratch/next && | |
759 | git config --get-all remote.scratch.fetch >config-result && | |
760 | sort <config-result >../actual.setup-ffonly && | |
761 | ||
762 | git remote set-branches --add scratch pu && | |
763 | git config --get-all remote.scratch.fetch >config-result && | |
764 | sort <config-result >../actual.respect-ffonly | |
765 | ) && | |
766 | test_cmp expect.initial actual.initial && | |
767 | test_cmp expect.add actual.add && | |
768 | test_cmp expect.replace actual.replace && | |
769 | test_cmp expect.add-two actual.add-two && | |
770 | test_cmp expect.setup-ffonly actual.setup-ffonly && | |
771 | test_cmp expect.respect-ffonly actual.respect-ffonly | |
772 | ' | |
773 | ||
774 | test_expect_success 'remote set-branches with --mirror' ' | |
775 | echo "+refs/*:refs/*" >expect.initial && | |
776 | echo "+refs/heads/master:refs/heads/master" >expect.replace && | |
777 | git clone --mirror .git/ setbranches-mirror && | |
778 | ( | |
779 | cd setbranches-mirror && | |
780 | git remote rename origin scratch && | |
781 | git config --get-all remote.scratch.fetch >../actual.initial && | |
782 | ||
783 | git remote set-branches scratch heads/master && | |
784 | git config --get-all remote.scratch.fetch >../actual.replace | |
785 | ) && | |
786 | test_cmp expect.initial actual.initial && | |
787 | test_cmp expect.replace actual.replace | |
788 | ' | |
789 | ||
790 | test_expect_success 'new remote' ' | |
791 | git remote add someremote foo && | |
792 | echo foo >expect && | |
793 | git config --get-all remote.someremote.url >actual && | |
794 | cmp expect actual | |
795 | ' | |
796 | ||
797 | test_expect_success 'remote set-url bar' ' | |
798 | git remote set-url someremote bar && | |
799 | echo bar >expect && | |
800 | git config --get-all remote.someremote.url >actual && | |
801 | cmp expect actual | |
802 | ' | |
803 | ||
804 | test_expect_success 'remote set-url baz bar' ' | |
805 | git remote set-url someremote baz bar && | |
806 | echo baz >expect && | |
807 | git config --get-all remote.someremote.url >actual && | |
808 | cmp expect actual | |
809 | ' | |
810 | ||
811 | test_expect_success 'remote set-url zot bar' ' | |
812 | test_must_fail git remote set-url someremote zot bar && | |
813 | echo baz >expect && | |
814 | git config --get-all remote.someremote.url >actual && | |
815 | cmp expect actual | |
816 | ' | |
817 | ||
818 | test_expect_success 'remote set-url --push zot baz' ' | |
819 | test_must_fail git remote set-url --push someremote zot baz && | |
820 | echo "YYY" >expect && | |
821 | echo baz >>expect && | |
822 | test_must_fail 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 | |
826 | ' | |
827 | ||
828 | test_expect_success 'remote set-url --push zot' ' | |
829 | git remote set-url --push someremote zot && | |
830 | echo zot >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 | |
837 | ' | |
838 | ||
839 | test_expect_success 'remote set-url --push qux zot' ' | |
840 | git remote set-url --push someremote qux zot && | |
841 | echo qux >expect && | |
842 | echo "YYY" >>expect && | |
843 | echo baz >>expect && | |
844 | git config --get-all remote.someremote.pushurl >actual && | |
845 | echo "YYY" >>actual && | |
846 | git config --get-all remote.someremote.url >>actual && | |
847 | cmp expect actual | |
848 | ' | |
849 | ||
850 | test_expect_success 'remote set-url --push foo qu+x' ' | |
851 | git remote set-url --push someremote foo qu+x && | |
852 | echo foo >expect && | |
853 | echo "YYY" >>expect && | |
854 | echo baz >>expect && | |
855 | git config --get-all remote.someremote.pushurl >actual && | |
856 | echo "YYY" >>actual && | |
857 | git config --get-all remote.someremote.url >>actual && | |
858 | cmp expect actual | |
859 | ' | |
860 | ||
861 | test_expect_success 'remote set-url --push --add aaa' ' | |
862 | git remote set-url --push --add someremote aaa && | |
863 | echo foo >expect && | |
864 | echo aaa >>expect && | |
865 | echo "YYY" >>expect && | |
866 | echo baz >>expect && | |
867 | git config --get-all remote.someremote.pushurl >actual && | |
868 | echo "YYY" >>actual && | |
869 | git config --get-all remote.someremote.url >>actual && | |
870 | cmp expect actual | |
871 | ' | |
872 | ||
873 | test_expect_success 'remote set-url --push bar aaa' ' | |
874 | git remote set-url --push someremote bar aaa && | |
875 | echo foo >expect && | |
876 | echo bar >>expect && | |
877 | echo "YYY" >>expect && | |
878 | echo baz >>expect && | |
879 | git config --get-all remote.someremote.pushurl >actual && | |
880 | echo "YYY" >>actual && | |
881 | git config --get-all remote.someremote.url >>actual && | |
882 | cmp expect actual | |
883 | ' | |
884 | ||
885 | test_expect_success 'remote set-url --push --delete bar' ' | |
886 | git remote set-url --push --delete someremote bar && | |
887 | echo foo >expect && | |
888 | echo "YYY" >>expect && | |
889 | echo baz >>expect && | |
890 | git config --get-all remote.someremote.pushurl >actual && | |
891 | echo "YYY" >>actual && | |
892 | git config --get-all remote.someremote.url >>actual && | |
893 | cmp expect actual | |
894 | ' | |
895 | ||
896 | test_expect_success 'remote set-url --push --delete foo' ' | |
897 | git remote set-url --push --delete someremote foo && | |
898 | echo "YYY" >expect && | |
899 | echo baz >>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 | |
904 | ' | |
905 | ||
906 | test_expect_success 'remote set-url --add bbb' ' | |
907 | git remote set-url --add someremote bbb && | |
908 | echo "YYY" >expect && | |
909 | echo baz >>expect && | |
910 | echo bbb >>expect && | |
911 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
912 | echo "YYY" >>actual && | |
913 | git config --get-all remote.someremote.url >>actual && | |
914 | cmp expect actual | |
915 | ' | |
916 | ||
917 | test_expect_success 'remote set-url --delete .*' ' | |
918 | test_must_fail git remote set-url --delete someremote .\* && | |
919 | echo "YYY" >expect && | |
920 | echo baz >>expect && | |
921 | echo bbb >>expect && | |
922 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
923 | echo "YYY" >>actual && | |
924 | git config --get-all remote.someremote.url >>actual && | |
925 | cmp expect actual | |
926 | ' | |
927 | ||
928 | test_expect_success 'remote set-url --delete bbb' ' | |
929 | git remote set-url --delete someremote bbb && | |
930 | echo "YYY" >expect && | |
931 | echo baz >>expect && | |
932 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
933 | echo "YYY" >>actual && | |
934 | git config --get-all remote.someremote.url >>actual && | |
935 | cmp expect actual | |
936 | ' | |
937 | ||
938 | test_expect_success 'remote set-url --delete baz' ' | |
939 | test_must_fail git remote set-url --delete someremote baz && | |
940 | echo "YYY" >expect && | |
941 | echo baz >>expect && | |
942 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
943 | echo "YYY" >>actual && | |
944 | git config --get-all remote.someremote.url >>actual && | |
945 | cmp expect actual | |
946 | ' | |
947 | ||
948 | test_expect_success 'remote set-url --add ccc' ' | |
949 | git remote set-url --add someremote ccc && | |
950 | echo "YYY" >expect && | |
951 | echo baz >>expect && | |
952 | echo ccc >>expect && | |
953 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
954 | echo "YYY" >>actual && | |
955 | git config --get-all remote.someremote.url >>actual && | |
956 | cmp expect actual | |
957 | ' | |
958 | ||
959 | test_expect_success 'remote set-url --delete baz' ' | |
960 | git remote set-url --delete someremote baz && | |
961 | echo "YYY" >expect && | |
962 | echo ccc >>expect && | |
963 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
964 | echo "YYY" >>actual && | |
965 | git config --get-all remote.someremote.url >>actual && | |
966 | cmp expect actual | |
967 | ' | |
968 | ||
969 | test_done |