Git 2.33.8
[git.git] / t / t3200-branch.sh
blob354e625fbdbbdcd9ce4e864664e0c1cb31295c2d
1 #!/bin/sh
3 # Copyright (c) 2005 Amos Waterland
6 test_description='git branch assorted tests'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 . ./test-lib.sh
12 . "$TEST_DIRECTORY"/lib-rebase.sh
14 test_expect_success 'prepare a trivial repository' '
15 echo Hello >A &&
16 git update-index --add A &&
17 git commit -m "Initial commit." &&
18 git branch -M main &&
19 echo World >>A &&
20 git update-index --add A &&
21 git commit -m "Second commit." &&
22 HEAD=$(git rev-parse --verify HEAD)
25 test_expect_success 'git branch --help should not have created a bogus branch' '
26 test_might_fail git branch --man --help </dev/null >/dev/null 2>&1 &&
27 test_path_is_missing .git/refs/heads/--help
30 test_expect_success 'branch -h in broken repository' '
31 mkdir broken &&
33 cd broken &&
34 git init -b main &&
35 >.git/refs/heads/main &&
36 test_expect_code 129 git branch -h >usage 2>&1
37 ) &&
38 test_i18ngrep "[Uu]sage" broken/usage
41 test_expect_success 'git branch abc should create a branch' '
42 git branch abc && test_path_is_file .git/refs/heads/abc
45 test_expect_success 'git branch a/b/c should create a branch' '
46 git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c
49 test_expect_success 'git branch mb main... should create a branch' '
50 git branch mb main... && test_path_is_file .git/refs/heads/mb
53 test_expect_success 'git branch HEAD should fail' '
54 test_must_fail git branch HEAD
57 cat >expect <<EOF
58 $ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from main
59 EOF
60 test_expect_success 'git branch --create-reflog d/e/f should create a branch and a log' '
61 GIT_COMMITTER_DATE="2005-05-26 23:30" \
62 git -c core.logallrefupdates=false branch --create-reflog d/e/f &&
63 test_path_is_file .git/refs/heads/d/e/f &&
64 test_path_is_file .git/logs/refs/heads/d/e/f &&
65 test_cmp expect .git/logs/refs/heads/d/e/f
68 test_expect_success 'git branch -d d/e/f should delete a branch and a log' '
69 git branch -d d/e/f &&
70 test_path_is_missing .git/refs/heads/d/e/f &&
71 test_must_fail git reflog exists refs/heads/d/e/f
74 test_expect_success 'git branch j/k should work after branch j has been deleted' '
75 git branch j &&
76 git branch -d j &&
77 git branch j/k
80 test_expect_success 'git branch l should work after branch l/m has been deleted' '
81 git branch l/m &&
82 git branch -d l/m &&
83 git branch l
86 test_expect_success 'git branch -m dumps usage' '
87 test_expect_code 128 git branch -m 2>err &&
88 test_i18ngrep "branch name required" err
91 test_expect_success 'git branch -m m broken_symref should work' '
92 test_when_finished "git branch -D broken_symref" &&
93 git branch --create-reflog m &&
94 git symbolic-ref refs/heads/broken_symref refs/heads/i_am_broken &&
95 git branch -m m broken_symref &&
96 git reflog exists refs/heads/broken_symref &&
97 test_must_fail git reflog exists refs/heads/i_am_broken
100 test_expect_success 'git branch -m m m/m should work' '
101 git branch --create-reflog m &&
102 git branch -m m m/m &&
103 git reflog exists refs/heads/m/m
106 test_expect_success 'git branch -m n/n n should work' '
107 git branch --create-reflog n/n &&
108 git branch -m n/n n &&
109 git reflog exists refs/heads/n
112 # The topmost entry in reflog for branch bbb is about branch creation.
113 # Hence, we compare bbb@{1} (instead of bbb@{0}) with aaa@{0}.
115 test_expect_success 'git branch -m bbb should rename checked out branch' '
116 test_when_finished git branch -D bbb &&
117 test_when_finished git checkout main &&
118 git checkout -b aaa &&
119 git commit --allow-empty -m "a new commit" &&
120 git rev-parse aaa@{0} >expect &&
121 git branch -m bbb &&
122 git rev-parse bbb@{1} >actual &&
123 test_cmp expect actual &&
124 git symbolic-ref HEAD >actual &&
125 echo refs/heads/bbb >expect &&
126 test_cmp expect actual
129 test_expect_success 'renaming checked out branch works with d/f conflict' '
130 test_when_finished "git branch -D foo/bar || git branch -D foo" &&
131 test_when_finished git checkout main &&
132 git checkout -b foo &&
133 git branch -m foo/bar &&
134 git symbolic-ref HEAD >actual &&
135 echo refs/heads/foo/bar >expect &&
136 test_cmp expect actual
139 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
140 git branch o/o &&
141 git branch o/p &&
142 test_must_fail git branch -m o/o o
145 test_expect_success 'git branch -m o/q o/p should fail when o/p exists' '
146 git branch o/q &&
147 test_must_fail git branch -m o/q o/p
150 test_expect_success 'git branch -M o/q o/p should work when o/p exists' '
151 git branch -M o/q o/p
154 test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '
155 git branch o/q &&
156 git branch -m -f o/q o/p
159 test_expect_success 'git branch -m q r/q should fail when r exists' '
160 git branch q &&
161 git branch r &&
162 test_must_fail git branch -m q r/q
165 test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
166 git branch bar &&
167 git checkout -b foo &&
168 test_must_fail git branch -M bar foo
171 test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
172 git checkout -b baz &&
173 git branch bam &&
174 git branch -M baz bam &&
175 test $(git rev-parse --abbrev-ref HEAD) = bam
178 test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' '
179 msg="Branch: renamed refs/heads/baz to refs/heads/bam" &&
180 grep " 0\{40\}.*$msg$" .git/logs/HEAD &&
181 grep "^0\{40\}.*$msg$" .git/logs/HEAD
184 test_expect_success 'git branch -M should leave orphaned HEAD alone' '
185 git init -b main orphan &&
187 cd orphan &&
188 test_commit initial &&
189 git checkout --orphan lonely &&
190 grep lonely .git/HEAD &&
191 test_path_is_missing .git/refs/head/lonely &&
192 git branch -M main mistress &&
193 grep lonely .git/HEAD
197 test_expect_success 'resulting reflog can be shown by log -g' '
198 oid=$(git rev-parse HEAD) &&
199 cat >expect <<-EOF &&
200 HEAD@{0} $oid $msg
201 HEAD@{2} $oid checkout: moving from foo to baz
203 git log -g --format="%gd %H %gs" -2 HEAD >actual &&
204 test_cmp expect actual
207 test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' '
208 git checkout main &&
209 git worktree add -b baz bazdir &&
210 git worktree add -f bazdir2 baz &&
211 git branch -M baz bam &&
212 test $(git -C bazdir rev-parse --abbrev-ref HEAD) = bam &&
213 test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam &&
214 rm -r bazdir bazdir2 &&
215 git worktree prune
218 test_expect_success 'git branch -M baz bam should succeed within a worktree in which baz is checked out' '
219 git checkout -b baz &&
220 git worktree add -f bazdir baz &&
222 cd bazdir &&
223 git branch -M baz bam &&
224 test $(git rev-parse --abbrev-ref HEAD) = bam
225 ) &&
226 test $(git rev-parse --abbrev-ref HEAD) = bam &&
227 rm -r bazdir &&
228 git worktree prune
231 test_expect_success 'git branch -M main should work when main is checked out' '
232 git checkout main &&
233 git branch -M main
236 test_expect_success 'git branch -M main main should work when main is checked out' '
237 git checkout main &&
238 git branch -M main main
241 test_expect_success 'git branch -M topic topic should work when main is checked out' '
242 git checkout main &&
243 git branch topic &&
244 git branch -M topic topic
247 test_expect_success 'git branch -v -d t should work' '
248 git branch t &&
249 git rev-parse --verify refs/heads/t &&
250 git branch -v -d t &&
251 test_must_fail git rev-parse --verify refs/heads/t
254 test_expect_success 'git branch -v -m t s should work' '
255 git branch t &&
256 git rev-parse --verify refs/heads/t &&
257 git branch -v -m t s &&
258 test_must_fail git rev-parse --verify refs/heads/t &&
259 git rev-parse --verify refs/heads/s &&
260 git branch -d s
263 test_expect_success 'git branch -m -d t s should fail' '
264 git branch t &&
265 git rev-parse refs/heads/t &&
266 test_must_fail git branch -m -d t s &&
267 git branch -d t &&
268 test_must_fail git rev-parse refs/heads/t
271 test_expect_success 'git branch --list -d t should fail' '
272 git branch t &&
273 git rev-parse refs/heads/t &&
274 test_must_fail git branch --list -d t &&
275 git branch -d t &&
276 test_must_fail git rev-parse refs/heads/t
279 test_expect_success 'deleting checked-out branch from repo that is a submodule' '
280 test_when_finished "rm -rf repo1 repo2" &&
282 git init repo1 &&
283 git init repo1/sub &&
284 test_commit -C repo1/sub x &&
285 test_config_global protocol.file.allow always &&
286 git -C repo1 submodule add ./sub &&
287 git -C repo1 commit -m "adding sub" &&
289 git clone --recurse-submodules repo1 repo2 &&
290 git -C repo2/sub checkout -b work &&
291 test_must_fail git -C repo2/sub branch -D work
294 test_expect_success 'bare main worktree has HEAD at branch deleted by secondary worktree' '
295 test_when_finished "rm -rf nonbare base secondary" &&
297 git init -b main nonbare &&
298 test_commit -C nonbare x &&
299 git clone --bare nonbare bare &&
300 git -C bare worktree add --detach ../secondary main &&
301 git -C secondary branch -D main
304 test_expect_success 'git branch --list -v with --abbrev' '
305 test_when_finished "git branch -D t" &&
306 git branch t &&
307 git branch -v --list t >actual.default &&
308 git branch -v --list --abbrev t >actual.abbrev &&
309 test_cmp actual.default actual.abbrev &&
311 git branch -v --list --no-abbrev t >actual.noabbrev &&
312 git branch -v --list --abbrev=0 t >actual.0abbrev &&
313 git -c core.abbrev=no branch -v --list t >actual.noabbrev-conf &&
314 test_cmp actual.noabbrev actual.0abbrev &&
315 test_cmp actual.noabbrev actual.noabbrev-conf &&
317 git branch -v --list --abbrev=36 t >actual.36abbrev &&
318 # how many hexdigits are used?
319 read name objdefault rest <actual.abbrev &&
320 read name obj36 rest <actual.36abbrev &&
321 objfull=$(git rev-parse --verify t) &&
323 # are we really getting abbreviations?
324 test "$obj36" != "$objdefault" &&
325 expr "$obj36" : "$objdefault" >/dev/null &&
326 test "$objfull" != "$obj36" &&
327 expr "$objfull" : "$obj36" >/dev/null
331 test_expect_success 'git branch --column' '
332 COLUMNS=81 git branch --column=column >actual &&
333 cat >expect <<\EOF &&
334 a/b/c bam foo l * main n o/p r
335 abc bar j/k m/m mb o/o q topic
337 test_cmp expect actual
340 test_expect_success 'git branch --column with an extremely long branch name' '
341 long=this/is/a/part/of/long/branch/name &&
342 long=z$long/$long/$long/$long &&
343 test_when_finished "git branch -d $long" &&
344 git branch $long &&
345 COLUMNS=80 git branch --column=column >actual &&
346 cat >expect <<EOF &&
347 a/b/c
355 * main
362 topic
363 $long
365 test_cmp expect actual
368 test_expect_success 'git branch with column.*' '
369 git config column.ui column &&
370 git config column.branch "dense" &&
371 COLUMNS=80 git branch >actual &&
372 git config --unset column.branch &&
373 git config --unset column.ui &&
374 cat >expect <<\EOF &&
375 a/b/c bam foo l * main n o/p r
376 abc bar j/k m/m mb o/o q topic
378 test_cmp expect actual
381 test_expect_success 'git branch --column -v should fail' '
382 test_must_fail git branch --column -v
385 test_expect_success 'git branch -v with column.ui ignored' '
386 git config column.ui column &&
387 COLUMNS=80 git branch -v | cut -c -8 | sed "s/ *$//" >actual &&
388 git config --unset column.ui &&
389 cat >expect <<\EOF &&
390 a/b/c
398 * main
405 topic
407 test_cmp expect actual
410 mv .git/config .git/config-saved
412 test_expect_success SHA1 'git branch -m q q2 without config should succeed' '
413 git branch -m q q2 &&
414 git branch -m q2 q
417 mv .git/config-saved .git/config
419 git config branch.s/s.dummy Hello
421 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
422 git branch --create-reflog s/s &&
423 git reflog exists refs/heads/s/s &&
424 git branch --create-reflog s/t &&
425 git reflog exists refs/heads/s/t &&
426 git branch -d s/t &&
427 git branch -m s/s s &&
428 git reflog exists refs/heads/s
431 test_expect_success 'config information was renamed, too' '
432 test $(git config branch.s.dummy) = Hello &&
433 test_must_fail git config branch.s/s.dummy
436 test_expect_success 'git branch -m correctly renames multiple config sections' '
437 test_when_finished "git checkout main" &&
438 git checkout -b source main &&
440 # Assert that a config file with multiple config sections has
441 # those sections preserved...
442 cat >expect <<-\EOF &&
443 branch.dest.key1=value1
444 some.gar.b=age
445 branch.dest.key2=value2
447 cat >config.branch <<\EOF &&
448 ;; Note the lack of -\EOF above & mixed indenting here. This is
449 ;; intentional, we are also testing that the formatting of copied
450 ;; sections is preserved.
452 ;; Comment for source. Tabs
453 [branch "source"]
454 ;; Comment for the source value
455 key1 = value1
456 ;; Comment for some.gar. Spaces
457 [some "gar"]
458 ;; Comment for the some.gar value
459 b = age
460 ;; Comment for source, again. Mixed tabs/spaces.
461 [branch "source"]
462 ;; Comment for the source value, again
463 key2 = value2
465 cat config.branch >>.git/config &&
466 git branch -m source dest &&
467 git config -f .git/config -l | grep -F -e source -e dest -e some.gar >actual &&
468 test_cmp expect actual &&
470 # ...and that the comments for those sections are also
471 # preserved.
472 cat config.branch | sed "s/\"source\"/\"dest\"/" >expect &&
473 sed -n -e "/Note the lack/,\$p" .git/config >actual &&
474 test_cmp expect actual
477 test_expect_success 'git branch -c dumps usage' '
478 test_expect_code 128 git branch -c 2>err &&
479 test_i18ngrep "branch name required" err
482 test_expect_success 'git branch --copy dumps usage' '
483 test_expect_code 128 git branch --copy 2>err &&
484 test_i18ngrep "branch name required" err
487 test_expect_success 'git branch -c d e should work' '
488 git branch --create-reflog d &&
489 git reflog exists refs/heads/d &&
490 git config branch.d.dummy Hello &&
491 git branch -c d e &&
492 git reflog exists refs/heads/d &&
493 git reflog exists refs/heads/e &&
494 echo Hello >expect &&
495 git config branch.e.dummy >actual &&
496 test_cmp expect actual &&
497 echo Hello >expect &&
498 git config branch.d.dummy >actual &&
499 test_cmp expect actual
502 test_expect_success 'git branch --copy is a synonym for -c' '
503 git branch --create-reflog copy &&
504 git reflog exists refs/heads/copy &&
505 git config branch.copy.dummy Hello &&
506 git branch --copy copy copy-to &&
507 git reflog exists refs/heads/copy &&
508 git reflog exists refs/heads/copy-to &&
509 echo Hello >expect &&
510 git config branch.copy.dummy >actual &&
511 test_cmp expect actual &&
512 echo Hello >expect &&
513 git config branch.copy-to.dummy >actual &&
514 test_cmp expect actual
517 test_expect_success 'git branch -c ee ef should copy ee to create branch ef' '
518 git checkout -b ee &&
519 git reflog exists refs/heads/ee &&
520 git config branch.ee.dummy Hello &&
521 git branch -c ee ef &&
522 git reflog exists refs/heads/ee &&
523 git reflog exists refs/heads/ef &&
524 test $(git config branch.ee.dummy) = Hello &&
525 test $(git config branch.ef.dummy) = Hello &&
526 test $(git rev-parse --abbrev-ref HEAD) = ee
529 test_expect_success 'git branch -c f/f g/g should work' '
530 git branch --create-reflog f/f &&
531 git reflog exists refs/heads/f/f &&
532 git config branch.f/f.dummy Hello &&
533 git branch -c f/f g/g &&
534 git reflog exists refs/heads/f/f &&
535 git reflog exists refs/heads/g/g &&
536 test $(git config branch.f/f.dummy) = Hello &&
537 test $(git config branch.g/g.dummy) = Hello
540 test_expect_success 'git branch -c m2 m2 should work' '
541 git branch --create-reflog m2 &&
542 git reflog exists refs/heads/m2 &&
543 git config branch.m2.dummy Hello &&
544 git branch -c m2 m2 &&
545 git reflog exists refs/heads/m2 &&
546 test $(git config branch.m2.dummy) = Hello
549 test_expect_success 'git branch -c zz zz/zz should fail' '
550 git branch --create-reflog zz &&
551 git reflog exists refs/heads/zz &&
552 test_must_fail git branch -c zz zz/zz
555 test_expect_success 'git branch -c b/b b should fail' '
556 git branch --create-reflog b/b &&
557 test_must_fail git branch -c b/b b
560 test_expect_success 'git branch -C o/q o/p should work when o/p exists' '
561 git branch --create-reflog o/q &&
562 git reflog exists refs/heads/o/q &&
563 git reflog exists refs/heads/o/p &&
564 git branch -C o/q o/p
567 test_expect_success 'git branch -c -f o/q o/p should work when o/p exists' '
568 git reflog exists refs/heads/o/q &&
569 git reflog exists refs/heads/o/p &&
570 git branch -c -f o/q o/p
573 test_expect_success 'git branch -c qq rr/qq should fail when rr exists' '
574 git branch qq &&
575 git branch rr &&
576 test_must_fail git branch -c qq rr/qq
579 test_expect_success 'git branch -C b1 b2 should fail when b2 is checked out' '
580 git branch b1 &&
581 git checkout -b b2 &&
582 test_must_fail git branch -C b1 b2
585 test_expect_success 'git branch -C c1 c2 should succeed when c1 is checked out' '
586 git checkout -b c1 &&
587 git branch c2 &&
588 git branch -C c1 c2 &&
589 test $(git rev-parse --abbrev-ref HEAD) = c1
592 test_expect_success 'git branch -C c1 c2 should never touch HEAD' '
593 msg="Branch: copied refs/heads/c1 to refs/heads/c2" &&
594 ! grep "$msg$" .git/logs/HEAD
597 test_expect_success 'git branch -C main should work when main is checked out' '
598 git checkout main &&
599 git branch -C main
602 test_expect_success 'git branch -C main main should work when main is checked out' '
603 git checkout main &&
604 git branch -C main main
607 test_expect_success 'git branch -C main5 main5 should work when main is checked out' '
608 git checkout main &&
609 git branch main5 &&
610 git branch -C main5 main5
613 test_expect_success 'git branch -C ab cd should overwrite existing config for cd' '
614 git branch --create-reflog cd &&
615 git reflog exists refs/heads/cd &&
616 git config branch.cd.dummy CD &&
617 git branch --create-reflog ab &&
618 git reflog exists refs/heads/ab &&
619 git config branch.ab.dummy AB &&
620 git branch -C ab cd &&
621 git reflog exists refs/heads/ab &&
622 git reflog exists refs/heads/cd &&
623 test $(git config branch.ab.dummy) = AB &&
624 test $(git config branch.cd.dummy) = AB
627 test_expect_success 'git branch -c correctly copies multiple config sections' '
628 FOO=1 &&
629 export FOO &&
630 test_when_finished "git checkout main" &&
631 git checkout -b source2 main &&
633 # Assert that a config file with multiple config sections has
634 # those sections preserved...
635 cat >expect <<-\EOF &&
636 branch.source2.key1=value1
637 branch.dest2.key1=value1
638 more.gar.b=age
639 branch.source2.key2=value2
640 branch.dest2.key2=value2
642 cat >config.branch <<\EOF &&
643 ;; Note the lack of -\EOF above & mixed indenting here. This is
644 ;; intentional, we are also testing that the formatting of copied
645 ;; sections is preserved.
647 ;; Comment for source2. Tabs
648 [branch "source2"]
649 ;; Comment for the source2 value
650 key1 = value1
651 ;; Comment for more.gar. Spaces
652 [more "gar"]
653 ;; Comment for the more.gar value
654 b = age
655 ;; Comment for source2, again. Mixed tabs/spaces.
656 [branch "source2"]
657 ;; Comment for the source2 value, again
658 key2 = value2
660 cat config.branch >>.git/config &&
661 git branch -c source2 dest2 &&
662 git config -f .git/config -l | grep -F -e source2 -e dest2 -e more.gar >actual &&
663 test_cmp expect actual &&
665 # ...and that the comments and formatting for those sections
666 # is also preserved.
667 cat >expect <<\EOF &&
668 ;; Comment for source2. Tabs
669 [branch "source2"]
670 ;; Comment for the source2 value
671 key1 = value1
672 ;; Comment for more.gar. Spaces
673 [branch "dest2"]
674 ;; Comment for the source2 value
675 key1 = value1
676 ;; Comment for more.gar. Spaces
677 [more "gar"]
678 ;; Comment for the more.gar value
679 b = age
680 ;; Comment for source2, again. Mixed tabs/spaces.
681 [branch "source2"]
682 ;; Comment for the source2 value, again
683 key2 = value2
684 [branch "dest2"]
685 ;; Comment for the source2 value, again
686 key2 = value2
688 sed -n -e "/Comment for source2/,\$p" .git/config >actual &&
689 test_cmp expect actual
692 test_expect_success 'deleting a symref' '
693 git branch target &&
694 git symbolic-ref refs/heads/symref refs/heads/target &&
695 echo "Deleted branch symref (was refs/heads/target)." >expect &&
696 git branch -d symref >actual &&
697 test_path_is_file .git/refs/heads/target &&
698 test_path_is_missing .git/refs/heads/symref &&
699 test_cmp expect actual
702 test_expect_success 'deleting a dangling symref' '
703 git symbolic-ref refs/heads/dangling-symref nowhere &&
704 test_path_is_file .git/refs/heads/dangling-symref &&
705 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
706 git branch -d dangling-symref >actual &&
707 test_path_is_missing .git/refs/heads/dangling-symref &&
708 test_cmp expect actual
711 test_expect_success 'deleting a self-referential symref' '
712 git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
713 test_path_is_file .git/refs/heads/self-reference &&
714 echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
715 git branch -d self-reference >actual &&
716 test_path_is_missing .git/refs/heads/self-reference &&
717 test_cmp expect actual
720 test_expect_success 'renaming a symref is not allowed' '
721 git symbolic-ref refs/heads/topic refs/heads/main &&
722 test_must_fail git branch -m topic new-topic &&
723 git symbolic-ref refs/heads/topic &&
724 test_path_is_file .git/refs/heads/main &&
725 test_path_is_missing .git/refs/heads/new-topic
728 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
729 git branch --create-reflog u &&
730 mv .git/logs/refs/heads/u real-u &&
731 ln -s real-u .git/logs/refs/heads/u &&
732 test_must_fail git branch -m u v
735 test_expect_success 'test tracking setup via --track' '
736 git config remote.local.url . &&
737 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
738 (git show-ref -q refs/remotes/local/main || git fetch local) &&
739 git branch --track my1 local/main &&
740 test $(git config branch.my1.remote) = local &&
741 test $(git config branch.my1.merge) = refs/heads/main
744 test_expect_success 'test tracking setup (non-wildcard, matching)' '
745 git config remote.local.url . &&
746 git config remote.local.fetch refs/heads/main:refs/remotes/local/main &&
747 (git show-ref -q refs/remotes/local/main || git fetch local) &&
748 git branch --track my4 local/main &&
749 test $(git config branch.my4.remote) = local &&
750 test $(git config branch.my4.merge) = refs/heads/main
753 test_expect_success 'tracking setup fails on non-matching refspec' '
754 git config remote.local.url . &&
755 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
756 (git show-ref -q refs/remotes/local/main || git fetch local) &&
757 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
758 test_must_fail git branch --track my5 local/main &&
759 test_must_fail git config branch.my5.remote &&
760 test_must_fail git config branch.my5.merge
763 test_expect_success 'test tracking setup via config' '
764 git config branch.autosetupmerge true &&
765 git config remote.local.url . &&
766 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
767 (git show-ref -q refs/remotes/local/main || git fetch local) &&
768 git branch my3 local/main &&
769 test $(git config branch.my3.remote) = local &&
770 test $(git config branch.my3.merge) = refs/heads/main
773 test_expect_success 'test overriding tracking setup via --no-track' '
774 git config branch.autosetupmerge true &&
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/main || git fetch local) &&
778 git branch --no-track my2 local/main &&
779 git config branch.autosetupmerge false &&
780 ! test "$(git config branch.my2.remote)" = local &&
781 ! test "$(git config branch.my2.merge)" = refs/heads/main
784 test_expect_success 'no tracking without .fetch entries' '
785 git config branch.autosetupmerge true &&
786 git branch my6 s &&
787 git config branch.autosetupmerge false &&
788 test -z "$(git config branch.my6.remote)" &&
789 test -z "$(git config branch.my6.merge)"
792 test_expect_success 'test tracking setup via --track but deeper' '
793 git config remote.local.url . &&
794 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
795 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
796 git branch --track my7 local/o/o &&
797 test "$(git config branch.my7.remote)" = local &&
798 test "$(git config branch.my7.merge)" = refs/heads/o/o
801 test_expect_success 'test deleting branch deletes branch config' '
802 git branch -d my7 &&
803 test -z "$(git config branch.my7.remote)" &&
804 test -z "$(git config branch.my7.merge)"
807 test_expect_success 'test deleting branch without config' '
808 git branch my7 s &&
809 sha1=$(git rev-parse my7 | cut -c 1-7) &&
810 echo "Deleted branch my7 (was $sha1)." >expect &&
811 git branch -d my7 >actual 2>&1 &&
812 test_cmp expect actual
815 test_expect_success 'deleting currently checked out branch fails' '
816 git worktree add -b my7 my7 &&
817 test_must_fail git -C my7 branch -d my7 &&
818 test_must_fail git branch -d my7 &&
819 rm -r my7 &&
820 git worktree prune
823 test_expect_success 'test --track without .fetch entries' '
824 git branch --track my8 &&
825 test "$(git config branch.my8.remote)" &&
826 test "$(git config branch.my8.merge)"
829 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
830 git config branch.autosetupmerge always &&
831 git branch my9 HEAD^ &&
832 git config branch.autosetupmerge false
835 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
836 test_must_fail git branch --track my10 HEAD^
839 test_expect_success 'branch from tag w/--track causes failure' '
840 git tag foobar &&
841 test_must_fail git branch --track my11 foobar
844 test_expect_success '--set-upstream-to fails on multiple branches' '
845 echo "fatal: too many arguments to set new upstream" >expect &&
846 test_must_fail git branch --set-upstream-to main a b c 2>err &&
847 test_cmp expect err
850 test_expect_success '--set-upstream-to fails on detached HEAD' '
851 git checkout HEAD^{} &&
852 test_when_finished git checkout - &&
853 echo "fatal: could not set upstream of HEAD to main when it does not point to any branch." >expect &&
854 test_must_fail git branch --set-upstream-to main 2>err &&
855 test_cmp expect err
858 test_expect_success '--set-upstream-to fails on a missing dst branch' '
859 echo "fatal: branch '"'"'does-not-exist'"'"' does not exist" >expect &&
860 test_must_fail git branch --set-upstream-to main does-not-exist 2>err &&
861 test_cmp expect err
864 test_expect_success '--set-upstream-to fails on a missing src branch' '
865 test_must_fail git branch --set-upstream-to does-not-exist main 2>err &&
866 test_i18ngrep "the requested upstream branch '"'"'does-not-exist'"'"' does not exist" err
869 test_expect_success '--set-upstream-to fails on a non-ref' '
870 echo "fatal: Cannot setup tracking information; starting point '"'"'HEAD^{}'"'"' is not a branch." >expect &&
871 test_must_fail git branch --set-upstream-to HEAD^{} 2>err &&
872 test_cmp expect err
875 test_expect_success '--set-upstream-to fails on locked config' '
876 test_when_finished "rm -f .git/config.lock" &&
877 >.git/config.lock &&
878 git branch locked &&
879 test_must_fail git branch --set-upstream-to locked 2>err &&
880 test_i18ngrep "could not lock config file .git/config" err
883 test_expect_success 'use --set-upstream-to modify HEAD' '
884 test_config branch.main.remote foo &&
885 test_config branch.main.merge foo &&
886 git branch my12 &&
887 git branch --set-upstream-to my12 &&
888 test "$(git config branch.main.remote)" = "." &&
889 test "$(git config branch.main.merge)" = "refs/heads/my12"
892 test_expect_success 'use --set-upstream-to modify a particular branch' '
893 git branch my13 &&
894 git branch --set-upstream-to main my13 &&
895 test_when_finished "git branch --unset-upstream my13" &&
896 test "$(git config branch.my13.remote)" = "." &&
897 test "$(git config branch.my13.merge)" = "refs/heads/main"
900 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
901 echo "fatal: Branch '"'"'i-dont-exist'"'"' has no upstream information" >expect &&
902 test_must_fail git branch --unset-upstream i-dont-exist 2>err &&
903 test_cmp expect err
906 test_expect_success '--unset-upstream should fail if config is locked' '
907 test_when_finished "rm -f .git/config.lock" &&
908 git branch --set-upstream-to locked &&
909 >.git/config.lock &&
910 test_must_fail git branch --unset-upstream 2>err &&
911 test_i18ngrep "could not lock config file .git/config" err
914 test_expect_success 'test --unset-upstream on HEAD' '
915 git branch my14 &&
916 test_config branch.main.remote foo &&
917 test_config branch.main.merge foo &&
918 git branch --set-upstream-to my14 &&
919 git branch --unset-upstream &&
920 test_must_fail git config branch.main.remote &&
921 test_must_fail git config branch.main.merge &&
922 # fail for a branch without upstream set
923 echo "fatal: Branch '"'"'main'"'"' has no upstream information" >expect &&
924 test_must_fail git branch --unset-upstream 2>err &&
925 test_cmp expect err
928 test_expect_success '--unset-upstream should fail on multiple branches' '
929 echo "fatal: too many arguments to unset upstream" >expect &&
930 test_must_fail git branch --unset-upstream a b c 2>err &&
931 test_cmp expect err
934 test_expect_success '--unset-upstream should fail on detached HEAD' '
935 git checkout HEAD^{} &&
936 test_when_finished git checkout - &&
937 echo "fatal: could not unset upstream of HEAD when it does not point to any branch." >expect &&
938 test_must_fail git branch --unset-upstream 2>err &&
939 test_cmp expect err
942 test_expect_success 'test --unset-upstream on a particular branch' '
943 git branch my15 &&
944 git branch --set-upstream-to main my14 &&
945 git branch --unset-upstream my14 &&
946 test_must_fail git config branch.my14.remote &&
947 test_must_fail git config branch.my14.merge
950 test_expect_success 'disabled option --set-upstream fails' '
951 test_must_fail git branch --set-upstream origin/main
954 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
955 git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
956 cat >expect <<-\EOF &&
957 warning: Not setting branch my13 as its own upstream.
959 test_expect_code 1 git config branch.my13.remote &&
960 test_expect_code 1 git config branch.my13.merge &&
961 test_cmp expect actual
964 # Keep this test last, as it changes the current branch
965 cat >expect <<EOF
966 $ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from main
968 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
969 GIT_COMMITTER_DATE="2005-05-26 23:30" \
970 git checkout -b g/h/i -l main &&
971 test_path_is_file .git/refs/heads/g/h/i &&
972 test_path_is_file .git/logs/refs/heads/g/h/i &&
973 test_cmp expect .git/logs/refs/heads/g/h/i
976 test_expect_success 'checkout -b makes reflog by default' '
977 git checkout main &&
978 git config --unset core.logAllRefUpdates &&
979 git checkout -b alpha &&
980 git rev-parse --verify alpha@{0}
983 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
984 git checkout main &&
985 git config core.logAllRefUpdates false &&
986 git checkout -b beta &&
987 test_must_fail git rev-parse --verify beta@{0}
990 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
991 git checkout main &&
992 git checkout -lb gamma &&
993 git config --unset core.logAllRefUpdates &&
994 git rev-parse --verify gamma@{0}
997 test_expect_success 'avoid ambiguous track' '
998 git config branch.autosetupmerge true &&
999 git config remote.ambi1.url lalala &&
1000 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/main &&
1001 git config remote.ambi2.url lilili &&
1002 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/main &&
1003 test_must_fail git branch all1 main &&
1004 test -z "$(git config branch.all1.merge)"
1007 test_expect_success 'autosetuprebase local on a tracked local branch' '
1008 git config remote.local.url . &&
1009 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1010 git config branch.autosetuprebase local &&
1011 (git show-ref -q refs/remotes/local/o || git fetch local) &&
1012 git branch mybase &&
1013 git branch --track myr1 mybase &&
1014 test "$(git config branch.myr1.remote)" = . &&
1015 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
1016 test "$(git config branch.myr1.rebase)" = true
1019 test_expect_success 'autosetuprebase always on a tracked local branch' '
1020 git config remote.local.url . &&
1021 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1022 git config branch.autosetuprebase always &&
1023 (git show-ref -q refs/remotes/local/o || git fetch local) &&
1024 git branch mybase2 &&
1025 git branch --track myr2 mybase &&
1026 test "$(git config branch.myr2.remote)" = . &&
1027 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
1028 test "$(git config branch.myr2.rebase)" = true
1031 test_expect_success 'autosetuprebase remote on a tracked local branch' '
1032 git config remote.local.url . &&
1033 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1034 git config branch.autosetuprebase remote &&
1035 (git show-ref -q refs/remotes/local/o || git fetch local) &&
1036 git branch mybase3 &&
1037 git branch --track myr3 mybase2 &&
1038 test "$(git config branch.myr3.remote)" = . &&
1039 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
1040 ! test "$(git config branch.myr3.rebase)" = true
1043 test_expect_success 'autosetuprebase never on a tracked local branch' '
1044 git config remote.local.url . &&
1045 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1046 git config branch.autosetuprebase never &&
1047 (git show-ref -q refs/remotes/local/o || git fetch local) &&
1048 git branch mybase4 &&
1049 git branch --track myr4 mybase2 &&
1050 test "$(git config branch.myr4.remote)" = . &&
1051 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
1052 ! test "$(git config branch.myr4.rebase)" = true
1055 test_expect_success 'autosetuprebase local on a tracked remote branch' '
1056 git config remote.local.url . &&
1057 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1058 git config branch.autosetuprebase local &&
1059 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1060 git branch --track myr5 local/main &&
1061 test "$(git config branch.myr5.remote)" = local &&
1062 test "$(git config branch.myr5.merge)" = refs/heads/main &&
1063 ! test "$(git config branch.myr5.rebase)" = true
1066 test_expect_success 'autosetuprebase never on a tracked remote branch' '
1067 git config remote.local.url . &&
1068 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1069 git config branch.autosetuprebase never &&
1070 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1071 git branch --track myr6 local/main &&
1072 test "$(git config branch.myr6.remote)" = local &&
1073 test "$(git config branch.myr6.merge)" = refs/heads/main &&
1074 ! test "$(git config branch.myr6.rebase)" = true
1077 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
1078 git config remote.local.url . &&
1079 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1080 git config branch.autosetuprebase remote &&
1081 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1082 git branch --track myr7 local/main &&
1083 test "$(git config branch.myr7.remote)" = local &&
1084 test "$(git config branch.myr7.merge)" = refs/heads/main &&
1085 test "$(git config branch.myr7.rebase)" = true
1088 test_expect_success 'autosetuprebase always on a tracked remote branch' '
1089 git config remote.local.url . &&
1090 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1091 git config branch.autosetuprebase remote &&
1092 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1093 git branch --track myr8 local/main &&
1094 test "$(git config branch.myr8.remote)" = local &&
1095 test "$(git config branch.myr8.merge)" = refs/heads/main &&
1096 test "$(git config branch.myr8.rebase)" = true
1099 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
1100 git config --unset branch.autosetuprebase &&
1101 git config remote.local.url . &&
1102 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1103 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1104 git branch --track myr9 local/main &&
1105 test "$(git config branch.myr9.remote)" = local &&
1106 test "$(git config branch.myr9.merge)" = refs/heads/main &&
1107 test "z$(git config branch.myr9.rebase)" = z
1110 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
1111 git config remote.local.url . &&
1112 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1113 (git show-ref -q refs/remotes/local/o || git fetch local) &&
1114 git branch mybase10 &&
1115 git branch --track myr10 mybase2 &&
1116 test "$(git config branch.myr10.remote)" = . &&
1117 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
1118 test "z$(git config branch.myr10.rebase)" = z
1121 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
1122 git config remote.local.url . &&
1123 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1124 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1125 git branch --no-track myr11 mybase2 &&
1126 test "z$(git config branch.myr11.remote)" = z &&
1127 test "z$(git config branch.myr11.merge)" = z &&
1128 test "z$(git config branch.myr11.rebase)" = z
1131 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
1132 git config remote.local.url . &&
1133 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1134 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1135 git branch --no-track myr12 local/main &&
1136 test "z$(git config branch.myr12.remote)" = z &&
1137 test "z$(git config branch.myr12.merge)" = z &&
1138 test "z$(git config branch.myr12.rebase)" = z
1141 test_expect_success 'autosetuprebase never on an untracked local branch' '
1142 git config branch.autosetuprebase never &&
1143 git config remote.local.url . &&
1144 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1145 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1146 git branch --no-track myr13 mybase2 &&
1147 test "z$(git config branch.myr13.remote)" = z &&
1148 test "z$(git config branch.myr13.merge)" = z &&
1149 test "z$(git config branch.myr13.rebase)" = z
1152 test_expect_success 'autosetuprebase local on an untracked local branch' '
1153 git config branch.autosetuprebase local &&
1154 git config remote.local.url . &&
1155 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1156 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1157 git branch --no-track myr14 mybase2 &&
1158 test "z$(git config branch.myr14.remote)" = z &&
1159 test "z$(git config branch.myr14.merge)" = z &&
1160 test "z$(git config branch.myr14.rebase)" = z
1163 test_expect_success 'autosetuprebase remote on an untracked local branch' '
1164 git config branch.autosetuprebase remote &&
1165 git config remote.local.url . &&
1166 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1167 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1168 git branch --no-track myr15 mybase2 &&
1169 test "z$(git config branch.myr15.remote)" = z &&
1170 test "z$(git config branch.myr15.merge)" = z &&
1171 test "z$(git config branch.myr15.rebase)" = z
1174 test_expect_success 'autosetuprebase always on an untracked local branch' '
1175 git config branch.autosetuprebase always &&
1176 git config remote.local.url . &&
1177 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1178 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1179 git branch --no-track myr16 mybase2 &&
1180 test "z$(git config branch.myr16.remote)" = z &&
1181 test "z$(git config branch.myr16.merge)" = z &&
1182 test "z$(git config branch.myr16.rebase)" = z
1185 test_expect_success 'autosetuprebase never on an untracked remote branch' '
1186 git config branch.autosetuprebase never &&
1187 git config remote.local.url . &&
1188 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1189 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1190 git branch --no-track myr17 local/main &&
1191 test "z$(git config branch.myr17.remote)" = z &&
1192 test "z$(git config branch.myr17.merge)" = z &&
1193 test "z$(git config branch.myr17.rebase)" = z
1196 test_expect_success 'autosetuprebase local on an untracked remote branch' '
1197 git config branch.autosetuprebase local &&
1198 git config remote.local.url . &&
1199 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1200 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1201 git branch --no-track myr18 local/main &&
1202 test "z$(git config branch.myr18.remote)" = z &&
1203 test "z$(git config branch.myr18.merge)" = z &&
1204 test "z$(git config branch.myr18.rebase)" = z
1207 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
1208 git config branch.autosetuprebase remote &&
1209 git config remote.local.url . &&
1210 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1211 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1212 git branch --no-track myr19 local/main &&
1213 test "z$(git config branch.myr19.remote)" = z &&
1214 test "z$(git config branch.myr19.merge)" = z &&
1215 test "z$(git config branch.myr19.rebase)" = z
1218 test_expect_success 'autosetuprebase always on an untracked remote branch' '
1219 git config branch.autosetuprebase always &&
1220 git config remote.local.url . &&
1221 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1222 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1223 git branch --no-track myr20 local/main &&
1224 test "z$(git config branch.myr20.remote)" = z &&
1225 test "z$(git config branch.myr20.merge)" = z &&
1226 test "z$(git config branch.myr20.rebase)" = z
1229 test_expect_success 'autosetuprebase always on detached HEAD' '
1230 git config branch.autosetupmerge always &&
1231 test_when_finished git checkout main &&
1232 git checkout HEAD^0 &&
1233 git branch my11 &&
1234 test -z "$(git config branch.my11.remote)" &&
1235 test -z "$(git config branch.my11.merge)"
1238 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
1239 git config branch.autosetuprebase garbage &&
1240 test_must_fail git branch
1243 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
1244 git config --unset branch.autosetuprebase &&
1245 echo "[branch] autosetuprebase" >>.git/config &&
1246 test_must_fail git branch &&
1247 git config --unset branch.autosetuprebase
1250 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
1251 git checkout my9 &&
1252 git config --unset branch.my8.merge &&
1253 test_must_fail git branch -d my8
1256 test_expect_success 'attempt to delete a branch merged to its base' '
1257 # we are on my9 which is the initial commit; traditionally
1258 # we would not have allowed deleting my8 that is not merged
1259 # to my9, but it is set to track main that already has my8
1260 git config branch.my8.merge refs/heads/main &&
1261 git branch -d my8
1264 test_expect_success 'attempt to delete a branch merged to its base' '
1265 git checkout main &&
1266 echo Third >>A &&
1267 git commit -m "Third commit" A &&
1268 git branch -t my10 my9 &&
1269 git branch -f my10 HEAD^ &&
1270 # we are on main which is at the third commit, and my10
1271 # is behind us, so traditionally we would have allowed deleting
1272 # it; but my10 is set to track my9 that is further behind.
1273 test_must_fail git branch -d my10
1276 test_expect_success 'branch --delete --force removes dangling branch' '
1277 git checkout main &&
1278 test_commit unstable &&
1279 hash=$(git rev-parse HEAD) &&
1280 objpath=$(echo $hash | sed -e "s|^..|.git/objects/&/|") &&
1281 git branch --no-track dangling &&
1282 mv $objpath $objpath.x &&
1283 test_when_finished "mv $objpath.x $objpath" &&
1284 git branch --delete --force dangling &&
1285 git for-each-ref refs/heads/dangling >actual &&
1286 test_must_be_empty actual
1289 test_expect_success 'use --edit-description' '
1290 write_script editor <<-\EOF &&
1291 echo "New contents" >"$1"
1293 EDITOR=./editor git branch --edit-description &&
1294 write_script editor <<-\EOF &&
1295 git stripspace -s <"$1" >"EDITOR_OUTPUT"
1297 EDITOR=./editor git branch --edit-description &&
1298 echo "New contents" >expect &&
1299 test_cmp expect EDITOR_OUTPUT
1302 test_expect_success 'detect typo in branch name when using --edit-description' '
1303 write_script editor <<-\EOF &&
1304 echo "New contents" >"$1"
1306 test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
1309 test_expect_success 'refuse --edit-description on unborn branch for now' '
1310 test_when_finished "git checkout main" &&
1311 write_script editor <<-\EOF &&
1312 echo "New contents" >"$1"
1314 git checkout --orphan unborn &&
1315 test_must_fail env EDITOR=./editor git branch --edit-description
1318 test_expect_success '--merged catches invalid object names' '
1319 test_must_fail git branch --merged 0000000000000000000000000000000000000000
1322 test_expect_success '--list during rebase' '
1323 test_when_finished "reset_rebase" &&
1324 git checkout main &&
1325 FAKE_LINES="1 edit 2" &&
1326 export FAKE_LINES &&
1327 set_fake_editor &&
1328 git rebase -i HEAD~2 &&
1329 git branch --list >actual &&
1330 test_i18ngrep "rebasing main" actual
1333 test_expect_success '--list during rebase from detached HEAD' '
1334 test_when_finished "reset_rebase && git checkout main" &&
1335 git checkout main^0 &&
1336 oid=$(git rev-parse --short HEAD) &&
1337 FAKE_LINES="1 edit 2" &&
1338 export FAKE_LINES &&
1339 set_fake_editor &&
1340 git rebase -i HEAD~2 &&
1341 git branch --list >actual &&
1342 test_i18ngrep "rebasing detached HEAD $oid" actual
1345 test_expect_success 'tracking with unexpected .fetch refspec' '
1346 rm -rf a b c d &&
1347 git init -b main a &&
1349 cd a &&
1350 test_commit a
1351 ) &&
1352 git init -b main b &&
1354 cd b &&
1355 test_commit b
1356 ) &&
1357 git init -b main c &&
1359 cd c &&
1360 test_commit c &&
1361 git remote add a ../a &&
1362 git remote add b ../b &&
1363 git fetch --all
1364 ) &&
1365 git init -b main d &&
1367 cd d &&
1368 git remote add c ../c &&
1369 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
1370 git fetch c &&
1371 git branch --track local/a/main remotes/a/main &&
1372 test "$(git config branch.local/a/main.remote)" = "c" &&
1373 test "$(git config branch.local/a/main.merge)" = "refs/remotes/a/main" &&
1374 git rev-parse --verify a >expect &&
1375 git rev-parse --verify local/a/main >actual &&
1376 test_cmp expect actual
1380 test_expect_success 'configured committerdate sort' '
1381 git init -b main sort &&
1383 cd sort &&
1384 git config branch.sort committerdate &&
1385 test_commit initial &&
1386 git checkout -b a &&
1387 test_commit a &&
1388 git checkout -b c &&
1389 test_commit c &&
1390 git checkout -b b &&
1391 test_commit b &&
1392 git branch >actual &&
1393 cat >expect <<-\EOF &&
1394 main
1399 test_cmp expect actual
1403 test_expect_success 'option override configured sort' '
1405 cd sort &&
1406 git config branch.sort committerdate &&
1407 git branch --sort=refname >actual &&
1408 cat >expect <<-\EOF &&
1412 main
1414 test_cmp expect actual
1418 test_expect_success 'invalid sort parameter in configuration' '
1420 cd sort &&
1421 git config branch.sort "v:notvalid" &&
1422 test_must_fail git branch
1426 test_done