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