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)'
19 test_expect_success 'git branch --help should not have created a bogus branch' '
20 test_might_fail git branch --help </dev/null >/dev/null 2>/dev/null &&
21 test_path_is_missing .git/refs/heads/--help
24 test_expect_success 'branch -h in broken repository' '
29 >.git/refs/heads/master &&
30 test_expect_code 129 git branch -h >usage 2>&1
32 test_i18ngrep "[Uu]sage" broken/usage
35 test_expect_success 'git branch abc should create a branch' '
36 git branch abc && test_path_is_file .git/refs/heads/abc
39 test_expect_success 'git branch a/b/c should create a branch' '
40 git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c
43 test_expect_success 'git branch HEAD should fail' '
44 test_must_fail git branch HEAD
48 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
50 test_expect_success 'git branch -l d/e/f should create a branch and a log' '
51 GIT_COMMITTER_DATE="2005-05-26 23:30" \
52 git branch -l d/e/f &&
53 test_path_is_file .git/refs/heads/d/e/f &&
54 test_path_is_file .git/logs/refs/heads/d/e/f &&
55 test_cmp expect .git/logs/refs/heads/d/e/f
58 test_expect_success 'git branch -d d/e/f should delete a branch and a log' '
59 git branch -d d/e/f &&
60 test_path_is_missing .git/refs/heads/d/e/f &&
61 test_path_is_missing .git/logs/refs/heads/d/e/f
64 test_expect_success 'git branch j/k should work after branch j has been deleted' '
70 test_expect_success 'git branch l should work after branch l/m has been deleted' '
76 test_expect_success 'git branch -m dumps usage' '
77 test_expect_code 128 git branch -m 2>err &&
78 test_i18ngrep "too many branches for a rename operation" err
81 test_expect_success 'git branch -m m m/m should work' '
83 git branch -m m m/m &&
84 test_path_is_file .git/logs/refs/heads/m/m
87 test_expect_success 'git branch -m n/n n should work' '
89 git branch -m n/n n &&
90 test_path_is_file .git/logs/refs/heads/n
93 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
96 test_must_fail git branch -m o/o o
99 test_expect_success 'git branch -m q r/q should fail when r exists' '
102 test_must_fail git branch -m q r/q
105 test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
107 git checkout -b foo &&
108 test_must_fail git branch -M bar foo
111 test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
112 git checkout -b baz &&
114 git branch -M baz bam
117 test_expect_success 'git branch -M master should work when master is checked out' '
118 git checkout master &&
122 test_expect_success 'git branch -M master master should work when master is checked out' '
123 git checkout master &&
124 git branch -M master master
127 test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
128 git checkout master &&
129 git branch master2 &&
130 git branch -M master2 master2
133 test_expect_success 'git branch -v -d t should work' '
135 test_path_is_file .git/refs/heads/t &&
136 git branch -v -d t &&
137 test_path_is_missing .git/refs/heads/t
140 test_expect_success 'git branch -v -m t s should work' '
142 test_path_is_file .git/refs/heads/t &&
143 git branch -v -m t s &&
144 test_path_is_missing .git/refs/heads/t &&
145 test_path_is_file .git/refs/heads/s &&
149 test_expect_success 'git branch -m -d t s should fail' '
151 test_path_is_file .git/refs/heads/t &&
152 test_must_fail git branch -m -d t s &&
154 test_path_is_missing .git/refs/heads/t
157 test_expect_success 'git branch --list -d t should fail' '
159 test_path_is_file .git/refs/heads/t &&
160 test_must_fail git branch --list -d t &&
162 test_path_is_missing .git/refs/heads/t
165 test_expect_success 'git branch --column' '
166 COLUMNS=81 git branch --column=column >actual &&
167 cat >expected <<\EOF &&
168 a/b/c bam foo l * master n o/p r
169 abc bar j/k m/m master2 o/o q
171 test_cmp expected actual
174 test_expect_success 'git branch --column with an extremely long branch name' '
175 long=this/is/a/part/of/long/branch/name &&
176 long=z$long/$long/$long/$long &&
177 test_when_finished "git branch -d $long" &&
179 COLUMNS=80 git branch --column=column >actual &&
180 cat >expected <<EOF &&
198 test_cmp expected actual
201 test_expect_success 'git branch with column.*' '
202 git config column.ui column &&
203 git config column.branch "dense" &&
204 COLUMNS=80 git branch >actual &&
205 git config --unset column.branch &&
206 git config --unset column.ui &&
207 cat >expected <<\EOF &&
208 a/b/c bam foo l * master n o/p r
209 abc bar j/k m/m master2 o/o q
211 test_cmp expected actual
214 test_expect_success 'git branch --column -v should fail' '
215 test_must_fail git branch --column -v
218 test_expect_success 'git branch -v with column.ui ignored' '
219 git config column.ui column &&
220 COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
221 git config --unset column.ui &&
222 cat >expected <<\EOF &&
239 test_cmp expected actual
242 mv .git/config .git/config-saved
244 test_expect_success 'git branch -m q q2 without config should succeed' '
245 git branch -m q q2 &&
249 mv .git/config-saved .git/config
251 git config branch.s/s.dummy Hello
253 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
255 test_path_is_file .git/logs/refs/heads/s/s &&
257 test_path_is_file .git/logs/refs/heads/s/t &&
259 git branch -m s/s s &&
260 test_path_is_file .git/logs/refs/heads/s
263 test_expect_success 'config information was renamed, too' '
264 test $(git config branch.s.dummy) = Hello &&
265 test_must_fail git config branch.s/s/dummy
268 test_expect_success 'deleting a symref' '
270 git symbolic-ref refs/heads/symref refs/heads/target &&
271 echo "Deleted branch symref (was refs/heads/target)." >expect &&
272 git branch -d symref >actual &&
273 test_path_is_file .git/refs/heads/target &&
274 test_path_is_missing .git/refs/heads/symref &&
275 test_i18ncmp expect actual
278 test_expect_success 'deleting a dangling symref' '
279 git symbolic-ref refs/heads/dangling-symref nowhere &&
280 test_path_is_file .git/refs/heads/dangling-symref &&
281 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
282 git branch -d dangling-symref >actual &&
283 test_path_is_missing .git/refs/heads/dangling-symref &&
284 test_i18ncmp expect actual
287 test_expect_success 'renaming a symref is not allowed' '
288 git symbolic-ref refs/heads/master2 refs/heads/master &&
289 test_must_fail git branch -m master2 master3 &&
290 git symbolic-ref refs/heads/master2 &&
291 test_path_is_file .git/refs/heads/master &&
292 test_path_is_missing .git/refs/heads/master3
295 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
297 mv .git/logs/refs/heads/u real-u &&
298 ln -s real-u .git/logs/refs/heads/u &&
299 test_must_fail git branch -m u v
302 test_expect_success 'test tracking setup via --track' '
303 git config remote.local.url . &&
304 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
305 (git show-ref -q refs/remotes/local/master || git fetch local) &&
306 git branch --track my1 local/master &&
307 test $(git config branch.my1.remote) = local &&
308 test $(git config branch.my1.merge) = refs/heads/master
311 test_expect_success 'test tracking setup (non-wildcard, matching)' '
312 git config remote.local.url . &&
313 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
314 (git show-ref -q refs/remotes/local/master || git fetch local) &&
315 git branch --track my4 local/master &&
316 test $(git config branch.my4.remote) = local &&
317 test $(git config branch.my4.merge) = refs/heads/master
320 test_expect_success 'test tracking setup (non-wildcard, not matching)' '
321 git config remote.local.url . &&
322 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
323 (git show-ref -q refs/remotes/local/master || git fetch local) &&
324 git branch --track my5 local/master &&
325 ! test "$(git config branch.my5.remote)" = local &&
326 ! test "$(git config branch.my5.merge)" = refs/heads/master
329 test_expect_success 'test tracking setup via config' '
330 git config branch.autosetupmerge true &&
331 git config remote.local.url . &&
332 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
333 (git show-ref -q refs/remotes/local/master || git fetch local) &&
334 git branch my3 local/master &&
335 test $(git config branch.my3.remote) = local &&
336 test $(git config branch.my3.merge) = refs/heads/master
339 test_expect_success 'test overriding tracking setup via --no-track' '
340 git config branch.autosetupmerge true &&
341 git config remote.local.url . &&
342 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
343 (git show-ref -q refs/remotes/local/master || git fetch local) &&
344 git branch --no-track my2 local/master &&
345 git config branch.autosetupmerge false &&
346 ! test "$(git config branch.my2.remote)" = local &&
347 ! test "$(git config branch.my2.merge)" = refs/heads/master
350 test_expect_success 'no tracking without .fetch entries' '
351 git config branch.autosetupmerge true &&
353 git config branch.automsetupmerge false &&
354 test -z "$(git config branch.my6.remote)" &&
355 test -z "$(git config branch.my6.merge)"
358 test_expect_success 'test tracking setup via --track but deeper' '
359 git config remote.local.url . &&
360 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
361 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
362 git branch --track my7 local/o/o &&
363 test "$(git config branch.my7.remote)" = local &&
364 test "$(git config branch.my7.merge)" = refs/heads/o/o
367 test_expect_success 'test deleting branch deletes branch config' '
369 test -z "$(git config branch.my7.remote)" &&
370 test -z "$(git config branch.my7.merge)"
373 test_expect_success 'test deleting branch without config' '
375 sha1=$(git rev-parse my7 | cut -c 1-7) &&
376 echo "Deleted branch my7 (was $sha1)." >expect &&
377 git branch -d my7 >actual 2>&1 &&
378 test_i18ncmp expect actual
381 test_expect_success 'test --track without .fetch entries' '
382 git branch --track my8 &&
383 test "$(git config branch.my8.remote)" &&
384 test "$(git config branch.my8.merge)"
387 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
388 git config branch.autosetupmerge always &&
389 git branch my9 HEAD^ &&
390 git config branch.autosetupmerge false
393 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
394 test_must_fail git branch --track my10 HEAD^
397 test_expect_success 'branch from tag w/--track causes failure' '
399 test_must_fail git branch --track my11 foobar
402 test_expect_success '--set-upstream-to fails on multiple branches' '
403 test_must_fail git branch --set-upstream-to master a b c
406 test_expect_success '--set-upstream-to fails on detached HEAD' '
407 git checkout HEAD^{} &&
408 test_must_fail git branch --set-upstream-to master &&
412 test_expect_success 'use --set-upstream-to modify HEAD' '
413 test_config branch.master.remote foo &&
414 test_config branch.master.merge foo &&
416 git branch --set-upstream-to my12 &&
417 test "$(git config branch.master.remote)" = "." &&
418 test "$(git config branch.master.merge)" = "refs/heads/my12"
421 test_expect_success 'use --set-upstream-to modify a particular branch' '
423 git branch --set-upstream-to master my13 &&
424 test "$(git config branch.my13.remote)" = "." &&
425 test "$(git config branch.my13.merge)" = "refs/heads/master"
428 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
429 test_must_fail git branch --unset-upstream i-dont-exist
432 test_expect_success 'test --unset-upstream on HEAD' '
434 test_config branch.master.remote foo &&
435 test_config branch.master.merge foo &&
436 git branch --set-upstream-to my14 &&
437 git branch --unset-upstream &&
438 test_must_fail git config branch.master.remote &&
439 test_must_fail git config branch.master.merge &&
440 # fail for a branch without upstream set
441 test_must_fail git branch --unset-upstream
444 test_expect_success '--unset-upstream should fail on multiple branches' '
445 test_must_fail git branch --unset-upstream a b c
448 test_expect_success '--unset-upstream should fail on detached HEAD' '
449 git checkout HEAD^{} &&
450 test_must_fail git branch --unset-upstream &&
454 test_expect_success 'test --unset-upstream on a particular branch' '
456 git branch --set-upstream-to master my14 &&
457 git branch --unset-upstream my14 &&
458 test_must_fail git config branch.my14.remote &&
459 test_must_fail git config branch.my14.merge
462 test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
463 git update-ref refs/remotes/origin/master HEAD &&
464 git branch --set-upstream origin/master 2>actual &&
465 test_when_finished git update-ref -d refs/remotes/origin/master &&
466 test_when_finished git branch -d origin/master &&
467 cat >expected <<EOF &&
468 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
470 If you wanted to make '"'master'"' track '"'origin/master'"', do this:
472 git branch -d origin/master
473 git branch --set-upstream-to origin/master
475 test_cmp expected actual
478 test_expect_success '--set-upstream with two args only shows the deprecation message' '
479 git branch --set-upstream master my13 2>actual &&
480 test_when_finished git branch --unset-upstream master &&
481 cat >expected <<EOF &&
482 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
484 test_cmp expected actual
487 test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
488 git branch --set-upstream my13 2>actual &&
489 test_when_finished git branch --unset-upstream my13 &&
490 cat >expected <<EOF &&
491 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
493 test_cmp expected actual
496 # Keep this test last, as it changes the current branch
498 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
500 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
501 GIT_COMMITTER_DATE="2005-05-26 23:30" \
502 git checkout -b g/h/i -l master &&
503 test_path_is_file .git/refs/heads/g/h/i &&
504 test_path_is_file .git/logs/refs/heads/g/h/i &&
505 test_cmp expect .git/logs/refs/heads/g/h/i
508 test_expect_success 'checkout -b makes reflog by default' '
509 git checkout master &&
510 git config --unset core.logAllRefUpdates &&
511 git checkout -b alpha &&
512 git rev-parse --verify alpha@{0}
515 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
516 git checkout master &&
517 git config core.logAllRefUpdates false &&
518 git checkout -b beta &&
519 test_must_fail git rev-parse --verify beta@{0}
522 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
523 git checkout master &&
524 git checkout -lb gamma &&
525 git config --unset core.logAllRefUpdates &&
526 git rev-parse --verify gamma@{0}
529 test_expect_success 'avoid ambiguous track' '
530 git config branch.autosetupmerge true &&
531 git config remote.ambi1.url lalala &&
532 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
533 git config remote.ambi2.url lilili &&
534 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
535 git branch all1 master &&
536 test -z "$(git config branch.all1.merge)"
539 test_expect_success 'autosetuprebase local on a tracked local branch' '
540 git config remote.local.url . &&
541 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
542 git config branch.autosetuprebase local &&
543 (git show-ref -q refs/remotes/local/o || git fetch local) &&
545 git branch --track myr1 mybase &&
546 test "$(git config branch.myr1.remote)" = . &&
547 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
548 test "$(git config branch.myr1.rebase)" = true
551 test_expect_success 'autosetuprebase always on a tracked local branch' '
552 git config remote.local.url . &&
553 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
554 git config branch.autosetuprebase always &&
555 (git show-ref -q refs/remotes/local/o || git fetch local) &&
556 git branch mybase2 &&
557 git branch --track myr2 mybase &&
558 test "$(git config branch.myr2.remote)" = . &&
559 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
560 test "$(git config branch.myr2.rebase)" = true
563 test_expect_success 'autosetuprebase remote on a tracked local branch' '
564 git config remote.local.url . &&
565 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
566 git config branch.autosetuprebase remote &&
567 (git show-ref -q refs/remotes/local/o || git fetch local) &&
568 git branch mybase3 &&
569 git branch --track myr3 mybase2 &&
570 test "$(git config branch.myr3.remote)" = . &&
571 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
572 ! test "$(git config branch.myr3.rebase)" = true
575 test_expect_success 'autosetuprebase never on a tracked local branch' '
576 git config remote.local.url . &&
577 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
578 git config branch.autosetuprebase never &&
579 (git show-ref -q refs/remotes/local/o || git fetch local) &&
580 git branch mybase4 &&
581 git branch --track myr4 mybase2 &&
582 test "$(git config branch.myr4.remote)" = . &&
583 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
584 ! test "$(git config branch.myr4.rebase)" = true
587 test_expect_success 'autosetuprebase local on a tracked remote branch' '
588 git config remote.local.url . &&
589 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
590 git config branch.autosetuprebase local &&
591 (git show-ref -q refs/remotes/local/master || git fetch local) &&
592 git branch --track myr5 local/master &&
593 test "$(git config branch.myr5.remote)" = local &&
594 test "$(git config branch.myr5.merge)" = refs/heads/master &&
595 ! test "$(git config branch.myr5.rebase)" = true
598 test_expect_success 'autosetuprebase never on a tracked remote branch' '
599 git config remote.local.url . &&
600 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
601 git config branch.autosetuprebase never &&
602 (git show-ref -q refs/remotes/local/master || git fetch local) &&
603 git branch --track myr6 local/master &&
604 test "$(git config branch.myr6.remote)" = local &&
605 test "$(git config branch.myr6.merge)" = refs/heads/master &&
606 ! test "$(git config branch.myr6.rebase)" = true
609 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
610 git config remote.local.url . &&
611 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
612 git config branch.autosetuprebase remote &&
613 (git show-ref -q refs/remotes/local/master || git fetch local) &&
614 git branch --track myr7 local/master &&
615 test "$(git config branch.myr7.remote)" = local &&
616 test "$(git config branch.myr7.merge)" = refs/heads/master &&
617 test "$(git config branch.myr7.rebase)" = true
620 test_expect_success 'autosetuprebase always on a tracked remote branch' '
621 git config remote.local.url . &&
622 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
623 git config branch.autosetuprebase remote &&
624 (git show-ref -q refs/remotes/local/master || git fetch local) &&
625 git branch --track myr8 local/master &&
626 test "$(git config branch.myr8.remote)" = local &&
627 test "$(git config branch.myr8.merge)" = refs/heads/master &&
628 test "$(git config branch.myr8.rebase)" = true
631 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
632 git config --unset branch.autosetuprebase &&
633 git config remote.local.url . &&
634 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
635 (git show-ref -q refs/remotes/local/master || git fetch local) &&
636 git branch --track myr9 local/master &&
637 test "$(git config branch.myr9.remote)" = local &&
638 test "$(git config branch.myr9.merge)" = refs/heads/master &&
639 test "z$(git config branch.myr9.rebase)" = z
642 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
643 git config remote.local.url . &&
644 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
645 (git show-ref -q refs/remotes/local/o || git fetch local) &&
646 git branch mybase10 &&
647 git branch --track myr10 mybase2 &&
648 test "$(git config branch.myr10.remote)" = . &&
649 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
650 test "z$(git config branch.myr10.rebase)" = z
653 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
654 git config remote.local.url . &&
655 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
656 (git show-ref -q refs/remotes/local/master || git fetch local) &&
657 git branch --no-track myr11 mybase2 &&
658 test "z$(git config branch.myr11.remote)" = z &&
659 test "z$(git config branch.myr11.merge)" = z &&
660 test "z$(git config branch.myr11.rebase)" = z
663 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
664 git config remote.local.url . &&
665 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
666 (git show-ref -q refs/remotes/local/master || git fetch local) &&
667 git branch --no-track myr12 local/master &&
668 test "z$(git config branch.myr12.remote)" = z &&
669 test "z$(git config branch.myr12.merge)" = z &&
670 test "z$(git config branch.myr12.rebase)" = z
673 test_expect_success 'autosetuprebase never on an untracked local branch' '
674 git config branch.autosetuprebase never &&
675 git config remote.local.url . &&
676 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
677 (git show-ref -q refs/remotes/local/master || git fetch local) &&
678 git branch --no-track myr13 mybase2 &&
679 test "z$(git config branch.myr13.remote)" = z &&
680 test "z$(git config branch.myr13.merge)" = z &&
681 test "z$(git config branch.myr13.rebase)" = z
684 test_expect_success 'autosetuprebase local on an untracked local branch' '
685 git config branch.autosetuprebase local &&
686 git config remote.local.url . &&
687 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
688 (git show-ref -q refs/remotes/local/master || git fetch local) &&
689 git branch --no-track myr14 mybase2 &&
690 test "z$(git config branch.myr14.remote)" = z &&
691 test "z$(git config branch.myr14.merge)" = z &&
692 test "z$(git config branch.myr14.rebase)" = z
695 test_expect_success 'autosetuprebase remote on an untracked local branch' '
696 git config branch.autosetuprebase remote &&
697 git config remote.local.url . &&
698 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
699 (git show-ref -q refs/remotes/local/master || git fetch local) &&
700 git branch --no-track myr15 mybase2 &&
701 test "z$(git config branch.myr15.remote)" = z &&
702 test "z$(git config branch.myr15.merge)" = z &&
703 test "z$(git config branch.myr15.rebase)" = z
706 test_expect_success 'autosetuprebase always on an untracked local branch' '
707 git config branch.autosetuprebase always &&
708 git config remote.local.url . &&
709 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
710 (git show-ref -q refs/remotes/local/master || git fetch local) &&
711 git branch --no-track myr16 mybase2 &&
712 test "z$(git config branch.myr16.remote)" = z &&
713 test "z$(git config branch.myr16.merge)" = z &&
714 test "z$(git config branch.myr16.rebase)" = z
717 test_expect_success 'autosetuprebase never on an untracked remote branch' '
718 git config branch.autosetuprebase never &&
719 git config remote.local.url . &&
720 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
721 (git show-ref -q refs/remotes/local/master || git fetch local) &&
722 git branch --no-track myr17 local/master &&
723 test "z$(git config branch.myr17.remote)" = z &&
724 test "z$(git config branch.myr17.merge)" = z &&
725 test "z$(git config branch.myr17.rebase)" = z
728 test_expect_success 'autosetuprebase local on an untracked remote branch' '
729 git config branch.autosetuprebase local &&
730 git config remote.local.url . &&
731 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
732 (git show-ref -q refs/remotes/local/master || git fetch local) &&
733 git branch --no-track myr18 local/master &&
734 test "z$(git config branch.myr18.remote)" = z &&
735 test "z$(git config branch.myr18.merge)" = z &&
736 test "z$(git config branch.myr18.rebase)" = z
739 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
740 git config branch.autosetuprebase remote &&
741 git config remote.local.url . &&
742 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
743 (git show-ref -q refs/remotes/local/master || git fetch local) &&
744 git branch --no-track myr19 local/master &&
745 test "z$(git config branch.myr19.remote)" = z &&
746 test "z$(git config branch.myr19.merge)" = z &&
747 test "z$(git config branch.myr19.rebase)" = z
750 test_expect_success 'autosetuprebase always on an untracked remote branch' '
751 git config branch.autosetuprebase always &&
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 myr20 local/master &&
756 test "z$(git config branch.myr20.remote)" = z &&
757 test "z$(git config branch.myr20.merge)" = z &&
758 test "z$(git config branch.myr20.rebase)" = z
761 test_expect_success 'autosetuprebase always on detached HEAD' '
762 git config branch.autosetupmerge always &&
763 test_when_finished git checkout master &&
764 git checkout HEAD^0 &&
766 test -z "$(git config branch.my11.remote)" &&
767 test -z "$(git config branch.my11.merge)"
770 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
771 git config branch.autosetuprebase garbage &&
772 test_must_fail git branch
775 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
776 git config --unset branch.autosetuprebase &&
777 echo "[branch] autosetuprebase" >>.git/config &&
778 test_must_fail git branch &&
779 git config --unset branch.autosetuprebase
782 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
784 git config --unset branch.my8.merge &&
785 test_must_fail git branch -d my8
788 test_expect_success 'attempt to delete a branch merged to its base' '
789 # we are on my9 which is the initial commit; traditionally
790 # we would not have allowed deleting my8 that is not merged
791 # to my9, but it is set to track master that already has my8
792 git config branch.my8.merge refs/heads/master &&
796 test_expect_success 'attempt to delete a branch merged to its base' '
797 git checkout master &&
799 git commit -m "Third commit" A &&
800 git branch -t my10 my9 &&
801 git branch -f my10 HEAD^ &&
802 # we are on master which is at the third commit, and my10
803 # is behind us, so traditionally we would have allowed deleting
804 # it; but my10 is set to track my9 that is further behind.
805 test_must_fail git branch -d my10
808 test_expect_success 'use set-upstream on the current branch' '
809 git checkout master &&
810 git --bare init myupstream.git &&
811 git push myupstream.git master:refs/heads/frotz &&
812 git remote add origin myupstream.git &&
814 git branch --set-upstream master origin/frotz &&
816 test "z$(git config branch.master.remote)" = "zorigin" &&
817 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
821 test_expect_success 'use --edit-description' '
822 write_script editor <<-\EOF &&
823 echo "New contents" >"$1"
825 EDITOR=./editor git branch --edit-description &&
826 write_script editor <<-\EOF &&
827 git stripspace -s <"$1" >"EDITOR_OUTPUT"
829 EDITOR=./editor git branch --edit-description &&
830 echo "New contents" >expect &&
831 test_cmp EDITOR_OUTPUT expect
834 test_expect_success 'detect typo in branch name when using --edit-description' '
835 write_script editor <<-\EOF &&
836 echo "New contents" >"$1"
841 test_must_fail git branch --edit-description no-such-branch
845 test_expect_success 'refuse --edit-description on unborn branch for now' '
846 write_script editor <<-\EOF &&
847 echo "New contents" >"$1"
849 git checkout --orphan unborn &&
853 test_must_fail git branch --edit-description
857 test_expect_success '--merged catches invalid object names' '
858 test_must_fail git branch --merged 0000000000000000000000000000000000000000