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 m/m should work' '
84 git branch -m m m/m &&
85 git reflog exists refs/heads/m/m
88 test_expect_success 'git branch -m n/n n should work' '
90 git branch -m n/n n &&
91 git reflog exists refs/heads/n
94 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
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' '
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' '
111 git branch -m -f o/q o/p
114 test_expect_success 'git branch -m q r/q should fail when r exists' '
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' '
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 &&
129 git branch -M baz bam &&
130 test $(git rev-parse --abbrev-ref HEAD) = bam
133 test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' '
134 git checkout master &&
135 git worktree add -b baz bazdir &&
136 git worktree add -f bazdir2 baz &&
137 git branch -M baz bam &&
138 test $(git -C bazdir rev-parse --abbrev-ref HEAD) = bam &&
139 test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam
142 test_expect_success 'git branch -M baz bam should succeed within a worktree in which baz is checked out' '
143 git checkout -b baz &&
144 git worktree add -f bazdir3 baz &&
147 git branch -M baz bam &&
148 test $(git rev-parse --abbrev-ref HEAD) = bam
150 test $(git rev-parse --abbrev-ref HEAD) = bam
153 test_expect_success 'git branch -M master should work when master is checked out' '
154 git checkout master &&
158 test_expect_success 'git branch -M master master should work when master is checked out' '
159 git checkout master &&
160 git branch -M master master
163 test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
164 git checkout master &&
165 git branch master2 &&
166 git branch -M master2 master2
169 test_expect_success 'git branch -v -d t should work' '
171 test_path_is_file .git/refs/heads/t &&
172 git branch -v -d t &&
173 test_path_is_missing .git/refs/heads/t
176 test_expect_success 'git branch -v -m t s should work' '
178 test_path_is_file .git/refs/heads/t &&
179 git branch -v -m t s &&
180 test_path_is_missing .git/refs/heads/t &&
181 test_path_is_file .git/refs/heads/s &&
185 test_expect_success 'git branch -m -d t s should fail' '
187 test_path_is_file .git/refs/heads/t &&
188 test_must_fail git branch -m -d t s &&
190 test_path_is_missing .git/refs/heads/t
193 test_expect_success 'git branch --list -d t should fail' '
195 test_path_is_file .git/refs/heads/t &&
196 test_must_fail git branch --list -d t &&
198 test_path_is_missing .git/refs/heads/t
201 test_expect_success 'git branch --column' '
202 COLUMNS=81 git branch --column=column >actual &&
203 cat >expected <<\EOF &&
204 a/b/c bam foo l * master n o/p r
205 abc bar j/k m/m master2 o/o q
207 test_cmp expected actual
210 test_expect_success 'git branch --column with an extremely long branch name' '
211 long=this/is/a/part/of/long/branch/name &&
212 long=z$long/$long/$long/$long &&
213 test_when_finished "git branch -d $long" &&
215 COLUMNS=80 git branch --column=column >actual &&
216 cat >expected <<EOF &&
234 test_cmp expected actual
237 test_expect_success 'git branch with column.*' '
238 git config column.ui column &&
239 git config column.branch "dense" &&
240 COLUMNS=80 git branch >actual &&
241 git config --unset column.branch &&
242 git config --unset column.ui &&
243 cat >expected <<\EOF &&
244 a/b/c bam foo l * master n o/p r
245 abc bar j/k m/m master2 o/o q
247 test_cmp expected actual
250 test_expect_success 'git branch --column -v should fail' '
251 test_must_fail git branch --column -v
254 test_expect_success 'git branch -v with column.ui ignored' '
255 git config column.ui column &&
256 COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
257 git config --unset column.ui &&
258 cat >expected <<\EOF &&
275 test_cmp expected actual
278 mv .git/config .git/config-saved
280 test_expect_success 'git branch -m q q2 without config should succeed' '
281 git branch -m q q2 &&
285 mv .git/config-saved .git/config
287 git config branch.s/s.dummy Hello
289 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
291 git reflog exists refs/heads/s/s &&
293 git reflog exists refs/heads/s/t &&
295 git branch -m s/s s &&
296 git reflog exists refs/heads/s
299 test_expect_success 'config information was renamed, too' '
300 test $(git config branch.s.dummy) = Hello &&
301 test_must_fail git config branch.s/s/dummy
304 test_expect_success 'deleting a symref' '
306 git symbolic-ref refs/heads/symref refs/heads/target &&
307 echo "Deleted branch symref (was refs/heads/target)." >expect &&
308 git branch -d symref >actual &&
309 test_path_is_file .git/refs/heads/target &&
310 test_path_is_missing .git/refs/heads/symref &&
311 test_i18ncmp expect actual
314 test_expect_success 'deleting a dangling symref' '
315 git symbolic-ref refs/heads/dangling-symref nowhere &&
316 test_path_is_file .git/refs/heads/dangling-symref &&
317 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
318 git branch -d dangling-symref >actual &&
319 test_path_is_missing .git/refs/heads/dangling-symref &&
320 test_i18ncmp expect actual
323 test_expect_success 'deleting a self-referential symref' '
324 git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
325 test_path_is_file .git/refs/heads/self-reference &&
326 echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
327 git branch -d self-reference >actual &&
328 test_path_is_missing .git/refs/heads/self-reference &&
329 test_i18ncmp expect actual
332 test_expect_success 'renaming a symref is not allowed' '
333 git symbolic-ref refs/heads/master2 refs/heads/master &&
334 test_must_fail git branch -m master2 master3 &&
335 git symbolic-ref refs/heads/master2 &&
336 test_path_is_file .git/refs/heads/master &&
337 test_path_is_missing .git/refs/heads/master3
340 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
342 mv .git/logs/refs/heads/u real-u &&
343 ln -s real-u .git/logs/refs/heads/u &&
344 test_must_fail git branch -m u v
347 test_expect_success 'test tracking setup via --track' '
348 git config remote.local.url . &&
349 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
350 (git show-ref -q refs/remotes/local/master || git fetch local) &&
351 git branch --track my1 local/master &&
352 test $(git config branch.my1.remote) = local &&
353 test $(git config branch.my1.merge) = refs/heads/master
356 test_expect_success 'test tracking setup (non-wildcard, matching)' '
357 git config remote.local.url . &&
358 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
359 (git show-ref -q refs/remotes/local/master || git fetch local) &&
360 git branch --track my4 local/master &&
361 test $(git config branch.my4.remote) = local &&
362 test $(git config branch.my4.merge) = refs/heads/master
365 test_expect_success 'tracking setup fails on non-matching refspec' '
366 git config remote.local.url . &&
367 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
368 (git show-ref -q refs/remotes/local/master || git fetch local) &&
369 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
370 test_must_fail git branch --track my5 local/master &&
371 test_must_fail git config branch.my5.remote &&
372 test_must_fail git config branch.my5.merge
375 test_expect_success 'test tracking setup via config' '
376 git config branch.autosetupmerge true &&
377 git config remote.local.url . &&
378 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
379 (git show-ref -q refs/remotes/local/master || git fetch local) &&
380 git branch my3 local/master &&
381 test $(git config branch.my3.remote) = local &&
382 test $(git config branch.my3.merge) = refs/heads/master
385 test_expect_success 'test overriding tracking setup via --no-track' '
386 git config branch.autosetupmerge true &&
387 git config remote.local.url . &&
388 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
389 (git show-ref -q refs/remotes/local/master || git fetch local) &&
390 git branch --no-track my2 local/master &&
391 git config branch.autosetupmerge false &&
392 ! test "$(git config branch.my2.remote)" = local &&
393 ! test "$(git config branch.my2.merge)" = refs/heads/master
396 test_expect_success 'no tracking without .fetch entries' '
397 git config branch.autosetupmerge true &&
399 git config branch.autosetupmerge false &&
400 test -z "$(git config branch.my6.remote)" &&
401 test -z "$(git config branch.my6.merge)"
404 test_expect_success 'test tracking setup via --track but deeper' '
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/o/o || git fetch local) &&
408 git branch --track my7 local/o/o &&
409 test "$(git config branch.my7.remote)" = local &&
410 test "$(git config branch.my7.merge)" = refs/heads/o/o
413 test_expect_success 'test deleting branch deletes branch config' '
415 test -z "$(git config branch.my7.remote)" &&
416 test -z "$(git config branch.my7.merge)"
419 test_expect_success 'test deleting branch without config' '
421 sha1=$(git rev-parse my7 | cut -c 1-7) &&
422 echo "Deleted branch my7 (was $sha1)." >expect &&
423 git branch -d my7 >actual 2>&1 &&
424 test_i18ncmp expect actual
427 test_expect_success 'deleting currently checked out branch fails' '
428 git worktree add -b my7 my7 &&
429 test_must_fail git -C my7 branch -d my7 &&
430 test_must_fail git branch -d my7
433 test_expect_success 'test --track without .fetch entries' '
434 git branch --track my8 &&
435 test "$(git config branch.my8.remote)" &&
436 test "$(git config branch.my8.merge)"
439 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
440 git config branch.autosetupmerge always &&
441 git branch my9 HEAD^ &&
442 git config branch.autosetupmerge false
445 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
446 test_must_fail git branch --track my10 HEAD^
449 test_expect_success 'branch from tag w/--track causes failure' '
451 test_must_fail git branch --track my11 foobar
454 test_expect_success '--set-upstream-to fails on multiple branches' '
455 test_must_fail git branch --set-upstream-to master a b c
458 test_expect_success '--set-upstream-to fails on detached HEAD' '
459 git checkout HEAD^{} &&
460 test_must_fail git branch --set-upstream-to master &&
464 test_expect_success '--set-upstream-to fails on a missing dst branch' '
465 test_must_fail git branch --set-upstream-to master does-not-exist
468 test_expect_success '--set-upstream-to fails on a missing src branch' '
469 test_must_fail git branch --set-upstream-to does-not-exist master
472 test_expect_success '--set-upstream-to fails on a non-ref' '
473 test_must_fail git branch --set-upstream-to HEAD^{}
476 test_expect_success '--set-upstream-to fails on locked config' '
477 test_when_finished "rm -f .git/config.lock" &&
480 test_must_fail git branch --set-upstream-to locked
483 test_expect_success 'use --set-upstream-to modify HEAD' '
484 test_config branch.master.remote foo &&
485 test_config branch.master.merge foo &&
487 git branch --set-upstream-to my12 &&
488 test "$(git config branch.master.remote)" = "." &&
489 test "$(git config branch.master.merge)" = "refs/heads/my12"
492 test_expect_success 'use --set-upstream-to modify a particular branch' '
494 git branch --set-upstream-to master my13 &&
495 test "$(git config branch.my13.remote)" = "." &&
496 test "$(git config branch.my13.merge)" = "refs/heads/master"
499 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
500 test_must_fail git branch --unset-upstream i-dont-exist
503 test_expect_success '--unset-upstream should fail if config is locked' '
504 test_when_finished "rm -f .git/config.lock" &&
505 git branch --set-upstream-to locked &&
507 test_must_fail git branch --unset-upstream
510 test_expect_success 'test --unset-upstream on HEAD' '
512 test_config branch.master.remote foo &&
513 test_config branch.master.merge foo &&
514 git branch --set-upstream-to my14 &&
515 git branch --unset-upstream &&
516 test_must_fail git config branch.master.remote &&
517 test_must_fail git config branch.master.merge &&
518 # fail for a branch without upstream set
519 test_must_fail git branch --unset-upstream
522 test_expect_success '--unset-upstream should fail on multiple branches' '
523 test_must_fail git branch --unset-upstream a b c
526 test_expect_success '--unset-upstream should fail on detached HEAD' '
527 git checkout HEAD^{} &&
528 test_must_fail git branch --unset-upstream &&
532 test_expect_success 'test --unset-upstream on a particular branch' '
534 git branch --set-upstream-to master my14 &&
535 git branch --unset-upstream my14 &&
536 test_must_fail git config branch.my14.remote &&
537 test_must_fail git config branch.my14.merge
540 test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
541 git update-ref refs/remotes/origin/master HEAD &&
542 git branch --set-upstream origin/master 2>actual &&
543 test_when_finished git update-ref -d refs/remotes/origin/master &&
544 test_when_finished git branch -d origin/master &&
545 cat >expected <<EOF &&
546 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
548 If you wanted to make '"'master'"' track '"'origin/master'"', do this:
550 git branch -d origin/master
551 git branch --set-upstream-to origin/master
553 test_i18ncmp expected actual
556 test_expect_success '--set-upstream with two args only shows the deprecation message' '
557 git branch --set-upstream master my13 2>actual &&
558 test_when_finished git branch --unset-upstream master &&
559 cat >expected <<EOF &&
560 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
562 test_i18ncmp expected actual
565 test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
566 git branch --set-upstream my13 2>actual &&
567 test_when_finished git branch --unset-upstream my13 &&
568 cat >expected <<EOF &&
569 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
571 test_i18ncmp expected actual
574 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
575 git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
576 cat >expected <<-\EOF &&
577 warning: Not setting branch my13 as its own upstream.
579 test_expect_code 1 git config branch.my13.remote &&
580 test_expect_code 1 git config branch.my13.merge &&
581 test_i18ncmp expected actual
584 # Keep this test last, as it changes the current branch
586 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
588 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
589 GIT_COMMITTER_DATE="2005-05-26 23:30" \
590 git checkout -b g/h/i -l master &&
591 test_path_is_file .git/refs/heads/g/h/i &&
592 test_path_is_file .git/logs/refs/heads/g/h/i &&
593 test_cmp expect .git/logs/refs/heads/g/h/i
596 test_expect_success 'checkout -b makes reflog by default' '
597 git checkout master &&
598 git config --unset core.logAllRefUpdates &&
599 git checkout -b alpha &&
600 git rev-parse --verify alpha@{0}
603 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
604 git checkout master &&
605 git config core.logAllRefUpdates false &&
606 git checkout -b beta &&
607 test_must_fail git rev-parse --verify beta@{0}
610 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
611 git checkout master &&
612 git checkout -lb gamma &&
613 git config --unset core.logAllRefUpdates &&
614 git rev-parse --verify gamma@{0}
617 test_expect_success 'avoid ambiguous track' '
618 git config branch.autosetupmerge true &&
619 git config remote.ambi1.url lalala &&
620 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
621 git config remote.ambi2.url lilili &&
622 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
623 test_must_fail git branch all1 master &&
624 test -z "$(git config branch.all1.merge)"
627 test_expect_success 'autosetuprebase local on a tracked local branch' '
628 git config remote.local.url . &&
629 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
630 git config branch.autosetuprebase local &&
631 (git show-ref -q refs/remotes/local/o || git fetch local) &&
633 git branch --track myr1 mybase &&
634 test "$(git config branch.myr1.remote)" = . &&
635 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
636 test "$(git config branch.myr1.rebase)" = true
639 test_expect_success 'autosetuprebase always on a tracked local branch' '
640 git config remote.local.url . &&
641 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
642 git config branch.autosetuprebase always &&
643 (git show-ref -q refs/remotes/local/o || git fetch local) &&
644 git branch mybase2 &&
645 git branch --track myr2 mybase &&
646 test "$(git config branch.myr2.remote)" = . &&
647 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
648 test "$(git config branch.myr2.rebase)" = true
651 test_expect_success 'autosetuprebase remote on a tracked local branch' '
652 git config remote.local.url . &&
653 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
654 git config branch.autosetuprebase remote &&
655 (git show-ref -q refs/remotes/local/o || git fetch local) &&
656 git branch mybase3 &&
657 git branch --track myr3 mybase2 &&
658 test "$(git config branch.myr3.remote)" = . &&
659 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
660 ! test "$(git config branch.myr3.rebase)" = true
663 test_expect_success 'autosetuprebase never on a tracked local branch' '
664 git config remote.local.url . &&
665 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
666 git config branch.autosetuprebase never &&
667 (git show-ref -q refs/remotes/local/o || git fetch local) &&
668 git branch mybase4 &&
669 git branch --track myr4 mybase2 &&
670 test "$(git config branch.myr4.remote)" = . &&
671 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
672 ! test "$(git config branch.myr4.rebase)" = true
675 test_expect_success 'autosetuprebase local on a tracked remote branch' '
676 git config remote.local.url . &&
677 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
678 git config branch.autosetuprebase local &&
679 (git show-ref -q refs/remotes/local/master || git fetch local) &&
680 git branch --track myr5 local/master &&
681 test "$(git config branch.myr5.remote)" = local &&
682 test "$(git config branch.myr5.merge)" = refs/heads/master &&
683 ! test "$(git config branch.myr5.rebase)" = true
686 test_expect_success 'autosetuprebase never on a tracked remote branch' '
687 git config remote.local.url . &&
688 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
689 git config branch.autosetuprebase never &&
690 (git show-ref -q refs/remotes/local/master || git fetch local) &&
691 git branch --track myr6 local/master &&
692 test "$(git config branch.myr6.remote)" = local &&
693 test "$(git config branch.myr6.merge)" = refs/heads/master &&
694 ! test "$(git config branch.myr6.rebase)" = true
697 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
698 git config remote.local.url . &&
699 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
700 git config branch.autosetuprebase remote &&
701 (git show-ref -q refs/remotes/local/master || git fetch local) &&
702 git branch --track myr7 local/master &&
703 test "$(git config branch.myr7.remote)" = local &&
704 test "$(git config branch.myr7.merge)" = refs/heads/master &&
705 test "$(git config branch.myr7.rebase)" = true
708 test_expect_success 'autosetuprebase always on a tracked remote 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/master || git fetch local) &&
713 git branch --track myr8 local/master &&
714 test "$(git config branch.myr8.remote)" = local &&
715 test "$(git config branch.myr8.merge)" = refs/heads/master &&
716 test "$(git config branch.myr8.rebase)" = true
719 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
720 git config --unset branch.autosetuprebase &&
721 git config remote.local.url . &&
722 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
723 (git show-ref -q refs/remotes/local/master || git fetch local) &&
724 git branch --track myr9 local/master &&
725 test "$(git config branch.myr9.remote)" = local &&
726 test "$(git config branch.myr9.merge)" = refs/heads/master &&
727 test "z$(git config branch.myr9.rebase)" = z
730 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
731 git config remote.local.url . &&
732 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
733 (git show-ref -q refs/remotes/local/o || git fetch local) &&
734 git branch mybase10 &&
735 git branch --track myr10 mybase2 &&
736 test "$(git config branch.myr10.remote)" = . &&
737 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
738 test "z$(git config branch.myr10.rebase)" = z
741 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
742 git config remote.local.url . &&
743 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
744 (git show-ref -q refs/remotes/local/master || git fetch local) &&
745 git branch --no-track myr11 mybase2 &&
746 test "z$(git config branch.myr11.remote)" = z &&
747 test "z$(git config branch.myr11.merge)" = z &&
748 test "z$(git config branch.myr11.rebase)" = z
751 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
752 git config remote.local.url . &&
753 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
754 (git show-ref -q refs/remotes/local/master || git fetch local) &&
755 git branch --no-track myr12 local/master &&
756 test "z$(git config branch.myr12.remote)" = z &&
757 test "z$(git config branch.myr12.merge)" = z &&
758 test "z$(git config branch.myr12.rebase)" = z
761 test_expect_success 'autosetuprebase never on an untracked local branch' '
762 git config branch.autosetuprebase never &&
763 git config remote.local.url . &&
764 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
765 (git show-ref -q refs/remotes/local/master || git fetch local) &&
766 git branch --no-track myr13 mybase2 &&
767 test "z$(git config branch.myr13.remote)" = z &&
768 test "z$(git config branch.myr13.merge)" = z &&
769 test "z$(git config branch.myr13.rebase)" = z
772 test_expect_success 'autosetuprebase local on an untracked local branch' '
773 git config branch.autosetuprebase local &&
774 git config remote.local.url . &&
775 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
776 (git show-ref -q refs/remotes/local/master || git fetch local) &&
777 git branch --no-track myr14 mybase2 &&
778 test "z$(git config branch.myr14.remote)" = z &&
779 test "z$(git config branch.myr14.merge)" = z &&
780 test "z$(git config branch.myr14.rebase)" = z
783 test_expect_success 'autosetuprebase remote on an untracked local branch' '
784 git config branch.autosetuprebase remote &&
785 git config remote.local.url . &&
786 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
787 (git show-ref -q refs/remotes/local/master || git fetch local) &&
788 git branch --no-track myr15 mybase2 &&
789 test "z$(git config branch.myr15.remote)" = z &&
790 test "z$(git config branch.myr15.merge)" = z &&
791 test "z$(git config branch.myr15.rebase)" = z
794 test_expect_success 'autosetuprebase always on an untracked local branch' '
795 git config branch.autosetuprebase always &&
796 git config remote.local.url . &&
797 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
798 (git show-ref -q refs/remotes/local/master || git fetch local) &&
799 git branch --no-track myr16 mybase2 &&
800 test "z$(git config branch.myr16.remote)" = z &&
801 test "z$(git config branch.myr16.merge)" = z &&
802 test "z$(git config branch.myr16.rebase)" = z
805 test_expect_success 'autosetuprebase never on an untracked remote branch' '
806 git config branch.autosetuprebase never &&
807 git config remote.local.url . &&
808 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
809 (git show-ref -q refs/remotes/local/master || git fetch local) &&
810 git branch --no-track myr17 local/master &&
811 test "z$(git config branch.myr17.remote)" = z &&
812 test "z$(git config branch.myr17.merge)" = z &&
813 test "z$(git config branch.myr17.rebase)" = z
816 test_expect_success 'autosetuprebase local on an untracked remote branch' '
817 git config branch.autosetuprebase local &&
818 git config remote.local.url . &&
819 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
820 (git show-ref -q refs/remotes/local/master || git fetch local) &&
821 git branch --no-track myr18 local/master &&
822 test "z$(git config branch.myr18.remote)" = z &&
823 test "z$(git config branch.myr18.merge)" = z &&
824 test "z$(git config branch.myr18.rebase)" = z
827 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
828 git config branch.autosetuprebase remote &&
829 git config remote.local.url . &&
830 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
831 (git show-ref -q refs/remotes/local/master || git fetch local) &&
832 git branch --no-track myr19 local/master &&
833 test "z$(git config branch.myr19.remote)" = z &&
834 test "z$(git config branch.myr19.merge)" = z &&
835 test "z$(git config branch.myr19.rebase)" = z
838 test_expect_success 'autosetuprebase always on an untracked remote branch' '
839 git config branch.autosetuprebase always &&
840 git config remote.local.url . &&
841 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
842 (git show-ref -q refs/remotes/local/master || git fetch local) &&
843 git branch --no-track myr20 local/master &&
844 test "z$(git config branch.myr20.remote)" = z &&
845 test "z$(git config branch.myr20.merge)" = z &&
846 test "z$(git config branch.myr20.rebase)" = z
849 test_expect_success 'autosetuprebase always on detached HEAD' '
850 git config branch.autosetupmerge always &&
851 test_when_finished git checkout master &&
852 git checkout HEAD^0 &&
854 test -z "$(git config branch.my11.remote)" &&
855 test -z "$(git config branch.my11.merge)"
858 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
859 git config branch.autosetuprebase garbage &&
860 test_must_fail git branch
863 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
864 git config --unset branch.autosetuprebase &&
865 echo "[branch] autosetuprebase" >>.git/config &&
866 test_must_fail git branch &&
867 git config --unset branch.autosetuprebase
870 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
872 git config --unset branch.my8.merge &&
873 test_must_fail git branch -d my8
876 test_expect_success 'attempt to delete a branch merged to its base' '
877 # we are on my9 which is the initial commit; traditionally
878 # we would not have allowed deleting my8 that is not merged
879 # to my9, but it is set to track master that already has my8
880 git config branch.my8.merge refs/heads/master &&
884 test_expect_success 'attempt to delete a branch merged to its base' '
885 git checkout master &&
887 git commit -m "Third commit" A &&
888 git branch -t my10 my9 &&
889 git branch -f my10 HEAD^ &&
890 # we are on master which is at the third commit, and my10
891 # is behind us, so traditionally we would have allowed deleting
892 # it; but my10 is set to track my9 that is further behind.
893 test_must_fail git branch -d my10
896 test_expect_success 'use set-upstream on the current branch' '
897 git checkout master &&
898 git --bare init myupstream.git &&
899 git push myupstream.git master:refs/heads/frotz &&
900 git remote add origin myupstream.git &&
902 git branch --set-upstream master origin/frotz &&
904 test "z$(git config branch.master.remote)" = "zorigin" &&
905 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
909 test_expect_success 'use --edit-description' '
910 write_script editor <<-\EOF &&
911 echo "New contents" >"$1"
913 EDITOR=./editor git branch --edit-description &&
914 write_script editor <<-\EOF &&
915 git stripspace -s <"$1" >"EDITOR_OUTPUT"
917 EDITOR=./editor git branch --edit-description &&
918 echo "New contents" >expect &&
919 test_cmp EDITOR_OUTPUT expect
922 test_expect_success 'detect typo in branch name when using --edit-description' '
923 write_script editor <<-\EOF &&
924 echo "New contents" >"$1"
926 test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
929 test_expect_success 'refuse --edit-description on unborn branch for now' '
930 write_script editor <<-\EOF &&
931 echo "New contents" >"$1"
933 git checkout --orphan unborn &&
934 test_must_fail env EDITOR=./editor git branch --edit-description
937 test_expect_success '--merged catches invalid object names' '
938 test_must_fail git branch --merged 0000000000000000000000000000000000000000
941 test_expect_success 'tracking with unexpected .fetch refspec' '
957 git remote add a ../a &&
958 git remote add b ../b &&
964 git remote add c ../c &&
965 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
967 git branch --track local/a/master remotes/a/master &&
968 test "$(git config branch.local/a/master.remote)" = "c" &&
969 test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
970 git rev-parse --verify a >expect &&
971 git rev-parse --verify local/a/master >actual &&
972 test_cmp expect actual