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