3 test_description='git remote porcelain-ish'
14 git commit -m "Initial" &&
15 git checkout -b side &&
19 git commit -m "Second" &&
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
30 check_remote_track () {
31 actual=$(git remote show "$1" | sed -ne 's|^ \(.*\) tracked$|\1|p')
33 tokens_match "$*" "$actual"
36 check_tracking_branch () {
38 r=$(git for-each-ref "--format=%(refname)" |
39 sed -ne "s|^refs/remotes/$1/||p") &&
41 tokens_match "$*" "$r"
44 test_expect_success setup '
46 setup_repository one &&
47 setup_repository two &&
49 cd two && git branch another
55 test_expect_success 'remote information for the origin' '
58 tokens_match origin "$(git remote)" &&
59 check_remote_track origin master side &&
60 check_tracking_branch origin HEAD master side
64 test_expect_success 'add another remote' '
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 &&
76 test_cmp expect actual
80 test_expect_success 'remote forces tracking branches' '
83 case `git config remote.second.fetch` in
90 test_expect_success 'remove remote' '
93 git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master &&
98 test_expect_success 'remove remote' '
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 &&
106 test_cmp expect actual
110 test_expect_success 'remove remote protects non-remote branches' '
114 Note: A non-remote branch was not removed; to delete it, use:
119 Note: Non-remote branches were not removed; to delete them, use:
120 git branch -d foobranch
125 git config --add remote.oops.fetch "+refs/*:refs/*" &&
126 git remote rm oops 2>actual1 &&
127 git branch foobranch &&
128 git config --add remote.oops.fetch "+refs/*:refs/*" &&
129 git remote rm oops 2>actual2 &&
130 git branch -d foobranch &&
132 test_cmp expect1 actual1 &&
133 test_cmp expect2 actual2
137 cat > test/expect << EOF
139 Fetch URL: $(pwd)/one
143 master new (next fetch will store in remotes/origin)
145 Local branches configured for 'git pull':
146 ahead merges with remote master
147 master merges with remote master
148 octopus merges with remote topic-a
149 and with remote topic-b
150 and with remote topic-c
151 rebase rebases onto remote master
152 Local refs configured for 'git push':
153 master pushes to master (local out of date)
154 master pushes to upstream (create)
158 HEAD branch (remote HEAD is ambiguous, may be one of the following):
161 Local refs configured for 'git push':
162 ahead forces to master (fast-forwardable)
163 master pushes to another (up to date)
166 test_expect_success 'show' '
168 git config --add remote.origin.fetch refs/heads/master:refs/heads/upstream &&
170 git checkout -b ahead origin/master &&
173 git commit -m update file &&
174 git checkout master &&
175 git branch --track octopus origin/master &&
176 git branch --track rebase origin/master &&
177 git branch -d -r origin/master &&
178 git config --add remote.two.url ../two &&
179 git config --add remote.two.pushurl ../three &&
180 git config branch.rebase.rebase true &&
181 git config branch.octopus.merge "topic-a topic-b topic-c" &&
185 git commit -m update file) &&
186 git config --add remote.origin.push : &&
187 git config --add remote.origin.push refs/heads/master:refs/heads/upstream &&
188 git config --add remote.origin.push +refs/tags/lastbackup &&
189 git config --add remote.two.push +refs/heads/ahead:refs/heads/master &&
190 git config --add remote.two.push refs/heads/master:refs/heads/another &&
191 git remote show origin two > output &&
192 git branch -d rebase octopus &&
193 test_cmp expect output)
196 cat > test/expect << EOF
198 Fetch URL: $(pwd)/one
200 HEAD branch: (not queried)
201 Remote branches: (status not queried)
204 Local branches configured for 'git pull':
205 ahead merges with remote master
206 master merges with remote master
207 Local refs configured for 'git push' (status not queried):
208 (matching) pushes to (matching)
209 refs/heads/master pushes to refs/heads/upstream
210 refs/tags/lastbackup forces to refs/tags/lastbackup
213 test_expect_success 'show -n' '
214 (mv one one.unreachable &&
216 git remote show -n origin > output &&
217 mv ../one.unreachable ../one &&
218 test_cmp expect output)
221 test_expect_success 'prune' '
223 git branch -m side side2) &&
226 git remote prune origin &&
227 git rev-parse refs/remotes/origin/side2 &&
228 test_must_fail git rev-parse refs/remotes/origin/side)
231 test_expect_success 'set-head --delete' '
233 git symbolic-ref refs/remotes/origin/HEAD &&
234 git remote set-head --delete origin &&
235 test_must_fail git symbolic-ref refs/remotes/origin/HEAD)
238 test_expect_success 'set-head --auto' '
240 git remote set-head --auto origin &&
241 echo refs/remotes/origin/master >expect &&
242 git symbolic-ref refs/remotes/origin/HEAD >output &&
243 test_cmp expect output
247 cat >test/expect <<EOF
248 error: Multiple remote HEAD branches. Please choose one explicitly with:
249 git remote set-head two another
250 git remote set-head two master
253 test_expect_success 'set-head --auto fails w/multiple HEADs' '
255 test_must_fail git remote set-head --auto two >output 2>&1 &&
256 test_cmp expect output)
259 cat >test/expect <<EOF
260 refs/remotes/origin/side2
263 test_expect_success 'set-head explicit' '
265 git remote set-head origin side2 &&
266 git symbolic-ref refs/remotes/origin/HEAD >output &&
267 git remote set-head origin master &&
268 test_cmp expect output)
271 cat > test/expect << EOF
274 * [would prune] origin/side2
277 test_expect_success 'prune --dry-run' '
279 git branch -m side2 side) &&
281 git remote prune --dry-run origin > output &&
282 git rev-parse refs/remotes/origin/side2 &&
283 test_must_fail git rev-parse refs/remotes/origin/side &&
285 git branch -m side side2) &&
286 test_cmp expect output)
289 test_expect_success 'add --mirror && prune' '
293 git remote add --mirror -f origin ../one) &&
295 git branch -m side2 side) &&
297 git rev-parse --verify refs/heads/side2 &&
298 test_must_fail git rev-parse --verify refs/heads/side &&
300 git remote prune origin &&
301 test_must_fail git rev-parse --verify refs/heads/side2 &&
302 git rev-parse --verify refs/heads/side)
305 test_expect_success 'add alt && prune' '
309 git remote add -f origin ../one &&
310 git config remote.alt.url ../one &&
311 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") &&
313 git branch -m side side2) &&
315 git rev-parse --verify refs/remotes/origin/side &&
316 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
318 git remote prune alt &&
319 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
320 git rev-parse --verify refs/remotes/origin/side2)
323 cat >test/expect <<\EOF
327 test_expect_success 'add with reachable tags (default)' '
331 git commit -m "Foobar" &&
332 git tag -a -m "Foobar tag" foobar-tag &&
333 git reset --hard HEAD~1 &&
334 git tag -a -m "Some tag" some-tag) &&
338 git remote add -f origin ../one &&
339 git tag -l some-tag >../test/output &&
340 git tag -l foobar-tag >>../test/output &&
341 test_must_fail git config remote.origin.tagopt) &&
342 test_cmp test/expect test/output
345 cat >test/expect <<\EOF
351 test_expect_success 'add --tags' '
356 git remote add -f --tags origin ../one &&
357 git tag -l some-tag >../test/output &&
358 git tag -l foobar-tag >>../test/output &&
359 git config remote.origin.tagopt >>../test/output) &&
360 test_cmp test/expect test/output
363 cat >test/expect <<\EOF
367 test_expect_success 'add --no-tags' '
372 git remote add -f --no-tags origin ../one &&
373 git tag -l some-tag >../test/output &&
374 git tag -l foobar-tag >../test/output &&
375 git config remote.origin.tagopt >>../test/output) &&
377 git tag -d some-tag foobar-tag) &&
378 test_cmp test/expect test/output
381 test_expect_success 'reject --no-no-tags' '
383 test_must_fail git remote add -f --no-no-tags neworigin ../one)
386 cat > one/expect << EOF
394 test_expect_success 'update' '
397 git remote add drosophila ../two &&
398 git remote add apis ../mirror &&
400 git branch -r > output &&
401 test_cmp expect output)
405 cat > one/expect << EOF
415 test_expect_success 'update with arguments' '
418 for b in $(git branch -r)
420 git branch -r -d $b || break
422 git remote add manduca ../mirror &&
423 git remote add megaloprepus ../mirror &&
424 git config remotes.phobaeticus "drosophila megaloprepus" &&
425 git config remotes.titanus manduca &&
426 git remote update phobaeticus titanus &&
427 git branch -r > output &&
428 test_cmp expect output)
432 test_expect_success 'update --prune' '
435 git branch -m side2 side3) &&
437 git remote update --prune &&
438 (cd ../one && git branch -m side3 side2)
439 git rev-parse refs/remotes/origin/side3 &&
440 test_must_fail git rev-parse refs/remotes/origin/side2)
443 cat > one/expect << EOF
452 test_expect_success 'update default' '
455 for b in $(git branch -r)
457 git branch -r -d $b || break
459 git config remote.drosophila.skipDefaultUpdate true &&
460 git remote update default &&
461 git branch -r > output &&
462 test_cmp expect output)
466 cat > one/expect << EOF
472 test_expect_success 'update default (overridden, with funny whitespace)' '
475 for b in $(git branch -r)
477 git branch -r -d $b || break
479 git config remotes.default "$(printf "\t drosophila \n")" &&
480 git remote update default &&
481 git branch -r > output &&
482 test_cmp expect output)
486 test_expect_success 'update (with remotes.default defined)' '
489 for b in $(git branch -r)
491 git branch -r -d $b || break
493 git config remotes.default "drosophila" &&
495 git branch -r > output &&
496 test_cmp expect output)
500 test_expect_success '"remote show" does not show symbolic refs' '
502 git clone one three &&
504 git remote show origin > output &&
505 ! grep "^ *HEAD$" < output &&
506 ! grep -i stale < output)
510 test_expect_success 'reject adding remote with an invalid name' '
512 test_must_fail git remote add some:url desired-name
516 # The first three test if the tracking branches are properly renamed,
517 # the last two ones check if the config is updated.
519 test_expect_success 'rename a remote' '
521 git clone one four &&
523 git remote rename origin upstream &&
524 rmdir .git/refs/remotes/origin &&
525 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
526 test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
527 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
528 test "$(git config branch.master.remote)" = "upstream")
532 cat > remotes_origin << EOF
534 Push: refs/heads/master:refs/heads/upstream
535 Pull: refs/heads/master:refs/heads/origin
538 test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
539 git clone one five &&
540 origin_url=$(pwd)/one &&
542 git remote rm origin &&
543 mkdir -p .git/remotes &&
544 cat ../remotes_origin > .git/remotes/origin &&
545 git remote rename origin origin &&
546 ! test -f .git/remotes/origin &&
547 test "$(git config remote.origin.url)" = "$origin_url" &&
548 test "$(git config remote.origin.push)" = "refs/heads/master:refs/heads/upstream" &&
549 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
552 test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
554 origin_url=$(pwd)/one &&
556 git remote rm origin &&
557 echo "$origin_url" > .git/branches/origin &&
558 git remote rename origin origin &&
559 ! test -f .git/branches/origin &&
560 test "$(git config remote.origin.url)" = "$origin_url" &&
561 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
564 test_expect_success 'remote prune to cause a dangling symref' '
565 git clone one seven &&
568 git checkout side2 &&
573 git remote prune origin
575 grep "has become dangling" err &&
577 : And the dangling symref will not cause other annoying errors &&
582 ! grep "points nowhere" err &&
585 test_must_fail git branch nomore origin
587 grep "dangling symref" err
590 test_expect_success 'show empty remote' '
592 test_create_repo empty &&
593 git clone empty empty-clone &&
596 git remote show origin
600 test_expect_success 'new remote' '
601 git remote add someremote foo &&
603 git config --get-all remote.someremote.url >actual &&
607 test_expect_success 'remote set-url bar' '
608 git remote set-url someremote bar &&
610 git config --get-all remote.someremote.url >actual &&
614 test_expect_success 'remote set-url baz bar' '
615 git remote set-url someremote baz bar &&
617 git config --get-all remote.someremote.url >actual &&
621 test_expect_success 'remote set-url zot bar' '
622 test_must_fail git remote set-url someremote zot bar &&
624 git config --get-all remote.someremote.url >actual &&
628 test_expect_success 'remote set-url --push zot baz' '
629 test_must_fail git remote set-url --push someremote zot baz &&
630 echo "YYY" >expect &&
632 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
633 echo "YYY" >>actual &&
634 git config --get-all remote.someremote.url >>actual &&
638 test_expect_success 'remote set-url --push zot' '
639 git remote set-url --push someremote zot &&
641 echo "YYY" >>expect &&
643 git config --get-all remote.someremote.pushurl >actual &&
644 echo "YYY" >>actual &&
645 git config --get-all remote.someremote.url >>actual &&
649 test_expect_success 'remote set-url --push qux zot' '
650 git remote set-url --push someremote qux zot &&
652 echo "YYY" >>expect &&
654 git config --get-all remote.someremote.pushurl >actual &&
655 echo "YYY" >>actual &&
656 git config --get-all remote.someremote.url >>actual &&
660 test_expect_success 'remote set-url --push foo qu+x' '
661 git remote set-url --push someremote foo qu+x &&
663 echo "YYY" >>expect &&
665 git config --get-all remote.someremote.pushurl >actual &&
666 echo "YYY" >>actual &&
667 git config --get-all remote.someremote.url >>actual &&
671 test_expect_success 'remote set-url --push --add aaa' '
672 git remote set-url --push --add someremote aaa &&
675 echo "YYY" >>expect &&
677 git config --get-all remote.someremote.pushurl >actual &&
678 echo "YYY" >>actual &&
679 git config --get-all remote.someremote.url >>actual &&
683 test_expect_success 'remote set-url --push bar aaa' '
684 git remote set-url --push someremote bar aaa &&
687 echo "YYY" >>expect &&
689 git config --get-all remote.someremote.pushurl >actual &&
690 echo "YYY" >>actual &&
691 git config --get-all remote.someremote.url >>actual &&
695 test_expect_success 'remote set-url --push --delete bar' '
696 git remote set-url --push --delete someremote bar &&
698 echo "YYY" >>expect &&
700 git config --get-all remote.someremote.pushurl >actual &&
701 echo "YYY" >>actual &&
702 git config --get-all remote.someremote.url >>actual &&
706 test_expect_success 'remote set-url --push --delete foo' '
707 git remote set-url --push --delete someremote foo &&
708 echo "YYY" >expect &&
710 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
711 echo "YYY" >>actual &&
712 git config --get-all remote.someremote.url >>actual &&
716 test_expect_success 'remote set-url --add bbb' '
717 git remote set-url --add someremote bbb &&
718 echo "YYY" >expect &&
721 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
722 echo "YYY" >>actual &&
723 git config --get-all remote.someremote.url >>actual &&
727 test_expect_success 'remote set-url --delete .*' '
728 test_must_fail git remote set-url --delete someremote .\* &&
729 echo "YYY" >expect &&
732 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
733 echo "YYY" >>actual &&
734 git config --get-all remote.someremote.url >>actual &&
738 test_expect_success 'remote set-url --delete bbb' '
739 git remote set-url --delete someremote bbb &&
740 echo "YYY" >expect &&
742 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
743 echo "YYY" >>actual &&
744 git config --get-all remote.someremote.url >>actual &&
748 test_expect_success 'remote set-url --delete baz' '
749 test_must_fail git remote set-url --delete someremote baz &&
750 echo "YYY" >expect &&
752 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
753 echo "YYY" >>actual &&
754 git config --get-all remote.someremote.url >>actual &&
758 test_expect_success 'remote set-url --add ccc' '
759 git remote set-url --add someremote ccc &&
760 echo "YYY" >expect &&
763 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
764 echo "YYY" >>actual &&
765 git config --get-all remote.someremote.url >>actual &&
769 test_expect_success 'remote set-url --delete baz' '
770 git remote set-url --delete someremote baz &&
771 echo "YYY" >expect &&
773 test_must_fail git config --get-all remote.someremote.pushurl >actual &&
774 echo "YYY" >>actual &&
775 git config --get-all remote.someremote.url >>actual &&