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:
118 Note: Non-remote branches were not removed; to delete them, use:
119 git branch -d foobranch
124 git config --add remote.oops.fetch "+refs/*:refs/*" &&
125 git remote rm oops 2>actual1 &&
126 git branch foobranch &&
127 git config --add remote.oops.fetch "+refs/*:refs/*" &&
128 git remote rm oops 2>actual2 &&
129 git branch -d foobranch &&
131 test_cmp expect1 actual1 &&
132 test_cmp expect2 actual2
136 cat > test
/expect
<< EOF
141 master new (next fetch will store in remotes/origin)
143 Local branches configured for 'git pull':
144 ahead merges with remote master
145 master merges with remote master
146 octopus merges with remote topic-a
147 and with remote topic-b
148 and with remote topic-c
149 rebase rebases onto remote master
150 Local refs configured for 'git push':
151 master pushes to master (local out of date)
152 master pushes to upstream (create)
155 HEAD branch (remote HEAD is ambiguous, may be one of the following):
158 Local refs configured for 'git push':
159 ahead forces to master (fast forwardable)
160 master pushes to another (up to date)
163 test_expect_success
'show' '
165 git config --add remote.origin.fetch refs/heads/master:refs/heads/upstream &&
167 git checkout -b ahead origin/master &&
170 git commit -m update file &&
171 git checkout master &&
172 git branch --track octopus origin/master &&
173 git branch --track rebase origin/master &&
174 git branch -d -r origin/master &&
175 git config --add remote.two.url ../two &&
176 git config branch.rebase.rebase true &&
177 git config branch.octopus.merge "topic-a topic-b topic-c" &&
181 git commit -m update file) &&
182 git config --add remote.origin.push : &&
183 git config --add remote.origin.push refs/heads/master:refs/heads/upstream &&
184 git config --add remote.origin.push +refs/tags/lastbackup &&
185 git config --add remote.two.push +refs/heads/ahead:refs/heads/master &&
186 git config --add remote.two.push refs/heads/master:refs/heads/another &&
187 git remote show origin two > output &&
188 git branch -d rebase octopus &&
189 test_cmp expect output)
192 cat > test
/expect
<< EOF
195 HEAD branch: (not queried)
196 Remote branches: (status not queried)
199 Local branches configured for 'git pull':
200 ahead merges with remote master
201 master merges with remote master
202 Local refs configured for 'git push' (status not queried):
203 (matching) pushes to (matching)
204 refs/heads/master pushes to refs/heads/upstream
205 refs/tags/lastbackup forces to refs/tags/lastbackup
208 test_expect_success
'show -n' '
209 (mv one one.unreachable &&
211 git remote show -n origin > output &&
212 mv ../one.unreachable ../one &&
213 test_cmp expect output)
216 test_expect_success
'prune' '
218 git branch -m side side2) &&
221 git remote prune origin &&
222 git rev-parse refs/remotes/origin/side2 &&
223 test_must_fail git rev-parse refs/remotes/origin/side)
226 test_expect_success
'set-head --delete' '
228 git symbolic-ref refs/remotes/origin/HEAD &&
229 git remote set-head --delete origin &&
230 test_must_fail git symbolic-ref refs/remotes/origin/HEAD)
233 test_expect_success
'set-head --auto' '
235 git remote set-head --auto origin &&
236 echo refs/remotes/origin/master >expect &&
237 git symbolic-ref refs/remotes/origin/HEAD >output &&
238 test_cmp expect output
242 cat >test
/expect
<<EOF
243 error: Multiple remote HEAD branches. Please choose one explicitly with:
244 git remote set-head two another
245 git remote set-head two master
248 test_expect_success
'set-head --auto fails w/multiple HEADs' '
250 test_must_fail git remote set-head --auto two >output 2>&1 &&
251 test_cmp expect output)
254 cat >test
/expect
<<EOF
255 refs/remotes/origin/side2
258 test_expect_success
'set-head explicit' '
260 git remote set-head origin side2 &&
261 git symbolic-ref refs/remotes/origin/HEAD >output &&
262 git remote set-head origin master &&
263 test_cmp expect output)
266 cat > test
/expect
<< EOF
269 * [would prune] origin/side2
272 test_expect_success
'prune --dry-run' '
274 git branch -m side2 side) &&
276 git remote prune --dry-run origin > output &&
277 git rev-parse refs/remotes/origin/side2 &&
278 test_must_fail git rev-parse refs/remotes/origin/side &&
280 git branch -m side side2) &&
281 test_cmp expect output)
284 test_expect_success
'add --mirror && prune' '
288 git remote add --mirror -f origin ../one) &&
290 git branch -m side2 side) &&
292 git rev-parse --verify refs/heads/side2 &&
293 test_must_fail git rev-parse --verify refs/heads/side &&
295 git remote prune origin &&
296 test_must_fail git rev-parse --verify refs/heads/side2 &&
297 git rev-parse --verify refs/heads/side)
300 test_expect_success
'add alt && prune' '
304 git remote add -f origin ../one &&
305 git config remote.alt.url ../one &&
306 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") &&
308 git branch -m side side2) &&
310 git rev-parse --verify refs/remotes/origin/side &&
311 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
313 git remote prune alt &&
314 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
315 git rev-parse --verify refs/remotes/origin/side2)
318 cat > one
/expect
<< EOF
326 test_expect_success
'update' '
329 git remote add drosophila ../two &&
330 git remote add apis ../mirror &&
332 git branch -r > output &&
333 test_cmp expect output)
337 cat > one
/expect
<< EOF
347 test_expect_success
'update with arguments' '
350 for b in $(git branch -r)
352 git branch -r -d $b || break
354 git remote add manduca ../mirror &&
355 git remote add megaloprepus ../mirror &&
356 git config remotes.phobaeticus "drosophila megaloprepus" &&
357 git config remotes.titanus manduca &&
358 git remote update phobaeticus titanus &&
359 git branch -r > output &&
360 test_cmp expect output)
364 cat > one
/expect
<< EOF
373 test_expect_success
'update default' '
376 for b in $(git branch -r)
378 git branch -r -d $b || break
380 git config remote.drosophila.skipDefaultUpdate true &&
381 git remote update default &&
382 git branch -r > output &&
383 test_cmp expect output)
387 cat > one
/expect
<< EOF
393 test_expect_success
'update default (overridden, with funny whitespace)' '
396 for b in $(git branch -r)
398 git branch -r -d $b || break
400 git config remotes.default "$(printf "\t drosophila \n")" &&
401 git remote update default &&
402 git branch -r > output &&
403 test_cmp expect output)
407 test_expect_success
'"remote show" does not show symbolic refs' '
409 git clone one three &&
411 git remote show origin > output &&
412 ! grep "^ *HEAD$" < output &&
413 ! grep -i stale < output)
417 test_expect_success
'reject adding remote with an invalid name' '
419 test_must_fail git remote add some:url desired-name
423 # The first three test if the tracking branches are properly renamed,
424 # the last two ones check if the config is updated.
426 test_expect_success
'rename a remote' '
428 git clone one four &&
430 git remote rename origin upstream &&
431 rmdir .git/refs/remotes/origin &&
432 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
433 test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
434 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
435 test "$(git config branch.master.remote)" = "upstream")
439 cat > remotes_origin
<< EOF
441 Push: refs/heads/master:refs/heads/upstream
442 Pull: refs/heads/master:refs/heads/origin
445 test_expect_success
'migrate a remote from named file in $GIT_DIR/remotes' '
446 git clone one five &&
447 origin_url=$(pwd)/one &&
449 git remote rm origin &&
450 mkdir -p .git/remotes &&
451 cat ../remotes_origin > .git/remotes/origin &&
452 git remote rename origin origin &&
453 ! test -f .git/remotes/origin &&
454 test "$(git config remote.origin.url)" = "$origin_url" &&
455 test "$(git config remote.origin.push)" = "refs/heads/master:refs/heads/upstream" &&
456 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
459 test_expect_success
'migrate a remote from named file in $GIT_DIR/branches' '
461 origin_url=$(pwd)/one &&
463 git remote rm origin &&
464 echo "$origin_url" > .git/branches/origin &&
465 git remote rename origin origin &&
466 ! test -f .git/branches/origin &&
467 test "$(git config remote.origin.url)" = "$origin_url" &&
468 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
471 test_expect_success
'remote prune to cause a dangling symref' '
472 git clone one seven &&
475 git checkout side2 &&
480 git remote prune origin
482 grep "has become dangling" err &&
484 : And the dangling symref will not cause other annoying errors
489 ! grep "points nowhere" err
492 test_must_fail git branch nomore origin
494 grep "dangling symref" err
497 test_expect_success
'show empty remote' '
499 test_create_repo empty &&
500 git clone empty empty-clone &&
503 git remote show origin