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 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
106 test_must_fail git branch -m o/o o
109 test_expect_success 'git branch -m o/q o/p should fail when o/p exists' '
111 test_must_fail git branch -m o/q o/p
114 test_expect_success 'git branch -M o/q o/p should work when o/p exists' '
115 git branch -M o/q o/p
118 test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '
120 git branch -m -f o/q o/p
123 test_expect_success 'git branch -m q r/q should fail when r exists' '
126 test_must_fail git branch -m q r/q
129 test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
131 git checkout -b foo &&
132 test_must_fail git branch -M bar foo
135 test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
136 git checkout -b baz &&
138 git branch -M baz bam &&
139 test $(git rev-parse --abbrev-ref HEAD) = bam
142 test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' '
143 git checkout master &&
144 git worktree add -b baz bazdir &&
145 git worktree add -f bazdir2 baz &&
146 git branch -M baz bam &&
147 test $(git -C bazdir rev-parse --abbrev-ref HEAD) = bam &&
148 test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam
151 test_expect_success 'git branch -M baz bam should succeed within a worktree in which baz is checked out' '
152 git checkout -b baz &&
153 git worktree add -f bazdir3 baz &&
156 git branch -M baz bam &&
157 test $(git rev-parse --abbrev-ref HEAD) = bam
159 test $(git rev-parse --abbrev-ref HEAD) = bam
162 test_expect_success 'git branch -M master should work when master is checked out' '
163 git checkout master &&
167 test_expect_success 'git branch -M master master should work when master is checked out' '
168 git checkout master &&
169 git branch -M master master
172 test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
173 git checkout master &&
174 git branch master2 &&
175 git branch -M master2 master2
178 test_expect_success 'git branch -v -d t should work' '
180 test_path_is_file .git/refs/heads/t &&
181 git branch -v -d t &&
182 test_path_is_missing .git/refs/heads/t
185 test_expect_success 'git branch -v -m t s should work' '
187 test_path_is_file .git/refs/heads/t &&
188 git branch -v -m t s &&
189 test_path_is_missing .git/refs/heads/t &&
190 test_path_is_file .git/refs/heads/s &&
194 test_expect_success 'git branch -m -d t s should fail' '
196 test_path_is_file .git/refs/heads/t &&
197 test_must_fail git branch -m -d t s &&
199 test_path_is_missing .git/refs/heads/t
202 test_expect_success 'git branch --list -d t should fail' '
204 test_path_is_file .git/refs/heads/t &&
205 test_must_fail git branch --list -d t &&
207 test_path_is_missing .git/refs/heads/t
210 test_expect_success 'git branch --list -v with --abbrev' '
211 test_when_finished "git branch -D t" &&
213 git branch -v --list t >actual.default &&
214 git branch -v --list --abbrev t >actual.abbrev &&
215 test_cmp actual.default actual.abbrev &&
217 git branch -v --list --no-abbrev t >actual.noabbrev &&
218 git branch -v --list --abbrev=0 t >actual.0abbrev &&
219 test_cmp actual.noabbrev actual.0abbrev &&
221 git branch -v --list --abbrev=36 t >actual.36abbrev &&
222 # how many hexdigits are used?
223 read name objdefault rest <actual.abbrev &&
224 read name obj36 rest <actual.36abbrev &&
225 objfull=$(git rev-parse --verify t) &&
227 # are we really getting abbreviations?
228 test "$obj36" != "$objdefault" &&
229 expr "$obj36" : "$objdefault" >/dev/null &&
230 test "$objfull" != "$obj36" &&
231 expr "$objfull" : "$obj36" >/dev/null
235 test_expect_success 'git branch --column' '
236 COLUMNS=81 git branch --column=column >actual &&
237 cat >expected <<\EOF &&
238 a/b/c bam foo l * master n o/p r
239 abc bar j/k m/m master2 o/o q
241 test_cmp expected actual
244 test_expect_success 'git branch --column with an extremely long branch name' '
245 long=this/is/a/part/of/long/branch/name &&
246 long=z$long/$long/$long/$long &&
247 test_when_finished "git branch -d $long" &&
249 COLUMNS=80 git branch --column=column >actual &&
250 cat >expected <<EOF &&
268 test_cmp expected actual
271 test_expect_success 'git branch with column.*' '
272 git config column.ui column &&
273 git config column.branch "dense" &&
274 COLUMNS=80 git branch >actual &&
275 git config --unset column.branch &&
276 git config --unset column.ui &&
277 cat >expected <<\EOF &&
278 a/b/c bam foo l * master n o/p r
279 abc bar j/k m/m master2 o/o q
281 test_cmp expected actual
284 test_expect_success 'git branch --column -v should fail' '
285 test_must_fail git branch --column -v
288 test_expect_success 'git branch -v with column.ui ignored' '
289 git config column.ui column &&
290 COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
291 git config --unset column.ui &&
292 cat >expected <<\EOF &&
309 test_cmp expected actual
312 mv .git/config .git/config-saved
314 test_expect_success 'git branch -m q q2 without config should succeed' '
315 git branch -m q q2 &&
319 mv .git/config-saved .git/config
321 git config branch.s/s.dummy Hello
323 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
325 git reflog exists refs/heads/s/s &&
327 git reflog exists refs/heads/s/t &&
329 git branch -m s/s s &&
330 git reflog exists refs/heads/s
333 test_expect_success 'config information was renamed, too' '
334 test $(git config branch.s.dummy) = Hello &&
335 test_must_fail git config branch.s/s/dummy
338 test_expect_success 'deleting a symref' '
340 git symbolic-ref refs/heads/symref refs/heads/target &&
341 echo "Deleted branch symref (was refs/heads/target)." >expect &&
342 git branch -d symref >actual &&
343 test_path_is_file .git/refs/heads/target &&
344 test_path_is_missing .git/refs/heads/symref &&
345 test_i18ncmp expect actual
348 test_expect_success 'deleting a dangling symref' '
349 git symbolic-ref refs/heads/dangling-symref nowhere &&
350 test_path_is_file .git/refs/heads/dangling-symref &&
351 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
352 git branch -d dangling-symref >actual &&
353 test_path_is_missing .git/refs/heads/dangling-symref &&
354 test_i18ncmp expect actual
357 test_expect_success 'deleting a self-referential symref' '
358 git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
359 test_path_is_file .git/refs/heads/self-reference &&
360 echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
361 git branch -d self-reference >actual &&
362 test_path_is_missing .git/refs/heads/self-reference &&
363 test_i18ncmp expect actual
366 test_expect_success 'renaming a symref is not allowed' '
367 git symbolic-ref refs/heads/master2 refs/heads/master &&
368 test_must_fail git branch -m master2 master3 &&
369 git symbolic-ref refs/heads/master2 &&
370 test_path_is_file .git/refs/heads/master &&
371 test_path_is_missing .git/refs/heads/master3
374 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
376 mv .git/logs/refs/heads/u real-u &&
377 ln -s real-u .git/logs/refs/heads/u &&
378 test_must_fail git branch -m u v
381 test_expect_success 'test tracking setup via --track' '
382 git config remote.local.url . &&
383 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
384 (git show-ref -q refs/remotes/local/master || git fetch local) &&
385 git branch --track my1 local/master &&
386 test $(git config branch.my1.remote) = local &&
387 test $(git config branch.my1.merge) = refs/heads/master
390 test_expect_success 'test tracking setup (non-wildcard, matching)' '
391 git config remote.local.url . &&
392 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
393 (git show-ref -q refs/remotes/local/master || git fetch local) &&
394 git branch --track my4 local/master &&
395 test $(git config branch.my4.remote) = local &&
396 test $(git config branch.my4.merge) = refs/heads/master
399 test_expect_success 'tracking setup fails on non-matching refspec' '
400 git config remote.local.url . &&
401 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
402 (git show-ref -q refs/remotes/local/master || git fetch local) &&
403 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
404 test_must_fail git branch --track my5 local/master &&
405 test_must_fail git config branch.my5.remote &&
406 test_must_fail git config branch.my5.merge
409 test_expect_success 'test tracking setup via config' '
410 git config branch.autosetupmerge true &&
411 git config remote.local.url . &&
412 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
413 (git show-ref -q refs/remotes/local/master || git fetch local) &&
414 git branch my3 local/master &&
415 test $(git config branch.my3.remote) = local &&
416 test $(git config branch.my3.merge) = refs/heads/master
419 test_expect_success 'test overriding tracking setup via --no-track' '
420 git config branch.autosetupmerge true &&
421 git config remote.local.url . &&
422 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
423 (git show-ref -q refs/remotes/local/master || git fetch local) &&
424 git branch --no-track my2 local/master &&
425 git config branch.autosetupmerge false &&
426 ! test "$(git config branch.my2.remote)" = local &&
427 ! test "$(git config branch.my2.merge)" = refs/heads/master
430 test_expect_success 'no tracking without .fetch entries' '
431 git config branch.autosetupmerge true &&
433 git config branch.autosetupmerge false &&
434 test -z "$(git config branch.my6.remote)" &&
435 test -z "$(git config branch.my6.merge)"
438 test_expect_success 'test tracking setup via --track but deeper' '
439 git config remote.local.url . &&
440 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
441 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
442 git branch --track my7 local/o/o &&
443 test "$(git config branch.my7.remote)" = local &&
444 test "$(git config branch.my7.merge)" = refs/heads/o/o
447 test_expect_success 'test deleting branch deletes branch config' '
449 test -z "$(git config branch.my7.remote)" &&
450 test -z "$(git config branch.my7.merge)"
453 test_expect_success 'test deleting branch without config' '
455 sha1=$(git rev-parse my7 | cut -c 1-7) &&
456 echo "Deleted branch my7 (was $sha1)." >expect &&
457 git branch -d my7 >actual 2>&1 &&
458 test_i18ncmp expect actual
461 test_expect_success 'deleting currently checked out branch fails' '
462 git worktree add -b my7 my7 &&
463 test_must_fail git -C my7 branch -d my7 &&
464 test_must_fail git branch -d my7
467 test_expect_success 'test --track without .fetch entries' '
468 git branch --track my8 &&
469 test "$(git config branch.my8.remote)" &&
470 test "$(git config branch.my8.merge)"
473 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
474 git config branch.autosetupmerge always &&
475 git branch my9 HEAD^ &&
476 git config branch.autosetupmerge false
479 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
480 test_must_fail git branch --track my10 HEAD^
483 test_expect_success 'branch from tag w/--track causes failure' '
485 test_must_fail git branch --track my11 foobar
488 test_expect_success '--set-upstream-to fails on multiple branches' '
489 test_must_fail git branch --set-upstream-to master a b c
492 test_expect_success '--set-upstream-to fails on detached HEAD' '
493 git checkout HEAD^{} &&
494 test_must_fail git branch --set-upstream-to master &&
498 test_expect_success '--set-upstream-to fails on a missing dst branch' '
499 test_must_fail git branch --set-upstream-to master does-not-exist
502 test_expect_success '--set-upstream-to fails on a missing src branch' '
503 test_must_fail git branch --set-upstream-to does-not-exist master
506 test_expect_success '--set-upstream-to fails on a non-ref' '
507 test_must_fail git branch --set-upstream-to HEAD^{}
510 test_expect_success '--set-upstream-to fails on locked config' '
511 test_when_finished "rm -f .git/config.lock" &&
514 test_must_fail git branch --set-upstream-to locked
517 test_expect_success 'use --set-upstream-to modify HEAD' '
518 test_config branch.master.remote foo &&
519 test_config branch.master.merge foo &&
521 git branch --set-upstream-to my12 &&
522 test "$(git config branch.master.remote)" = "." &&
523 test "$(git config branch.master.merge)" = "refs/heads/my12"
526 test_expect_success 'use --set-upstream-to modify a particular branch' '
528 git branch --set-upstream-to master my13 &&
529 test "$(git config branch.my13.remote)" = "." &&
530 test "$(git config branch.my13.merge)" = "refs/heads/master"
533 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
534 test_must_fail git branch --unset-upstream i-dont-exist
537 test_expect_success '--unset-upstream should fail if config is locked' '
538 test_when_finished "rm -f .git/config.lock" &&
539 git branch --set-upstream-to locked &&
541 test_must_fail git branch --unset-upstream
544 test_expect_success 'test --unset-upstream on HEAD' '
546 test_config branch.master.remote foo &&
547 test_config branch.master.merge foo &&
548 git branch --set-upstream-to my14 &&
549 git branch --unset-upstream &&
550 test_must_fail git config branch.master.remote &&
551 test_must_fail git config branch.master.merge &&
552 # fail for a branch without upstream set
553 test_must_fail git branch --unset-upstream
556 test_expect_success '--unset-upstream should fail on multiple branches' '
557 test_must_fail git branch --unset-upstream a b c
560 test_expect_success '--unset-upstream should fail on detached HEAD' '
561 git checkout HEAD^{} &&
562 test_must_fail git branch --unset-upstream &&
566 test_expect_success 'test --unset-upstream on a particular branch' '
568 git branch --set-upstream-to master my14 &&
569 git branch --unset-upstream my14 &&
570 test_must_fail git config branch.my14.remote &&
571 test_must_fail git config branch.my14.merge
574 test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
575 git update-ref refs/remotes/origin/master HEAD &&
576 git branch --set-upstream origin/master 2>actual &&
577 test_when_finished git update-ref -d refs/remotes/origin/master &&
578 test_when_finished git branch -d origin/master &&
579 cat >expected <<EOF &&
580 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
582 If you wanted to make '"'master'"' track '"'origin/master'"', do this:
584 git branch -d origin/master
585 git branch --set-upstream-to origin/master
587 test_i18ncmp expected actual
590 test_expect_success '--set-upstream with two args only shows the deprecation message' '
591 git branch --set-upstream master my13 2>actual &&
592 test_when_finished git branch --unset-upstream master &&
593 cat >expected <<EOF &&
594 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
596 test_i18ncmp expected actual
599 test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
600 git branch --set-upstream my13 2>actual &&
601 test_when_finished git branch --unset-upstream my13 &&
602 cat >expected <<EOF &&
603 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
605 test_i18ncmp expected actual
608 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
609 git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
610 cat >expected <<-\EOF &&
611 warning: Not setting branch my13 as its own upstream.
613 test_expect_code 1 git config branch.my13.remote &&
614 test_expect_code 1 git config branch.my13.merge &&
615 test_i18ncmp expected actual
618 # Keep this test last, as it changes the current branch
620 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
622 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
623 GIT_COMMITTER_DATE="2005-05-26 23:30" \
624 git checkout -b g/h/i -l master &&
625 test_path_is_file .git/refs/heads/g/h/i &&
626 test_path_is_file .git/logs/refs/heads/g/h/i &&
627 test_cmp expect .git/logs/refs/heads/g/h/i
630 test_expect_success 'checkout -b makes reflog by default' '
631 git checkout master &&
632 git config --unset core.logAllRefUpdates &&
633 git checkout -b alpha &&
634 git rev-parse --verify alpha@{0}
637 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
638 git checkout master &&
639 git config core.logAllRefUpdates false &&
640 git checkout -b beta &&
641 test_must_fail git rev-parse --verify beta@{0}
644 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
645 git checkout master &&
646 git checkout -lb gamma &&
647 git config --unset core.logAllRefUpdates &&
648 git rev-parse --verify gamma@{0}
651 test_expect_success 'avoid ambiguous track' '
652 git config branch.autosetupmerge true &&
653 git config remote.ambi1.url lalala &&
654 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
655 git config remote.ambi2.url lilili &&
656 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
657 test_must_fail git branch all1 master &&
658 test -z "$(git config branch.all1.merge)"
661 test_expect_success 'autosetuprebase local on a tracked local branch' '
662 git config remote.local.url . &&
663 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
664 git config branch.autosetuprebase local &&
665 (git show-ref -q refs/remotes/local/o || git fetch local) &&
667 git branch --track myr1 mybase &&
668 test "$(git config branch.myr1.remote)" = . &&
669 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
670 test "$(git config branch.myr1.rebase)" = true
673 test_expect_success 'autosetuprebase always on a tracked local branch' '
674 git config remote.local.url . &&
675 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
676 git config branch.autosetuprebase always &&
677 (git show-ref -q refs/remotes/local/o || git fetch local) &&
678 git branch mybase2 &&
679 git branch --track myr2 mybase &&
680 test "$(git config branch.myr2.remote)" = . &&
681 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
682 test "$(git config branch.myr2.rebase)" = true
685 test_expect_success 'autosetuprebase remote on a tracked local branch' '
686 git config remote.local.url . &&
687 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
688 git config branch.autosetuprebase remote &&
689 (git show-ref -q refs/remotes/local/o || git fetch local) &&
690 git branch mybase3 &&
691 git branch --track myr3 mybase2 &&
692 test "$(git config branch.myr3.remote)" = . &&
693 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
694 ! test "$(git config branch.myr3.rebase)" = true
697 test_expect_success 'autosetuprebase never on a tracked local branch' '
698 git config remote.local.url . &&
699 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
700 git config branch.autosetuprebase never &&
701 (git show-ref -q refs/remotes/local/o || git fetch local) &&
702 git branch mybase4 &&
703 git branch --track myr4 mybase2 &&
704 test "$(git config branch.myr4.remote)" = . &&
705 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
706 ! test "$(git config branch.myr4.rebase)" = true
709 test_expect_success 'autosetuprebase local on a tracked remote branch' '
710 git config remote.local.url . &&
711 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
712 git config branch.autosetuprebase local &&
713 (git show-ref -q refs/remotes/local/master || git fetch local) &&
714 git branch --track myr5 local/master &&
715 test "$(git config branch.myr5.remote)" = local &&
716 test "$(git config branch.myr5.merge)" = refs/heads/master &&
717 ! test "$(git config branch.myr5.rebase)" = true
720 test_expect_success 'autosetuprebase never on a tracked remote 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/master || git fetch local) &&
725 git branch --track myr6 local/master &&
726 test "$(git config branch.myr6.remote)" = local &&
727 test "$(git config branch.myr6.merge)" = refs/heads/master &&
728 ! test "$(git config branch.myr6.rebase)" = true
731 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
732 git config remote.local.url . &&
733 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
734 git config branch.autosetuprebase remote &&
735 (git show-ref -q refs/remotes/local/master || git fetch local) &&
736 git branch --track myr7 local/master &&
737 test "$(git config branch.myr7.remote)" = local &&
738 test "$(git config branch.myr7.merge)" = refs/heads/master &&
739 test "$(git config branch.myr7.rebase)" = true
742 test_expect_success 'autosetuprebase always on a tracked remote branch' '
743 git config remote.local.url . &&
744 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
745 git config branch.autosetuprebase remote &&
746 (git show-ref -q refs/remotes/local/master || git fetch local) &&
747 git branch --track myr8 local/master &&
748 test "$(git config branch.myr8.remote)" = local &&
749 test "$(git config branch.myr8.merge)" = refs/heads/master &&
750 test "$(git config branch.myr8.rebase)" = true
753 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
754 git config --unset branch.autosetuprebase &&
755 git config remote.local.url . &&
756 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
757 (git show-ref -q refs/remotes/local/master || git fetch local) &&
758 git branch --track myr9 local/master &&
759 test "$(git config branch.myr9.remote)" = local &&
760 test "$(git config branch.myr9.merge)" = refs/heads/master &&
761 test "z$(git config branch.myr9.rebase)" = z
764 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
765 git config remote.local.url . &&
766 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
767 (git show-ref -q refs/remotes/local/o || git fetch local) &&
768 git branch mybase10 &&
769 git branch --track myr10 mybase2 &&
770 test "$(git config branch.myr10.remote)" = . &&
771 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
772 test "z$(git config branch.myr10.rebase)" = z
775 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
776 git config remote.local.url . &&
777 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
778 (git show-ref -q refs/remotes/local/master || git fetch local) &&
779 git branch --no-track myr11 mybase2 &&
780 test "z$(git config branch.myr11.remote)" = z &&
781 test "z$(git config branch.myr11.merge)" = z &&
782 test "z$(git config branch.myr11.rebase)" = z
785 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
786 git config remote.local.url . &&
787 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
788 (git show-ref -q refs/remotes/local/master || git fetch local) &&
789 git branch --no-track myr12 local/master &&
790 test "z$(git config branch.myr12.remote)" = z &&
791 test "z$(git config branch.myr12.merge)" = z &&
792 test "z$(git config branch.myr12.rebase)" = z
795 test_expect_success 'autosetuprebase never on an untracked local branch' '
796 git config branch.autosetuprebase never &&
797 git config remote.local.url . &&
798 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
799 (git show-ref -q refs/remotes/local/master || git fetch local) &&
800 git branch --no-track myr13 mybase2 &&
801 test "z$(git config branch.myr13.remote)" = z &&
802 test "z$(git config branch.myr13.merge)" = z &&
803 test "z$(git config branch.myr13.rebase)" = z
806 test_expect_success 'autosetuprebase local on an untracked local branch' '
807 git config branch.autosetuprebase local &&
808 git config remote.local.url . &&
809 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
810 (git show-ref -q refs/remotes/local/master || git fetch local) &&
811 git branch --no-track myr14 mybase2 &&
812 test "z$(git config branch.myr14.remote)" = z &&
813 test "z$(git config branch.myr14.merge)" = z &&
814 test "z$(git config branch.myr14.rebase)" = z
817 test_expect_success 'autosetuprebase remote on an untracked local branch' '
818 git config branch.autosetuprebase remote &&
819 git config remote.local.url . &&
820 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
821 (git show-ref -q refs/remotes/local/master || git fetch local) &&
822 git branch --no-track myr15 mybase2 &&
823 test "z$(git config branch.myr15.remote)" = z &&
824 test "z$(git config branch.myr15.merge)" = z &&
825 test "z$(git config branch.myr15.rebase)" = z
828 test_expect_success 'autosetuprebase always on an untracked local branch' '
829 git config branch.autosetuprebase always &&
830 git config remote.local.url . &&
831 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
832 (git show-ref -q refs/remotes/local/master || git fetch local) &&
833 git branch --no-track myr16 mybase2 &&
834 test "z$(git config branch.myr16.remote)" = z &&
835 test "z$(git config branch.myr16.merge)" = z &&
836 test "z$(git config branch.myr16.rebase)" = z
839 test_expect_success 'autosetuprebase never on an untracked remote branch' '
840 git config branch.autosetuprebase never &&
841 git config remote.local.url . &&
842 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
843 (git show-ref -q refs/remotes/local/master || git fetch local) &&
844 git branch --no-track myr17 local/master &&
845 test "z$(git config branch.myr17.remote)" = z &&
846 test "z$(git config branch.myr17.merge)" = z &&
847 test "z$(git config branch.myr17.rebase)" = z
850 test_expect_success 'autosetuprebase local on an untracked remote branch' '
851 git config branch.autosetuprebase local &&
852 git config remote.local.url . &&
853 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
854 (git show-ref -q refs/remotes/local/master || git fetch local) &&
855 git branch --no-track myr18 local/master &&
856 test "z$(git config branch.myr18.remote)" = z &&
857 test "z$(git config branch.myr18.merge)" = z &&
858 test "z$(git config branch.myr18.rebase)" = z
861 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
862 git config branch.autosetuprebase remote &&
863 git config remote.local.url . &&
864 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
865 (git show-ref -q refs/remotes/local/master || git fetch local) &&
866 git branch --no-track myr19 local/master &&
867 test "z$(git config branch.myr19.remote)" = z &&
868 test "z$(git config branch.myr19.merge)" = z &&
869 test "z$(git config branch.myr19.rebase)" = z
872 test_expect_success 'autosetuprebase always on an untracked remote branch' '
873 git config branch.autosetuprebase always &&
874 git config remote.local.url . &&
875 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
876 (git show-ref -q refs/remotes/local/master || git fetch local) &&
877 git branch --no-track myr20 local/master &&
878 test "z$(git config branch.myr20.remote)" = z &&
879 test "z$(git config branch.myr20.merge)" = z &&
880 test "z$(git config branch.myr20.rebase)" = z
883 test_expect_success 'autosetuprebase always on detached HEAD' '
884 git config branch.autosetupmerge always &&
885 test_when_finished git checkout master &&
886 git checkout HEAD^0 &&
888 test -z "$(git config branch.my11.remote)" &&
889 test -z "$(git config branch.my11.merge)"
892 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
893 git config branch.autosetuprebase garbage &&
894 test_must_fail git branch
897 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
898 git config --unset branch.autosetuprebase &&
899 echo "[branch] autosetuprebase" >>.git/config &&
900 test_must_fail git branch &&
901 git config --unset branch.autosetuprebase
904 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
906 git config --unset branch.my8.merge &&
907 test_must_fail git branch -d my8
910 test_expect_success 'attempt to delete a branch merged to its base' '
911 # we are on my9 which is the initial commit; traditionally
912 # we would not have allowed deleting my8 that is not merged
913 # to my9, but it is set to track master that already has my8
914 git config branch.my8.merge refs/heads/master &&
918 test_expect_success 'attempt to delete a branch merged to its base' '
919 git checkout master &&
921 git commit -m "Third commit" A &&
922 git branch -t my10 my9 &&
923 git branch -f my10 HEAD^ &&
924 # we are on master which is at the third commit, and my10
925 # is behind us, so traditionally we would have allowed deleting
926 # it; but my10 is set to track my9 that is further behind.
927 test_must_fail git branch -d my10
930 test_expect_success 'use set-upstream on the current branch' '
931 git checkout master &&
932 git --bare init myupstream.git &&
933 git push myupstream.git master:refs/heads/frotz &&
934 git remote add origin myupstream.git &&
936 git branch --set-upstream master origin/frotz &&
938 test "z$(git config branch.master.remote)" = "zorigin" &&
939 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
943 test_expect_success 'use --edit-description' '
944 write_script editor <<-\EOF &&
945 echo "New contents" >"$1"
947 EDITOR=./editor git branch --edit-description &&
948 write_script editor <<-\EOF &&
949 git stripspace -s <"$1" >"EDITOR_OUTPUT"
951 EDITOR=./editor git branch --edit-description &&
952 echo "New contents" >expect &&
953 test_cmp EDITOR_OUTPUT expect
956 test_expect_success 'detect typo in branch name when using --edit-description' '
957 write_script editor <<-\EOF &&
958 echo "New contents" >"$1"
960 test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
963 test_expect_success 'refuse --edit-description on unborn branch for now' '
964 write_script editor <<-\EOF &&
965 echo "New contents" >"$1"
967 git checkout --orphan unborn &&
968 test_must_fail env EDITOR=./editor git branch --edit-description
971 test_expect_success '--merged catches invalid object names' '
972 test_must_fail git branch --merged 0000000000000000000000000000000000000000
975 test_expect_success 'tracking with unexpected .fetch refspec' '
991 git remote add a ../a &&
992 git remote add b ../b &&
998 git remote add c ../c &&
999 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
1001 git branch --track local/a/master remotes/a/master &&
1002 test "$(git config branch.local/a/master.remote)" = "c" &&
1003 test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
1004 git rev-parse --verify a >expect &&
1005 git rev-parse --verify local/a/master >actual &&
1006 test_cmp expect actual