branch: allow -f with -m and -d
[git.git] / t / t3200-branch.sh
blobe7bbb8f0ec4c90dc0e14e9da6528960287780c91
1 #!/bin/sh
3 # Copyright (c) 2005 Amos Waterland
6 test_description='git branch assorted tests'
8 . ./test-lib.sh
10 test_expect_success 'prepare a trivial repository' '
11 echo Hello >A &&
12 git update-index --add A &&
13 git commit -m "Initial commit." &&
14 echo World >>A &&
15 git update-index --add A &&
16 git commit -m "Second commit." &&
17 HEAD=$(git rev-parse --verify HEAD)
20 test_expect_success 'git branch --help should not have created a bogus branch' '
21 test_might_fail git branch --man --help </dev/null >/dev/null 2>&1 &&
22 test_path_is_missing .git/refs/heads/--help
25 test_expect_success 'branch -h in broken repository' '
26 mkdir broken &&
28 cd broken &&
29 git init &&
30 >.git/refs/heads/master &&
31 test_expect_code 129 git branch -h >usage 2>&1
32 ) &&
33 test_i18ngrep "[Uu]sage" broken/usage
36 test_expect_success 'git branch abc should create a branch' '
37 git branch abc && test_path_is_file .git/refs/heads/abc
40 test_expect_success 'git branch a/b/c should create a branch' '
41 git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c
44 test_expect_success 'git branch HEAD should fail' '
45 test_must_fail git branch HEAD
48 cat >expect <<EOF
49 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
50 EOF
51 test_expect_success 'git branch -l d/e/f should create a branch and a log' '
52 GIT_COMMITTER_DATE="2005-05-26 23:30" \
53 git branch -l d/e/f &&
54 test_path_is_file .git/refs/heads/d/e/f &&
55 test_path_is_file .git/logs/refs/heads/d/e/f &&
56 test_cmp expect .git/logs/refs/heads/d/e/f
59 test_expect_success 'git branch -d d/e/f should delete a branch and a log' '
60 git branch -d d/e/f &&
61 test_path_is_missing .git/refs/heads/d/e/f &&
62 test_path_is_missing .git/logs/refs/heads/d/e/f
65 test_expect_success 'git branch j/k should work after branch j has been deleted' '
66 git branch j &&
67 git branch -d j &&
68 git branch j/k
71 test_expect_success 'git branch l should work after branch l/m has been deleted' '
72 git branch l/m &&
73 git branch -d l/m &&
74 git branch l
77 test_expect_success 'git branch -m dumps usage' '
78 test_expect_code 128 git branch -m 2>err &&
79 test_i18ngrep "branch name required" err
82 test_expect_success 'git branch -m m m/m should work' '
83 git branch -l m &&
84 git branch -m m m/m &&
85 test_path_is_file .git/logs/refs/heads/m/m
88 test_expect_success 'git branch -m n/n n should work' '
89 git branch -l n/n &&
90 git branch -m n/n n &&
91 test_path_is_file .git/logs/refs/heads/n
94 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
95 git branch o/o &&
96 git branch o/p &&
97 test_must_fail git branch -m o/o o
100 test_expect_success 'git branch -m o/q o/p should fail when o/p exists' '
101 git branch o/q &&
102 test_must_fail git branch -m o/q o/p
105 test_expect_success 'git branch -M o/q o/p should work when o/p exists' '
106 git branch -M o/q o/p
109 test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '
110 git branch o/q &&
111 git branch -m -f o/q o/p
114 test_expect_success 'git branch -m q r/q should fail when r exists' '
115 git branch q &&
116 git branch r &&
117 test_must_fail git branch -m q r/q
120 test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
121 git branch bar &&
122 git checkout -b foo &&
123 test_must_fail git branch -M bar foo
126 test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
127 git checkout -b baz &&
128 git branch bam &&
129 git branch -M baz bam
132 test_expect_success 'git branch -M master should work when master is checked out' '
133 git checkout master &&
134 git branch -M master
137 test_expect_success 'git branch -M master master should work when master is checked out' '
138 git checkout master &&
139 git branch -M master master
142 test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
143 git checkout master &&
144 git branch master2 &&
145 git branch -M master2 master2
148 test_expect_success 'git branch -v -d t should work' '
149 git branch t &&
150 test_path_is_file .git/refs/heads/t &&
151 git branch -v -d t &&
152 test_path_is_missing .git/refs/heads/t
155 test_expect_success 'git branch -v -m t s should work' '
156 git branch t &&
157 test_path_is_file .git/refs/heads/t &&
158 git branch -v -m t s &&
159 test_path_is_missing .git/refs/heads/t &&
160 test_path_is_file .git/refs/heads/s &&
161 git branch -d s
164 test_expect_success 'git branch -m -d t s should fail' '
165 git branch t &&
166 test_path_is_file .git/refs/heads/t &&
167 test_must_fail git branch -m -d t s &&
168 git branch -d t &&
169 test_path_is_missing .git/refs/heads/t
172 test_expect_success 'git branch --list -d t should fail' '
173 git branch t &&
174 test_path_is_file .git/refs/heads/t &&
175 test_must_fail git branch --list -d t &&
176 git branch -d t &&
177 test_path_is_missing .git/refs/heads/t
180 test_expect_success 'git branch --column' '
181 COLUMNS=81 git branch --column=column >actual &&
182 cat >expected <<\EOF &&
183 a/b/c bam foo l * master n o/p r
184 abc bar j/k m/m master2 o/o q
186 test_cmp expected actual
189 test_expect_success 'git branch --column with an extremely long branch name' '
190 long=this/is/a/part/of/long/branch/name &&
191 long=z$long/$long/$long/$long &&
192 test_when_finished "git branch -d $long" &&
193 git branch $long &&
194 COLUMNS=80 git branch --column=column >actual &&
195 cat >expected <<EOF &&
196 a/b/c
204 * master
205 master2
211 $long
213 test_cmp expected actual
216 test_expect_success 'git branch with column.*' '
217 git config column.ui column &&
218 git config column.branch "dense" &&
219 COLUMNS=80 git branch >actual &&
220 git config --unset column.branch &&
221 git config --unset column.ui &&
222 cat >expected <<\EOF &&
223 a/b/c bam foo l * master n o/p r
224 abc bar j/k m/m master2 o/o q
226 test_cmp expected actual
229 test_expect_success 'git branch --column -v should fail' '
230 test_must_fail git branch --column -v
233 test_expect_success 'git branch -v with column.ui ignored' '
234 git config column.ui column &&
235 COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
236 git config --unset column.ui &&
237 cat >expected <<\EOF &&
238 a/b/c
246 * master
247 master2
254 test_cmp expected actual
257 mv .git/config .git/config-saved
259 test_expect_success 'git branch -m q q2 without config should succeed' '
260 git branch -m q q2 &&
261 git branch -m q2 q
264 mv .git/config-saved .git/config
266 git config branch.s/s.dummy Hello
268 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
269 git branch -l s/s &&
270 test_path_is_file .git/logs/refs/heads/s/s &&
271 git branch -l s/t &&
272 test_path_is_file .git/logs/refs/heads/s/t &&
273 git branch -d s/t &&
274 git branch -m s/s s &&
275 test_path_is_file .git/logs/refs/heads/s
278 test_expect_success 'config information was renamed, too' '
279 test $(git config branch.s.dummy) = Hello &&
280 test_must_fail git config branch.s/s/dummy
283 test_expect_success 'deleting a symref' '
284 git branch target &&
285 git symbolic-ref refs/heads/symref refs/heads/target &&
286 echo "Deleted branch symref (was refs/heads/target)." >expect &&
287 git branch -d symref >actual &&
288 test_path_is_file .git/refs/heads/target &&
289 test_path_is_missing .git/refs/heads/symref &&
290 test_i18ncmp expect actual
293 test_expect_success 'deleting a dangling symref' '
294 git symbolic-ref refs/heads/dangling-symref nowhere &&
295 test_path_is_file .git/refs/heads/dangling-symref &&
296 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
297 git branch -d dangling-symref >actual &&
298 test_path_is_missing .git/refs/heads/dangling-symref &&
299 test_i18ncmp expect actual
302 test_expect_success 'renaming a symref is not allowed' '
303 git symbolic-ref refs/heads/master2 refs/heads/master &&
304 test_must_fail git branch -m master2 master3 &&
305 git symbolic-ref refs/heads/master2 &&
306 test_path_is_file .git/refs/heads/master &&
307 test_path_is_missing .git/refs/heads/master3
310 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
311 git branch -l u &&
312 mv .git/logs/refs/heads/u real-u &&
313 ln -s real-u .git/logs/refs/heads/u &&
314 test_must_fail git branch -m u v
317 test_expect_success 'test tracking setup via --track' '
318 git config remote.local.url . &&
319 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
320 (git show-ref -q refs/remotes/local/master || git fetch local) &&
321 git branch --track my1 local/master &&
322 test $(git config branch.my1.remote) = local &&
323 test $(git config branch.my1.merge) = refs/heads/master
326 test_expect_success 'test tracking setup (non-wildcard, matching)' '
327 git config remote.local.url . &&
328 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
329 (git show-ref -q refs/remotes/local/master || git fetch local) &&
330 git branch --track my4 local/master &&
331 test $(git config branch.my4.remote) = local &&
332 test $(git config branch.my4.merge) = refs/heads/master
335 test_expect_success 'tracking setup fails on non-matching refspec' '
336 git config remote.local.url . &&
337 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
338 (git show-ref -q refs/remotes/local/master || git fetch local) &&
339 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
340 test_must_fail git branch --track my5 local/master &&
341 test_must_fail git config branch.my5.remote &&
342 test_must_fail git config branch.my5.merge
345 test_expect_success 'test tracking setup via config' '
346 git config branch.autosetupmerge true &&
347 git config remote.local.url . &&
348 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
349 (git show-ref -q refs/remotes/local/master || git fetch local) &&
350 git branch my3 local/master &&
351 test $(git config branch.my3.remote) = local &&
352 test $(git config branch.my3.merge) = refs/heads/master
355 test_expect_success 'test overriding tracking setup via --no-track' '
356 git config branch.autosetupmerge true &&
357 git config remote.local.url . &&
358 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
359 (git show-ref -q refs/remotes/local/master || git fetch local) &&
360 git branch --no-track my2 local/master &&
361 git config branch.autosetupmerge false &&
362 ! test "$(git config branch.my2.remote)" = local &&
363 ! test "$(git config branch.my2.merge)" = refs/heads/master
366 test_expect_success 'no tracking without .fetch entries' '
367 git config branch.autosetupmerge true &&
368 git branch my6 s &&
369 git config branch.autosetupmerge false &&
370 test -z "$(git config branch.my6.remote)" &&
371 test -z "$(git config branch.my6.merge)"
374 test_expect_success 'test tracking setup via --track but deeper' '
375 git config remote.local.url . &&
376 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
377 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
378 git branch --track my7 local/o/o &&
379 test "$(git config branch.my7.remote)" = local &&
380 test "$(git config branch.my7.merge)" = refs/heads/o/o
383 test_expect_success 'test deleting branch deletes branch config' '
384 git branch -d my7 &&
385 test -z "$(git config branch.my7.remote)" &&
386 test -z "$(git config branch.my7.merge)"
389 test_expect_success 'test deleting branch without config' '
390 git branch my7 s &&
391 sha1=$(git rev-parse my7 | cut -c 1-7) &&
392 echo "Deleted branch my7 (was $sha1)." >expect &&
393 git branch -d my7 >actual 2>&1 &&
394 test_i18ncmp expect actual
397 test_expect_success 'test --track without .fetch entries' '
398 git branch --track my8 &&
399 test "$(git config branch.my8.remote)" &&
400 test "$(git config branch.my8.merge)"
403 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
404 git config branch.autosetupmerge always &&
405 git branch my9 HEAD^ &&
406 git config branch.autosetupmerge false
409 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
410 test_must_fail git branch --track my10 HEAD^
413 test_expect_success 'branch from tag w/--track causes failure' '
414 git tag foobar &&
415 test_must_fail git branch --track my11 foobar
418 test_expect_success '--set-upstream-to fails on multiple branches' '
419 test_must_fail git branch --set-upstream-to master a b c
422 test_expect_success '--set-upstream-to fails on detached HEAD' '
423 git checkout HEAD^{} &&
424 test_must_fail git branch --set-upstream-to master &&
425 git checkout -
428 test_expect_success '--set-upstream-to fails on a missing dst branch' '
429 test_must_fail git branch --set-upstream-to master does-not-exist
432 test_expect_success '--set-upstream-to fails on a missing src branch' '
433 test_must_fail git branch --set-upstream-to does-not-exist master
436 test_expect_success '--set-upstream-to fails on a non-ref' '
437 test_must_fail git branch --set-upstream-to HEAD^{}
440 test_expect_success 'use --set-upstream-to modify HEAD' '
441 test_config branch.master.remote foo &&
442 test_config branch.master.merge foo &&
443 git branch my12 &&
444 git branch --set-upstream-to my12 &&
445 test "$(git config branch.master.remote)" = "." &&
446 test "$(git config branch.master.merge)" = "refs/heads/my12"
449 test_expect_success 'use --set-upstream-to modify a particular branch' '
450 git branch my13 &&
451 git branch --set-upstream-to master my13 &&
452 test "$(git config branch.my13.remote)" = "." &&
453 test "$(git config branch.my13.merge)" = "refs/heads/master"
456 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
457 test_must_fail git branch --unset-upstream i-dont-exist
460 test_expect_success 'test --unset-upstream on HEAD' '
461 git branch my14 &&
462 test_config branch.master.remote foo &&
463 test_config branch.master.merge foo &&
464 git branch --set-upstream-to my14 &&
465 git branch --unset-upstream &&
466 test_must_fail git config branch.master.remote &&
467 test_must_fail git config branch.master.merge &&
468 # fail for a branch without upstream set
469 test_must_fail git branch --unset-upstream
472 test_expect_success '--unset-upstream should fail on multiple branches' '
473 test_must_fail git branch --unset-upstream a b c
476 test_expect_success '--unset-upstream should fail on detached HEAD' '
477 git checkout HEAD^{} &&
478 test_must_fail git branch --unset-upstream &&
479 git checkout -
482 test_expect_success 'test --unset-upstream on a particular branch' '
483 git branch my15 &&
484 git branch --set-upstream-to master my14 &&
485 git branch --unset-upstream my14 &&
486 test_must_fail git config branch.my14.remote &&
487 test_must_fail git config branch.my14.merge
490 test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
491 git update-ref refs/remotes/origin/master HEAD &&
492 git branch --set-upstream origin/master 2>actual &&
493 test_when_finished git update-ref -d refs/remotes/origin/master &&
494 test_when_finished git branch -d origin/master &&
495 cat >expected <<EOF &&
496 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
498 If you wanted to make '"'master'"' track '"'origin/master'"', do this:
500 git branch -d origin/master
501 git branch --set-upstream-to origin/master
503 test_cmp expected actual
506 test_expect_success '--set-upstream with two args only shows the deprecation message' '
507 git branch --set-upstream master my13 2>actual &&
508 test_when_finished git branch --unset-upstream master &&
509 cat >expected <<EOF &&
510 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
512 test_cmp expected actual
515 test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
516 git branch --set-upstream my13 2>actual &&
517 test_when_finished git branch --unset-upstream my13 &&
518 cat >expected <<EOF &&
519 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
521 test_cmp expected actual
524 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
525 git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
526 cat >expected <<-\EOF &&
527 warning: Not setting branch my13 as its own upstream.
529 test_expect_code 1 git config branch.my13.remote &&
530 test_expect_code 1 git config branch.my13.merge &&
531 test_i18ncmp expected actual
534 # Keep this test last, as it changes the current branch
535 cat >expect <<EOF
536 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
538 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
539 GIT_COMMITTER_DATE="2005-05-26 23:30" \
540 git checkout -b g/h/i -l master &&
541 test_path_is_file .git/refs/heads/g/h/i &&
542 test_path_is_file .git/logs/refs/heads/g/h/i &&
543 test_cmp expect .git/logs/refs/heads/g/h/i
546 test_expect_success 'checkout -b makes reflog by default' '
547 git checkout master &&
548 git config --unset core.logAllRefUpdates &&
549 git checkout -b alpha &&
550 git rev-parse --verify alpha@{0}
553 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
554 git checkout master &&
555 git config core.logAllRefUpdates false &&
556 git checkout -b beta &&
557 test_must_fail git rev-parse --verify beta@{0}
560 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
561 git checkout master &&
562 git checkout -lb gamma &&
563 git config --unset core.logAllRefUpdates &&
564 git rev-parse --verify gamma@{0}
567 test_expect_success 'avoid ambiguous track' '
568 git config branch.autosetupmerge true &&
569 git config remote.ambi1.url lalala &&
570 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
571 git config remote.ambi2.url lilili &&
572 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
573 git branch all1 master &&
574 test -z "$(git config branch.all1.merge)"
577 test_expect_success 'autosetuprebase local on a tracked local branch' '
578 git config remote.local.url . &&
579 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
580 git config branch.autosetuprebase local &&
581 (git show-ref -q refs/remotes/local/o || git fetch local) &&
582 git branch mybase &&
583 git branch --track myr1 mybase &&
584 test "$(git config branch.myr1.remote)" = . &&
585 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
586 test "$(git config branch.myr1.rebase)" = true
589 test_expect_success 'autosetuprebase always on a tracked local branch' '
590 git config remote.local.url . &&
591 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
592 git config branch.autosetuprebase always &&
593 (git show-ref -q refs/remotes/local/o || git fetch local) &&
594 git branch mybase2 &&
595 git branch --track myr2 mybase &&
596 test "$(git config branch.myr2.remote)" = . &&
597 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
598 test "$(git config branch.myr2.rebase)" = true
601 test_expect_success 'autosetuprebase remote on a tracked local branch' '
602 git config remote.local.url . &&
603 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
604 git config branch.autosetuprebase remote &&
605 (git show-ref -q refs/remotes/local/o || git fetch local) &&
606 git branch mybase3 &&
607 git branch --track myr3 mybase2 &&
608 test "$(git config branch.myr3.remote)" = . &&
609 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
610 ! test "$(git config branch.myr3.rebase)" = true
613 test_expect_success 'autosetuprebase never on a tracked local branch' '
614 git config remote.local.url . &&
615 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
616 git config branch.autosetuprebase never &&
617 (git show-ref -q refs/remotes/local/o || git fetch local) &&
618 git branch mybase4 &&
619 git branch --track myr4 mybase2 &&
620 test "$(git config branch.myr4.remote)" = . &&
621 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
622 ! test "$(git config branch.myr4.rebase)" = true
625 test_expect_success 'autosetuprebase local on a tracked remote branch' '
626 git config remote.local.url . &&
627 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
628 git config branch.autosetuprebase local &&
629 (git show-ref -q refs/remotes/local/master || git fetch local) &&
630 git branch --track myr5 local/master &&
631 test "$(git config branch.myr5.remote)" = local &&
632 test "$(git config branch.myr5.merge)" = refs/heads/master &&
633 ! test "$(git config branch.myr5.rebase)" = true
636 test_expect_success 'autosetuprebase never on a tracked remote branch' '
637 git config remote.local.url . &&
638 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
639 git config branch.autosetuprebase never &&
640 (git show-ref -q refs/remotes/local/master || git fetch local) &&
641 git branch --track myr6 local/master &&
642 test "$(git config branch.myr6.remote)" = local &&
643 test "$(git config branch.myr6.merge)" = refs/heads/master &&
644 ! test "$(git config branch.myr6.rebase)" = true
647 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
648 git config remote.local.url . &&
649 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
650 git config branch.autosetuprebase remote &&
651 (git show-ref -q refs/remotes/local/master || git fetch local) &&
652 git branch --track myr7 local/master &&
653 test "$(git config branch.myr7.remote)" = local &&
654 test "$(git config branch.myr7.merge)" = refs/heads/master &&
655 test "$(git config branch.myr7.rebase)" = true
658 test_expect_success 'autosetuprebase always on a tracked remote branch' '
659 git config remote.local.url . &&
660 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
661 git config branch.autosetuprebase remote &&
662 (git show-ref -q refs/remotes/local/master || git fetch local) &&
663 git branch --track myr8 local/master &&
664 test "$(git config branch.myr8.remote)" = local &&
665 test "$(git config branch.myr8.merge)" = refs/heads/master &&
666 test "$(git config branch.myr8.rebase)" = true
669 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
670 git config --unset branch.autosetuprebase &&
671 git config remote.local.url . &&
672 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
673 (git show-ref -q refs/remotes/local/master || git fetch local) &&
674 git branch --track myr9 local/master &&
675 test "$(git config branch.myr9.remote)" = local &&
676 test "$(git config branch.myr9.merge)" = refs/heads/master &&
677 test "z$(git config branch.myr9.rebase)" = z
680 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
681 git config remote.local.url . &&
682 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
683 (git show-ref -q refs/remotes/local/o || git fetch local) &&
684 git branch mybase10 &&
685 git branch --track myr10 mybase2 &&
686 test "$(git config branch.myr10.remote)" = . &&
687 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
688 test "z$(git config branch.myr10.rebase)" = z
691 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
692 git config remote.local.url . &&
693 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
694 (git show-ref -q refs/remotes/local/master || git fetch local) &&
695 git branch --no-track myr11 mybase2 &&
696 test "z$(git config branch.myr11.remote)" = z &&
697 test "z$(git config branch.myr11.merge)" = z &&
698 test "z$(git config branch.myr11.rebase)" = z
701 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
702 git config remote.local.url . &&
703 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
704 (git show-ref -q refs/remotes/local/master || git fetch local) &&
705 git branch --no-track myr12 local/master &&
706 test "z$(git config branch.myr12.remote)" = z &&
707 test "z$(git config branch.myr12.merge)" = z &&
708 test "z$(git config branch.myr12.rebase)" = z
711 test_expect_success 'autosetuprebase never on an untracked local branch' '
712 git config branch.autosetuprebase never &&
713 git config remote.local.url . &&
714 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
715 (git show-ref -q refs/remotes/local/master || git fetch local) &&
716 git branch --no-track myr13 mybase2 &&
717 test "z$(git config branch.myr13.remote)" = z &&
718 test "z$(git config branch.myr13.merge)" = z &&
719 test "z$(git config branch.myr13.rebase)" = z
722 test_expect_success 'autosetuprebase local on an untracked local branch' '
723 git config branch.autosetuprebase local &&
724 git config remote.local.url . &&
725 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
726 (git show-ref -q refs/remotes/local/master || git fetch local) &&
727 git branch --no-track myr14 mybase2 &&
728 test "z$(git config branch.myr14.remote)" = z &&
729 test "z$(git config branch.myr14.merge)" = z &&
730 test "z$(git config branch.myr14.rebase)" = z
733 test_expect_success 'autosetuprebase remote on an untracked local branch' '
734 git config branch.autosetuprebase remote &&
735 git config remote.local.url . &&
736 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
737 (git show-ref -q refs/remotes/local/master || git fetch local) &&
738 git branch --no-track myr15 mybase2 &&
739 test "z$(git config branch.myr15.remote)" = z &&
740 test "z$(git config branch.myr15.merge)" = z &&
741 test "z$(git config branch.myr15.rebase)" = z
744 test_expect_success 'autosetuprebase always on an untracked local branch' '
745 git config branch.autosetuprebase always &&
746 git config remote.local.url . &&
747 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
748 (git show-ref -q refs/remotes/local/master || git fetch local) &&
749 git branch --no-track myr16 mybase2 &&
750 test "z$(git config branch.myr16.remote)" = z &&
751 test "z$(git config branch.myr16.merge)" = z &&
752 test "z$(git config branch.myr16.rebase)" = z
755 test_expect_success 'autosetuprebase never on an untracked remote branch' '
756 git config branch.autosetuprebase never &&
757 git config remote.local.url . &&
758 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
759 (git show-ref -q refs/remotes/local/master || git fetch local) &&
760 git branch --no-track myr17 local/master &&
761 test "z$(git config branch.myr17.remote)" = z &&
762 test "z$(git config branch.myr17.merge)" = z &&
763 test "z$(git config branch.myr17.rebase)" = z
766 test_expect_success 'autosetuprebase local on an untracked remote branch' '
767 git config branch.autosetuprebase local &&
768 git config remote.local.url . &&
769 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
770 (git show-ref -q refs/remotes/local/master || git fetch local) &&
771 git branch --no-track myr18 local/master &&
772 test "z$(git config branch.myr18.remote)" = z &&
773 test "z$(git config branch.myr18.merge)" = z &&
774 test "z$(git config branch.myr18.rebase)" = z
777 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
778 git config branch.autosetuprebase remote &&
779 git config remote.local.url . &&
780 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
781 (git show-ref -q refs/remotes/local/master || git fetch local) &&
782 git branch --no-track myr19 local/master &&
783 test "z$(git config branch.myr19.remote)" = z &&
784 test "z$(git config branch.myr19.merge)" = z &&
785 test "z$(git config branch.myr19.rebase)" = z
788 test_expect_success 'autosetuprebase always on an untracked remote branch' '
789 git config branch.autosetuprebase always &&
790 git config remote.local.url . &&
791 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
792 (git show-ref -q refs/remotes/local/master || git fetch local) &&
793 git branch --no-track myr20 local/master &&
794 test "z$(git config branch.myr20.remote)" = z &&
795 test "z$(git config branch.myr20.merge)" = z &&
796 test "z$(git config branch.myr20.rebase)" = z
799 test_expect_success 'autosetuprebase always on detached HEAD' '
800 git config branch.autosetupmerge always &&
801 test_when_finished git checkout master &&
802 git checkout HEAD^0 &&
803 git branch my11 &&
804 test -z "$(git config branch.my11.remote)" &&
805 test -z "$(git config branch.my11.merge)"
808 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
809 git config branch.autosetuprebase garbage &&
810 test_must_fail git branch
813 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
814 git config --unset branch.autosetuprebase &&
815 echo "[branch] autosetuprebase" >>.git/config &&
816 test_must_fail git branch &&
817 git config --unset branch.autosetuprebase
820 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
821 git checkout my9 &&
822 git config --unset branch.my8.merge &&
823 test_must_fail git branch -d my8
826 test_expect_success 'attempt to delete a branch merged to its base' '
827 # we are on my9 which is the initial commit; traditionally
828 # we would not have allowed deleting my8 that is not merged
829 # to my9, but it is set to track master that already has my8
830 git config branch.my8.merge refs/heads/master &&
831 git branch -d my8
834 test_expect_success 'attempt to delete a branch merged to its base' '
835 git checkout master &&
836 echo Third >>A &&
837 git commit -m "Third commit" A &&
838 git branch -t my10 my9 &&
839 git branch -f my10 HEAD^ &&
840 # we are on master which is at the third commit, and my10
841 # is behind us, so traditionally we would have allowed deleting
842 # it; but my10 is set to track my9 that is further behind.
843 test_must_fail git branch -d my10
846 test_expect_success 'use set-upstream on the current branch' '
847 git checkout master &&
848 git --bare init myupstream.git &&
849 git push myupstream.git master:refs/heads/frotz &&
850 git remote add origin myupstream.git &&
851 git fetch &&
852 git branch --set-upstream master origin/frotz &&
854 test "z$(git config branch.master.remote)" = "zorigin" &&
855 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
859 test_expect_success 'use --edit-description' '
860 write_script editor <<-\EOF &&
861 echo "New contents" >"$1"
863 EDITOR=./editor git branch --edit-description &&
864 write_script editor <<-\EOF &&
865 git stripspace -s <"$1" >"EDITOR_OUTPUT"
867 EDITOR=./editor git branch --edit-description &&
868 echo "New contents" >expect &&
869 test_cmp EDITOR_OUTPUT expect
872 test_expect_success 'detect typo in branch name when using --edit-description' '
873 write_script editor <<-\EOF &&
874 echo "New contents" >"$1"
876 test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
879 test_expect_success 'refuse --edit-description on unborn branch for now' '
880 write_script editor <<-\EOF &&
881 echo "New contents" >"$1"
883 git checkout --orphan unborn &&
884 test_must_fail env EDITOR=./editor git branch --edit-description
887 test_expect_success '--merged catches invalid object names' '
888 test_must_fail git branch --merged 0000000000000000000000000000000000000000
891 test_expect_success 'tracking with unexpected .fetch refspec' '
892 rm -rf a b c d &&
893 git init a &&
895 cd a &&
896 test_commit a
897 ) &&
898 git init b &&
900 cd b &&
901 test_commit b
902 ) &&
903 git init c &&
905 cd c &&
906 test_commit c &&
907 git remote add a ../a &&
908 git remote add b ../b &&
909 git fetch --all
910 ) &&
911 git init d &&
913 cd d &&
914 git remote add c ../c &&
915 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
916 git fetch c &&
917 git branch --track local/a/master remotes/a/master &&
918 test "$(git config branch.local/a/master.remote)" = "c" &&
919 test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
920 git rev-parse --verify a >expect &&
921 git rev-parse --verify local/a/master >actual &&
922 test_cmp expect actual
926 test_done