3 # Copyright (c) 2005 Amos Waterland
6 test_description='git branch assorted tests'
10 test_expect_success 'prepare a trivial repository' '
12 git update-index --add A &&
13 git commit -m "Initial commit." &&
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' '
30 >.git/refs/heads/master &&
31 test_expect_code 129 git branch -h >usage 2>&1
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
49 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
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_must_fail git reflog exists refs/heads/d/e/f
65 test_expect_success 'git branch j/k should work after branch j has been deleted' '
71 test_expect_success 'git branch l should work after branch l/m has been deleted' '
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 broken_symref should work' '
83 test_when_finished "git branch -D broken_symref" &&
85 git symbolic-ref refs/heads/broken_symref refs/heads/i_am_broken &&
86 git branch -m m broken_symref &&
87 git reflog exists refs/heads/broken_symref &&
88 test_must_fail git reflog exists refs/heads/i_am_broken
91 test_expect_success 'git branch -m m m/m should work' '
93 git branch -m m m/m &&
94 git reflog exists refs/heads/m/m
97 test_expect_success 'git branch -m n/n n should work' '
99 git branch -m n/n n &&
100 git reflog exists refs/heads/n
103 # The topmost entry in reflog for branch bbb is about branch creation.
104 # Hence, we compare bbb@{1} (instead of bbb@{0}) with aaa@{0}.
106 test_expect_success 'git branch -m bbb should rename checked out branch' '
107 test_when_finished git branch -D bbb &&
108 test_when_finished git checkout master &&
109 git checkout -b aaa &&
110 git commit --allow-empty -m "a new commit" &&
111 git rev-parse aaa@{0} >expect &&
113 git rev-parse bbb@{1} >actual &&
114 test_cmp expect actual &&
115 git symbolic-ref HEAD >actual &&
116 echo refs/heads/bbb >expect &&
117 test_cmp expect actual
120 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
123 test_must_fail git branch -m o/o o
126 test_expect_success 'git branch -m o/q o/p should fail when o/p exists' '
128 test_must_fail git branch -m o/q o/p
131 test_expect_success 'git branch -M o/q o/p should work when o/p exists' '
132 git branch -M o/q o/p
135 test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '
137 git branch -m -f o/q o/p
140 test_expect_success 'git branch -m q r/q should fail when r exists' '
143 test_must_fail git branch -m q r/q
146 test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
148 git checkout -b foo &&
149 test_must_fail git branch -M bar foo
152 test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
153 git checkout -b baz &&
155 git branch -M baz bam &&
156 test $(git rev-parse --abbrev-ref HEAD) = bam
159 test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' '
160 msg="Branch: renamed refs/heads/baz to refs/heads/bam" &&
161 grep " 0\{40\}.*$msg$" .git/logs/HEAD &&
162 grep "^0\{40\}.*$msg$" .git/logs/HEAD
165 test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' '
166 git checkout master &&
167 git worktree add -b baz bazdir &&
168 git worktree add -f bazdir2 baz &&
169 git branch -M baz bam &&
170 test $(git -C bazdir rev-parse --abbrev-ref HEAD) = bam &&
171 test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam
174 test_expect_success 'git branch -M baz bam should succeed within a worktree in which baz is checked out' '
175 git checkout -b baz &&
176 git worktree add -f bazdir3 baz &&
179 git branch -M baz bam &&
180 test $(git rev-parse --abbrev-ref HEAD) = bam
182 test $(git rev-parse --abbrev-ref HEAD) = bam
185 test_expect_success 'git branch -M master should work when master is checked out' '
186 git checkout master &&
190 test_expect_success 'git branch -M master master should work when master is checked out' '
191 git checkout master &&
192 git branch -M master master
195 test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
196 git checkout master &&
197 git branch master2 &&
198 git branch -M master2 master2
201 test_expect_success 'git branch -v -d t should work' '
203 test_path_is_file .git/refs/heads/t &&
204 git branch -v -d t &&
205 test_path_is_missing .git/refs/heads/t
208 test_expect_success 'git branch -v -m t s should work' '
210 test_path_is_file .git/refs/heads/t &&
211 git branch -v -m t s &&
212 test_path_is_missing .git/refs/heads/t &&
213 test_path_is_file .git/refs/heads/s &&
217 test_expect_success 'git branch -m -d t s should fail' '
219 test_path_is_file .git/refs/heads/t &&
220 test_must_fail git branch -m -d t s &&
222 test_path_is_missing .git/refs/heads/t
225 test_expect_success 'git branch --list -d t should fail' '
227 test_path_is_file .git/refs/heads/t &&
228 test_must_fail git branch --list -d t &&
230 test_path_is_missing .git/refs/heads/t
233 test_expect_success 'git branch --list -v with --abbrev' '
234 test_when_finished "git branch -D t" &&
236 git branch -v --list t >actual.default &&
237 git branch -v --list --abbrev t >actual.abbrev &&
238 test_cmp actual.default actual.abbrev &&
240 git branch -v --list --no-abbrev t >actual.noabbrev &&
241 git branch -v --list --abbrev=0 t >actual.0abbrev &&
242 test_cmp actual.noabbrev actual.0abbrev &&
244 git branch -v --list --abbrev=36 t >actual.36abbrev &&
245 # how many hexdigits are used?
246 read name objdefault rest <actual.abbrev &&
247 read name obj36 rest <actual.36abbrev &&
248 objfull=$(git rev-parse --verify t) &&
250 # are we really getting abbreviations?
251 test "$obj36" != "$objdefault" &&
252 expr "$obj36" : "$objdefault" >/dev/null &&
253 test "$objfull" != "$obj36" &&
254 expr "$objfull" : "$obj36" >/dev/null
258 test_expect_success 'git branch --column' '
259 COLUMNS=81 git branch --column=column >actual &&
260 cat >expected <<\EOF &&
261 a/b/c bam foo l * master n o/p r
262 abc bar j/k m/m master2 o/o q
264 test_cmp expected actual
267 test_expect_success 'git branch --column with an extremely long branch name' '
268 long=this/is/a/part/of/long/branch/name &&
269 long=z$long/$long/$long/$long &&
270 test_when_finished "git branch -d $long" &&
272 COLUMNS=80 git branch --column=column >actual &&
273 cat >expected <<EOF &&
291 test_cmp expected actual
294 test_expect_success 'git branch with column.*' '
295 git config column.ui column &&
296 git config column.branch "dense" &&
297 COLUMNS=80 git branch >actual &&
298 git config --unset column.branch &&
299 git config --unset column.ui &&
300 cat >expected <<\EOF &&
301 a/b/c bam foo l * master n o/p r
302 abc bar j/k m/m master2 o/o q
304 test_cmp expected actual
307 test_expect_success 'git branch --column -v should fail' '
308 test_must_fail git branch --column -v
311 test_expect_success 'git branch -v with column.ui ignored' '
312 git config column.ui column &&
313 COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
314 git config --unset column.ui &&
315 cat >expected <<\EOF &&
332 test_cmp expected actual
335 mv .git/config .git/config-saved
337 test_expect_success 'git branch -m q q2 without config should succeed' '
338 git branch -m q q2 &&
342 mv .git/config-saved .git/config
344 git config branch.s/s.dummy Hello
346 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
348 git reflog exists refs/heads/s/s &&
350 git reflog exists refs/heads/s/t &&
352 git branch -m s/s s &&
353 git reflog exists refs/heads/s
356 test_expect_success 'config information was renamed, too' '
357 test $(git config branch.s.dummy) = Hello &&
358 test_must_fail git config branch.s/s.dummy
361 test_expect_success 'deleting a symref' '
363 git symbolic-ref refs/heads/symref refs/heads/target &&
364 echo "Deleted branch symref (was refs/heads/target)." >expect &&
365 git branch -d symref >actual &&
366 test_path_is_file .git/refs/heads/target &&
367 test_path_is_missing .git/refs/heads/symref &&
368 test_i18ncmp expect actual
371 test_expect_success 'deleting a dangling symref' '
372 git symbolic-ref refs/heads/dangling-symref nowhere &&
373 test_path_is_file .git/refs/heads/dangling-symref &&
374 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
375 git branch -d dangling-symref >actual &&
376 test_path_is_missing .git/refs/heads/dangling-symref &&
377 test_i18ncmp expect actual
380 test_expect_success 'deleting a self-referential symref' '
381 git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
382 test_path_is_file .git/refs/heads/self-reference &&
383 echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
384 git branch -d self-reference >actual &&
385 test_path_is_missing .git/refs/heads/self-reference &&
386 test_i18ncmp expect actual
389 test_expect_success 'renaming a symref is not allowed' '
390 git symbolic-ref refs/heads/master2 refs/heads/master &&
391 test_must_fail git branch -m master2 master3 &&
392 git symbolic-ref refs/heads/master2 &&
393 test_path_is_file .git/refs/heads/master &&
394 test_path_is_missing .git/refs/heads/master3
397 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
399 mv .git/logs/refs/heads/u real-u &&
400 ln -s real-u .git/logs/refs/heads/u &&
401 test_must_fail git branch -m u v
404 test_expect_success 'test tracking setup via --track' '
405 git config remote.local.url . &&
406 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
407 (git show-ref -q refs/remotes/local/master || git fetch local) &&
408 git branch --track my1 local/master &&
409 test $(git config branch.my1.remote) = local &&
410 test $(git config branch.my1.merge) = refs/heads/master
413 test_expect_success 'test tracking setup (non-wildcard, matching)' '
414 git config remote.local.url . &&
415 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
416 (git show-ref -q refs/remotes/local/master || git fetch local) &&
417 git branch --track my4 local/master &&
418 test $(git config branch.my4.remote) = local &&
419 test $(git config branch.my4.merge) = refs/heads/master
422 test_expect_success 'tracking setup fails on non-matching refspec' '
423 git config remote.local.url . &&
424 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
425 (git show-ref -q refs/remotes/local/master || git fetch local) &&
426 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
427 test_must_fail git branch --track my5 local/master &&
428 test_must_fail git config branch.my5.remote &&
429 test_must_fail git config branch.my5.merge
432 test_expect_success 'test tracking setup via config' '
433 git config branch.autosetupmerge true &&
434 git config remote.local.url . &&
435 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
436 (git show-ref -q refs/remotes/local/master || git fetch local) &&
437 git branch my3 local/master &&
438 test $(git config branch.my3.remote) = local &&
439 test $(git config branch.my3.merge) = refs/heads/master
442 test_expect_success 'test overriding tracking setup via --no-track' '
443 git config branch.autosetupmerge true &&
444 git config remote.local.url . &&
445 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
446 (git show-ref -q refs/remotes/local/master || git fetch local) &&
447 git branch --no-track my2 local/master &&
448 git config branch.autosetupmerge false &&
449 ! test "$(git config branch.my2.remote)" = local &&
450 ! test "$(git config branch.my2.merge)" = refs/heads/master
453 test_expect_success 'no tracking without .fetch entries' '
454 git config branch.autosetupmerge true &&
456 git config branch.autosetupmerge false &&
457 test -z "$(git config branch.my6.remote)" &&
458 test -z "$(git config branch.my6.merge)"
461 test_expect_success 'test tracking setup via --track but deeper' '
462 git config remote.local.url . &&
463 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
464 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
465 git branch --track my7 local/o/o &&
466 test "$(git config branch.my7.remote)" = local &&
467 test "$(git config branch.my7.merge)" = refs/heads/o/o
470 test_expect_success 'test deleting branch deletes branch config' '
472 test -z "$(git config branch.my7.remote)" &&
473 test -z "$(git config branch.my7.merge)"
476 test_expect_success 'test deleting branch without config' '
478 sha1=$(git rev-parse my7 | cut -c 1-7) &&
479 echo "Deleted branch my7 (was $sha1)." >expect &&
480 git branch -d my7 >actual 2>&1 &&
481 test_i18ncmp expect actual
484 test_expect_success 'deleting currently checked out branch fails' '
485 git worktree add -b my7 my7 &&
486 test_must_fail git -C my7 branch -d my7 &&
487 test_must_fail git branch -d my7
490 test_expect_success 'test --track without .fetch entries' '
491 git branch --track my8 &&
492 test "$(git config branch.my8.remote)" &&
493 test "$(git config branch.my8.merge)"
496 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
497 git config branch.autosetupmerge always &&
498 git branch my9 HEAD^ &&
499 git config branch.autosetupmerge false
502 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
503 test_must_fail git branch --track my10 HEAD^
506 test_expect_success 'branch from tag w/--track causes failure' '
508 test_must_fail git branch --track my11 foobar
511 test_expect_success '--set-upstream-to fails on multiple branches' '
512 test_must_fail git branch --set-upstream-to master a b c
515 test_expect_success '--set-upstream-to fails on detached HEAD' '
516 git checkout HEAD^{} &&
517 test_must_fail git branch --set-upstream-to master &&
521 test_expect_success '--set-upstream-to fails on a missing dst branch' '
522 test_must_fail git branch --set-upstream-to master does-not-exist
525 test_expect_success '--set-upstream-to fails on a missing src branch' '
526 test_must_fail git branch --set-upstream-to does-not-exist master
529 test_expect_success '--set-upstream-to fails on a non-ref' '
530 test_must_fail git branch --set-upstream-to HEAD^{}
533 test_expect_success '--set-upstream-to fails on locked config' '
534 test_when_finished "rm -f .git/config.lock" &&
537 test_must_fail git branch --set-upstream-to locked
540 test_expect_success 'use --set-upstream-to modify HEAD' '
541 test_config branch.master.remote foo &&
542 test_config branch.master.merge foo &&
544 git branch --set-upstream-to my12 &&
545 test "$(git config branch.master.remote)" = "." &&
546 test "$(git config branch.master.merge)" = "refs/heads/my12"
549 test_expect_success 'use --set-upstream-to modify a particular branch' '
551 git branch --set-upstream-to master my13 &&
552 test "$(git config branch.my13.remote)" = "." &&
553 test "$(git config branch.my13.merge)" = "refs/heads/master"
556 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
557 test_must_fail git branch --unset-upstream i-dont-exist
560 test_expect_success '--unset-upstream should fail if config is locked' '
561 test_when_finished "rm -f .git/config.lock" &&
562 git branch --set-upstream-to locked &&
564 test_must_fail git branch --unset-upstream
567 test_expect_success 'test --unset-upstream on HEAD' '
569 test_config branch.master.remote foo &&
570 test_config branch.master.merge foo &&
571 git branch --set-upstream-to my14 &&
572 git branch --unset-upstream &&
573 test_must_fail git config branch.master.remote &&
574 test_must_fail git config branch.master.merge &&
575 # fail for a branch without upstream set
576 test_must_fail git branch --unset-upstream
579 test_expect_success '--unset-upstream should fail on multiple branches' '
580 test_must_fail git branch --unset-upstream a b c
583 test_expect_success '--unset-upstream should fail on detached HEAD' '
584 git checkout HEAD^{} &&
585 test_must_fail git branch --unset-upstream &&
589 test_expect_success 'test --unset-upstream on a particular branch' '
591 git branch --set-upstream-to master my14 &&
592 git branch --unset-upstream my14 &&
593 test_must_fail git config branch.my14.remote &&
594 test_must_fail git config branch.my14.merge
597 test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
598 git update-ref refs/remotes/origin/master HEAD &&
599 git branch --set-upstream origin/master 2>actual &&
600 test_when_finished git update-ref -d refs/remotes/origin/master &&
601 test_when_finished git branch -d origin/master &&
602 cat >expected <<EOF &&
603 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
605 If you wanted to make '"'master'"' track '"'origin/master'"', do this:
607 git branch -d origin/master
608 git branch --set-upstream-to origin/master
610 test_i18ncmp expected actual
613 test_expect_success '--set-upstream with two args only shows the deprecation message' '
614 git branch --set-upstream master my13 2>actual &&
615 test_when_finished git branch --unset-upstream master &&
616 cat >expected <<EOF &&
617 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
619 test_i18ncmp expected actual
622 test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
623 git branch --set-upstream my13 2>actual &&
624 test_when_finished git branch --unset-upstream my13 &&
625 cat >expected <<EOF &&
626 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
628 test_i18ncmp expected actual
631 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
632 git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
633 cat >expected <<-\EOF &&
634 warning: Not setting branch my13 as its own upstream.
636 test_expect_code 1 git config branch.my13.remote &&
637 test_expect_code 1 git config branch.my13.merge &&
638 test_i18ncmp expected actual
641 # Keep this test last, as it changes the current branch
643 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
645 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
646 GIT_COMMITTER_DATE="2005-05-26 23:30" \
647 git checkout -b g/h/i -l master &&
648 test_path_is_file .git/refs/heads/g/h/i &&
649 test_path_is_file .git/logs/refs/heads/g/h/i &&
650 test_cmp expect .git/logs/refs/heads/g/h/i
653 test_expect_success 'checkout -b makes reflog by default' '
654 git checkout master &&
655 git config --unset core.logAllRefUpdates &&
656 git checkout -b alpha &&
657 git rev-parse --verify alpha@{0}
660 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
661 git checkout master &&
662 git config core.logAllRefUpdates false &&
663 git checkout -b beta &&
664 test_must_fail git rev-parse --verify beta@{0}
667 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
668 git checkout master &&
669 git checkout -lb gamma &&
670 git config --unset core.logAllRefUpdates &&
671 git rev-parse --verify gamma@{0}
674 test_expect_success 'avoid ambiguous track' '
675 git config branch.autosetupmerge true &&
676 git config remote.ambi1.url lalala &&
677 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
678 git config remote.ambi2.url lilili &&
679 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
680 test_must_fail git branch all1 master &&
681 test -z "$(git config branch.all1.merge)"
684 test_expect_success 'autosetuprebase local on a tracked local branch' '
685 git config remote.local.url . &&
686 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
687 git config branch.autosetuprebase local &&
688 (git show-ref -q refs/remotes/local/o || git fetch local) &&
690 git branch --track myr1 mybase &&
691 test "$(git config branch.myr1.remote)" = . &&
692 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
693 test "$(git config branch.myr1.rebase)" = true
696 test_expect_success 'autosetuprebase always on a tracked local branch' '
697 git config remote.local.url . &&
698 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
699 git config branch.autosetuprebase always &&
700 (git show-ref -q refs/remotes/local/o || git fetch local) &&
701 git branch mybase2 &&
702 git branch --track myr2 mybase &&
703 test "$(git config branch.myr2.remote)" = . &&
704 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
705 test "$(git config branch.myr2.rebase)" = true
708 test_expect_success 'autosetuprebase remote on a tracked local branch' '
709 git config remote.local.url . &&
710 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
711 git config branch.autosetuprebase remote &&
712 (git show-ref -q refs/remotes/local/o || git fetch local) &&
713 git branch mybase3 &&
714 git branch --track myr3 mybase2 &&
715 test "$(git config branch.myr3.remote)" = . &&
716 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
717 ! test "$(git config branch.myr3.rebase)" = true
720 test_expect_success 'autosetuprebase never on a tracked local branch' '
721 git config remote.local.url . &&
722 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
723 git config branch.autosetuprebase never &&
724 (git show-ref -q refs/remotes/local/o || git fetch local) &&
725 git branch mybase4 &&
726 git branch --track myr4 mybase2 &&
727 test "$(git config branch.myr4.remote)" = . &&
728 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
729 ! test "$(git config branch.myr4.rebase)" = true
732 test_expect_success 'autosetuprebase local on a tracked remote branch' '
733 git config remote.local.url . &&
734 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
735 git config branch.autosetuprebase local &&
736 (git show-ref -q refs/remotes/local/master || git fetch local) &&
737 git branch --track myr5 local/master &&
738 test "$(git config branch.myr5.remote)" = local &&
739 test "$(git config branch.myr5.merge)" = refs/heads/master &&
740 ! test "$(git config branch.myr5.rebase)" = true
743 test_expect_success 'autosetuprebase never on a tracked remote branch' '
744 git config remote.local.url . &&
745 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
746 git config branch.autosetuprebase never &&
747 (git show-ref -q refs/remotes/local/master || git fetch local) &&
748 git branch --track myr6 local/master &&
749 test "$(git config branch.myr6.remote)" = local &&
750 test "$(git config branch.myr6.merge)" = refs/heads/master &&
751 ! test "$(git config branch.myr6.rebase)" = true
754 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
755 git config remote.local.url . &&
756 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
757 git config branch.autosetuprebase remote &&
758 (git show-ref -q refs/remotes/local/master || git fetch local) &&
759 git branch --track myr7 local/master &&
760 test "$(git config branch.myr7.remote)" = local &&
761 test "$(git config branch.myr7.merge)" = refs/heads/master &&
762 test "$(git config branch.myr7.rebase)" = true
765 test_expect_success 'autosetuprebase always on a tracked remote branch' '
766 git config remote.local.url . &&
767 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
768 git config branch.autosetuprebase remote &&
769 (git show-ref -q refs/remotes/local/master || git fetch local) &&
770 git branch --track myr8 local/master &&
771 test "$(git config branch.myr8.remote)" = local &&
772 test "$(git config branch.myr8.merge)" = refs/heads/master &&
773 test "$(git config branch.myr8.rebase)" = true
776 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
777 git config --unset branch.autosetuprebase &&
778 git config remote.local.url . &&
779 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
780 (git show-ref -q refs/remotes/local/master || git fetch local) &&
781 git branch --track myr9 local/master &&
782 test "$(git config branch.myr9.remote)" = local &&
783 test "$(git config branch.myr9.merge)" = refs/heads/master &&
784 test "z$(git config branch.myr9.rebase)" = z
787 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
788 git config remote.local.url . &&
789 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
790 (git show-ref -q refs/remotes/local/o || git fetch local) &&
791 git branch mybase10 &&
792 git branch --track myr10 mybase2 &&
793 test "$(git config branch.myr10.remote)" = . &&
794 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
795 test "z$(git config branch.myr10.rebase)" = z
798 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
799 git config remote.local.url . &&
800 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
801 (git show-ref -q refs/remotes/local/master || git fetch local) &&
802 git branch --no-track myr11 mybase2 &&
803 test "z$(git config branch.myr11.remote)" = z &&
804 test "z$(git config branch.myr11.merge)" = z &&
805 test "z$(git config branch.myr11.rebase)" = z
808 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
809 git config remote.local.url . &&
810 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
811 (git show-ref -q refs/remotes/local/master || git fetch local) &&
812 git branch --no-track myr12 local/master &&
813 test "z$(git config branch.myr12.remote)" = z &&
814 test "z$(git config branch.myr12.merge)" = z &&
815 test "z$(git config branch.myr12.rebase)" = z
818 test_expect_success 'autosetuprebase never on an untracked local branch' '
819 git config branch.autosetuprebase never &&
820 git config remote.local.url . &&
821 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
822 (git show-ref -q refs/remotes/local/master || git fetch local) &&
823 git branch --no-track myr13 mybase2 &&
824 test "z$(git config branch.myr13.remote)" = z &&
825 test "z$(git config branch.myr13.merge)" = z &&
826 test "z$(git config branch.myr13.rebase)" = z
829 test_expect_success 'autosetuprebase local on an untracked local branch' '
830 git config branch.autosetuprebase local &&
831 git config remote.local.url . &&
832 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
833 (git show-ref -q refs/remotes/local/master || git fetch local) &&
834 git branch --no-track myr14 mybase2 &&
835 test "z$(git config branch.myr14.remote)" = z &&
836 test "z$(git config branch.myr14.merge)" = z &&
837 test "z$(git config branch.myr14.rebase)" = z
840 test_expect_success 'autosetuprebase remote on an untracked local branch' '
841 git config branch.autosetuprebase remote &&
842 git config remote.local.url . &&
843 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
844 (git show-ref -q refs/remotes/local/master || git fetch local) &&
845 git branch --no-track myr15 mybase2 &&
846 test "z$(git config branch.myr15.remote)" = z &&
847 test "z$(git config branch.myr15.merge)" = z &&
848 test "z$(git config branch.myr15.rebase)" = z
851 test_expect_success 'autosetuprebase always on an untracked local branch' '
852 git config branch.autosetuprebase always &&
853 git config remote.local.url . &&
854 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
855 (git show-ref -q refs/remotes/local/master || git fetch local) &&
856 git branch --no-track myr16 mybase2 &&
857 test "z$(git config branch.myr16.remote)" = z &&
858 test "z$(git config branch.myr16.merge)" = z &&
859 test "z$(git config branch.myr16.rebase)" = z
862 test_expect_success 'autosetuprebase never on an untracked remote branch' '
863 git config branch.autosetuprebase never &&
864 git config remote.local.url . &&
865 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
866 (git show-ref -q refs/remotes/local/master || git fetch local) &&
867 git branch --no-track myr17 local/master &&
868 test "z$(git config branch.myr17.remote)" = z &&
869 test "z$(git config branch.myr17.merge)" = z &&
870 test "z$(git config branch.myr17.rebase)" = z
873 test_expect_success 'autosetuprebase local on an untracked remote branch' '
874 git config branch.autosetuprebase local &&
875 git config remote.local.url . &&
876 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
877 (git show-ref -q refs/remotes/local/master || git fetch local) &&
878 git branch --no-track myr18 local/master &&
879 test "z$(git config branch.myr18.remote)" = z &&
880 test "z$(git config branch.myr18.merge)" = z &&
881 test "z$(git config branch.myr18.rebase)" = z
884 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
885 git config branch.autosetuprebase remote &&
886 git config remote.local.url . &&
887 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
888 (git show-ref -q refs/remotes/local/master || git fetch local) &&
889 git branch --no-track myr19 local/master &&
890 test "z$(git config branch.myr19.remote)" = z &&
891 test "z$(git config branch.myr19.merge)" = z &&
892 test "z$(git config branch.myr19.rebase)" = z
895 test_expect_success 'autosetuprebase always on an untracked remote branch' '
896 git config branch.autosetuprebase always &&
897 git config remote.local.url . &&
898 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
899 (git show-ref -q refs/remotes/local/master || git fetch local) &&
900 git branch --no-track myr20 local/master &&
901 test "z$(git config branch.myr20.remote)" = z &&
902 test "z$(git config branch.myr20.merge)" = z &&
903 test "z$(git config branch.myr20.rebase)" = z
906 test_expect_success 'autosetuprebase always on detached HEAD' '
907 git config branch.autosetupmerge always &&
908 test_when_finished git checkout master &&
909 git checkout HEAD^0 &&
911 test -z "$(git config branch.my11.remote)" &&
912 test -z "$(git config branch.my11.merge)"
915 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
916 git config branch.autosetuprebase garbage &&
917 test_must_fail git branch
920 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
921 git config --unset branch.autosetuprebase &&
922 echo "[branch] autosetuprebase" >>.git/config &&
923 test_must_fail git branch &&
924 git config --unset branch.autosetuprebase
927 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
929 git config --unset branch.my8.merge &&
930 test_must_fail git branch -d my8
933 test_expect_success 'attempt to delete a branch merged to its base' '
934 # we are on my9 which is the initial commit; traditionally
935 # we would not have allowed deleting my8 that is not merged
936 # to my9, but it is set to track master that already has my8
937 git config branch.my8.merge refs/heads/master &&
941 test_expect_success 'attempt to delete a branch merged to its base' '
942 git checkout master &&
944 git commit -m "Third commit" A &&
945 git branch -t my10 my9 &&
946 git branch -f my10 HEAD^ &&
947 # we are on master which is at the third commit, and my10
948 # is behind us, so traditionally we would have allowed deleting
949 # it; but my10 is set to track my9 that is further behind.
950 test_must_fail git branch -d my10
953 test_expect_success 'use set-upstream on the current branch' '
954 git checkout master &&
955 git --bare init myupstream.git &&
956 git push myupstream.git master:refs/heads/frotz &&
957 git remote add origin myupstream.git &&
959 git branch --set-upstream master origin/frotz &&
961 test "z$(git config branch.master.remote)" = "zorigin" &&
962 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
966 test_expect_success 'use --edit-description' '
967 write_script editor <<-\EOF &&
968 echo "New contents" >"$1"
970 EDITOR=./editor git branch --edit-description &&
971 write_script editor <<-\EOF &&
972 git stripspace -s <"$1" >"EDITOR_OUTPUT"
974 EDITOR=./editor git branch --edit-description &&
975 echo "New contents" >expect &&
976 test_cmp EDITOR_OUTPUT expect
979 test_expect_success 'detect typo in branch name when using --edit-description' '
980 write_script editor <<-\EOF &&
981 echo "New contents" >"$1"
983 test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
986 test_expect_success 'refuse --edit-description on unborn branch for now' '
987 write_script editor <<-\EOF &&
988 echo "New contents" >"$1"
990 git checkout --orphan unborn &&
991 test_must_fail env EDITOR=./editor git branch --edit-description
994 test_expect_success '--merged catches invalid object names' '
995 test_must_fail git branch --merged 0000000000000000000000000000000000000000
998 test_expect_success '--merged is incompatible with --no-merged' '
999 test_must_fail git branch --merged HEAD --no-merged HEAD
1002 test_expect_success 'tracking with unexpected .fetch refspec' '
1018 git remote add a ../a &&
1019 git remote add b ../b &&
1025 git remote add c ../c &&
1026 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
1028 git branch --track local/a/master remotes/a/master &&
1029 test "$(git config branch.local/a/master.remote)" = "c" &&
1030 test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
1031 git rev-parse --verify a >expect &&
1032 git rev-parse --verify local/a/master >actual &&
1033 test_cmp expect actual