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
111 *MINGW
*) pwd() { builtin pwd -W; } ;;
113 cat > test
/expect
<< EOF
116 Remote branch merged with 'git pull' while on branch master
118 New remote branch (next fetch will store in remotes/origin)
120 Tracked remote branches
123 Local branches pushed with 'git push'
125 +refs/tags/lastbackup
128 test_expect_success
'show' '
130 git config --add remote.origin.fetch \
131 refs/heads/master:refs/heads/upstream &&
133 git branch -d -r origin/master &&
137 git commit -m update file) &&
138 git config remote.origin.push \
139 refs/heads/master:refs/heads/upstream &&
140 git config --add remote.origin.push \
141 +refs/tags/lastbackup &&
142 git remote show origin > output &&
143 test_cmp expect output)
146 cat > test
/expect
<< EOF
149 Remote branch merged with 'git pull' while on branch master
151 Tracked remote branches
154 Local branches pushed with 'git push'
156 +refs/tags/lastbackup
159 test_expect_success
'show -n' '
160 (mv one one.unreachable &&
162 git remote show -n origin > output &&
163 mv ../one.unreachable ../one &&
164 test_cmp expect output)
167 test_expect_success
'prune' '
169 git branch -m side side2) &&
172 git remote prune origin &&
173 git rev-parse refs/remotes/origin/side2 &&
174 test_must_fail git rev-parse refs/remotes/origin/side)
177 cat > test
/expect
<< EOF
180 * [would prune] origin/side2
183 test_expect_success
'prune --dry-run' '
185 git branch -m side2 side) &&
187 git remote prune --dry-run origin > output &&
188 git rev-parse refs/remotes/origin/side2 &&
189 test_must_fail git rev-parse refs/remotes/origin/side &&
191 git branch -m side side2) &&
192 test_cmp expect output)
195 test_expect_success
'add --mirror && prune' '
199 git remote add --mirror -f origin ../one) &&
201 git branch -m side2 side) &&
203 git rev-parse --verify refs/heads/side2 &&
204 test_must_fail git rev-parse --verify refs/heads/side &&
206 git remote prune origin &&
207 test_must_fail git rev-parse --verify refs/heads/side2 &&
208 git rev-parse --verify refs/heads/side)
211 test_expect_success
'add alt && prune' '
215 git remote add -f origin ../one &&
216 git config remote.alt.url ../one &&
217 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") &&
219 git branch -m side side2) &&
221 git rev-parse --verify refs/remotes/origin/side &&
222 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
224 git remote prune alt &&
225 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
226 git rev-parse --verify refs/remotes/origin/side2)
229 cat > one
/expect
<< EOF
237 test_expect_success
'update' '
240 git remote add drosophila ../two &&
241 git remote add apis ../mirror &&
243 git branch -r > output &&
244 test_cmp expect output)
248 cat > one
/expect
<< EOF
258 test_expect_success
'update with arguments' '
261 for b in $(git branch -r)
263 git branch -r -d $b || break
265 git remote add manduca ../mirror &&
266 git remote add megaloprepus ../mirror &&
267 git config remotes.phobaeticus "drosophila megaloprepus" &&
268 git config remotes.titanus manduca &&
269 git remote update phobaeticus titanus &&
270 git branch -r > output &&
271 test_cmp expect output)
275 cat > one
/expect
<< EOF
284 test_expect_success
'update default' '
287 for b in $(git branch -r)
289 git branch -r -d $b || break
291 git config remote.drosophila.skipDefaultUpdate true &&
292 git remote update default &&
293 git branch -r > output &&
294 test_cmp expect output)
298 cat > one
/expect
<< EOF
304 test_expect_success
'update default (overridden, with funny whitespace)' '
307 for b in $(git branch -r)
309 git branch -r -d $b || break
311 git config remotes.default "$(printf "\t drosophila \n")" &&
312 git remote update default &&
313 git branch -r > output &&
314 test_cmp expect output)
318 test_expect_success
'"remote show" does not show symbolic refs' '
320 git clone one three &&
322 git remote show origin > output &&
323 ! grep HEAD < output &&
324 ! grep -i stale < output)
328 test_expect_success
'reject adding remote with an invalid name' '
330 test_must_fail git remote add some:url desired-name