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
138 Fetch URL: $(pwd)/one
142 master new (next fetch will store in remotes/origin)
144 Local branches configured for 'git pull':
145 ahead merges with remote master
146 master merges with remote master
147 octopus merges with remote topic-a
148 and with remote topic-b
149 and with remote topic-c
150 rebase rebases onto remote master
151 Local refs configured for 'git push':
152 master pushes to master (local out of date)
153 master pushes to upstream (create)
157 HEAD branch (remote HEAD is ambiguous, may be one of the following):
160 Local refs configured for 'git push':
161 ahead forces to master (fast-forwardable)
162 master pushes to another (up to date)
165 test_expect_success 'show' '
167 git config --add remote.origin.fetch refs/heads/master:refs/heads/upstream &&
169 git checkout -b ahead origin/master &&
172 git commit -m update file &&
173 git checkout master &&
174 git branch --track octopus origin/master &&
175 git branch --track rebase origin/master &&
176 git branch -d -r origin/master &&
177 git config --add remote.two.url ../two &&
178 git config --add remote.two.pushurl ../three &&
179 git config branch.rebase.rebase true &&
180 git config branch.octopus.merge "topic-a topic-b topic-c" &&
184 git commit -m update file) &&
185 git config --add remote.origin.push : &&
186 git config --add remote.origin.push refs/heads/master:refs/heads/upstream &&
187 git config --add remote.origin.push +refs/tags/lastbackup &&
188 git config --add remote.two.push +refs/heads/ahead:refs/heads/master &&
189 git config --add remote.two.push refs/heads/master:refs/heads/another &&
190 git remote show origin two > output &&
191 git branch -d rebase octopus &&
192 test_cmp expect output)
195 cat > test/expect << EOF
197 Fetch URL: $(pwd)/one
199 HEAD branch: (not queried)
200 Remote branches: (status not queried)
203 Local branches configured for 'git pull':
204 ahead merges with remote master
205 master merges with remote master
206 Local refs configured for 'git push' (status not queried):
207 (matching) pushes to (matching)
208 refs/heads/master pushes to refs/heads/upstream
209 refs/tags/lastbackup forces to refs/tags/lastbackup
212 test_expect_success 'show -n' '
213 (mv one one.unreachable &&
215 git remote show -n origin > output &&
216 mv ../one.unreachable ../one &&
217 test_cmp expect output)
220 test_expect_success 'prune' '
222 git branch -m side side2) &&
225 git remote prune origin &&
226 git rev-parse refs/remotes/origin/side2 &&
227 test_must_fail git rev-parse refs/remotes/origin/side)
230 test_expect_success 'set-head --delete' '
232 git symbolic-ref refs/remotes/origin/HEAD &&
233 git remote set-head --delete origin &&
234 test_must_fail git symbolic-ref refs/remotes/origin/HEAD)
237 test_expect_success 'set-head --auto' '
239 git remote set-head --auto origin &&
240 echo refs/remotes/origin/master >expect &&
241 git symbolic-ref refs/remotes/origin/HEAD >output &&
242 test_cmp expect output
246 cat >test/expect <<EOF
247 error: Multiple remote HEAD branches. Please choose one explicitly with:
248 git remote set-head two another
249 git remote set-head two master
252 test_expect_success 'set-head --auto fails w/multiple HEADs' '
254 test_must_fail git remote set-head --auto two >output 2>&1 &&
255 test_cmp expect output)
258 cat >test/expect <<EOF
259 refs/remotes/origin/side2
262 test_expect_success 'set-head explicit' '
264 git remote set-head origin side2 &&
265 git symbolic-ref refs/remotes/origin/HEAD >output &&
266 git remote set-head origin master &&
267 test_cmp expect output)
270 cat > test/expect << EOF
273 * [would prune] origin/side2
276 test_expect_success 'prune --dry-run' '
278 git branch -m side2 side) &&
280 git remote prune --dry-run origin > output &&
281 git rev-parse refs/remotes/origin/side2 &&
282 test_must_fail git rev-parse refs/remotes/origin/side &&
284 git branch -m side side2) &&
285 test_cmp expect output)
288 test_expect_success 'add --mirror && prune' '
292 git remote add --mirror -f origin ../one) &&
294 git branch -m side2 side) &&
296 git rev-parse --verify refs/heads/side2 &&
297 test_must_fail git rev-parse --verify refs/heads/side &&
299 git remote prune origin &&
300 test_must_fail git rev-parse --verify refs/heads/side2 &&
301 git rev-parse --verify refs/heads/side)
304 test_expect_success 'add alt && prune' '
308 git remote add -f origin ../one &&
309 git config remote.alt.url ../one &&
310 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") &&
312 git branch -m side side2) &&
314 git rev-parse --verify refs/remotes/origin/side &&
315 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
317 git remote prune alt &&
318 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
319 git rev-parse --verify refs/remotes/origin/side2)
322 cat > one/expect << EOF
330 test_expect_success 'update' '
333 git remote add drosophila ../two &&
334 git remote add apis ../mirror &&
336 git branch -r > output &&
337 test_cmp expect output)
341 cat > one/expect << EOF
351 test_expect_success 'update with arguments' '
354 for b in $(git branch -r)
356 git branch -r -d $b || break
358 git remote add manduca ../mirror &&
359 git remote add megaloprepus ../mirror &&
360 git config remotes.phobaeticus "drosophila megaloprepus" &&
361 git config remotes.titanus manduca &&
362 git remote update phobaeticus titanus &&
363 git branch -r > output &&
364 test_cmp expect output)
368 test_expect_success 'update --prune' '
371 git branch -m side2 side3) &&
373 git remote update --prune &&
374 (cd ../one && git branch -m side3 side2)
375 git rev-parse refs/remotes/origin/side3 &&
376 test_must_fail git rev-parse refs/remotes/origin/side2)
379 cat > one/expect << EOF
388 test_expect_success 'update default' '
391 for b in $(git branch -r)
393 git branch -r -d $b || break
395 git config remote.drosophila.skipDefaultUpdate true &&
396 git remote update default &&
397 git branch -r > output &&
398 test_cmp expect output)
402 cat > one/expect << EOF
408 test_expect_success 'update default (overridden, with funny whitespace)' '
411 for b in $(git branch -r)
413 git branch -r -d $b || break
415 git config remotes.default "$(printf "\t drosophila \n")" &&
416 git remote update default &&
417 git branch -r > output &&
418 test_cmp expect output)
422 test_expect_success '"remote show" does not show symbolic refs' '
424 git clone one three &&
426 git remote show origin > output &&
427 ! grep "^ *HEAD$" < output &&
428 ! grep -i stale < output)
432 test_expect_success 'reject adding remote with an invalid name' '
434 test_must_fail git remote add some:url desired-name
438 # The first three test if the tracking branches are properly renamed,
439 # the last two ones check if the config is updated.
441 test_expect_success 'rename a remote' '
443 git clone one four &&
445 git remote rename origin upstream &&
446 rmdir .git/refs/remotes/origin &&
447 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
448 test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
449 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
450 test "$(git config branch.master.remote)" = "upstream")
454 cat > remotes_origin << EOF
456 Push: refs/heads/master:refs/heads/upstream
457 Pull: refs/heads/master:refs/heads/origin
460 test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
461 git clone one five &&
462 origin_url=$(pwd)/one &&
464 git remote rm origin &&
465 mkdir -p .git/remotes &&
466 cat ../remotes_origin > .git/remotes/origin &&
467 git remote rename origin origin &&
468 ! test -f .git/remotes/origin &&
469 test "$(git config remote.origin.url)" = "$origin_url" &&
470 test "$(git config remote.origin.push)" = "refs/heads/master:refs/heads/upstream" &&
471 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
474 test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
476 origin_url=$(pwd)/one &&
478 git remote rm origin &&
479 echo "$origin_url" > .git/branches/origin &&
480 git remote rename origin origin &&
481 ! test -f .git/branches/origin &&
482 test "$(git config remote.origin.url)" = "$origin_url" &&
483 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
486 test_expect_success 'remote prune to cause a dangling symref' '
487 git clone one seven &&
490 git checkout side2 &&
495 git remote prune origin
497 grep "has become dangling" err &&
499 : And the dangling symref will not cause other annoying errors
504 ! grep "points nowhere" err
507 test_must_fail git branch nomore origin
509 grep "dangling symref" err
512 test_expect_success 'show empty remote' '
514 test_create_repo empty &&
515 git clone empty empty-clone &&
518 git remote show origin