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 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
120 Local branches pushed with 'git push'
122 +refs/tags/lastbackup
125 test_expect_success
'show' '
127 git config --add remote.origin.fetch \
128 refs/heads/master:refs/heads/upstream &&
130 git branch -d -r origin/master &&
134 git commit -m update file) &&
135 git config remote.origin.push \
136 refs/heads/master:refs/heads/upstream &&
137 git config --add remote.origin.push \
138 +refs/tags/lastbackup &&
139 git remote show origin > output &&
140 test_cmp expect output)
143 cat > test
/expect
<< EOF
146 Remote branch merged with 'git pull' while on branch master
148 Tracked remote branches
151 Local branches pushed with 'git push'
153 +refs/tags/lastbackup
156 test_expect_success
'show -n' '
157 (mv one one.unreachable &&
159 git remote show -n origin > output &&
160 mv ../one.unreachable ../one &&
161 test_cmp expect output)
164 test_expect_success
'prune' '
166 git branch -m side side2) &&
169 git remote prune origin &&
170 git rev-parse refs/remotes/origin/side2 &&
171 test_must_fail git rev-parse refs/remotes/origin/side)
174 cat > test
/expect
<< EOF
177 * [would prune] origin/side2
180 test_expect_success
'prune --dry-run' '
182 git branch -m side2 side) &&
184 git remote prune --dry-run origin > output &&
185 git rev-parse refs/remotes/origin/side2 &&
186 test_must_fail git rev-parse refs/remotes/origin/side &&
188 git branch -m side side2) &&
189 test_cmp expect output)
192 test_expect_success
'add --mirror && prune' '
196 git remote add --mirror -f origin ../one) &&
198 git branch -m side2 side) &&
200 git rev-parse --verify refs/heads/side2 &&
201 test_must_fail git rev-parse --verify refs/heads/side &&
203 git remote prune origin &&
204 test_must_fail git rev-parse --verify refs/heads/side2 &&
205 git rev-parse --verify refs/heads/side)
208 test_expect_success
'add alt && prune' '
212 git remote add -f origin ../one &&
213 git config remote.alt.url ../one &&
214 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") &&
216 git branch -m side side2) &&
218 git rev-parse --verify refs/remotes/origin/side &&
219 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
221 git remote prune alt &&
222 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
223 git rev-parse --verify refs/remotes/origin/side2)
226 cat > one
/expect
<< EOF
234 test_expect_success
'update' '
237 git remote add drosophila ../two &&
238 git remote add apis ../mirror &&
240 git branch -r > output &&
241 test_cmp expect output)
245 cat > one
/expect
<< EOF
255 test_expect_success
'update with arguments' '
258 for b in $(git branch -r)
260 git branch -r -d $b || break
262 git remote add manduca ../mirror &&
263 git remote add megaloprepus ../mirror &&
264 git config remotes.phobaeticus "drosophila megaloprepus" &&
265 git config remotes.titanus manduca &&
266 git remote update phobaeticus titanus &&
267 git branch -r > output &&
268 test_cmp expect output)
272 cat > one
/expect
<< EOF
281 test_expect_success
'update default' '
284 for b in $(git branch -r)
286 git branch -r -d $b || break
288 git config remote.drosophila.skipDefaultUpdate true &&
289 git remote update default &&
290 git branch -r > output &&
291 test_cmp expect output)
295 cat > one
/expect
<< EOF
301 test_expect_success
'update default (overridden, with funny whitespace)' '
304 for b in $(git branch -r)
306 git branch -r -d $b || break
308 git config remotes.default "$(printf "\t drosophila \n")" &&
309 git remote update default &&
310 git branch -r > output &&
311 test_cmp expect output)
315 test_expect_success
'"remote show" does not show symbolic refs' '
317 git clone one three &&
319 git remote show origin > output &&
320 ! grep HEAD < output &&
321 ! grep -i stale < output)
325 test_expect_success
'reject adding remote with an invalid name' '
327 test_must_fail git remote add some:url desired-name
331 # The first three test if the tracking branches are properly renamed,
332 # the last two ones check if the config is updated.
334 test_expect_success
'rename a remote' '
336 git clone one four &&
338 git remote rename origin upstream &&
339 rmdir .git/refs/remotes/origin &&
340 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
341 test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
342 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
343 test "$(git config branch.master.remote)" = "upstream")
347 cat > remotes_origin
<< EOF
349 Push: refs/heads/master:refs/heads/upstream
350 Pull: refs/heads/master:refs/heads/origin
353 test_expect_success
'migrate a remote from named file in $GIT_DIR/remotes' '
354 git clone one five &&
355 origin_url=$(pwd)/one &&
357 git remote rm origin &&
358 mkdir -p .git/remotes &&
359 cat ../remotes_origin > .git/remotes/origin &&
360 git remote rename origin origin &&
361 ! test -f .git/remotes/origin &&
362 test "$(git config remote.origin.url)" = "$origin_url" &&
363 test "$(git config remote.origin.push)" = "refs/heads/master:refs/heads/upstream" &&
364 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
367 test_expect_success
'migrate a remote from named file in $GIT_DIR/branches' '
369 origin_url=$(pwd)/one &&
371 git remote rm origin &&
372 echo "$origin_url" > .git/branches/origin &&
373 git remote rename origin origin &&
374 ! test -f .git/branches/origin &&
375 test "$(git config remote.origin.url)" = "$origin_url" &&
376 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")