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 -e '1,/Tracked/d') &&
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
140 Remote branch merged with 'git pull' while on branch master
142 New remote branch (next fetch will store in remotes/origin)
144 Tracked remote branches
147 Local branches pushed with 'git push'
149 +refs/tags/lastbackup
152 HEAD branch (remote HEAD is ambiguous, may be one of the following):
157 test_expect_success
'show' '
159 git config --add remote.origin.fetch \
160 refs/heads/master:refs/heads/upstream &&
162 git branch -d -r origin/master &&
163 git config --add remote.two.url ../two &&
167 git commit -m update file) &&
168 git config remote.origin.push \
169 refs/heads/master:refs/heads/upstream &&
170 git config --add remote.origin.push \
171 +refs/tags/lastbackup &&
172 git remote show origin two > output &&
173 test_cmp expect output)
176 cat > test
/expect
<< EOF
179 HEAD branch: (not queried)
180 Remote branch merged with 'git pull' while on branch master
182 Tracked remote branches
185 Local branches pushed with 'git push'
187 +refs/tags/lastbackup
190 test_expect_success
'show -n' '
191 (mv one one.unreachable &&
193 git remote show -n origin > output &&
194 mv ../one.unreachable ../one &&
195 test_cmp expect output)
198 test_expect_success
'prune' '
200 git branch -m side side2) &&
203 git remote prune origin &&
204 git rev-parse refs/remotes/origin/side2 &&
205 test_must_fail git rev-parse refs/remotes/origin/side)
208 cat > test
/expect
<< EOF
211 * [would prune] origin/side2
214 test_expect_success
'prune --dry-run' '
216 git branch -m side2 side) &&
218 git remote prune --dry-run origin > output &&
219 git rev-parse refs/remotes/origin/side2 &&
220 test_must_fail git rev-parse refs/remotes/origin/side &&
222 git branch -m side side2) &&
223 test_cmp expect output)
226 test_expect_success
'add --mirror && prune' '
230 git remote add --mirror -f origin ../one) &&
232 git branch -m side2 side) &&
234 git rev-parse --verify refs/heads/side2 &&
235 test_must_fail git rev-parse --verify refs/heads/side &&
237 git remote prune origin &&
238 test_must_fail git rev-parse --verify refs/heads/side2 &&
239 git rev-parse --verify refs/heads/side)
242 test_expect_success
'add alt && prune' '
246 git remote add -f origin ../one &&
247 git config remote.alt.url ../one &&
248 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") &&
250 git branch -m side side2) &&
252 git rev-parse --verify refs/remotes/origin/side &&
253 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
255 git remote prune alt &&
256 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
257 git rev-parse --verify refs/remotes/origin/side2)
260 cat > one
/expect
<< EOF
268 test_expect_success
'update' '
271 git remote add drosophila ../two &&
272 git remote add apis ../mirror &&
274 git branch -r > output &&
275 test_cmp expect output)
279 cat > one
/expect
<< EOF
289 test_expect_success
'update with arguments' '
292 for b in $(git branch -r)
294 git branch -r -d $b || break
296 git remote add manduca ../mirror &&
297 git remote add megaloprepus ../mirror &&
298 git config remotes.phobaeticus "drosophila megaloprepus" &&
299 git config remotes.titanus manduca &&
300 git remote update phobaeticus titanus &&
301 git branch -r > output &&
302 test_cmp expect output)
306 cat > one
/expect
<< EOF
315 test_expect_success
'update default' '
318 for b in $(git branch -r)
320 git branch -r -d $b || break
322 git config remote.drosophila.skipDefaultUpdate true &&
323 git remote update default &&
324 git branch -r > output &&
325 test_cmp expect output)
329 cat > one
/expect
<< EOF
335 test_expect_success
'update default (overridden, with funny whitespace)' '
338 for b in $(git branch -r)
340 git branch -r -d $b || break
342 git config remotes.default "$(printf "\t drosophila \n")" &&
343 git remote update default &&
344 git branch -r > output &&
345 test_cmp expect output)
349 test_expect_success
'"remote show" does not show symbolic refs' '
351 git clone one three &&
353 git remote show origin > output &&
354 ! grep "^ *HEAD$" < output &&
355 ! grep -i stale < output)
359 test_expect_success
'reject adding remote with an invalid name' '
361 test_must_fail git remote add some:url desired-name
365 # The first three test if the tracking branches are properly renamed,
366 # the last two ones check if the config is updated.
368 test_expect_success
'rename a remote' '
370 git clone one four &&
372 git remote rename origin upstream &&
373 rmdir .git/refs/remotes/origin &&
374 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
375 test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
376 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
377 test "$(git config branch.master.remote)" = "upstream")
381 cat > remotes_origin
<< EOF
383 Push: refs/heads/master:refs/heads/upstream
384 Pull: refs/heads/master:refs/heads/origin
387 test_expect_success
'migrate a remote from named file in $GIT_DIR/remotes' '
388 git clone one five &&
389 origin_url=$(pwd)/one &&
391 git remote rm origin &&
392 mkdir -p .git/remotes &&
393 cat ../remotes_origin > .git/remotes/origin &&
394 git remote rename origin origin &&
395 ! test -f .git/remotes/origin &&
396 test "$(git config remote.origin.url)" = "$origin_url" &&
397 test "$(git config remote.origin.push)" = "refs/heads/master:refs/heads/upstream" &&
398 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
401 test_expect_success
'migrate a remote from named file in $GIT_DIR/branches' '
403 origin_url=$(pwd)/one &&
405 git remote rm origin &&
406 echo "$origin_url" > .git/branches/origin &&
407 git remote rename origin origin &&
408 ! test -f .git/branches/origin &&
409 test "$(git config remote.origin.url)" = "$origin_url" &&
410 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
413 test_expect_success
'remote prune to cause a dangling symref' '
414 git clone one seven &&
417 git checkout side2 &&
422 git remote prune origin
424 grep "has become dangling" err &&
426 : And the dangling symref will not cause other annoying errors
431 ! grep "points nowhere" err
434 test_must_fail git branch nomore origin
436 grep "dangling symref" err