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
139 Remote branch merged with 'git pull' while on branch master
141 New remote branch (next fetch will store in remotes/origin)
143 Tracked remote branches
146 Local branches pushed with 'git push'
148 +refs/tags/lastbackup
151 test_expect_success 'show' '
153 git config --add remote.origin.fetch \
154 refs/heads/master:refs/heads/upstream &&
156 git branch -d -r origin/master &&
160 git commit -m update file) &&
161 git config remote.origin.push \
162 refs/heads/master:refs/heads/upstream &&
163 git config --add remote.origin.push \
164 +refs/tags/lastbackup &&
165 git remote show origin > output &&
166 test_cmp expect output)
169 cat > test/expect << EOF
172 Remote branch merged with 'git pull' while on branch master
174 Tracked remote branches
177 Local branches pushed with 'git push'
179 +refs/tags/lastbackup
182 test_expect_success 'show -n' '
183 (mv one one.unreachable &&
185 git remote show -n origin > output &&
186 mv ../one.unreachable ../one &&
187 test_cmp expect output)
190 test_expect_success 'prune' '
192 git branch -m side side2) &&
195 git remote prune origin &&
196 git rev-parse refs/remotes/origin/side2 &&
197 test_must_fail git rev-parse refs/remotes/origin/side)
200 cat > test/expect << EOF
203 * [would prune] origin/side2
206 test_expect_success 'prune --dry-run' '
208 git branch -m side2 side) &&
210 git remote prune --dry-run origin > output &&
211 git rev-parse refs/remotes/origin/side2 &&
212 test_must_fail git rev-parse refs/remotes/origin/side &&
214 git branch -m side side2) &&
215 test_cmp expect output)
218 test_expect_success 'add --mirror && prune' '
222 git remote add --mirror -f origin ../one) &&
224 git branch -m side2 side) &&
226 git rev-parse --verify refs/heads/side2 &&
227 test_must_fail git rev-parse --verify refs/heads/side &&
229 git remote prune origin &&
230 test_must_fail git rev-parse --verify refs/heads/side2 &&
231 git rev-parse --verify refs/heads/side)
234 test_expect_success 'add alt && prune' '
238 git remote add -f origin ../one &&
239 git config remote.alt.url ../one &&
240 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") &&
242 git branch -m side side2) &&
244 git rev-parse --verify refs/remotes/origin/side &&
245 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
247 git remote prune alt &&
248 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
249 git rev-parse --verify refs/remotes/origin/side2)
252 cat > one/expect << EOF
260 test_expect_success 'update' '
263 git remote add drosophila ../two &&
264 git remote add apis ../mirror &&
266 git branch -r > output &&
267 test_cmp expect output)
271 cat > one/expect << EOF
281 test_expect_success 'update with arguments' '
284 for b in $(git branch -r)
286 git branch -r -d $b || break
288 git remote add manduca ../mirror &&
289 git remote add megaloprepus ../mirror &&
290 git config remotes.phobaeticus "drosophila megaloprepus" &&
291 git config remotes.titanus manduca &&
292 git remote update phobaeticus titanus &&
293 git branch -r > output &&
294 test_cmp expect output)
298 cat > one/expect << EOF
307 test_expect_success 'update default' '
310 for b in $(git branch -r)
312 git branch -r -d $b || break
314 git config remote.drosophila.skipDefaultUpdate true &&
315 git remote update default &&
316 git branch -r > output &&
317 test_cmp expect output)
321 cat > one/expect << EOF
327 test_expect_success 'update default (overridden, with funny whitespace)' '
330 for b in $(git branch -r)
332 git branch -r -d $b || break
334 git config remotes.default "$(printf "\t drosophila \n")" &&
335 git remote update default &&
336 git branch -r > output &&
337 test_cmp expect output)
341 test_expect_success '"remote show" does not show symbolic refs' '
343 git clone one three &&
345 git remote show origin > output &&
346 ! grep HEAD < output &&
347 ! grep -i stale < output)
351 test_expect_success 'reject adding remote with an invalid name' '
353 test_must_fail git remote add some:url desired-name
357 # The first three test if the tracking branches are properly renamed,
358 # the last two ones check if the config is updated.
360 test_expect_success 'rename a remote' '
362 git clone one four &&
364 git remote rename origin upstream &&
365 rmdir .git/refs/remotes/origin &&
366 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
367 test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
368 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
369 test "$(git config branch.master.remote)" = "upstream")
373 cat > remotes_origin << EOF
375 Push: refs/heads/master:refs/heads/upstream
376 Pull: refs/heads/master:refs/heads/origin
379 test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
380 git clone one five &&
381 origin_url=$(pwd)/one &&
383 git remote rm origin &&
384 mkdir -p .git/remotes &&
385 cat ../remotes_origin > .git/remotes/origin &&
386 git remote rename origin origin &&
387 ! test -f .git/remotes/origin &&
388 test "$(git config remote.origin.url)" = "$origin_url" &&
389 test "$(git config remote.origin.push)" = "refs/heads/master:refs/heads/upstream" &&
390 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
393 test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
395 origin_url=$(pwd)/one &&
397 git remote rm origin &&
398 echo "$origin_url" > .git/branches/origin &&
399 git remote rename origin origin &&
400 ! test -f .git/branches/origin &&
401 test "$(git config remote.origin.url)" = "$origin_url" &&
402 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")