utf8: fix overflow when returning string width
[alt-git.git] / t / t3200-branch.sh
blob631a0b506af5c3a4a4dc89b42dc8d59322b08d0c
1 #!/bin/sh
3 # Copyright (c) 2005 Amos Waterland
6 test_description='git branch assorted tests'
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/lib-rebase.sh
11 test_expect_success 'prepare a trivial repository' '
12 echo Hello >A &&
13 git update-index --add A &&
14 git commit -m "Initial commit." &&
15 git branch -M main &&
16 echo World >>A &&
17 git update-index --add A &&
18 git commit -m "Second commit." &&
19 HEAD=$(git rev-parse --verify HEAD)
22 test_expect_success 'git branch --help should not have created a bogus branch' '
23 test_might_fail git branch --man --help </dev/null >/dev/null 2>&1 &&
24 test_path_is_missing .git/refs/heads/--help
27 test_expect_success 'branch -h in broken repository' '
28 mkdir broken &&
30 cd broken &&
31 git init -b main &&
32 >.git/refs/heads/main &&
33 test_expect_code 129 git branch -h >usage 2>&1
34 ) &&
35 test_i18ngrep "[Uu]sage" broken/usage
38 test_expect_success 'git branch abc should create a branch' '
39 git branch abc && test_path_is_file .git/refs/heads/abc
42 test_expect_success 'git branch a/b/c should create a branch' '
43 git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c
46 test_expect_success 'git branch mb main... should create a branch' '
47 git branch mb main... && test_path_is_file .git/refs/heads/mb
50 test_expect_success 'git branch HEAD should fail' '
51 test_must_fail git branch HEAD
54 cat >expect <<EOF
55 $ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from main
56 EOF
57 test_expect_success 'git branch --create-reflog d/e/f should create a branch and a log' '
58 GIT_COMMITTER_DATE="2005-05-26 23:30" \
59 git -c core.logallrefupdates=false branch --create-reflog d/e/f &&
60 test_path_is_file .git/refs/heads/d/e/f &&
61 test_path_is_file .git/logs/refs/heads/d/e/f &&
62 test_cmp expect .git/logs/refs/heads/d/e/f
65 test_expect_success 'git branch -d d/e/f should delete a branch and a log' '
66 git branch -d d/e/f &&
67 test_path_is_missing .git/refs/heads/d/e/f &&
68 test_must_fail git reflog exists refs/heads/d/e/f
71 test_expect_success 'git branch j/k should work after branch j has been deleted' '
72 git branch j &&
73 git branch -d j &&
74 git branch j/k
77 test_expect_success 'git branch l should work after branch l/m has been deleted' '
78 git branch l/m &&
79 git branch -d l/m &&
80 git branch l
83 test_expect_success 'git branch -m dumps usage' '
84 test_expect_code 128 git branch -m 2>err &&
85 test_i18ngrep "branch name required" err
88 test_expect_success 'git branch -m m broken_symref should work' '
89 test_when_finished "git branch -D broken_symref" &&
90 git branch --create-reflog m &&
91 git symbolic-ref refs/heads/broken_symref refs/heads/i_am_broken &&
92 git branch -m m broken_symref &&
93 git reflog exists refs/heads/broken_symref &&
94 test_must_fail git reflog exists refs/heads/i_am_broken
97 test_expect_success 'git branch -m m m/m should work' '
98 git branch --create-reflog m &&
99 git branch -m m m/m &&
100 git reflog exists refs/heads/m/m
103 test_expect_success 'git branch -m n/n n should work' '
104 git branch --create-reflog n/n &&
105 git branch -m n/n n &&
106 git reflog exists refs/heads/n
109 # The topmost entry in reflog for branch bbb is about branch creation.
110 # Hence, we compare bbb@{1} (instead of bbb@{0}) with aaa@{0}.
112 test_expect_success 'git branch -m bbb should rename checked out branch' '
113 test_when_finished git branch -D bbb &&
114 test_when_finished git checkout main &&
115 git checkout -b aaa &&
116 git commit --allow-empty -m "a new commit" &&
117 git rev-parse aaa@{0} >expect &&
118 git branch -m bbb &&
119 git rev-parse bbb@{1} >actual &&
120 test_cmp expect actual &&
121 git symbolic-ref HEAD >actual &&
122 echo refs/heads/bbb >expect &&
123 test_cmp expect actual
126 test_expect_success 'renaming checked out branch works with d/f conflict' '
127 test_when_finished "git branch -D foo/bar || git branch -D foo" &&
128 test_when_finished git checkout main &&
129 git checkout -b foo &&
130 git branch -m foo/bar &&
131 git symbolic-ref HEAD >actual &&
132 echo refs/heads/foo/bar >expect &&
133 test_cmp expect actual
136 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
137 git branch o/o &&
138 git branch o/p &&
139 test_must_fail git branch -m o/o o
142 test_expect_success 'git branch -m o/q o/p should fail when o/p exists' '
143 git branch o/q &&
144 test_must_fail git branch -m o/q o/p
147 test_expect_success 'git branch -M o/q o/p should work when o/p exists' '
148 git branch -M o/q o/p
151 test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '
152 git branch o/q &&
153 git branch -m -f o/q o/p
156 test_expect_success 'git branch -m q r/q should fail when r exists' '
157 git branch q &&
158 git branch r &&
159 test_must_fail git branch -m q r/q
162 test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
163 git branch bar &&
164 git checkout -b foo &&
165 test_must_fail git branch -M bar foo
168 test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
169 git checkout -b baz &&
170 git branch bam &&
171 git branch -M baz bam &&
172 test $(git rev-parse --abbrev-ref HEAD) = bam
175 test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' '
176 msg="Branch: renamed refs/heads/baz to refs/heads/bam" &&
177 grep " 0\{40\}.*$msg$" .git/logs/HEAD &&
178 grep "^0\{40\}.*$msg$" .git/logs/HEAD
181 test_expect_success 'git branch -M should leave orphaned HEAD alone' '
182 git init -b main orphan &&
184 cd orphan &&
185 test_commit initial &&
186 git checkout --orphan lonely &&
187 grep lonely .git/HEAD &&
188 test_path_is_missing .git/refs/head/lonely &&
189 git branch -M main mistress &&
190 grep lonely .git/HEAD
194 test_expect_success 'resulting reflog can be shown by log -g' '
195 oid=$(git rev-parse HEAD) &&
196 cat >expect <<-EOF &&
197 HEAD@{0} $oid $msg
198 HEAD@{2} $oid checkout: moving from foo to baz
200 git log -g --format="%gd %H %gs" -2 HEAD >actual &&
201 test_cmp expect actual
204 test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' '
205 git checkout main &&
206 git worktree add -b baz bazdir &&
207 git worktree add -f bazdir2 baz &&
208 git branch -M baz bam &&
209 test $(git -C bazdir rev-parse --abbrev-ref HEAD) = bam &&
210 test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam &&
211 rm -r bazdir bazdir2 &&
212 git worktree prune
215 test_expect_success 'git branch -M baz bam should succeed within a worktree in which baz is checked out' '
216 git checkout -b baz &&
217 git worktree add -f bazdir baz &&
219 cd bazdir &&
220 git branch -M baz bam &&
221 test $(git rev-parse --abbrev-ref HEAD) = bam
222 ) &&
223 test $(git rev-parse --abbrev-ref HEAD) = bam &&
224 rm -r bazdir &&
225 git worktree prune
228 test_expect_success 'git branch -M main should work when main is checked out' '
229 git checkout main &&
230 git branch -M main
233 test_expect_success 'git branch -M main main should work when main is checked out' '
234 git checkout main &&
235 git branch -M main main
238 test_expect_success 'git branch -M topic topic should work when main is checked out' '
239 git checkout main &&
240 git branch topic &&
241 git branch -M topic topic
244 test_expect_success 'git branch -v -d t should work' '
245 git branch t &&
246 git rev-parse --verify refs/heads/t &&
247 git branch -v -d t &&
248 test_must_fail git rev-parse --verify refs/heads/t
251 test_expect_success 'git branch -v -m t s should work' '
252 git branch t &&
253 git rev-parse --verify refs/heads/t &&
254 git branch -v -m t s &&
255 test_must_fail git rev-parse --verify refs/heads/t &&
256 git rev-parse --verify refs/heads/s &&
257 git branch -d s
260 test_expect_success 'git branch -m -d t s should fail' '
261 git branch t &&
262 git rev-parse refs/heads/t &&
263 test_must_fail git branch -m -d t s &&
264 git branch -d t &&
265 test_must_fail git rev-parse refs/heads/t
268 test_expect_success 'git branch --list -d t should fail' '
269 git branch t &&
270 git rev-parse refs/heads/t &&
271 test_must_fail git branch --list -d t &&
272 git branch -d t &&
273 test_must_fail git rev-parse refs/heads/t
276 test_expect_success 'deleting checked-out branch from repo that is a submodule' '
277 test_when_finished "rm -rf repo1 repo2" &&
279 git init repo1 &&
280 git init repo1/sub &&
281 test_commit -C repo1/sub x &&
282 test_config_global protocol.file.allow always &&
283 git -C repo1 submodule add ./sub &&
284 git -C repo1 commit -m "adding sub" &&
286 git clone --recurse-submodules repo1 repo2 &&
287 git -C repo2/sub checkout -b work &&
288 test_must_fail git -C repo2/sub branch -D work
291 test_expect_success 'bare main worktree has HEAD at branch deleted by secondary worktree' '
292 test_when_finished "rm -rf nonbare base secondary" &&
294 git init -b main nonbare &&
295 test_commit -C nonbare x &&
296 git clone --bare nonbare bare &&
297 git -C bare worktree add --detach ../secondary main &&
298 git -C secondary branch -D main
301 test_expect_success 'git branch --list -v with --abbrev' '
302 test_when_finished "git branch -D t" &&
303 git branch t &&
304 git branch -v --list t >actual.default &&
305 git branch -v --list --abbrev t >actual.abbrev &&
306 test_cmp actual.default actual.abbrev &&
308 git branch -v --list --no-abbrev t >actual.noabbrev &&
309 git branch -v --list --abbrev=0 t >actual.0abbrev &&
310 test_cmp actual.noabbrev actual.0abbrev &&
312 git branch -v --list --abbrev=36 t >actual.36abbrev &&
313 # how many hexdigits are used?
314 read name objdefault rest <actual.abbrev &&
315 read name obj36 rest <actual.36abbrev &&
316 objfull=$(git rev-parse --verify t) &&
318 # are we really getting abbreviations?
319 test "$obj36" != "$objdefault" &&
320 expr "$obj36" : "$objdefault" >/dev/null &&
321 test "$objfull" != "$obj36" &&
322 expr "$objfull" : "$obj36" >/dev/null
326 test_expect_success 'git branch --column' '
327 COLUMNS=81 git branch --column=column >actual &&
328 cat >expect <<\EOF &&
329 a/b/c bam foo l * main n o/p r
330 abc bar j/k m/m mb o/o q topic
332 test_cmp expect actual
335 test_expect_success 'git branch --column with an extremely long branch name' '
336 long=this/is/a/part/of/long/branch/name &&
337 long=z$long/$long/$long/$long &&
338 test_when_finished "git branch -d $long" &&
339 git branch $long &&
340 COLUMNS=80 git branch --column=column >actual &&
341 cat >expect <<EOF &&
342 a/b/c
350 * main
357 topic
358 $long
360 test_cmp expect actual
363 test_expect_success 'git branch with column.*' '
364 git config column.ui column &&
365 git config column.branch "dense" &&
366 COLUMNS=80 git branch >actual &&
367 git config --unset column.branch &&
368 git config --unset column.ui &&
369 cat >expect <<\EOF &&
370 a/b/c bam foo l * main n o/p r
371 abc bar j/k m/m mb o/o q topic
373 test_cmp expect actual
376 test_expect_success 'git branch --column -v should fail' '
377 test_must_fail git branch --column -v
380 test_expect_success 'git branch -v with column.ui ignored' '
381 git config column.ui column &&
382 COLUMNS=80 git branch -v | cut -c -8 | sed "s/ *$//" >actual &&
383 git config --unset column.ui &&
384 cat >expect <<\EOF &&
385 a/b/c
393 * main
400 topic
402 test_cmp expect actual
405 mv .git/config .git/config-saved
407 test_expect_success SHA1 'git branch -m q q2 without config should succeed' '
408 git branch -m q q2 &&
409 git branch -m q2 q
412 mv .git/config-saved .git/config
414 git config branch.s/s.dummy Hello
416 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
417 git branch --create-reflog s/s &&
418 git reflog exists refs/heads/s/s &&
419 git branch --create-reflog s/t &&
420 git reflog exists refs/heads/s/t &&
421 git branch -d s/t &&
422 git branch -m s/s s &&
423 git reflog exists refs/heads/s
426 test_expect_success 'config information was renamed, too' '
427 test $(git config branch.s.dummy) = Hello &&
428 test_must_fail git config branch.s/s.dummy
431 test_expect_success 'git branch -m correctly renames multiple config sections' '
432 test_when_finished "git checkout main" &&
433 git checkout -b source main &&
435 # Assert that a config file with multiple config sections has
436 # those sections preserved...
437 cat >expect <<-\EOF &&
438 branch.dest.key1=value1
439 some.gar.b=age
440 branch.dest.key2=value2
442 cat >config.branch <<\EOF &&
443 ;; Note the lack of -\EOF above & mixed indenting here. This is
444 ;; intentional, we are also testing that the formatting of copied
445 ;; sections is preserved.
447 ;; Comment for source. Tabs
448 [branch "source"]
449 ;; Comment for the source value
450 key1 = value1
451 ;; Comment for some.gar. Spaces
452 [some "gar"]
453 ;; Comment for the some.gar value
454 b = age
455 ;; Comment for source, again. Mixed tabs/spaces.
456 [branch "source"]
457 ;; Comment for the source value, again
458 key2 = value2
460 cat config.branch >>.git/config &&
461 git branch -m source dest &&
462 git config -f .git/config -l | grep -F -e source -e dest -e some.gar >actual &&
463 test_cmp expect actual &&
465 # ...and that the comments for those sections are also
466 # preserved.
467 cat config.branch | sed "s/\"source\"/\"dest\"/" >expect &&
468 sed -n -e "/Note the lack/,\$p" .git/config >actual &&
469 test_cmp expect actual
472 test_expect_success 'git branch -c dumps usage' '
473 test_expect_code 128 git branch -c 2>err &&
474 test_i18ngrep "branch name required" err
477 test_expect_success 'git branch --copy dumps usage' '
478 test_expect_code 128 git branch --copy 2>err &&
479 test_i18ngrep "branch name required" err
482 test_expect_success 'git branch -c d e should work' '
483 git branch --create-reflog d &&
484 git reflog exists refs/heads/d &&
485 git config branch.d.dummy Hello &&
486 git branch -c d e &&
487 git reflog exists refs/heads/d &&
488 git reflog exists refs/heads/e &&
489 echo Hello >expect &&
490 git config branch.e.dummy >actual &&
491 test_cmp expect actual &&
492 echo Hello >expect &&
493 git config branch.d.dummy >actual &&
494 test_cmp expect actual
497 test_expect_success 'git branch --copy is a synonym for -c' '
498 git branch --create-reflog copy &&
499 git reflog exists refs/heads/copy &&
500 git config branch.copy.dummy Hello &&
501 git branch --copy copy copy-to &&
502 git reflog exists refs/heads/copy &&
503 git reflog exists refs/heads/copy-to &&
504 echo Hello >expect &&
505 git config branch.copy.dummy >actual &&
506 test_cmp expect actual &&
507 echo Hello >expect &&
508 git config branch.copy-to.dummy >actual &&
509 test_cmp expect actual
512 test_expect_success 'git branch -c ee ef should copy ee to create branch ef' '
513 git checkout -b ee &&
514 git reflog exists refs/heads/ee &&
515 git config branch.ee.dummy Hello &&
516 git branch -c ee ef &&
517 git reflog exists refs/heads/ee &&
518 git reflog exists refs/heads/ef &&
519 test $(git config branch.ee.dummy) = Hello &&
520 test $(git config branch.ef.dummy) = Hello &&
521 test $(git rev-parse --abbrev-ref HEAD) = ee
524 test_expect_success 'git branch -c f/f g/g should work' '
525 git branch --create-reflog f/f &&
526 git reflog exists refs/heads/f/f &&
527 git config branch.f/f.dummy Hello &&
528 git branch -c f/f g/g &&
529 git reflog exists refs/heads/f/f &&
530 git reflog exists refs/heads/g/g &&
531 test $(git config branch.f/f.dummy) = Hello &&
532 test $(git config branch.g/g.dummy) = Hello
535 test_expect_success 'git branch -c m2 m2 should work' '
536 git branch --create-reflog m2 &&
537 git reflog exists refs/heads/m2 &&
538 git config branch.m2.dummy Hello &&
539 git branch -c m2 m2 &&
540 git reflog exists refs/heads/m2 &&
541 test $(git config branch.m2.dummy) = Hello
544 test_expect_success 'git branch -c zz zz/zz should fail' '
545 git branch --create-reflog zz &&
546 git reflog exists refs/heads/zz &&
547 test_must_fail git branch -c zz zz/zz
550 test_expect_success 'git branch -c b/b b should fail' '
551 git branch --create-reflog b/b &&
552 test_must_fail git branch -c b/b b
555 test_expect_success 'git branch -C o/q o/p should work when o/p exists' '
556 git branch --create-reflog o/q &&
557 git reflog exists refs/heads/o/q &&
558 git reflog exists refs/heads/o/p &&
559 git branch -C o/q o/p
562 test_expect_success 'git branch -c -f o/q o/p should work when o/p exists' '
563 git reflog exists refs/heads/o/q &&
564 git reflog exists refs/heads/o/p &&
565 git branch -c -f o/q o/p
568 test_expect_success 'git branch -c qq rr/qq should fail when rr exists' '
569 git branch qq &&
570 git branch rr &&
571 test_must_fail git branch -c qq rr/qq
574 test_expect_success 'git branch -C b1 b2 should fail when b2 is checked out' '
575 git branch b1 &&
576 git checkout -b b2 &&
577 test_must_fail git branch -C b1 b2
580 test_expect_success 'git branch -C c1 c2 should succeed when c1 is checked out' '
581 git checkout -b c1 &&
582 git branch c2 &&
583 git branch -C c1 c2 &&
584 test $(git rev-parse --abbrev-ref HEAD) = c1
587 test_expect_success 'git branch -C c1 c2 should never touch HEAD' '
588 msg="Branch: copied refs/heads/c1 to refs/heads/c2" &&
589 ! grep "$msg$" .git/logs/HEAD
592 test_expect_success 'git branch -C main should work when main is checked out' '
593 git checkout main &&
594 git branch -C main
597 test_expect_success 'git branch -C main main should work when main is checked out' '
598 git checkout main &&
599 git branch -C main main
602 test_expect_success 'git branch -C main5 main5 should work when main is checked out' '
603 git checkout main &&
604 git branch main5 &&
605 git branch -C main5 main5
608 test_expect_success 'git branch -C ab cd should overwrite existing config for cd' '
609 git branch --create-reflog cd &&
610 git reflog exists refs/heads/cd &&
611 git config branch.cd.dummy CD &&
612 git branch --create-reflog ab &&
613 git reflog exists refs/heads/ab &&
614 git config branch.ab.dummy AB &&
615 git branch -C ab cd &&
616 git reflog exists refs/heads/ab &&
617 git reflog exists refs/heads/cd &&
618 test $(git config branch.ab.dummy) = AB &&
619 test $(git config branch.cd.dummy) = AB
622 test_expect_success 'git branch -c correctly copies multiple config sections' '
623 FOO=1 &&
624 export FOO &&
625 test_when_finished "git checkout main" &&
626 git checkout -b source2 main &&
628 # Assert that a config file with multiple config sections has
629 # those sections preserved...
630 cat >expect <<-\EOF &&
631 branch.source2.key1=value1
632 branch.dest2.key1=value1
633 more.gar.b=age
634 branch.source2.key2=value2
635 branch.dest2.key2=value2
637 cat >config.branch <<\EOF &&
638 ;; Note the lack of -\EOF above & mixed indenting here. This is
639 ;; intentional, we are also testing that the formatting of copied
640 ;; sections is preserved.
642 ;; Comment for source2. Tabs
643 [branch "source2"]
644 ;; Comment for the source2 value
645 key1 = value1
646 ;; Comment for more.gar. Spaces
647 [more "gar"]
648 ;; Comment for the more.gar value
649 b = age
650 ;; Comment for source2, again. Mixed tabs/spaces.
651 [branch "source2"]
652 ;; Comment for the source2 value, again
653 key2 = value2
655 cat config.branch >>.git/config &&
656 git branch -c source2 dest2 &&
657 git config -f .git/config -l | grep -F -e source2 -e dest2 -e more.gar >actual &&
658 test_cmp expect actual &&
660 # ...and that the comments and formatting for those sections
661 # is also preserved.
662 cat >expect <<\EOF &&
663 ;; Comment for source2. Tabs
664 [branch "source2"]
665 ;; Comment for the source2 value
666 key1 = value1
667 ;; Comment for more.gar. Spaces
668 [branch "dest2"]
669 ;; Comment for the source2 value
670 key1 = value1
671 ;; Comment for more.gar. Spaces
672 [more "gar"]
673 ;; Comment for the more.gar value
674 b = age
675 ;; Comment for source2, again. Mixed tabs/spaces.
676 [branch "source2"]
677 ;; Comment for the source2 value, again
678 key2 = value2
679 [branch "dest2"]
680 ;; Comment for the source2 value, again
681 key2 = value2
683 sed -n -e "/Comment for source2/,\$p" .git/config >actual &&
684 test_cmp expect actual
687 test_expect_success 'deleting a symref' '
688 git branch target &&
689 git symbolic-ref refs/heads/symref refs/heads/target &&
690 echo "Deleted branch symref (was refs/heads/target)." >expect &&
691 git branch -d symref >actual &&
692 test_path_is_file .git/refs/heads/target &&
693 test_path_is_missing .git/refs/heads/symref &&
694 test_i18ncmp expect actual
697 test_expect_success 'deleting a dangling symref' '
698 git symbolic-ref refs/heads/dangling-symref nowhere &&
699 test_path_is_file .git/refs/heads/dangling-symref &&
700 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
701 git branch -d dangling-symref >actual &&
702 test_path_is_missing .git/refs/heads/dangling-symref &&
703 test_i18ncmp expect actual
706 test_expect_success 'deleting a self-referential symref' '
707 git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
708 test_path_is_file .git/refs/heads/self-reference &&
709 echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
710 git branch -d self-reference >actual &&
711 test_path_is_missing .git/refs/heads/self-reference &&
712 test_i18ncmp expect actual
715 test_expect_success 'renaming a symref is not allowed' '
716 git symbolic-ref refs/heads/topic refs/heads/main &&
717 test_must_fail git branch -m topic new-topic &&
718 git symbolic-ref refs/heads/topic &&
719 test_path_is_file .git/refs/heads/main &&
720 test_path_is_missing .git/refs/heads/new-topic
723 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
724 git branch --create-reflog u &&
725 mv .git/logs/refs/heads/u real-u &&
726 ln -s real-u .git/logs/refs/heads/u &&
727 test_must_fail git branch -m u v
730 test_expect_success 'test tracking setup via --track' '
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/main || git fetch local) &&
734 git branch --track my1 local/main &&
735 test $(git config branch.my1.remote) = local &&
736 test $(git config branch.my1.merge) = refs/heads/main
739 test_expect_success 'test tracking setup (non-wildcard, matching)' '
740 git config remote.local.url . &&
741 git config remote.local.fetch refs/heads/main:refs/remotes/local/main &&
742 (git show-ref -q refs/remotes/local/main || git fetch local) &&
743 git branch --track my4 local/main &&
744 test $(git config branch.my4.remote) = local &&
745 test $(git config branch.my4.merge) = refs/heads/main
748 test_expect_success 'tracking setup fails on non-matching refspec' '
749 git config remote.local.url . &&
750 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
751 (git show-ref -q refs/remotes/local/main || git fetch local) &&
752 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
753 test_must_fail git branch --track my5 local/main &&
754 test_must_fail git config branch.my5.remote &&
755 test_must_fail git config branch.my5.merge
758 test_expect_success 'test tracking setup via config' '
759 git config branch.autosetupmerge true &&
760 git config remote.local.url . &&
761 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
762 (git show-ref -q refs/remotes/local/main || git fetch local) &&
763 git branch my3 local/main &&
764 test $(git config branch.my3.remote) = local &&
765 test $(git config branch.my3.merge) = refs/heads/main
768 test_expect_success 'test overriding tracking setup via --no-track' '
769 git config branch.autosetupmerge true &&
770 git config remote.local.url . &&
771 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
772 (git show-ref -q refs/remotes/local/main || git fetch local) &&
773 git branch --no-track my2 local/main &&
774 git config branch.autosetupmerge false &&
775 ! test "$(git config branch.my2.remote)" = local &&
776 ! test "$(git config branch.my2.merge)" = refs/heads/main
779 test_expect_success 'no tracking without .fetch entries' '
780 git config branch.autosetupmerge true &&
781 git branch my6 s &&
782 git config branch.autosetupmerge false &&
783 test -z "$(git config branch.my6.remote)" &&
784 test -z "$(git config branch.my6.merge)"
787 test_expect_success 'test tracking setup via --track but deeper' '
788 git config remote.local.url . &&
789 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
790 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
791 git branch --track my7 local/o/o &&
792 test "$(git config branch.my7.remote)" = local &&
793 test "$(git config branch.my7.merge)" = refs/heads/o/o
796 test_expect_success 'test deleting branch deletes branch config' '
797 git branch -d my7 &&
798 test -z "$(git config branch.my7.remote)" &&
799 test -z "$(git config branch.my7.merge)"
802 test_expect_success 'test deleting branch without config' '
803 git branch my7 s &&
804 sha1=$(git rev-parse my7 | cut -c 1-7) &&
805 echo "Deleted branch my7 (was $sha1)." >expect &&
806 git branch -d my7 >actual 2>&1 &&
807 test_i18ncmp expect actual
810 test_expect_success 'deleting currently checked out branch fails' '
811 git worktree add -b my7 my7 &&
812 test_must_fail git -C my7 branch -d my7 &&
813 test_must_fail git branch -d my7 &&
814 rm -r my7 &&
815 git worktree prune
818 test_expect_success 'test --track without .fetch entries' '
819 git branch --track my8 &&
820 test "$(git config branch.my8.remote)" &&
821 test "$(git config branch.my8.merge)"
824 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
825 git config branch.autosetupmerge always &&
826 git branch my9 HEAD^ &&
827 git config branch.autosetupmerge false
830 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
831 test_must_fail git branch --track my10 HEAD^
834 test_expect_success 'branch from tag w/--track causes failure' '
835 git tag foobar &&
836 test_must_fail git branch --track my11 foobar
839 test_expect_success '--set-upstream-to fails on multiple branches' '
840 echo "fatal: too many arguments to set new upstream" >expect &&
841 test_must_fail git branch --set-upstream-to main a b c 2>err &&
842 test_i18ncmp expect err
845 test_expect_success '--set-upstream-to fails on detached HEAD' '
846 git checkout HEAD^{} &&
847 test_when_finished git checkout - &&
848 echo "fatal: could not set upstream of HEAD to main when it does not point to any branch." >expect &&
849 test_must_fail git branch --set-upstream-to main 2>err &&
850 test_i18ncmp expect err
853 test_expect_success '--set-upstream-to fails on a missing dst branch' '
854 echo "fatal: branch '"'"'does-not-exist'"'"' does not exist" >expect &&
855 test_must_fail git branch --set-upstream-to main does-not-exist 2>err &&
856 test_i18ncmp expect err
859 test_expect_success '--set-upstream-to fails on a missing src branch' '
860 test_must_fail git branch --set-upstream-to does-not-exist main 2>err &&
861 test_i18ngrep "the requested upstream branch '"'"'does-not-exist'"'"' does not exist" err
864 test_expect_success '--set-upstream-to fails on a non-ref' '
865 echo "fatal: Cannot setup tracking information; starting point '"'"'HEAD^{}'"'"' is not a branch." >expect &&
866 test_must_fail git branch --set-upstream-to HEAD^{} 2>err &&
867 test_i18ncmp expect err
870 test_expect_success '--set-upstream-to fails on locked config' '
871 test_when_finished "rm -f .git/config.lock" &&
872 >.git/config.lock &&
873 git branch locked &&
874 test_must_fail git branch --set-upstream-to locked 2>err &&
875 test_i18ngrep "could not lock config file .git/config" err
878 test_expect_success 'use --set-upstream-to modify HEAD' '
879 test_config branch.main.remote foo &&
880 test_config branch.main.merge foo &&
881 git branch my12 &&
882 git branch --set-upstream-to my12 &&
883 test "$(git config branch.main.remote)" = "." &&
884 test "$(git config branch.main.merge)" = "refs/heads/my12"
887 test_expect_success 'use --set-upstream-to modify a particular branch' '
888 git branch my13 &&
889 git branch --set-upstream-to main my13 &&
890 test_when_finished "git branch --unset-upstream my13" &&
891 test "$(git config branch.my13.remote)" = "." &&
892 test "$(git config branch.my13.merge)" = "refs/heads/main"
895 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
896 echo "fatal: Branch '"'"'i-dont-exist'"'"' has no upstream information" >expect &&
897 test_must_fail git branch --unset-upstream i-dont-exist 2>err &&
898 test_i18ncmp expect err
901 test_expect_success '--unset-upstream should fail if config is locked' '
902 test_when_finished "rm -f .git/config.lock" &&
903 git branch --set-upstream-to locked &&
904 >.git/config.lock &&
905 test_must_fail git branch --unset-upstream 2>err &&
906 test_i18ngrep "could not lock config file .git/config" err
909 test_expect_success 'test --unset-upstream on HEAD' '
910 git branch my14 &&
911 test_config branch.main.remote foo &&
912 test_config branch.main.merge foo &&
913 git branch --set-upstream-to my14 &&
914 git branch --unset-upstream &&
915 test_must_fail git config branch.main.remote &&
916 test_must_fail git config branch.main.merge &&
917 # fail for a branch without upstream set
918 echo "fatal: Branch '"'"'main'"'"' has no upstream information" >expect &&
919 test_must_fail git branch --unset-upstream 2>err &&
920 test_i18ncmp expect err
923 test_expect_success '--unset-upstream should fail on multiple branches' '
924 echo "fatal: too many arguments to unset upstream" >expect &&
925 test_must_fail git branch --unset-upstream a b c 2>err &&
926 test_i18ncmp expect err
929 test_expect_success '--unset-upstream should fail on detached HEAD' '
930 git checkout HEAD^{} &&
931 test_when_finished git checkout - &&
932 echo "fatal: could not unset upstream of HEAD when it does not point to any branch." >expect &&
933 test_must_fail git branch --unset-upstream 2>err &&
934 test_i18ncmp expect err
937 test_expect_success 'test --unset-upstream on a particular branch' '
938 git branch my15 &&
939 git branch --set-upstream-to main my14 &&
940 git branch --unset-upstream my14 &&
941 test_must_fail git config branch.my14.remote &&
942 test_must_fail git config branch.my14.merge
945 test_expect_success 'disabled option --set-upstream fails' '
946 test_must_fail git branch --set-upstream origin/main
949 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
950 git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
951 cat >expect <<-\EOF &&
952 warning: Not setting branch my13 as its own upstream.
954 test_expect_code 1 git config branch.my13.remote &&
955 test_expect_code 1 git config branch.my13.merge &&
956 test_i18ncmp expect actual
959 # Keep this test last, as it changes the current branch
960 cat >expect <<EOF
961 $ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from main
963 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
964 GIT_COMMITTER_DATE="2005-05-26 23:30" \
965 git checkout -b g/h/i -l main &&
966 test_path_is_file .git/refs/heads/g/h/i &&
967 test_path_is_file .git/logs/refs/heads/g/h/i &&
968 test_cmp expect .git/logs/refs/heads/g/h/i
971 test_expect_success 'checkout -b makes reflog by default' '
972 git checkout main &&
973 git config --unset core.logAllRefUpdates &&
974 git checkout -b alpha &&
975 git rev-parse --verify alpha@{0}
978 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
979 git checkout main &&
980 git config core.logAllRefUpdates false &&
981 git checkout -b beta &&
982 test_must_fail git rev-parse --verify beta@{0}
985 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
986 git checkout main &&
987 git checkout -lb gamma &&
988 git config --unset core.logAllRefUpdates &&
989 git rev-parse --verify gamma@{0}
992 test_expect_success 'avoid ambiguous track' '
993 git config branch.autosetupmerge true &&
994 git config remote.ambi1.url lalala &&
995 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/main &&
996 git config remote.ambi2.url lilili &&
997 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/main &&
998 test_must_fail git branch all1 main &&
999 test -z "$(git config branch.all1.merge)"
1002 test_expect_success 'autosetuprebase local on a tracked local branch' '
1003 git config remote.local.url . &&
1004 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1005 git config branch.autosetuprebase local &&
1006 (git show-ref -q refs/remotes/local/o || git fetch local) &&
1007 git branch mybase &&
1008 git branch --track myr1 mybase &&
1009 test "$(git config branch.myr1.remote)" = . &&
1010 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
1011 test "$(git config branch.myr1.rebase)" = true
1014 test_expect_success 'autosetuprebase always on a tracked local branch' '
1015 git config remote.local.url . &&
1016 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1017 git config branch.autosetuprebase always &&
1018 (git show-ref -q refs/remotes/local/o || git fetch local) &&
1019 git branch mybase2 &&
1020 git branch --track myr2 mybase &&
1021 test "$(git config branch.myr2.remote)" = . &&
1022 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
1023 test "$(git config branch.myr2.rebase)" = true
1026 test_expect_success 'autosetuprebase remote on a tracked local branch' '
1027 git config remote.local.url . &&
1028 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1029 git config branch.autosetuprebase remote &&
1030 (git show-ref -q refs/remotes/local/o || git fetch local) &&
1031 git branch mybase3 &&
1032 git branch --track myr3 mybase2 &&
1033 test "$(git config branch.myr3.remote)" = . &&
1034 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
1035 ! test "$(git config branch.myr3.rebase)" = true
1038 test_expect_success 'autosetuprebase never on a tracked local branch' '
1039 git config remote.local.url . &&
1040 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1041 git config branch.autosetuprebase never &&
1042 (git show-ref -q refs/remotes/local/o || git fetch local) &&
1043 git branch mybase4 &&
1044 git branch --track myr4 mybase2 &&
1045 test "$(git config branch.myr4.remote)" = . &&
1046 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
1047 ! test "$(git config branch.myr4.rebase)" = true
1050 test_expect_success 'autosetuprebase local on a tracked remote branch' '
1051 git config remote.local.url . &&
1052 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1053 git config branch.autosetuprebase local &&
1054 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1055 git branch --track myr5 local/main &&
1056 test "$(git config branch.myr5.remote)" = local &&
1057 test "$(git config branch.myr5.merge)" = refs/heads/main &&
1058 ! test "$(git config branch.myr5.rebase)" = true
1061 test_expect_success 'autosetuprebase never on a tracked remote branch' '
1062 git config remote.local.url . &&
1063 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1064 git config branch.autosetuprebase never &&
1065 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1066 git branch --track myr6 local/main &&
1067 test "$(git config branch.myr6.remote)" = local &&
1068 test "$(git config branch.myr6.merge)" = refs/heads/main &&
1069 ! test "$(git config branch.myr6.rebase)" = true
1072 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
1073 git config remote.local.url . &&
1074 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1075 git config branch.autosetuprebase remote &&
1076 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1077 git branch --track myr7 local/main &&
1078 test "$(git config branch.myr7.remote)" = local &&
1079 test "$(git config branch.myr7.merge)" = refs/heads/main &&
1080 test "$(git config branch.myr7.rebase)" = true
1083 test_expect_success 'autosetuprebase always on a tracked remote branch' '
1084 git config remote.local.url . &&
1085 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1086 git config branch.autosetuprebase remote &&
1087 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1088 git branch --track myr8 local/main &&
1089 test "$(git config branch.myr8.remote)" = local &&
1090 test "$(git config branch.myr8.merge)" = refs/heads/main &&
1091 test "$(git config branch.myr8.rebase)" = true
1094 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
1095 git config --unset branch.autosetuprebase &&
1096 git config remote.local.url . &&
1097 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1098 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1099 git branch --track myr9 local/main &&
1100 test "$(git config branch.myr9.remote)" = local &&
1101 test "$(git config branch.myr9.merge)" = refs/heads/main &&
1102 test "z$(git config branch.myr9.rebase)" = z
1105 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
1106 git config remote.local.url . &&
1107 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1108 (git show-ref -q refs/remotes/local/o || git fetch local) &&
1109 git branch mybase10 &&
1110 git branch --track myr10 mybase2 &&
1111 test "$(git config branch.myr10.remote)" = . &&
1112 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
1113 test "z$(git config branch.myr10.rebase)" = z
1116 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
1117 git config remote.local.url . &&
1118 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1119 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1120 git branch --no-track myr11 mybase2 &&
1121 test "z$(git config branch.myr11.remote)" = z &&
1122 test "z$(git config branch.myr11.merge)" = z &&
1123 test "z$(git config branch.myr11.rebase)" = z
1126 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
1127 git config remote.local.url . &&
1128 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1129 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1130 git branch --no-track myr12 local/main &&
1131 test "z$(git config branch.myr12.remote)" = z &&
1132 test "z$(git config branch.myr12.merge)" = z &&
1133 test "z$(git config branch.myr12.rebase)" = z
1136 test_expect_success 'autosetuprebase never on an untracked local branch' '
1137 git config branch.autosetuprebase never &&
1138 git config remote.local.url . &&
1139 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1140 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1141 git branch --no-track myr13 mybase2 &&
1142 test "z$(git config branch.myr13.remote)" = z &&
1143 test "z$(git config branch.myr13.merge)" = z &&
1144 test "z$(git config branch.myr13.rebase)" = z
1147 test_expect_success 'autosetuprebase local on an untracked local branch' '
1148 git config branch.autosetuprebase local &&
1149 git config remote.local.url . &&
1150 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1151 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1152 git branch --no-track myr14 mybase2 &&
1153 test "z$(git config branch.myr14.remote)" = z &&
1154 test "z$(git config branch.myr14.merge)" = z &&
1155 test "z$(git config branch.myr14.rebase)" = z
1158 test_expect_success 'autosetuprebase remote on an untracked local branch' '
1159 git config branch.autosetuprebase remote &&
1160 git config remote.local.url . &&
1161 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1162 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1163 git branch --no-track myr15 mybase2 &&
1164 test "z$(git config branch.myr15.remote)" = z &&
1165 test "z$(git config branch.myr15.merge)" = z &&
1166 test "z$(git config branch.myr15.rebase)" = z
1169 test_expect_success 'autosetuprebase always on an untracked local branch' '
1170 git config branch.autosetuprebase always &&
1171 git config remote.local.url . &&
1172 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1173 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1174 git branch --no-track myr16 mybase2 &&
1175 test "z$(git config branch.myr16.remote)" = z &&
1176 test "z$(git config branch.myr16.merge)" = z &&
1177 test "z$(git config branch.myr16.rebase)" = z
1180 test_expect_success 'autosetuprebase never on an untracked remote branch' '
1181 git config branch.autosetuprebase never &&
1182 git config remote.local.url . &&
1183 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1184 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1185 git branch --no-track myr17 local/main &&
1186 test "z$(git config branch.myr17.remote)" = z &&
1187 test "z$(git config branch.myr17.merge)" = z &&
1188 test "z$(git config branch.myr17.rebase)" = z
1191 test_expect_success 'autosetuprebase local on an untracked remote branch' '
1192 git config branch.autosetuprebase local &&
1193 git config remote.local.url . &&
1194 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1195 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1196 git branch --no-track myr18 local/main &&
1197 test "z$(git config branch.myr18.remote)" = z &&
1198 test "z$(git config branch.myr18.merge)" = z &&
1199 test "z$(git config branch.myr18.rebase)" = z
1202 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
1203 git config branch.autosetuprebase remote &&
1204 git config remote.local.url . &&
1205 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1206 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1207 git branch --no-track myr19 local/main &&
1208 test "z$(git config branch.myr19.remote)" = z &&
1209 test "z$(git config branch.myr19.merge)" = z &&
1210 test "z$(git config branch.myr19.rebase)" = z
1213 test_expect_success 'autosetuprebase always on an untracked remote branch' '
1214 git config branch.autosetuprebase always &&
1215 git config remote.local.url . &&
1216 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1217 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1218 git branch --no-track myr20 local/main &&
1219 test "z$(git config branch.myr20.remote)" = z &&
1220 test "z$(git config branch.myr20.merge)" = z &&
1221 test "z$(git config branch.myr20.rebase)" = z
1224 test_expect_success 'autosetuprebase always on detached HEAD' '
1225 git config branch.autosetupmerge always &&
1226 test_when_finished git checkout main &&
1227 git checkout HEAD^0 &&
1228 git branch my11 &&
1229 test -z "$(git config branch.my11.remote)" &&
1230 test -z "$(git config branch.my11.merge)"
1233 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
1234 git config branch.autosetuprebase garbage &&
1235 test_must_fail git branch
1238 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
1239 git config --unset branch.autosetuprebase &&
1240 echo "[branch] autosetuprebase" >>.git/config &&
1241 test_must_fail git branch &&
1242 git config --unset branch.autosetuprebase
1245 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
1246 git checkout my9 &&
1247 git config --unset branch.my8.merge &&
1248 test_must_fail git branch -d my8
1251 test_expect_success 'attempt to delete a branch merged to its base' '
1252 # we are on my9 which is the initial commit; traditionally
1253 # we would not have allowed deleting my8 that is not merged
1254 # to my9, but it is set to track main that already has my8
1255 git config branch.my8.merge refs/heads/main &&
1256 git branch -d my8
1259 test_expect_success 'attempt to delete a branch merged to its base' '
1260 git checkout main &&
1261 echo Third >>A &&
1262 git commit -m "Third commit" A &&
1263 git branch -t my10 my9 &&
1264 git branch -f my10 HEAD^ &&
1265 # we are on main which is at the third commit, and my10
1266 # is behind us, so traditionally we would have allowed deleting
1267 # it; but my10 is set to track my9 that is further behind.
1268 test_must_fail git branch -d my10
1271 test_expect_success 'use --edit-description' '
1272 write_script editor <<-\EOF &&
1273 echo "New contents" >"$1"
1275 EDITOR=./editor git branch --edit-description &&
1276 write_script editor <<-\EOF &&
1277 git stripspace -s <"$1" >"EDITOR_OUTPUT"
1279 EDITOR=./editor git branch --edit-description &&
1280 echo "New contents" >expect &&
1281 test_cmp expect EDITOR_OUTPUT
1284 test_expect_success 'detect typo in branch name when using --edit-description' '
1285 write_script editor <<-\EOF &&
1286 echo "New contents" >"$1"
1288 test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
1291 test_expect_success 'refuse --edit-description on unborn branch for now' '
1292 test_when_finished "git checkout main" &&
1293 write_script editor <<-\EOF &&
1294 echo "New contents" >"$1"
1296 git checkout --orphan unborn &&
1297 test_must_fail env EDITOR=./editor git branch --edit-description
1300 test_expect_success '--merged catches invalid object names' '
1301 test_must_fail git branch --merged 0000000000000000000000000000000000000000
1304 test_expect_success '--list during rebase' '
1305 test_when_finished "reset_rebase" &&
1306 git checkout main &&
1307 FAKE_LINES="1 edit 2" &&
1308 export FAKE_LINES &&
1309 set_fake_editor &&
1310 git rebase -i HEAD~2 &&
1311 git branch --list >actual &&
1312 test_i18ngrep "rebasing main" actual
1315 test_expect_success '--list during rebase from detached HEAD' '
1316 test_when_finished "reset_rebase && git checkout main" &&
1317 git checkout main^0 &&
1318 oid=$(git rev-parse --short HEAD) &&
1319 FAKE_LINES="1 edit 2" &&
1320 export FAKE_LINES &&
1321 set_fake_editor &&
1322 git rebase -i HEAD~2 &&
1323 git branch --list >actual &&
1324 test_i18ngrep "rebasing detached HEAD $oid" actual
1327 test_expect_success 'tracking with unexpected .fetch refspec' '
1328 rm -rf a b c d &&
1329 git init -b main a &&
1331 cd a &&
1332 test_commit a
1333 ) &&
1334 git init -b main b &&
1336 cd b &&
1337 test_commit b
1338 ) &&
1339 git init -b main c &&
1341 cd c &&
1342 test_commit c &&
1343 git remote add a ../a &&
1344 git remote add b ../b &&
1345 git fetch --all
1346 ) &&
1347 git init -b main d &&
1349 cd d &&
1350 git remote add c ../c &&
1351 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
1352 git fetch c &&
1353 git branch --track local/a/main remotes/a/main &&
1354 test "$(git config branch.local/a/main.remote)" = "c" &&
1355 test "$(git config branch.local/a/main.merge)" = "refs/remotes/a/main" &&
1356 git rev-parse --verify a >expect &&
1357 git rev-parse --verify local/a/main >actual &&
1358 test_cmp expect actual
1362 test_expect_success 'configured committerdate sort' '
1363 git init -b main sort &&
1365 cd sort &&
1366 git config branch.sort committerdate &&
1367 test_commit initial &&
1368 git checkout -b a &&
1369 test_commit a &&
1370 git checkout -b c &&
1371 test_commit c &&
1372 git checkout -b b &&
1373 test_commit b &&
1374 git branch >actual &&
1375 cat >expect <<-\EOF &&
1376 main
1381 test_cmp expect actual
1385 test_expect_success 'option override configured sort' '
1387 cd sort &&
1388 git config branch.sort committerdate &&
1389 git branch --sort=refname >actual &&
1390 cat >expect <<-\EOF &&
1394 main
1396 test_cmp expect actual
1400 test_expect_success 'invalid sort parameter in configuration' '
1402 cd sort &&
1403 git config branch.sort "v:notvalid" &&
1404 test_must_fail git branch
1408 test_done