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 -n -e '$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 cat > test
/expect
<< EOF
113 Remote branch merged with 'git pull' while on branch master
115 New remote branch (next fetch will store in remotes/origin)
117 Tracked remote branches
119 Local branches pushed with 'git push'
120 master:upstream +refs/tags/lastbackup
123 test_expect_success
'show' '
125 git config --add remote.origin.fetch \
126 refs/heads/master:refs/heads/upstream &&
128 git branch -d -r origin/master &&
132 git commit -m update file) &&
133 git config remote.origin.push \
134 refs/heads/master:refs/heads/upstream &&
135 git config --add remote.origin.push \
136 +refs/tags/lastbackup &&
137 git remote show origin > output &&
138 test_cmp expect output)
141 cat > test
/expect
<< EOF
144 Remote branch merged with 'git pull' while on branch master
146 Tracked remote branches
148 Local branches pushed with 'git push'
149 master:upstream +refs/tags/lastbackup
152 test_expect_success
'show -n' '
153 (mv one one.unreachable &&
155 git remote show -n origin > output &&
156 mv ../one.unreachable ../one &&
157 test_cmp expect output)
160 test_expect_success
'prune' '
162 git branch -m side side2) &&
165 git remote prune origin &&
166 git rev-parse refs/remotes/origin/side2 &&
167 test_must_fail git rev-parse refs/remotes/origin/side)
170 cat > test
/expect
<< EOF
173 * [would prune] origin/side2
176 test_expect_success
'prune --dry-run' '
178 git branch -m side2 side) &&
180 git remote prune --dry-run origin > output &&
181 git rev-parse refs/remotes/origin/side2 &&
182 test_must_fail git rev-parse refs/remotes/origin/side &&
184 git branch -m side side2) &&
185 test_cmp expect output)
188 test_expect_success
'add --mirror && prune' '
192 git remote add --mirror -f origin ../one) &&
194 git branch -m side2 side) &&
196 git rev-parse --verify refs/heads/side2 &&
197 test_must_fail git rev-parse --verify refs/heads/side &&
199 git remote prune origin &&
200 test_must_fail git rev-parse --verify refs/heads/side2 &&
201 git rev-parse --verify refs/heads/side)
204 test_expect_success
'add alt && prune' '
208 git remote add -f origin ../one &&
209 git config remote.alt.url ../one &&
210 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") &&
212 git branch -m side side2) &&
214 git rev-parse --verify refs/remotes/origin/side &&
215 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
217 git remote prune alt &&
218 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
219 git rev-parse --verify refs/remotes/origin/side2)
222 cat > one
/expect
<< EOF
230 test_expect_success
'update' '
233 git remote add drosophila ../two &&
234 git remote add apis ../mirror &&
236 git branch -r > output &&
237 test_cmp expect output)
241 cat > one
/expect
<< EOF
251 test_expect_success
'update with arguments' '
254 for b in $(git branch -r)
256 git branch -r -d $b || break
258 git remote add manduca ../mirror &&
259 git remote add megaloprepus ../mirror &&
260 git config remotes.phobaeticus "drosophila megaloprepus" &&
261 git config remotes.titanus manduca &&
262 git remote update phobaeticus titanus &&
263 git branch -r > output &&
264 test_cmp expect output)
268 cat > one
/expect
<< EOF
277 test_expect_success
'update default' '
280 for b in $(git branch -r)
282 git branch -r -d $b || break
284 git config remote.drosophila.skipDefaultUpdate true &&
285 git remote update default &&
286 git branch -r > output &&
287 test_cmp expect output)
291 cat > one
/expect
<< EOF
297 test_expect_success
'update default (overridden, with funny whitespace)' '
300 for b in $(git branch -r)
302 git branch -r -d $b || break
304 git config remotes.default "$(printf "\t drosophila \n")" &&
305 git remote update default &&
306 git branch -r > output &&
307 test_cmp expect output)
311 test_expect_success
'"remote show" does not show symbolic refs' '
313 git clone one three &&
315 git remote show origin > output &&
316 ! grep HEAD < output &&
317 ! grep -i stale < output)
321 test_expect_success
'reject adding remote with an invalid name' '
323 test_must_fail git remote add some:url desired-name