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