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
132 test_expect_success 'git branch -M master should work when master is checked out' '
133 git checkout master &&
137 test_expect_success 'git branch -M master master should work when master is checked out' '
138 git checkout master &&
139 git branch -M master master
142 test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
143 git checkout master &&
144 git branch master2 &&
145 git branch -M master2 master2
148 test_expect_success 'git branch -v -d t should work' '
150 test_path_is_file .git/refs/heads/t &&
151 git branch -v -d t &&
152 test_path_is_missing .git/refs/heads/t
155 test_expect_success 'git branch -v -m t s should work' '
157 test_path_is_file .git/refs/heads/t &&
158 git branch -v -m t s &&
159 test_path_is_missing .git/refs/heads/t &&
160 test_path_is_file .git/refs/heads/s &&
164 test_expect_success 'git branch -m -d t s should fail' '
166 test_path_is_file .git/refs/heads/t &&
167 test_must_fail git branch -m -d t s &&
169 test_path_is_missing .git/refs/heads/t
172 test_expect_success 'git branch --list -d t should fail' '
174 test_path_is_file .git/refs/heads/t &&
175 test_must_fail git branch --list -d t &&
177 test_path_is_missing .git/refs/heads/t
180 test_expect_success 'git branch --column' '
181 COLUMNS=81 git branch --column=column >actual &&
182 cat >expected <<\EOF &&
183 a/b/c bam foo l * master n o/p r
184 abc bar j/k m/m master2 o/o q
186 test_cmp expected actual
189 test_expect_success 'git branch --column with an extremely long branch name' '
190 long=this/is/a/part/of/long/branch/name &&
191 long=z$long/$long/$long/$long &&
192 test_when_finished "git branch -d $long" &&
194 COLUMNS=80 git branch --column=column >actual &&
195 cat >expected <<EOF &&
213 test_cmp expected actual
216 test_expect_success 'git branch with column.*' '
217 git config column.ui column &&
218 git config column.branch "dense" &&
219 COLUMNS=80 git branch >actual &&
220 git config --unset column.branch &&
221 git config --unset column.ui &&
222 cat >expected <<\EOF &&
223 a/b/c bam foo l * master n o/p r
224 abc bar j/k m/m master2 o/o q
226 test_cmp expected actual
229 test_expect_success 'git branch --column -v should fail' '
230 test_must_fail git branch --column -v
233 test_expect_success 'git branch -v with column.ui ignored' '
234 git config column.ui column &&
235 COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
236 git config --unset column.ui &&
237 cat >expected <<\EOF &&
254 test_cmp expected actual
257 mv .git/config .git/config-saved
259 test_expect_success 'git branch -m q q2 without config should succeed' '
260 git branch -m q q2 &&
264 mv .git/config-saved .git/config
266 git config branch.s/s.dummy Hello
268 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
270 git reflog exists refs/heads/s/s &&
272 git reflog exists refs/heads/s/t &&
274 git branch -m s/s s &&
275 git reflog exists refs/heads/s
278 test_expect_success 'config information was renamed, too' '
279 test $(git config branch.s.dummy) = Hello &&
280 test_must_fail git config branch.s/s/dummy
283 test_expect_success 'deleting a symref' '
285 git symbolic-ref refs/heads/symref refs/heads/target &&
286 echo "Deleted branch symref (was refs/heads/target)." >expect &&
287 git branch -d symref >actual &&
288 test_path_is_file .git/refs/heads/target &&
289 test_path_is_missing .git/refs/heads/symref &&
290 test_i18ncmp expect actual
293 test_expect_success 'deleting a dangling symref' '
294 git symbolic-ref refs/heads/dangling-symref nowhere &&
295 test_path_is_file .git/refs/heads/dangling-symref &&
296 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
297 git branch -d dangling-symref >actual &&
298 test_path_is_missing .git/refs/heads/dangling-symref &&
299 test_i18ncmp expect actual
302 test_expect_success 'deleting a self-referential symref' '
303 git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
304 test_path_is_file .git/refs/heads/self-reference &&
305 echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
306 git branch -d self-reference >actual &&
307 test_path_is_missing .git/refs/heads/self-reference &&
308 test_i18ncmp expect actual
311 test_expect_success 'renaming a symref is not allowed' '
312 git symbolic-ref refs/heads/master2 refs/heads/master &&
313 test_must_fail git branch -m master2 master3 &&
314 git symbolic-ref refs/heads/master2 &&
315 test_path_is_file .git/refs/heads/master &&
316 test_path_is_missing .git/refs/heads/master3
319 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
321 mv .git/logs/refs/heads/u real-u &&
322 ln -s real-u .git/logs/refs/heads/u &&
323 test_must_fail git branch -m u v
326 test_expect_success 'test tracking setup via --track' '
327 git config remote.local.url . &&
328 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
329 (git show-ref -q refs/remotes/local/master || git fetch local) &&
330 git branch --track my1 local/master &&
331 test $(git config branch.my1.remote) = local &&
332 test $(git config branch.my1.merge) = refs/heads/master
335 test_expect_success 'test tracking setup (non-wildcard, matching)' '
336 git config remote.local.url . &&
337 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
338 (git show-ref -q refs/remotes/local/master || git fetch local) &&
339 git branch --track my4 local/master &&
340 test $(git config branch.my4.remote) = local &&
341 test $(git config branch.my4.merge) = refs/heads/master
344 test_expect_success 'tracking setup fails on non-matching refspec' '
345 git config remote.local.url . &&
346 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
347 (git show-ref -q refs/remotes/local/master || git fetch local) &&
348 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
349 test_must_fail git branch --track my5 local/master &&
350 test_must_fail git config branch.my5.remote &&
351 test_must_fail git config branch.my5.merge
354 test_expect_success 'test tracking setup via config' '
355 git config branch.autosetupmerge true &&
356 git config remote.local.url . &&
357 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
358 (git show-ref -q refs/remotes/local/master || git fetch local) &&
359 git branch my3 local/master &&
360 test $(git config branch.my3.remote) = local &&
361 test $(git config branch.my3.merge) = refs/heads/master
364 test_expect_success 'test overriding tracking setup via --no-track' '
365 git config branch.autosetupmerge true &&
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 branch --no-track my2 local/master &&
370 git config branch.autosetupmerge false &&
371 ! test "$(git config branch.my2.remote)" = local &&
372 ! test "$(git config branch.my2.merge)" = refs/heads/master
375 test_expect_success 'no tracking without .fetch entries' '
376 git config branch.autosetupmerge true &&
378 git config branch.autosetupmerge false &&
379 test -z "$(git config branch.my6.remote)" &&
380 test -z "$(git config branch.my6.merge)"
383 test_expect_success 'test tracking setup via --track but deeper' '
384 git config remote.local.url . &&
385 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
386 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
387 git branch --track my7 local/o/o &&
388 test "$(git config branch.my7.remote)" = local &&
389 test "$(git config branch.my7.merge)" = refs/heads/o/o
392 test_expect_success 'test deleting branch deletes branch config' '
394 test -z "$(git config branch.my7.remote)" &&
395 test -z "$(git config branch.my7.merge)"
398 test_expect_success 'test deleting branch without config' '
400 sha1=$(git rev-parse my7 | cut -c 1-7) &&
401 echo "Deleted branch my7 (was $sha1)." >expect &&
402 git branch -d my7 >actual 2>&1 &&
403 test_i18ncmp expect actual
406 test_expect_success 'deleting currently checked out branch fails' '
407 git worktree add -b my7 my7 &&
408 test_must_fail git -C my7 branch -d my7 &&
409 test_must_fail git branch -d my7
412 test_expect_success 'test --track without .fetch entries' '
413 git branch --track my8 &&
414 test "$(git config branch.my8.remote)" &&
415 test "$(git config branch.my8.merge)"
418 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
419 git config branch.autosetupmerge always &&
420 git branch my9 HEAD^ &&
421 git config branch.autosetupmerge false
424 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
425 test_must_fail git branch --track my10 HEAD^
428 test_expect_success 'branch from tag w/--track causes failure' '
430 test_must_fail git branch --track my11 foobar
433 test_expect_success '--set-upstream-to fails on multiple branches' '
434 test_must_fail git branch --set-upstream-to master a b c
437 test_expect_success '--set-upstream-to fails on detached HEAD' '
438 git checkout HEAD^{} &&
439 test_must_fail git branch --set-upstream-to master &&
443 test_expect_success '--set-upstream-to fails on a missing dst branch' '
444 test_must_fail git branch --set-upstream-to master does-not-exist
447 test_expect_success '--set-upstream-to fails on a missing src branch' '
448 test_must_fail git branch --set-upstream-to does-not-exist master
451 test_expect_success '--set-upstream-to fails on a non-ref' '
452 test_must_fail git branch --set-upstream-to HEAD^{}
455 test_expect_success '--set-upstream-to fails on locked config' '
456 test_when_finished "rm -f .git/config.lock" &&
459 test_must_fail git branch --set-upstream-to locked
462 test_expect_success 'use --set-upstream-to modify HEAD' '
463 test_config branch.master.remote foo &&
464 test_config branch.master.merge foo &&
466 git branch --set-upstream-to my12 &&
467 test "$(git config branch.master.remote)" = "." &&
468 test "$(git config branch.master.merge)" = "refs/heads/my12"
471 test_expect_success 'use --set-upstream-to modify a particular branch' '
473 git branch --set-upstream-to master my13 &&
474 test "$(git config branch.my13.remote)" = "." &&
475 test "$(git config branch.my13.merge)" = "refs/heads/master"
478 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
479 test_must_fail git branch --unset-upstream i-dont-exist
482 test_expect_success '--unset-upstream should fail if config is locked' '
483 test_when_finished "rm -f .git/config.lock" &&
484 git branch --set-upstream-to locked &&
486 test_must_fail git branch --unset-upstream
489 test_expect_success 'test --unset-upstream on HEAD' '
491 test_config branch.master.remote foo &&
492 test_config branch.master.merge foo &&
493 git branch --set-upstream-to my14 &&
494 git branch --unset-upstream &&
495 test_must_fail git config branch.master.remote &&
496 test_must_fail git config branch.master.merge &&
497 # fail for a branch without upstream set
498 test_must_fail git branch --unset-upstream
501 test_expect_success '--unset-upstream should fail on multiple branches' '
502 test_must_fail git branch --unset-upstream a b c
505 test_expect_success '--unset-upstream should fail on detached HEAD' '
506 git checkout HEAD^{} &&
507 test_must_fail git branch --unset-upstream &&
511 test_expect_success 'test --unset-upstream on a particular branch' '
513 git branch --set-upstream-to master my14 &&
514 git branch --unset-upstream my14 &&
515 test_must_fail git config branch.my14.remote &&
516 test_must_fail git config branch.my14.merge
519 test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
520 git update-ref refs/remotes/origin/master HEAD &&
521 git branch --set-upstream origin/master 2>actual &&
522 test_when_finished git update-ref -d refs/remotes/origin/master &&
523 test_when_finished git branch -d origin/master &&
524 cat >expected <<EOF &&
525 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
527 If you wanted to make '"'master'"' track '"'origin/master'"', do this:
529 git branch -d origin/master
530 git branch --set-upstream-to origin/master
532 test_cmp expected actual
535 test_expect_success '--set-upstream with two args only shows the deprecation message' '
536 git branch --set-upstream master my13 2>actual &&
537 test_when_finished git branch --unset-upstream master &&
538 cat >expected <<EOF &&
539 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
541 test_cmp expected actual
544 test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
545 git branch --set-upstream my13 2>actual &&
546 test_when_finished git branch --unset-upstream my13 &&
547 cat >expected <<EOF &&
548 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
550 test_cmp expected actual
553 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
554 git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
555 cat >expected <<-\EOF &&
556 warning: Not setting branch my13 as its own upstream.
558 test_expect_code 1 git config branch.my13.remote &&
559 test_expect_code 1 git config branch.my13.merge &&
560 test_i18ncmp expected actual
563 # Keep this test last, as it changes the current branch
565 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
567 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
568 GIT_COMMITTER_DATE="2005-05-26 23:30" \
569 git checkout -b g/h/i -l master &&
570 test_path_is_file .git/refs/heads/g/h/i &&
571 test_path_is_file .git/logs/refs/heads/g/h/i &&
572 test_cmp expect .git/logs/refs/heads/g/h/i
575 test_expect_success 'checkout -b makes reflog by default' '
576 git checkout master &&
577 git config --unset core.logAllRefUpdates &&
578 git checkout -b alpha &&
579 git rev-parse --verify alpha@{0}
582 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
583 git checkout master &&
584 git config core.logAllRefUpdates false &&
585 git checkout -b beta &&
586 test_must_fail git rev-parse --verify beta@{0}
589 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
590 git checkout master &&
591 git checkout -lb gamma &&
592 git config --unset core.logAllRefUpdates &&
593 git rev-parse --verify gamma@{0}
596 test_expect_success 'avoid ambiguous track' '
597 git config branch.autosetupmerge true &&
598 git config remote.ambi1.url lalala &&
599 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
600 git config remote.ambi2.url lilili &&
601 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
602 test_must_fail git branch all1 master &&
603 test -z "$(git config branch.all1.merge)"
606 test_expect_success 'autosetuprebase local on a tracked local branch' '
607 git config remote.local.url . &&
608 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
609 git config branch.autosetuprebase local &&
610 (git show-ref -q refs/remotes/local/o || git fetch local) &&
612 git branch --track myr1 mybase &&
613 test "$(git config branch.myr1.remote)" = . &&
614 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
615 test "$(git config branch.myr1.rebase)" = true
618 test_expect_success 'autosetuprebase always on a tracked local branch' '
619 git config remote.local.url . &&
620 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
621 git config branch.autosetuprebase always &&
622 (git show-ref -q refs/remotes/local/o || git fetch local) &&
623 git branch mybase2 &&
624 git branch --track myr2 mybase &&
625 test "$(git config branch.myr2.remote)" = . &&
626 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
627 test "$(git config branch.myr2.rebase)" = true
630 test_expect_success 'autosetuprebase remote on a tracked local branch' '
631 git config remote.local.url . &&
632 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
633 git config branch.autosetuprebase remote &&
634 (git show-ref -q refs/remotes/local/o || git fetch local) &&
635 git branch mybase3 &&
636 git branch --track myr3 mybase2 &&
637 test "$(git config branch.myr3.remote)" = . &&
638 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
639 ! test "$(git config branch.myr3.rebase)" = true
642 test_expect_success 'autosetuprebase never on a tracked local branch' '
643 git config remote.local.url . &&
644 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
645 git config branch.autosetuprebase never &&
646 (git show-ref -q refs/remotes/local/o || git fetch local) &&
647 git branch mybase4 &&
648 git branch --track myr4 mybase2 &&
649 test "$(git config branch.myr4.remote)" = . &&
650 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
651 ! test "$(git config branch.myr4.rebase)" = true
654 test_expect_success 'autosetuprebase local on a tracked remote branch' '
655 git config remote.local.url . &&
656 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
657 git config branch.autosetuprebase local &&
658 (git show-ref -q refs/remotes/local/master || git fetch local) &&
659 git branch --track myr5 local/master &&
660 test "$(git config branch.myr5.remote)" = local &&
661 test "$(git config branch.myr5.merge)" = refs/heads/master &&
662 ! test "$(git config branch.myr5.rebase)" = true
665 test_expect_success 'autosetuprebase never on a tracked remote branch' '
666 git config remote.local.url . &&
667 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
668 git config branch.autosetuprebase never &&
669 (git show-ref -q refs/remotes/local/master || git fetch local) &&
670 git branch --track myr6 local/master &&
671 test "$(git config branch.myr6.remote)" = local &&
672 test "$(git config branch.myr6.merge)" = refs/heads/master &&
673 ! test "$(git config branch.myr6.rebase)" = true
676 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
677 git config remote.local.url . &&
678 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
679 git config branch.autosetuprebase remote &&
680 (git show-ref -q refs/remotes/local/master || git fetch local) &&
681 git branch --track myr7 local/master &&
682 test "$(git config branch.myr7.remote)" = local &&
683 test "$(git config branch.myr7.merge)" = refs/heads/master &&
684 test "$(git config branch.myr7.rebase)" = true
687 test_expect_success 'autosetuprebase always on a tracked remote branch' '
688 git config remote.local.url . &&
689 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
690 git config branch.autosetuprebase remote &&
691 (git show-ref -q refs/remotes/local/master || git fetch local) &&
692 git branch --track myr8 local/master &&
693 test "$(git config branch.myr8.remote)" = local &&
694 test "$(git config branch.myr8.merge)" = refs/heads/master &&
695 test "$(git config branch.myr8.rebase)" = true
698 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
699 git config --unset branch.autosetuprebase &&
700 git config remote.local.url . &&
701 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
702 (git show-ref -q refs/remotes/local/master || git fetch local) &&
703 git branch --track myr9 local/master &&
704 test "$(git config branch.myr9.remote)" = local &&
705 test "$(git config branch.myr9.merge)" = refs/heads/master &&
706 test "z$(git config branch.myr9.rebase)" = z
709 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
710 git config remote.local.url . &&
711 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
712 (git show-ref -q refs/remotes/local/o || git fetch local) &&
713 git branch mybase10 &&
714 git branch --track myr10 mybase2 &&
715 test "$(git config branch.myr10.remote)" = . &&
716 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
717 test "z$(git config branch.myr10.rebase)" = z
720 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
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 --no-track myr11 mybase2 &&
725 test "z$(git config branch.myr11.remote)" = z &&
726 test "z$(git config branch.myr11.merge)" = z &&
727 test "z$(git config branch.myr11.rebase)" = z
730 test_expect_success 'autosetuprebase unconfigured on untracked remote 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/master || git fetch local) &&
734 git branch --no-track myr12 local/master &&
735 test "z$(git config branch.myr12.remote)" = z &&
736 test "z$(git config branch.myr12.merge)" = z &&
737 test "z$(git config branch.myr12.rebase)" = z
740 test_expect_success 'autosetuprebase never on an untracked local branch' '
741 git config branch.autosetuprebase never &&
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 myr13 mybase2 &&
746 test "z$(git config branch.myr13.remote)" = z &&
747 test "z$(git config branch.myr13.merge)" = z &&
748 test "z$(git config branch.myr13.rebase)" = z
751 test_expect_success 'autosetuprebase local on an untracked local branch' '
752 git config branch.autosetuprebase local &&
753 git config remote.local.url . &&
754 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
755 (git show-ref -q refs/remotes/local/master || git fetch local) &&
756 git branch --no-track myr14 mybase2 &&
757 test "z$(git config branch.myr14.remote)" = z &&
758 test "z$(git config branch.myr14.merge)" = z &&
759 test "z$(git config branch.myr14.rebase)" = z
762 test_expect_success 'autosetuprebase remote on an untracked local branch' '
763 git config branch.autosetuprebase remote &&
764 git config remote.local.url . &&
765 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
766 (git show-ref -q refs/remotes/local/master || git fetch local) &&
767 git branch --no-track myr15 mybase2 &&
768 test "z$(git config branch.myr15.remote)" = z &&
769 test "z$(git config branch.myr15.merge)" = z &&
770 test "z$(git config branch.myr15.rebase)" = z
773 test_expect_success 'autosetuprebase always on an untracked local branch' '
774 git config branch.autosetuprebase always &&
775 git config remote.local.url . &&
776 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
777 (git show-ref -q refs/remotes/local/master || git fetch local) &&
778 git branch --no-track myr16 mybase2 &&
779 test "z$(git config branch.myr16.remote)" = z &&
780 test "z$(git config branch.myr16.merge)" = z &&
781 test "z$(git config branch.myr16.rebase)" = z
784 test_expect_success 'autosetuprebase never on an untracked remote branch' '
785 git config branch.autosetuprebase never &&
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 myr17 local/master &&
790 test "z$(git config branch.myr17.remote)" = z &&
791 test "z$(git config branch.myr17.merge)" = z &&
792 test "z$(git config branch.myr17.rebase)" = z
795 test_expect_success 'autosetuprebase local on an untracked remote branch' '
796 git config branch.autosetuprebase local &&
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 myr18 local/master &&
801 test "z$(git config branch.myr18.remote)" = z &&
802 test "z$(git config branch.myr18.merge)" = z &&
803 test "z$(git config branch.myr18.rebase)" = z
806 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
807 git config branch.autosetuprebase remote &&
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 myr19 local/master &&
812 test "z$(git config branch.myr19.remote)" = z &&
813 test "z$(git config branch.myr19.merge)" = z &&
814 test "z$(git config branch.myr19.rebase)" = z
817 test_expect_success 'autosetuprebase always on an untracked remote branch' '
818 git config branch.autosetuprebase always &&
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 myr20 local/master &&
823 test "z$(git config branch.myr20.remote)" = z &&
824 test "z$(git config branch.myr20.merge)" = z &&
825 test "z$(git config branch.myr20.rebase)" = z
828 test_expect_success 'autosetuprebase always on detached HEAD' '
829 git config branch.autosetupmerge always &&
830 test_when_finished git checkout master &&
831 git checkout HEAD^0 &&
833 test -z "$(git config branch.my11.remote)" &&
834 test -z "$(git config branch.my11.merge)"
837 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
838 git config branch.autosetuprebase garbage &&
839 test_must_fail git branch
842 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
843 git config --unset branch.autosetuprebase &&
844 echo "[branch] autosetuprebase" >>.git/config &&
845 test_must_fail git branch &&
846 git config --unset branch.autosetuprebase
849 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
851 git config --unset branch.my8.merge &&
852 test_must_fail git branch -d my8
855 test_expect_success 'attempt to delete a branch merged to its base' '
856 # we are on my9 which is the initial commit; traditionally
857 # we would not have allowed deleting my8 that is not merged
858 # to my9, but it is set to track master that already has my8
859 git config branch.my8.merge refs/heads/master &&
863 test_expect_success 'attempt to delete a branch merged to its base' '
864 git checkout master &&
866 git commit -m "Third commit" A &&
867 git branch -t my10 my9 &&
868 git branch -f my10 HEAD^ &&
869 # we are on master which is at the third commit, and my10
870 # is behind us, so traditionally we would have allowed deleting
871 # it; but my10 is set to track my9 that is further behind.
872 test_must_fail git branch -d my10
875 test_expect_success 'use set-upstream on the current branch' '
876 git checkout master &&
877 git --bare init myupstream.git &&
878 git push myupstream.git master:refs/heads/frotz &&
879 git remote add origin myupstream.git &&
881 git branch --set-upstream master origin/frotz &&
883 test "z$(git config branch.master.remote)" = "zorigin" &&
884 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
888 test_expect_success 'use --edit-description' '
889 write_script editor <<-\EOF &&
890 echo "New contents" >"$1"
892 EDITOR=./editor git branch --edit-description &&
893 write_script editor <<-\EOF &&
894 git stripspace -s <"$1" >"EDITOR_OUTPUT"
896 EDITOR=./editor git branch --edit-description &&
897 echo "New contents" >expect &&
898 test_cmp EDITOR_OUTPUT expect
901 test_expect_success 'detect typo in branch name when using --edit-description' '
902 write_script editor <<-\EOF &&
903 echo "New contents" >"$1"
905 test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
908 test_expect_success 'refuse --edit-description on unborn branch for now' '
909 write_script editor <<-\EOF &&
910 echo "New contents" >"$1"
912 git checkout --orphan unborn &&
913 test_must_fail env EDITOR=./editor git branch --edit-description
916 test_expect_success '--merged catches invalid object names' '
917 test_must_fail git branch --merged 0000000000000000000000000000000000000000
920 test_expect_success 'tracking with unexpected .fetch refspec' '
936 git remote add a ../a &&
937 git remote add b ../b &&
943 git remote add c ../c &&
944 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
946 git branch --track local/a/master remotes/a/master &&
947 test "$(git config branch.local/a/master.remote)" = "c" &&
948 test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
949 git rev-parse --verify a >expect &&
950 git rev-parse --verify local/a/master >actual &&
951 test_cmp expect actual