]>
Commit | Line | Data |
---|---|---|
683b5679 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='git remote porcelain-ish' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
683b5679 JH |
7 | setup_repository () { |
8 | mkdir "$1" && ( | |
9 | cd "$1" && | |
10 | git init && | |
11 | >file && | |
12 | git add file && | |
84521ed6 | 13 | test_tick && |
683b5679 JH |
14 | git commit -m "Initial" && |
15 | git checkout -b side && | |
16 | >elif && | |
17 | git add elif && | |
84521ed6 | 18 | test_tick && |
683b5679 JH |
19 | git commit -m "Second" && |
20 | git checkout master | |
21 | ) | |
22 | } | |
23 | ||
24 | tokens_match () { | |
25 | echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect && | |
26 | echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual && | |
82ebb0b6 | 27 | test_cmp expect actual |
683b5679 JH |
28 | } |
29 | ||
30 | check_remote_track () { | |
7ecbbf87 | 31 | actual=$(git remote show "$1" | sed -ne 's|^ \(.*\) tracked$|\1|p') |
683b5679 JH |
32 | shift && |
33 | tokens_match "$*" "$actual" | |
34 | } | |
35 | ||
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" | |
42 | } | |
43 | ||
44 | test_expect_success setup ' | |
45 | ||
46 | setup_repository one && | |
47 | setup_repository two && | |
48 | ( | |
49 | cd two && git branch another | |
50 | ) && | |
51 | git clone one test | |
52 | ||
53 | ' | |
54 | ||
f7dc6a96 | 55 | test_expect_success C_LOCALE_OUTPUT 'remote information for the origin' ' |
683b5679 JH |
56 | ( |
57 | cd test && | |
58 | tokens_match origin "$(git remote)" && | |
59 | check_remote_track origin master side && | |
60 | check_tracking_branch origin HEAD master side | |
61 | ) | |
62 | ' | |
63 | ||
64 | test_expect_success 'add another remote' ' | |
65 | ( | |
66 | cd test && | |
67 | git remote add -f second ../two && | |
68 | tokens_match "origin second" "$(git remote)" && | |
683b5679 JH |
69 | check_tracking_branch second master side another && |
70 | git for-each-ref "--format=%(refname)" refs/remotes | | |
71 | sed -e "/^refs\/remotes\/origin\//d" \ | |
72 | -e "/^refs\/remotes\/second\//d" >actual && | |
73 | >expect && | |
82ebb0b6 | 74 | test_cmp expect actual |
683b5679 JH |
75 | ) |
76 | ' | |
77 | ||
f7dc6a96 JX |
78 | test_expect_success C_LOCALE_OUTPUT 'check remote tracking' ' |
79 | ( | |
80 | cd test && | |
81 | check_remote_track origin master side && | |
82 | check_remote_track second master side another | |
83 | ) | |
84 | ' | |
85 | ||
1ce89cc4 JK |
86 | test_expect_success 'remote forces tracking branches' ' |
87 | ( | |
88 | cd test && | |
89 | case `git config remote.second.fetch` in | |
90 | +*) true ;; | |
91 | *) false ;; | |
92 | esac | |
93 | ) | |
94 | ' | |
95 | ||
683b5679 JH |
96 | test_expect_success 'remove remote' ' |
97 | ( | |
98 | cd test && | |
3b9dcff5 | 99 | git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master && |
683b5679 JH |
100 | git remote rm second |
101 | ) | |
102 | ' | |
103 | ||
f7dc6a96 | 104 | test_expect_success C_LOCALE_OUTPUT 'remove remote' ' |
683b5679 JH |
105 | ( |
106 | cd test && | |
107 | tokens_match origin "$(git remote)" && | |
108 | check_remote_track origin master side && | |
109 | git for-each-ref "--format=%(refname)" refs/remotes | | |
110 | sed -e "/^refs\/remotes\/origin\//d" >actual && | |
111 | >expect && | |
82ebb0b6 | 112 | test_cmp expect actual |
683b5679 JH |
113 | ) |
114 | ' | |
115 | ||
13931236 | 116 | test_expect_success 'remove remote protects local branches' ' |
441adf0c JS |
117 | ( |
118 | cd test && | |
65f83dc0 | 119 | { cat >expect1 <<EOF |
13931236 MM |
120 | Note: A branch outside the refs/remotes/ hierarchy was not removed; |
121 | to delete it, use: | |
441adf0c JS |
122 | git branch -d master |
123 | EOF | |
65f83dc0 BC |
124 | } && |
125 | { cat >expect2 <<EOF | |
13931236 MM |
126 | Note: Some branches outside the refs/remotes/ hierarchy were not removed; |
127 | to delete them, use: | |
441adf0c JS |
128 | git branch -d foobranch |
129 | git branch -d master | |
130 | EOF | |
65f83dc0 | 131 | } && |
f3b1fbf8 | 132 | git tag footag && |
441adf0c | 133 | git config --add remote.oops.fetch "+refs/*:refs/*" && |
e17dba8f | 134 | git remote remove oops 2>actual1 && |
441adf0c JS |
135 | git branch foobranch && |
136 | git config --add remote.oops.fetch "+refs/*:refs/*" && | |
137 | git remote rm oops 2>actual2 && | |
138 | git branch -d foobranch && | |
139 | git tag -d footag && | |
f7dc6a96 JX |
140 | test_i18ncmp expect1 actual1 && |
141 | test_i18ncmp expect2 actual2 | |
441adf0c JS |
142 | ) |
143 | ' | |
144 | ||
4704640b JS |
145 | cat > test/expect << EOF |
146 | * remote origin | |
857f8c30 MG |
147 | Fetch URL: $(pwd)/one |
148 | Push URL: $(pwd)/one | |
e61e0cc6 | 149 | HEAD branch: master |
7ecbbf87 JS |
150 | Remote branches: |
151 | master new (next fetch will store in remotes/origin) | |
152 | side tracked | |
153 | Local branches configured for 'git pull': | |
e5dcbfd9 | 154 | ahead merges with remote master |
7ecbbf87 JS |
155 | master merges with remote master |
156 | octopus merges with remote topic-a | |
157 | and with remote topic-b | |
158 | and with remote topic-c | |
159 | rebase rebases onto remote master | |
e5dcbfd9 JS |
160 | Local refs configured for 'git push': |
161 | master pushes to master (local out of date) | |
162 | master pushes to upstream (create) | |
e61e0cc6 | 163 | * remote two |
857f8c30 MG |
164 | Fetch URL: ../two |
165 | Push URL: ../three | |
e61e0cc6 JS |
166 | HEAD branch (remote HEAD is ambiguous, may be one of the following): |
167 | another | |
168 | master | |
e5dcbfd9 | 169 | Local refs configured for 'git push': |
a75d7b54 | 170 | ahead forces to master (fast-forwardable) |
e5dcbfd9 | 171 | master pushes to another (up to date) |
4704640b JS |
172 | EOF |
173 | ||
174 | test_expect_success 'show' ' | |
175 | (cd test && | |
7ecbbf87 | 176 | git config --add remote.origin.fetch refs/heads/master:refs/heads/upstream && |
4704640b | 177 | git fetch && |
e5dcbfd9 JS |
178 | git checkout -b ahead origin/master && |
179 | echo 1 >> file && | |
180 | test_tick && | |
181 | git commit -m update file && | |
182 | git checkout master && | |
7ecbbf87 JS |
183 | git branch --track octopus origin/master && |
184 | git branch --track rebase origin/master && | |
4704640b | 185 | git branch -d -r origin/master && |
e61e0cc6 | 186 | git config --add remote.two.url ../two && |
857f8c30 | 187 | git config --add remote.two.pushurl ../three && |
7ecbbf87 JS |
188 | git config branch.rebase.rebase true && |
189 | git config branch.octopus.merge "topic-a topic-b topic-c" && | |
4704640b JS |
190 | (cd ../one && |
191 | echo 1 > file && | |
84521ed6 | 192 | test_tick && |
4704640b | 193 | git commit -m update file) && |
e5dcbfd9 JS |
194 | git config --add remote.origin.push : && |
195 | git config --add remote.origin.push refs/heads/master:refs/heads/upstream && | |
7ecbbf87 | 196 | git config --add remote.origin.push +refs/tags/lastbackup && |
e5dcbfd9 JS |
197 | git config --add remote.two.push +refs/heads/ahead:refs/heads/master && |
198 | git config --add remote.two.push refs/heads/master:refs/heads/another && | |
e61e0cc6 | 199 | git remote show origin two > output && |
7ecbbf87 | 200 | git branch -d rebase octopus && |
f7dc6a96 | 201 | test_i18ncmp expect output) |
4704640b JS |
202 | ' |
203 | ||
0ecfcb3b OM |
204 | cat > test/expect << EOF |
205 | * remote origin | |
857f8c30 MG |
206 | Fetch URL: $(pwd)/one |
207 | Push URL: $(pwd)/one | |
e61e0cc6 | 208 | HEAD branch: (not queried) |
7ecbbf87 | 209 | Remote branches: (status not queried) |
20244ea2 JS |
210 | master |
211 | side | |
e5dcbfd9 JS |
212 | Local branches configured for 'git pull': |
213 | ahead merges with remote master | |
7ecbbf87 | 214 | master merges with remote master |
e5dcbfd9 JS |
215 | Local refs configured for 'git push' (status not queried): |
216 | (matching) pushes to (matching) | |
217 | refs/heads/master pushes to refs/heads/upstream | |
218 | refs/tags/lastbackup forces to refs/tags/lastbackup | |
0ecfcb3b OM |
219 | EOF |
220 | ||
221 | test_expect_success 'show -n' ' | |
222 | (mv one one.unreachable && | |
223 | cd test && | |
224 | git remote show -n origin > output && | |
225 | mv ../one.unreachable ../one && | |
f7dc6a96 | 226 | test_i18ncmp expect output) |
0ecfcb3b OM |
227 | ' |
228 | ||
4704640b JS |
229 | test_expect_success 'prune' ' |
230 | (cd one && | |
231 | git branch -m side side2) && | |
232 | (cd test && | |
233 | git fetch origin && | |
234 | git remote prune origin && | |
235 | git rev-parse refs/remotes/origin/side2 && | |
d492b31c | 236 | test_must_fail git rev-parse refs/remotes/origin/side) |
4704640b JS |
237 | ' |
238 | ||
bc14fac8 JS |
239 | test_expect_success 'set-head --delete' ' |
240 | (cd test && | |
241 | git symbolic-ref refs/remotes/origin/HEAD && | |
242 | git remote set-head --delete origin && | |
243 | test_must_fail git symbolic-ref refs/remotes/origin/HEAD) | |
244 | ' | |
245 | ||
246 | test_expect_success 'set-head --auto' ' | |
247 | (cd test && | |
248 | git remote set-head --auto origin && | |
249 | echo refs/remotes/origin/master >expect && | |
250 | git symbolic-ref refs/remotes/origin/HEAD >output && | |
251 | test_cmp expect output | |
252 | ) | |
253 | ' | |
254 | ||
255 | cat >test/expect <<EOF | |
256 | error: Multiple remote HEAD branches. Please choose one explicitly with: | |
257 | git remote set-head two another | |
258 | git remote set-head two master | |
259 | EOF | |
260 | ||
261 | test_expect_success 'set-head --auto fails w/multiple HEADs' ' | |
262 | (cd test && | |
263 | test_must_fail git remote set-head --auto two >output 2>&1 && | |
f7dc6a96 | 264 | test_i18ncmp expect output) |
bc14fac8 JS |
265 | ' |
266 | ||
267 | cat >test/expect <<EOF | |
268 | refs/remotes/origin/side2 | |
269 | EOF | |
270 | ||
271 | test_expect_success 'set-head explicit' ' | |
272 | (cd test && | |
273 | git remote set-head origin side2 && | |
274 | git symbolic-ref refs/remotes/origin/HEAD >output && | |
275 | git remote set-head origin master && | |
276 | test_cmp expect output) | |
277 | ' | |
278 | ||
8d767927 OM |
279 | cat > test/expect << EOF |
280 | Pruning origin | |
86521aca | 281 | URL: $(pwd)/one |
8d767927 OM |
282 | * [would prune] origin/side2 |
283 | EOF | |
284 | ||
285 | test_expect_success 'prune --dry-run' ' | |
286 | (cd one && | |
287 | git branch -m side2 side) && | |
288 | (cd test && | |
289 | git remote prune --dry-run origin > output && | |
290 | git rev-parse refs/remotes/origin/side2 && | |
d492b31c | 291 | test_must_fail git rev-parse refs/remotes/origin/side && |
8d767927 OM |
292 | (cd ../one && |
293 | git branch -m side side2) && | |
f7dc6a96 | 294 | test_i18ncmp expect output) |
8d767927 OM |
295 | ' |
296 | ||
4ebc914c JS |
297 | test_expect_success 'add --mirror && prune' ' |
298 | (mkdir mirror && | |
299 | cd mirror && | |
8ee5d731 | 300 | git init --bare && |
4ebc914c JS |
301 | git remote add --mirror -f origin ../one) && |
302 | (cd one && | |
303 | git branch -m side2 side) && | |
304 | (cd mirror && | |
305 | git rev-parse --verify refs/heads/side2 && | |
d492b31c | 306 | test_must_fail git rev-parse --verify refs/heads/side && |
4ebc914c JS |
307 | git fetch origin && |
308 | git remote prune origin && | |
d492b31c | 309 | test_must_fail git rev-parse --verify refs/heads/side2 && |
4ebc914c JS |
310 | git rev-parse --verify refs/heads/side) |
311 | ' | |
312 | ||
a9f5a355 JK |
313 | test_expect_success 'add --mirror=fetch' ' |
314 | mkdir mirror-fetch && | |
315 | git init mirror-fetch/parent && | |
316 | (cd mirror-fetch/parent && | |
317 | test_commit one) && | |
318 | git init --bare mirror-fetch/child && | |
319 | (cd mirror-fetch/child && | |
320 | git remote add --mirror=fetch -f parent ../parent) | |
321 | ' | |
322 | ||
323 | test_expect_success 'fetch mirrors act as mirrors during fetch' ' | |
324 | (cd mirror-fetch/parent && | |
325 | git branch new && | |
326 | git branch -m master renamed | |
327 | ) && | |
328 | (cd mirror-fetch/child && | |
329 | git fetch parent && | |
330 | git rev-parse --verify refs/heads/new && | |
331 | git rev-parse --verify refs/heads/renamed | |
332 | ) | |
333 | ' | |
334 | ||
335 | test_expect_success 'fetch mirrors can prune' ' | |
336 | (cd mirror-fetch/child && | |
337 | git remote prune parent && | |
338 | test_must_fail git rev-parse --verify refs/heads/master | |
339 | ) | |
340 | ' | |
341 | ||
342 | test_expect_success 'fetch mirrors do not act as mirrors during push' ' | |
343 | (cd mirror-fetch/parent && | |
344 | git checkout HEAD^0 | |
345 | ) && | |
346 | (cd mirror-fetch/child && | |
347 | git branch -m renamed renamed2 && | |
f10b7fcc | 348 | git push parent : |
a9f5a355 JK |
349 | ) && |
350 | (cd mirror-fetch/parent && | |
351 | git rev-parse --verify renamed && | |
352 | test_must_fail git rev-parse --verify refs/heads/renamed2 | |
353 | ) | |
354 | ' | |
355 | ||
3eafdc96 JK |
356 | test_expect_success 'add fetch mirror with specific branches' ' |
357 | git init --bare mirror-fetch/track && | |
358 | (cd mirror-fetch/track && | |
359 | git remote add --mirror=fetch -t heads/new parent ../parent | |
360 | ) | |
361 | ' | |
362 | ||
363 | test_expect_success 'fetch mirror respects specific branches' ' | |
364 | (cd mirror-fetch/track && | |
365 | git fetch parent && | |
366 | git rev-parse --verify refs/heads/new && | |
367 | test_must_fail git rev-parse --verify refs/heads/renamed | |
368 | ) | |
369 | ' | |
370 | ||
a9f5a355 JK |
371 | test_expect_success 'add --mirror=push' ' |
372 | mkdir mirror-push && | |
373 | git init --bare mirror-push/public && | |
374 | git init mirror-push/private && | |
375 | (cd mirror-push/private && | |
376 | test_commit one && | |
377 | git remote add --mirror=push public ../public | |
378 | ) | |
379 | ' | |
380 | ||
381 | test_expect_success 'push mirrors act as mirrors during push' ' | |
382 | (cd mirror-push/private && | |
383 | git branch new && | |
384 | git branch -m master renamed && | |
385 | git push public | |
386 | ) && | |
387 | (cd mirror-push/private && | |
388 | git rev-parse --verify refs/heads/new && | |
389 | git rev-parse --verify refs/heads/renamed && | |
390 | test_must_fail git rev-parse --verify refs/heads/master | |
391 | ) | |
392 | ' | |
393 | ||
394 | test_expect_success 'push mirrors do not act as mirrors during fetch' ' | |
395 | (cd mirror-push/public && | |
396 | git branch -m renamed renamed2 && | |
397 | git symbolic-ref HEAD refs/heads/renamed2 | |
398 | ) && | |
399 | (cd mirror-push/private && | |
400 | git fetch public && | |
401 | git rev-parse --verify refs/heads/renamed && | |
402 | test_must_fail git rev-parse --verify refs/heads/renamed2 | |
403 | ) | |
404 | ' | |
405 | ||
3eafdc96 JK |
406 | test_expect_success 'push mirrors do not allow you to specify refs' ' |
407 | git init mirror-push/track && | |
408 | (cd mirror-push/track && | |
409 | test_must_fail git remote add --mirror=push -t new public ../public | |
410 | ) | |
411 | ' | |
412 | ||
c175a7ad SP |
413 | test_expect_success 'add alt && prune' ' |
414 | (mkdir alttst && | |
415 | cd alttst && | |
416 | git init && | |
417 | git remote add -f origin ../one && | |
418 | git config remote.alt.url ../one && | |
419 | git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") && | |
420 | (cd one && | |
421 | git branch -m side side2) && | |
422 | (cd alttst && | |
423 | git rev-parse --verify refs/remotes/origin/side && | |
d492b31c | 424 | test_must_fail git rev-parse --verify refs/remotes/origin/side2 && |
c175a7ad SP |
425 | git fetch alt && |
426 | git remote prune alt && | |
d492b31c | 427 | test_must_fail git rev-parse --verify refs/remotes/origin/side && |
c175a7ad SP |
428 | git rev-parse --verify refs/remotes/origin/side2) |
429 | ' | |
430 | ||
111fb858 ST |
431 | cat >test/expect <<\EOF |
432 | some-tag | |
433 | EOF | |
434 | ||
435 | test_expect_success 'add with reachable tags (default)' ' | |
436 | (cd one && | |
437 | >foobar && | |
438 | git add foobar && | |
439 | git commit -m "Foobar" && | |
440 | git tag -a -m "Foobar tag" foobar-tag && | |
441 | git reset --hard HEAD~1 && | |
442 | git tag -a -m "Some tag" some-tag) && | |
443 | (mkdir add-tags && | |
444 | cd add-tags && | |
445 | git init && | |
446 | git remote add -f origin ../one && | |
447 | git tag -l some-tag >../test/output && | |
448 | git tag -l foobar-tag >>../test/output && | |
449 | test_must_fail git config remote.origin.tagopt) && | |
450 | test_cmp test/expect test/output | |
451 | ' | |
452 | ||
453 | cat >test/expect <<\EOF | |
454 | some-tag | |
455 | foobar-tag | |
456 | --tags | |
457 | EOF | |
458 | ||
459 | test_expect_success 'add --tags' ' | |
460 | (rm -rf add-tags && | |
461 | mkdir add-tags && | |
462 | cd add-tags && | |
463 | git init && | |
464 | git remote add -f --tags origin ../one && | |
465 | git tag -l some-tag >../test/output && | |
466 | git tag -l foobar-tag >>../test/output && | |
467 | git config remote.origin.tagopt >>../test/output) && | |
468 | test_cmp test/expect test/output | |
469 | ' | |
470 | ||
471 | cat >test/expect <<\EOF | |
472 | --no-tags | |
473 | EOF | |
474 | ||
475 | test_expect_success 'add --no-tags' ' | |
476 | (rm -rf add-tags && | |
477 | mkdir add-no-tags && | |
478 | cd add-no-tags && | |
479 | git init && | |
480 | git remote add -f --no-tags origin ../one && | |
481 | git tag -l some-tag >../test/output && | |
482 | git tag -l foobar-tag >../test/output && | |
483 | git config remote.origin.tagopt >>../test/output) && | |
484 | (cd one && | |
485 | git tag -d some-tag foobar-tag) && | |
486 | test_cmp test/expect test/output | |
487 | ' | |
488 | ||
489 | test_expect_success 'reject --no-no-tags' ' | |
490 | (cd add-no-tags && | |
491 | test_must_fail git remote add -f --no-no-tags neworigin ../one) | |
492 | ' | |
493 | ||
84521ed6 JS |
494 | cat > one/expect << EOF |
495 | apis/master | |
496 | apis/side | |
497 | drosophila/another | |
498 | drosophila/master | |
499 | drosophila/side | |
500 | EOF | |
501 | ||
502 | test_expect_success 'update' ' | |
503 | ||
504 | (cd one && | |
505 | git remote add drosophila ../two && | |
506 | git remote add apis ../mirror && | |
507 | git remote update && | |
508 | git branch -r > output && | |
3af82863 | 509 | test_cmp expect output) |
84521ed6 JS |
510 | |
511 | ' | |
512 | ||
513 | cat > one/expect << EOF | |
514 | drosophila/another | |
515 | drosophila/master | |
516 | drosophila/side | |
517 | manduca/master | |
518 | manduca/side | |
519 | megaloprepus/master | |
520 | megaloprepus/side | |
521 | EOF | |
522 | ||
523 | test_expect_success 'update with arguments' ' | |
524 | ||
525 | (cd one && | |
526 | for b in $(git branch -r) | |
527 | do | |
528 | git branch -r -d $b || break | |
529 | done && | |
530 | git remote add manduca ../mirror && | |
531 | git remote add megaloprepus ../mirror && | |
532 | git config remotes.phobaeticus "drosophila megaloprepus" && | |
533 | git config remotes.titanus manduca && | |
534 | git remote update phobaeticus titanus && | |
535 | git branch -r > output && | |
3af82863 | 536 | test_cmp expect output) |
84521ed6 JS |
537 | |
538 | ' | |
539 | ||
e2d41c64 BG |
540 | test_expect_success 'update --prune' ' |
541 | ||
542 | (cd one && | |
543 | git branch -m side2 side3) && | |
544 | (cd test && | |
545 | git remote update --prune && | |
65b26eb4 | 546 | (cd ../one && git branch -m side3 side2) && |
e2d41c64 BG |
547 | git rev-parse refs/remotes/origin/side3 && |
548 | test_must_fail git rev-parse refs/remotes/origin/side2) | |
549 | ' | |
550 | ||
84521ed6 JS |
551 | cat > one/expect << EOF |
552 | apis/master | |
553 | apis/side | |
554 | manduca/master | |
555 | manduca/side | |
556 | megaloprepus/master | |
557 | megaloprepus/side | |
558 | EOF | |
559 | ||
560 | test_expect_success 'update default' ' | |
561 | ||
562 | (cd one && | |
563 | for b in $(git branch -r) | |
564 | do | |
565 | git branch -r -d $b || break | |
566 | done && | |
567 | git config remote.drosophila.skipDefaultUpdate true && | |
568 | git remote update default && | |
569 | git branch -r > output && | |
3af82863 | 570 | test_cmp expect output) |
84521ed6 JS |
571 | |
572 | ' | |
573 | ||
574 | cat > one/expect << EOF | |
575 | drosophila/another | |
576 | drosophila/master | |
577 | drosophila/side | |
578 | EOF | |
579 | ||
580 | test_expect_success 'update default (overridden, with funny whitespace)' ' | |
581 | ||
582 | (cd one && | |
583 | for b in $(git branch -r) | |
584 | do | |
585 | git branch -r -d $b || break | |
586 | done && | |
587 | git config remotes.default "$(printf "\t drosophila \n")" && | |
588 | git remote update default && | |
589 | git branch -r > output && | |
3af82863 | 590 | test_cmp expect output) |
84521ed6 JS |
591 | |
592 | ' | |
593 | ||
4f2e842d BG |
594 | test_expect_success 'update (with remotes.default defined)' ' |
595 | ||
596 | (cd one && | |
597 | for b in $(git branch -r) | |
598 | do | |
599 | git branch -r -d $b || break | |
600 | done && | |
601 | git config remotes.default "drosophila" && | |
602 | git remote update && | |
603 | git branch -r > output && | |
604 | test_cmp expect output) | |
605 | ||
606 | ' | |
607 | ||
740fdd27 JS |
608 | test_expect_success '"remote show" does not show symbolic refs' ' |
609 | ||
610 | git clone one three && | |
611 | (cd three && | |
612 | git remote show origin > output && | |
e61e0cc6 | 613 | ! grep "^ *HEAD$" < output && |
740fdd27 JS |
614 | ! grep -i stale < output) |
615 | ||
616 | ' | |
617 | ||
24b6177e JF |
618 | test_expect_success 'reject adding remote with an invalid name' ' |
619 | ||
d492b31c | 620 | test_must_fail git remote add some:url desired-name |
24b6177e JF |
621 | |
622 | ' | |
623 | ||
bf98421a MV |
624 | # The first three test if the tracking branches are properly renamed, |
625 | # the last two ones check if the config is updated. | |
626 | ||
627 | test_expect_success 'rename a remote' ' | |
628 | ||
629 | git clone one four && | |
630 | (cd four && | |
631 | git remote rename origin upstream && | |
632 | rmdir .git/refs/remotes/origin && | |
633 | test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" && | |
634 | test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" && | |
635 | test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" && | |
636 | test "$(git config branch.master.remote)" = "upstream") | |
637 | ||
638 | ' | |
1dd1239a | 639 | |
28f555f6 MZ |
640 | test_expect_success 'rename does not update a non-default fetch refspec' ' |
641 | ||
642 | git clone one four.one && | |
643 | (cd four.one && | |
644 | git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* && | |
645 | git remote rename origin upstream && | |
b52d00ae MZ |
646 | test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" && |
647 | git rev-parse -q origin/master) | |
28f555f6 MZ |
648 | |
649 | ' | |
650 | ||
651 | test_expect_success 'rename a remote with name part of fetch spec' ' | |
652 | ||
653 | git clone one four.two && | |
654 | (cd four.two && | |
655 | git remote rename origin remote && | |
656 | git remote rename remote upstream && | |
657 | test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*") | |
658 | ||
659 | ' | |
660 | ||
60e5eee0 MZ |
661 | test_expect_success 'rename a remote with name prefix of other remote' ' |
662 | ||
663 | git clone one four.three && | |
664 | (cd four.three && | |
665 | git remote add o git://example.com/repo.git && | |
666 | git remote rename o upstream && | |
667 | test "$(git rev-parse origin/master)" = "$(git rev-parse master)") | |
668 | ||
669 | ' | |
670 | ||
1dd1239a MV |
671 | cat > remotes_origin << EOF |
672 | URL: $(pwd)/one | |
673 | Push: refs/heads/master:refs/heads/upstream | |
674 | Pull: refs/heads/master:refs/heads/origin | |
675 | EOF | |
676 | ||
677 | test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' ' | |
678 | git clone one five && | |
679 | origin_url=$(pwd)/one && | |
680 | (cd five && | |
e17dba8f | 681 | git remote remove origin && |
1dd1239a MV |
682 | mkdir -p .git/remotes && |
683 | cat ../remotes_origin > .git/remotes/origin && | |
684 | git remote rename origin origin && | |
685 | ! test -f .git/remotes/origin && | |
686 | test "$(git config remote.origin.url)" = "$origin_url" && | |
687 | test "$(git config remote.origin.push)" = "refs/heads/master:refs/heads/upstream" && | |
688 | test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin") | |
689 | ' | |
690 | ||
691 | test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' ' | |
692 | git clone one six && | |
693 | origin_url=$(pwd)/one && | |
694 | (cd six && | |
695 | git remote rm origin && | |
696 | echo "$origin_url" > .git/branches/origin && | |
697 | git remote rename origin origin && | |
698 | ! test -f .git/branches/origin && | |
699 | test "$(git config remote.origin.url)" = "$origin_url" && | |
700 | test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin") | |
701 | ' | |
702 | ||
f8948e2f JH |
703 | test_expect_success 'remote prune to cause a dangling symref' ' |
704 | git clone one seven && | |
705 | ( | |
706 | cd one && | |
707 | git checkout side2 && | |
708 | git branch -D master | |
709 | ) && | |
710 | ( | |
711 | cd seven && | |
712 | git remote prune origin | |
e01de1c9 | 713 | ) >err 2>&1 && |
f7dc6a96 | 714 | test_i18ngrep "has become dangling" err && |
f8948e2f | 715 | |
e01de1c9 | 716 | : And the dangling symref will not cause other annoying errors && |
f8948e2f JH |
717 | ( |
718 | cd seven && | |
719 | git branch -a | |
720 | ) 2>err && | |
e01de1c9 | 721 | ! grep "points nowhere" err && |
057e7138 JH |
722 | ( |
723 | cd seven && | |
724 | test_must_fail git branch nomore origin | |
725 | ) 2>err && | |
726 | grep "dangling symref" err | |
f8948e2f JH |
727 | ' |
728 | ||
6a01554e CB |
729 | test_expect_success 'show empty remote' ' |
730 | ||
731 | test_create_repo empty && | |
732 | git clone empty empty-clone && | |
733 | ( | |
734 | cd empty-clone && | |
735 | git remote show origin | |
736 | ) | |
737 | ' | |
738 | ||
3d8b6949 JN |
739 | test_expect_success 'remote set-branches requires a remote' ' |
740 | test_must_fail git remote set-branches && | |
741 | test_must_fail git remote set-branches --add | |
742 | ' | |
743 | ||
744 | test_expect_success 'remote set-branches' ' | |
745 | echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial && | |
746 | sort <<-\EOF >expect.add && | |
747 | +refs/heads/*:refs/remotes/scratch/* | |
748 | +refs/heads/other:refs/remotes/scratch/other | |
749 | EOF | |
750 | sort <<-\EOF >expect.replace && | |
751 | +refs/heads/maint:refs/remotes/scratch/maint | |
752 | +refs/heads/master:refs/remotes/scratch/master | |
753 | +refs/heads/next:refs/remotes/scratch/next | |
754 | EOF | |
755 | sort <<-\EOF >expect.add-two && | |
756 | +refs/heads/maint:refs/remotes/scratch/maint | |
757 | +refs/heads/master:refs/remotes/scratch/master | |
758 | +refs/heads/next:refs/remotes/scratch/next | |
759 | +refs/heads/pu:refs/remotes/scratch/pu | |
760 | +refs/heads/t/topic:refs/remotes/scratch/t/topic | |
761 | EOF | |
762 | sort <<-\EOF >expect.setup-ffonly && | |
763 | refs/heads/master:refs/remotes/scratch/master | |
764 | +refs/heads/next:refs/remotes/scratch/next | |
765 | EOF | |
766 | sort <<-\EOF >expect.respect-ffonly && | |
767 | refs/heads/master:refs/remotes/scratch/master | |
768 | +refs/heads/next:refs/remotes/scratch/next | |
769 | +refs/heads/pu:refs/remotes/scratch/pu | |
770 | EOF | |
771 | ||
772 | git clone .git/ setbranches && | |
773 | ( | |
774 | cd setbranches && | |
775 | git remote rename origin scratch && | |
776 | git config --get-all remote.scratch.fetch >config-result && | |
777 | sort <config-result >../actual.initial && | |
778 | ||
779 | git remote set-branches scratch --add other && | |
780 | git config --get-all remote.scratch.fetch >config-result && | |
781 | sort <config-result >../actual.add && | |
782 | ||
783 | git remote set-branches scratch maint master next && | |
784 | git config --get-all remote.scratch.fetch >config-result && | |
785 | sort <config-result >../actual.replace && | |
786 | ||
787 | git remote set-branches --add scratch pu t/topic && | |
788 | git config --get-all remote.scratch.fetch >config-result && | |
789 | sort <config-result >../actual.add-two && | |
790 | ||
791 | git config --unset-all remote.scratch.fetch && | |
792 | git config remote.scratch.fetch \ | |
793 | refs/heads/master:refs/remotes/scratch/master && | |
794 | git config --add remote.scratch.fetch \ | |
795 | +refs/heads/next:refs/remotes/scratch/next && | |
796 | git config --get-all remote.scratch.fetch >config-result && | |
797 | sort <config-result >../actual.setup-ffonly && | |
798 | ||
799 | git remote set-branches --add scratch pu && | |
800 | git config --get-all remote.scratch.fetch >config-result && | |
801 | sort <config-result >../actual.respect-ffonly | |
802 | ) && | |
803 | test_cmp expect.initial actual.initial && | |
804 | test_cmp expect.add actual.add && | |
805 | test_cmp expect.replace actual.replace && | |
806 | test_cmp expect.add-two actual.add-two && | |
807 | test_cmp expect.setup-ffonly actual.setup-ffonly && | |
808 | test_cmp expect.respect-ffonly actual.respect-ffonly | |
809 | ' | |
810 | ||
811 | test_expect_success 'remote set-branches with --mirror' ' | |
812 | echo "+refs/*:refs/*" >expect.initial && | |
813 | echo "+refs/heads/master:refs/heads/master" >expect.replace && | |
814 | git clone --mirror .git/ setbranches-mirror && | |
815 | ( | |
816 | cd setbranches-mirror && | |
817 | git remote rename origin scratch && | |
818 | git config --get-all remote.scratch.fetch >../actual.initial && | |
819 | ||
820 | git remote set-branches scratch heads/master && | |
821 | git config --get-all remote.scratch.fetch >../actual.replace | |
822 | ) && | |
823 | test_cmp expect.initial actual.initial && | |
824 | test_cmp expect.replace actual.replace | |
825 | ' | |
826 | ||
433f2be1 | 827 | test_expect_success 'new remote' ' |
433f2be1 IL |
828 | git remote add someremote foo && |
829 | echo foo >expect && | |
830 | git config --get-all remote.someremote.url >actual && | |
831 | cmp expect actual | |
433f2be1 IL |
832 | ' |
833 | ||
834 | test_expect_success 'remote set-url bar' ' | |
433f2be1 IL |
835 | git remote set-url someremote bar && |
836 | echo bar >expect && | |
837 | git config --get-all remote.someremote.url >actual && | |
838 | cmp expect actual | |
433f2be1 | 839 | ' |
057e7138 | 840 | |
433f2be1 | 841 | test_expect_success 'remote set-url baz bar' ' |
433f2be1 IL |
842 | git remote set-url someremote baz bar && |
843 | echo baz >expect && | |
844 | git config --get-all remote.someremote.url >actual && | |
845 | cmp expect actual | |
433f2be1 IL |
846 | ' |
847 | ||
848 | test_expect_success 'remote set-url zot bar' ' | |
433f2be1 IL |
849 | test_must_fail git remote set-url someremote zot bar && |
850 | echo baz >expect && | |
851 | git config --get-all remote.someremote.url >actual && | |
852 | cmp expect actual | |
433f2be1 IL |
853 | ' |
854 | ||
855 | test_expect_success 'remote set-url --push zot baz' ' | |
433f2be1 IL |
856 | test_must_fail git remote set-url --push someremote zot baz && |
857 | echo "YYY" >expect && | |
858 | echo baz >>expect && | |
859 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
860 | echo "YYY" >>actual && | |
861 | git config --get-all remote.someremote.url >>actual && | |
862 | cmp expect actual | |
433f2be1 IL |
863 | ' |
864 | ||
865 | test_expect_success 'remote set-url --push zot' ' | |
433f2be1 IL |
866 | git remote set-url --push someremote zot && |
867 | echo zot >expect && | |
868 | echo "YYY" >>expect && | |
869 | echo baz >>expect && | |
870 | git config --get-all remote.someremote.pushurl >actual && | |
871 | echo "YYY" >>actual && | |
872 | git config --get-all remote.someremote.url >>actual && | |
873 | cmp expect actual | |
433f2be1 IL |
874 | ' |
875 | ||
876 | test_expect_success 'remote set-url --push qux zot' ' | |
433f2be1 IL |
877 | git remote set-url --push someremote qux zot && |
878 | echo qux >expect && | |
879 | echo "YYY" >>expect && | |
880 | echo baz >>expect && | |
881 | git config --get-all remote.someremote.pushurl >actual && | |
882 | echo "YYY" >>actual && | |
883 | git config --get-all remote.someremote.url >>actual && | |
884 | cmp expect actual | |
433f2be1 IL |
885 | ' |
886 | ||
887 | test_expect_success 'remote set-url --push foo qu+x' ' | |
433f2be1 IL |
888 | git remote set-url --push someremote foo qu+x && |
889 | echo foo >expect && | |
890 | echo "YYY" >>expect && | |
891 | echo baz >>expect && | |
892 | git config --get-all remote.someremote.pushurl >actual && | |
893 | echo "YYY" >>actual && | |
894 | git config --get-all remote.someremote.url >>actual && | |
895 | cmp expect actual | |
433f2be1 IL |
896 | ' |
897 | ||
898 | test_expect_success 'remote set-url --push --add aaa' ' | |
433f2be1 IL |
899 | git remote set-url --push --add someremote aaa && |
900 | echo foo >expect && | |
901 | echo aaa >>expect && | |
902 | echo "YYY" >>expect && | |
903 | echo baz >>expect && | |
904 | git config --get-all remote.someremote.pushurl >actual && | |
905 | echo "YYY" >>actual && | |
906 | git config --get-all remote.someremote.url >>actual && | |
907 | cmp expect actual | |
433f2be1 IL |
908 | ' |
909 | ||
910 | test_expect_success 'remote set-url --push bar aaa' ' | |
433f2be1 IL |
911 | git remote set-url --push someremote bar aaa && |
912 | echo foo >expect && | |
913 | echo bar >>expect && | |
914 | echo "YYY" >>expect && | |
915 | echo baz >>expect && | |
916 | git config --get-all remote.someremote.pushurl >actual && | |
917 | echo "YYY" >>actual && | |
918 | git config --get-all remote.someremote.url >>actual && | |
919 | cmp expect actual | |
433f2be1 IL |
920 | ' |
921 | ||
922 | test_expect_success 'remote set-url --push --delete bar' ' | |
433f2be1 IL |
923 | git remote set-url --push --delete someremote bar && |
924 | echo foo >expect && | |
925 | echo "YYY" >>expect && | |
926 | echo baz >>expect && | |
927 | git config --get-all remote.someremote.pushurl >actual && | |
928 | echo "YYY" >>actual && | |
929 | git config --get-all remote.someremote.url >>actual && | |
930 | cmp expect actual | |
433f2be1 IL |
931 | ' |
932 | ||
933 | test_expect_success 'remote set-url --push --delete foo' ' | |
433f2be1 IL |
934 | git remote set-url --push --delete someremote foo && |
935 | echo "YYY" >expect && | |
936 | echo baz >>expect && | |
937 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
938 | echo "YYY" >>actual && | |
939 | git config --get-all remote.someremote.url >>actual && | |
940 | cmp expect actual | |
433f2be1 IL |
941 | ' |
942 | ||
943 | test_expect_success 'remote set-url --add bbb' ' | |
433f2be1 IL |
944 | git remote set-url --add someremote bbb && |
945 | echo "YYY" >expect && | |
946 | echo baz >>expect && | |
947 | echo bbb >>expect && | |
948 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
949 | echo "YYY" >>actual && | |
950 | git config --get-all remote.someremote.url >>actual && | |
951 | cmp expect actual | |
433f2be1 IL |
952 | ' |
953 | ||
954 | test_expect_success 'remote set-url --delete .*' ' | |
49de47cf | 955 | test_must_fail git remote set-url --delete someremote .\* && |
433f2be1 IL |
956 | echo "YYY" >expect && |
957 | echo baz >>expect && | |
958 | echo bbb >>expect && | |
959 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
960 | echo "YYY" >>actual && | |
961 | git config --get-all remote.someremote.url >>actual && | |
962 | cmp expect actual | |
433f2be1 IL |
963 | ' |
964 | ||
965 | test_expect_success 'remote set-url --delete bbb' ' | |
433f2be1 IL |
966 | git remote set-url --delete someremote bbb && |
967 | echo "YYY" >expect && | |
968 | echo baz >>expect && | |
969 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
970 | echo "YYY" >>actual && | |
971 | git config --get-all remote.someremote.url >>actual && | |
972 | cmp expect actual | |
433f2be1 IL |
973 | ' |
974 | ||
975 | test_expect_success 'remote set-url --delete baz' ' | |
433f2be1 IL |
976 | test_must_fail git remote set-url --delete someremote baz && |
977 | echo "YYY" >expect && | |
978 | echo baz >>expect && | |
979 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
980 | echo "YYY" >>actual && | |
981 | git config --get-all remote.someremote.url >>actual && | |
982 | cmp expect actual | |
433f2be1 IL |
983 | ' |
984 | ||
985 | test_expect_success 'remote set-url --add ccc' ' | |
433f2be1 IL |
986 | git remote set-url --add someremote ccc && |
987 | echo "YYY" >expect && | |
988 | echo baz >>expect && | |
989 | echo ccc >>expect && | |
990 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
991 | echo "YYY" >>actual && | |
992 | git config --get-all remote.someremote.url >>actual && | |
993 | cmp expect actual | |
433f2be1 IL |
994 | ' |
995 | ||
996 | test_expect_success 'remote set-url --delete baz' ' | |
433f2be1 IL |
997 | git remote set-url --delete someremote baz && |
998 | echo "YYY" >expect && | |
999 | echo ccc >>expect && | |
1000 | test_must_fail git config --get-all remote.someremote.pushurl >actual && | |
1001 | echo "YYY" >>actual && | |
1002 | git config --get-all remote.someremote.url >>actual && | |
1003 | cmp expect actual | |
433f2be1 IL |
1004 | ' |
1005 | ||
abf5f872 TR |
1006 | test_expect_success 'extra args: setup' ' |
1007 | # add a dummy origin so that this does not trigger failure | |
1008 | git remote add origin . | |
1009 | ' | |
1010 | ||
1011 | test_extra_arg () { | |
b17dd3f9 | 1012 | test_expect_success "extra args: $*" " |
abf5f872 TR |
1013 | test_must_fail git remote $* bogus_extra_arg 2>actual && |
1014 | grep '^usage:' actual | |
1015 | " | |
1016 | } | |
1017 | ||
2d2e3d25 | 1018 | test_extra_arg add nick url |
abf5f872 TR |
1019 | test_extra_arg rename origin newname |
1020 | test_extra_arg remove origin | |
1021 | test_extra_arg set-head origin master | |
1022 | # set-branches takes any number of args | |
1023 | test_extra_arg set-url origin newurl oldurl | |
b17dd3f9 TR |
1024 | # show takes any number of args |
1025 | # prune takes any number of args | |
abf5f872 TR |
1026 | # update takes any number of args |
1027 | ||
433f2be1 | 1028 | test_done |