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