Windows: Work around intermittent failures in mingw_rename
[git/dscho.git] / t / t5505-remote.sh
blob7267b1ae7072b404c35971a1bf909813f19b65a3
1 #!/bin/sh
3 test_description='git remote porcelain-ish'
5 . ./test-lib.sh
7 setup_repository () {
8 mkdir "$1" && (
9 cd "$1" &&
10 git init &&
11 >file &&
12 git add file &&
13 test_tick &&
14 git commit -m "Initial" &&
15 git checkout -b side &&
16 >elif &&
17 git add elif &&
18 test_tick &&
19 git commit -m "Second" &&
20 git checkout master
24 tokens_match () {
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 -ne 's|^ \(.*\) tracked$|\1|p')
32 shift &&
33 tokens_match "$*" "$actual"
36 check_tracking_branch () {
37 f="" &&
38 r=$(git for-each-ref "--format=%(refname)" |
39 sed -ne "s|^refs/remotes/$1/||p") &&
40 shift &&
41 tokens_match "$*" "$r"
44 test_expect_success setup '
46 setup_repository one &&
47 setup_repository two &&
49 cd two && git branch another
50 ) &&
51 git clone one test
55 test_expect_success 'remote information for the origin' '
57 cd test &&
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' '
66 cd test &&
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 &&
75 >expect &&
76 test_cmp expect actual
80 test_expect_success 'remote forces tracking branches' '
82 cd test &&
83 case `git config remote.second.fetch` in
84 +*) true ;;
85 *) false ;;
86 esac
90 test_expect_success 'remove remote' '
92 cd test &&
93 git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master &&
94 git remote rm second
98 test_expect_success 'remove remote' '
100 cd test &&
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 &&
105 >expect &&
106 test_cmp expect actual
110 test_expect_success 'remove remote protects non-remote branches' '
112 cd test &&
113 (cat >expect1 <<EOF
114 Note: A non-remote branch was not removed; to delete it, use:
115 git branch -d master
117 cat >expect2 <<EOF
118 Note: Non-remote branches were not removed; to delete them, use:
119 git branch -d foobranch
120 git branch -d master
122 ) &&
123 git tag footag
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 &&
130 git tag -d footag &&
131 test_cmp expect1 actual1 &&
132 test_cmp expect2 actual2
136 cat > test/expect << EOF
137 * remote origin
138 URL: $(pwd)/one
139 HEAD branch: master
140 Remote branches:
141 master new (next fetch will store in remotes/origin)
142 side tracked
143 Local branches configured for 'git pull':
144 ahead merges with remote master
145 master merges with remote master
146 octopus merges with remote topic-a
147 and with remote topic-b
148 and with remote topic-c
149 rebase rebases onto remote master
150 Local refs configured for 'git push':
151 master pushes to master (local out of date)
152 master pushes to upstream (create)
153 * remote two
154 URL: ../two
155 HEAD branch (remote HEAD is ambiguous, may be one of the following):
156 another
157 master
158 Local refs configured for 'git push':
159 ahead forces to master (fast forwardable)
160 master pushes to another (up to date)
163 test_expect_success 'show' '
164 (cd test &&
165 git config --add remote.origin.fetch refs/heads/master:refs/heads/upstream &&
166 git fetch &&
167 git checkout -b ahead origin/master &&
168 echo 1 >> file &&
169 test_tick &&
170 git commit -m update file &&
171 git checkout master &&
172 git branch --track octopus origin/master &&
173 git branch --track rebase origin/master &&
174 git branch -d -r origin/master &&
175 git config --add remote.two.url ../two &&
176 git config branch.rebase.rebase true &&
177 git config branch.octopus.merge "topic-a topic-b topic-c" &&
178 (cd ../one &&
179 echo 1 > file &&
180 test_tick &&
181 git commit -m update file) &&
182 git config --add remote.origin.push : &&
183 git config --add remote.origin.push refs/heads/master:refs/heads/upstream &&
184 git config --add remote.origin.push +refs/tags/lastbackup &&
185 git config --add remote.two.push +refs/heads/ahead:refs/heads/master &&
186 git config --add remote.two.push refs/heads/master:refs/heads/another &&
187 git remote show origin two > output &&
188 git branch -d rebase octopus &&
189 test_cmp expect output)
192 cat > test/expect << EOF
193 * remote origin
194 URL: $(pwd)/one
195 HEAD branch: (not queried)
196 Remote branches: (status not queried)
197 master
198 side
199 Local branches configured for 'git pull':
200 ahead merges with remote master
201 master merges with remote master
202 Local refs configured for 'git push' (status not queried):
203 (matching) pushes to (matching)
204 refs/heads/master pushes to refs/heads/upstream
205 refs/tags/lastbackup forces to refs/tags/lastbackup
208 test_expect_success 'show -n' '
209 (mv one one.unreachable &&
210 cd test &&
211 git remote show -n origin > output &&
212 mv ../one.unreachable ../one &&
213 test_cmp expect output)
216 test_expect_success 'prune' '
217 (cd one &&
218 git branch -m side side2) &&
219 (cd test &&
220 git fetch origin &&
221 git remote prune origin &&
222 git rev-parse refs/remotes/origin/side2 &&
223 test_must_fail git rev-parse refs/remotes/origin/side)
226 test_expect_success 'set-head --delete' '
227 (cd test &&
228 git symbolic-ref refs/remotes/origin/HEAD &&
229 git remote set-head --delete origin &&
230 test_must_fail git symbolic-ref refs/remotes/origin/HEAD)
233 test_expect_success 'set-head --auto' '
234 (cd test &&
235 git remote set-head --auto origin &&
236 echo refs/remotes/origin/master >expect &&
237 git symbolic-ref refs/remotes/origin/HEAD >output &&
238 test_cmp expect output
242 cat >test/expect <<EOF
243 error: Multiple remote HEAD branches. Please choose one explicitly with:
244 git remote set-head two another
245 git remote set-head two master
248 test_expect_success 'set-head --auto fails w/multiple HEADs' '
249 (cd test &&
250 set +x &&
251 test_must_fail git remote set-head --auto two >output 2>&1 &&
252 test_cmp expect output)
255 cat >test/expect <<EOF
256 refs/remotes/origin/side2
259 test_expect_success 'set-head explicit' '
260 (cd test &&
261 git remote set-head origin side2 &&
262 git symbolic-ref refs/remotes/origin/HEAD >output &&
263 git remote set-head origin master &&
264 test_cmp expect output)
267 cat > test/expect << EOF
268 Pruning origin
269 URL: $(pwd)/one
270 * [would prune] origin/side2
273 test_expect_success 'prune --dry-run' '
274 (cd one &&
275 git branch -m side2 side) &&
276 (cd test &&
277 git remote prune --dry-run origin > output &&
278 git rev-parse refs/remotes/origin/side2 &&
279 test_must_fail git rev-parse refs/remotes/origin/side &&
280 (cd ../one &&
281 git branch -m side side2) &&
282 test_cmp expect output)
285 test_expect_success 'add --mirror && prune' '
286 (mkdir mirror &&
287 cd mirror &&
288 git init --bare &&
289 git remote add --mirror -f origin ../one) &&
290 (cd one &&
291 git branch -m side2 side) &&
292 (cd mirror &&
293 git rev-parse --verify refs/heads/side2 &&
294 test_must_fail git rev-parse --verify refs/heads/side &&
295 git fetch origin &&
296 git remote prune origin &&
297 test_must_fail git rev-parse --verify refs/heads/side2 &&
298 git rev-parse --verify refs/heads/side)
301 test_expect_success 'add alt && prune' '
302 (mkdir alttst &&
303 cd alttst &&
304 git init &&
305 git remote add -f origin ../one &&
306 git config remote.alt.url ../one &&
307 git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") &&
308 (cd one &&
309 git branch -m side side2) &&
310 (cd alttst &&
311 git rev-parse --verify refs/remotes/origin/side &&
312 test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
313 git fetch alt &&
314 git remote prune alt &&
315 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
316 git rev-parse --verify refs/remotes/origin/side2)
319 cat > one/expect << EOF
320 apis/master
321 apis/side
322 drosophila/another
323 drosophila/master
324 drosophila/side
327 test_expect_success 'update' '
329 (cd one &&
330 git remote add drosophila ../two &&
331 git remote add apis ../mirror &&
332 git remote update &&
333 git branch -r > output &&
334 test_cmp expect output)
338 cat > one/expect << EOF
339 drosophila/another
340 drosophila/master
341 drosophila/side
342 manduca/master
343 manduca/side
344 megaloprepus/master
345 megaloprepus/side
348 test_expect_success 'update with arguments' '
350 (cd one &&
351 for b in $(git branch -r)
353 git branch -r -d $b || break
354 done &&
355 git remote add manduca ../mirror &&
356 git remote add megaloprepus ../mirror &&
357 git config remotes.phobaeticus "drosophila megaloprepus" &&
358 git config remotes.titanus manduca &&
359 git remote update phobaeticus titanus &&
360 git branch -r > output &&
361 test_cmp expect output)
365 cat > one/expect << EOF
366 apis/master
367 apis/side
368 manduca/master
369 manduca/side
370 megaloprepus/master
371 megaloprepus/side
374 test_expect_success 'update default' '
376 (cd one &&
377 for b in $(git branch -r)
379 git branch -r -d $b || break
380 done &&
381 git config remote.drosophila.skipDefaultUpdate true &&
382 git remote update default &&
383 git branch -r > output &&
384 test_cmp expect output)
388 cat > one/expect << EOF
389 drosophila/another
390 drosophila/master
391 drosophila/side
394 test_expect_success 'update default (overridden, with funny whitespace)' '
396 (cd one &&
397 for b in $(git branch -r)
399 git branch -r -d $b || break
400 done &&
401 git config remotes.default "$(printf "\t drosophila \n")" &&
402 git remote update default &&
403 git branch -r > output &&
404 test_cmp expect output)
408 test_expect_success '"remote show" does not show symbolic refs' '
410 git clone one three &&
411 (cd three &&
412 git remote show origin > output &&
413 ! grep "^ *HEAD$" < output &&
414 ! grep -i stale < output)
418 test_expect_success 'reject adding remote with an invalid name' '
420 test_must_fail git remote add some:url desired-name
424 # The first three test if the tracking branches are properly renamed,
425 # the last two ones check if the config is updated.
427 test_expect_success 'rename a remote' '
429 git clone one four &&
430 (cd four &&
431 git remote rename origin upstream &&
432 rmdir .git/refs/remotes/origin &&
433 test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
434 test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
435 test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
436 test "$(git config branch.master.remote)" = "upstream")
440 cat > remotes_origin << EOF
441 URL: $(pwd)/one
442 Push: refs/heads/master:refs/heads/upstream
443 Pull: refs/heads/master:refs/heads/origin
446 test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
447 git clone one five &&
448 origin_url=$(pwd)/one &&
449 (cd five &&
450 git remote rm origin &&
451 mkdir -p .git/remotes &&
452 cat ../remotes_origin > .git/remotes/origin &&
453 git remote rename origin origin &&
454 ! test -f .git/remotes/origin &&
455 test "$(git config remote.origin.url)" = "$origin_url" &&
456 test "$(git config remote.origin.push)" = "refs/heads/master:refs/heads/upstream" &&
457 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
460 test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
461 git clone one six &&
462 origin_url=$(pwd)/one &&
463 (cd six &&
464 git remote rm origin &&
465 echo "$origin_url" > .git/branches/origin &&
466 git remote rename origin origin &&
467 ! test -f .git/branches/origin &&
468 test "$(git config remote.origin.url)" = "$origin_url" &&
469 test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
472 test_expect_success 'remote prune to cause a dangling symref' '
473 git clone one seven &&
475 cd one &&
476 git checkout side2 &&
477 git branch -D master
478 ) &&
480 cd seven &&
481 git remote prune origin
482 ) 2>err &&
483 grep "has become dangling" err &&
485 : And the dangling symref will not cause other annoying errors
487 cd seven &&
488 git branch -a
489 ) 2>err &&
490 ! grep "points nowhere" err
492 cd seven &&
493 test_must_fail git branch nomore origin
494 ) 2>err &&
495 grep "dangling symref" err
498 test_done