t: add helper to convert object IDs to paths
[git/debian.git] / t / t3200-branch.sh
blobe9d7084d19c9d650f43f97d1c389c7fbc4cc51d2
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 echo World >>A &&
16 git update-index --add A &&
17 git commit -m "Second commit." &&
18 HEAD=$(git rev-parse --verify HEAD)
21 test_expect_success 'git branch --help should not have created a bogus branch' '
22 test_might_fail git branch --man --help </dev/null >/dev/null 2>&1 &&
23 test_path_is_missing .git/refs/heads/--help
26 test_expect_success 'branch -h in broken repository' '
27 mkdir broken &&
29 cd broken &&
30 git init &&
31 >.git/refs/heads/master &&
32 test_expect_code 129 git branch -h >usage 2>&1
33 ) &&
34 test_i18ngrep "[Uu]sage" broken/usage
37 test_expect_success 'git branch abc should create a branch' '
38 git branch abc && test_path_is_file .git/refs/heads/abc
41 test_expect_success 'git branch a/b/c should create a branch' '
42 git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c
45 test_expect_success 'git branch mb master... should create a branch' '
46 git branch mb master... && test_path_is_file .git/refs/heads/mb
49 test_expect_success 'git branch HEAD should fail' '
50 test_must_fail git branch HEAD
53 cat >expect <<EOF
54 $ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
55 EOF
56 test_expect_success 'git branch --create-reflog d/e/f should create a branch and a log' '
57 GIT_COMMITTER_DATE="2005-05-26 23:30" \
58 git -c core.logallrefupdates=false branch --create-reflog d/e/f &&
59 test_path_is_file .git/refs/heads/d/e/f &&
60 test_path_is_file .git/logs/refs/heads/d/e/f &&
61 test_cmp expect .git/logs/refs/heads/d/e/f
64 test_expect_success 'git branch -d d/e/f should delete a branch and a log' '
65 git branch -d d/e/f &&
66 test_path_is_missing .git/refs/heads/d/e/f &&
67 test_must_fail git reflog exists refs/heads/d/e/f
70 test_expect_success 'git branch j/k should work after branch j has been deleted' '
71 git branch j &&
72 git branch -d j &&
73 git branch j/k
76 test_expect_success 'git branch l should work after branch l/m has been deleted' '
77 git branch l/m &&
78 git branch -d l/m &&
79 git branch l
82 test_expect_success 'git branch -m dumps usage' '
83 test_expect_code 128 git branch -m 2>err &&
84 test_i18ngrep "branch name required" err
87 test_expect_success 'git branch -m m broken_symref should work' '
88 test_when_finished "git branch -D broken_symref" &&
89 git branch --create-reflog m &&
90 git symbolic-ref refs/heads/broken_symref refs/heads/i_am_broken &&
91 git branch -m m broken_symref &&
92 git reflog exists refs/heads/broken_symref &&
93 test_must_fail git reflog exists refs/heads/i_am_broken
96 test_expect_success 'git branch -m m m/m should work' '
97 git branch --create-reflog m &&
98 git branch -m m m/m &&
99 git reflog exists refs/heads/m/m
102 test_expect_success 'git branch -m n/n n should work' '
103 git branch --create-reflog n/n &&
104 git branch -m n/n n &&
105 git reflog exists refs/heads/n
108 # The topmost entry in reflog for branch bbb is about branch creation.
109 # Hence, we compare bbb@{1} (instead of bbb@{0}) with aaa@{0}.
111 test_expect_success 'git branch -m bbb should rename checked out branch' '
112 test_when_finished git branch -D bbb &&
113 test_when_finished git checkout master &&
114 git checkout -b aaa &&
115 git commit --allow-empty -m "a new commit" &&
116 git rev-parse aaa@{0} >expect &&
117 git branch -m bbb &&
118 git rev-parse bbb@{1} >actual &&
119 test_cmp expect actual &&
120 git symbolic-ref HEAD >actual &&
121 echo refs/heads/bbb >expect &&
122 test_cmp expect actual
125 test_expect_success 'renaming checked out branch works with d/f conflict' '
126 test_when_finished "git branch -D foo/bar || git branch -D foo" &&
127 test_when_finished git checkout master &&
128 git checkout -b foo &&
129 git branch -m foo/bar &&
130 git symbolic-ref HEAD >actual &&
131 echo refs/heads/foo/bar >expect &&
132 test_cmp expect actual
135 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
136 git branch o/o &&
137 git branch o/p &&
138 test_must_fail git branch -m o/o o
141 test_expect_success 'git branch -m o/q o/p should fail when o/p exists' '
142 git branch o/q &&
143 test_must_fail git branch -m o/q o/p
146 test_expect_success 'git branch -M o/q o/p should work when o/p exists' '
147 git branch -M o/q o/p
150 test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '
151 git branch o/q &&
152 git branch -m -f o/q o/p
155 test_expect_success 'git branch -m q r/q should fail when r exists' '
156 git branch q &&
157 git branch r &&
158 test_must_fail git branch -m q r/q
161 test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
162 git branch bar &&
163 git checkout -b foo &&
164 test_must_fail git branch -M bar foo
167 test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
168 git checkout -b baz &&
169 git branch bam &&
170 git branch -M baz bam &&
171 test $(git rev-parse --abbrev-ref HEAD) = bam
174 test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' '
175 msg="Branch: renamed refs/heads/baz to refs/heads/bam" &&
176 grep " 0\{40\}.*$msg$" .git/logs/HEAD &&
177 grep "^0\{40\}.*$msg$" .git/logs/HEAD
180 test_expect_success 'git branch -M should leave orphaned HEAD alone' '
181 git init orphan &&
183 cd orphan &&
184 test_commit initial &&
185 git checkout --orphan lonely &&
186 grep lonely .git/HEAD &&
187 test_path_is_missing .git/refs/head/lonely &&
188 git branch -M master mistress &&
189 grep lonely .git/HEAD
193 test_expect_success 'resulting reflog can be shown by log -g' '
194 oid=$(git rev-parse HEAD) &&
195 cat >expect <<-EOF &&
196 HEAD@{0} $oid $msg
197 HEAD@{2} $oid checkout: moving from foo to baz
199 git log -g --format="%gd %H %gs" -2 HEAD >actual &&
200 test_cmp expect actual
203 test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' '
204 git checkout master &&
205 git worktree add -b baz bazdir &&
206 git worktree add -f bazdir2 baz &&
207 git branch -M baz bam &&
208 test $(git -C bazdir rev-parse --abbrev-ref HEAD) = bam &&
209 test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam
212 test_expect_success 'git branch -M baz bam should succeed within a worktree in which baz is checked out' '
213 git checkout -b baz &&
214 git worktree add -f bazdir3 baz &&
216 cd bazdir3 &&
217 git branch -M baz bam &&
218 test $(git rev-parse --abbrev-ref HEAD) = bam
219 ) &&
220 test $(git rev-parse --abbrev-ref HEAD) = bam
223 test_expect_success 'git branch -M master should work when master is checked out' '
224 git checkout master &&
225 git branch -M master
228 test_expect_success 'git branch -M master master should work when master is checked out' '
229 git checkout master &&
230 git branch -M master master
233 test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
234 git checkout master &&
235 git branch master2 &&
236 git branch -M master2 master2
239 test_expect_success 'git branch -v -d t should work' '
240 git branch t &&
241 git rev-parse --verify refs/heads/t &&
242 git branch -v -d t &&
243 test_must_fail git rev-parse --verify refs/heads/t
246 test_expect_success 'git branch -v -m t s should work' '
247 git branch t &&
248 git rev-parse --verify refs/heads/t &&
249 git branch -v -m t s &&
250 test_must_fail git rev-parse --verify refs/heads/t &&
251 git rev-parse --verify refs/heads/s &&
252 git branch -d s
255 test_expect_success 'git branch -m -d t s should fail' '
256 git branch t &&
257 git rev-parse refs/heads/t &&
258 test_must_fail git branch -m -d t s &&
259 git branch -d t &&
260 test_must_fail git rev-parse refs/heads/t
263 test_expect_success 'git branch --list -d t should fail' '
264 git branch t &&
265 git rev-parse refs/heads/t &&
266 test_must_fail git branch --list -d t &&
267 git branch -d t &&
268 test_must_fail git rev-parse refs/heads/t
271 test_expect_success 'deleting checked-out branch from repo that is a submodule' '
272 test_when_finished "rm -rf repo1 repo2" &&
274 git init repo1 &&
275 git init repo1/sub &&
276 test_commit -C repo1/sub x &&
277 git -C repo1 submodule add ./sub &&
278 git -C repo1 commit -m "adding sub" &&
280 git clone --recurse-submodules repo1 repo2 &&
281 git -C repo2/sub checkout -b work &&
282 test_must_fail git -C repo2/sub branch -D work
285 test_expect_success 'bare main worktree has HEAD at branch deleted by secondary worktree' '
286 test_when_finished "rm -rf nonbare base secondary" &&
288 git init nonbare &&
289 test_commit -C nonbare x &&
290 git clone --bare nonbare bare &&
291 git -C bare worktree add --detach ../secondary master &&
292 git -C secondary branch -D master
295 test_expect_success 'git branch --list -v with --abbrev' '
296 test_when_finished "git branch -D t" &&
297 git branch t &&
298 git branch -v --list t >actual.default &&
299 git branch -v --list --abbrev t >actual.abbrev &&
300 test_cmp actual.default actual.abbrev &&
302 git branch -v --list --no-abbrev t >actual.noabbrev &&
303 git branch -v --list --abbrev=0 t >actual.0abbrev &&
304 test_cmp actual.noabbrev actual.0abbrev &&
306 git branch -v --list --abbrev=36 t >actual.36abbrev &&
307 # how many hexdigits are used?
308 read name objdefault rest <actual.abbrev &&
309 read name obj36 rest <actual.36abbrev &&
310 objfull=$(git rev-parse --verify t) &&
312 # are we really getting abbreviations?
313 test "$obj36" != "$objdefault" &&
314 expr "$obj36" : "$objdefault" >/dev/null &&
315 test "$objfull" != "$obj36" &&
316 expr "$objfull" : "$obj36" >/dev/null
320 test_expect_success 'git branch --column' '
321 COLUMNS=81 git branch --column=column >actual &&
322 cat >expected <<\EOF &&
323 a/b/c bam foo l * master mb o/o q
324 abc bar j/k m/m master2 n o/p r
326 test_cmp expected actual
329 test_expect_success 'git branch --column with an extremely long branch name' '
330 long=this/is/a/part/of/long/branch/name &&
331 long=z$long/$long/$long/$long &&
332 test_when_finished "git branch -d $long" &&
333 git branch $long &&
334 COLUMNS=80 git branch --column=column >actual &&
335 cat >expected <<EOF &&
336 a/b/c
344 * master
345 master2
352 $long
354 test_cmp expected actual
357 test_expect_success 'git branch with column.*' '
358 git config column.ui column &&
359 git config column.branch "dense" &&
360 COLUMNS=80 git branch >actual &&
361 git config --unset column.branch &&
362 git config --unset column.ui &&
363 cat >expected <<\EOF &&
364 a/b/c bam foo l * master mb o/o q
365 abc bar j/k m/m master2 n o/p r
367 test_cmp expected actual
370 test_expect_success 'git branch --column -v should fail' '
371 test_must_fail git branch --column -v
374 test_expect_success 'git branch -v with column.ui ignored' '
375 git config column.ui column &&
376 COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
377 git config --unset column.ui &&
378 cat >expected <<\EOF &&
379 a/b/c
387 * master
388 master2
396 test_cmp expected actual
399 mv .git/config .git/config-saved
401 test_expect_success 'git branch -m q q2 without config should succeed' '
402 git branch -m q q2 &&
403 git branch -m q2 q
406 mv .git/config-saved .git/config
408 git config branch.s/s.dummy Hello
410 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
411 git branch --create-reflog s/s &&
412 git reflog exists refs/heads/s/s &&
413 git branch --create-reflog s/t &&
414 git reflog exists refs/heads/s/t &&
415 git branch -d s/t &&
416 git branch -m s/s s &&
417 git reflog exists refs/heads/s
420 test_expect_success 'config information was renamed, too' '
421 test $(git config branch.s.dummy) = Hello &&
422 test_must_fail git config branch.s/s.dummy
425 test_expect_success 'git branch -m correctly renames multiple config sections' '
426 test_when_finished "git checkout master" &&
427 git checkout -b source master &&
429 # Assert that a config file with multiple config sections has
430 # those sections preserved...
431 cat >expect <<-\EOF &&
432 branch.dest.key1=value1
433 some.gar.b=age
434 branch.dest.key2=value2
436 cat >config.branch <<\EOF &&
437 ;; Note the lack of -\EOF above & mixed indenting here. This is
438 ;; intentional, we are also testing that the formatting of copied
439 ;; sections is preserved.
441 ;; Comment for source. Tabs
442 [branch "source"]
443 ;; Comment for the source value
444 key1 = value1
445 ;; Comment for some.gar. Spaces
446 [some "gar"]
447 ;; Comment for the some.gar value
448 b = age
449 ;; Comment for source, again. Mixed tabs/spaces.
450 [branch "source"]
451 ;; Comment for the source value, again
452 key2 = value2
454 cat config.branch >>.git/config &&
455 git branch -m source dest &&
456 git config -f .git/config -l | grep -F -e source -e dest -e some.gar >actual &&
457 test_cmp expect actual &&
459 # ...and that the comments for those sections are also
460 # preserved.
461 cat config.branch | sed "s/\"source\"/\"dest\"/" >expect &&
462 sed -n -e "/Note the lack/,\$p" .git/config >actual &&
463 test_cmp expect actual
466 test_expect_success 'git branch -c dumps usage' '
467 test_expect_code 128 git branch -c 2>err &&
468 test_i18ngrep "branch name required" err
471 test_expect_success 'git branch --copy dumps usage' '
472 test_expect_code 128 git branch --copy 2>err &&
473 test_i18ngrep "branch name required" err
476 test_expect_success 'git branch -c d e should work' '
477 git branch --create-reflog d &&
478 git reflog exists refs/heads/d &&
479 git config branch.d.dummy Hello &&
480 git branch -c d e &&
481 git reflog exists refs/heads/d &&
482 git reflog exists refs/heads/e &&
483 echo Hello >expect &&
484 git config branch.e.dummy >actual &&
485 test_cmp expect actual &&
486 echo Hello >expect &&
487 git config branch.d.dummy >actual &&
488 test_cmp expect actual
491 test_expect_success 'git branch --copy is a synonym for -c' '
492 git branch --create-reflog copy &&
493 git reflog exists refs/heads/copy &&
494 git config branch.copy.dummy Hello &&
495 git branch --copy copy copy-to &&
496 git reflog exists refs/heads/copy &&
497 git reflog exists refs/heads/copy-to &&
498 echo Hello >expect &&
499 git config branch.copy.dummy >actual &&
500 test_cmp expect actual &&
501 echo Hello >expect &&
502 git config branch.copy-to.dummy >actual &&
503 test_cmp expect actual
506 test_expect_success 'git branch -c ee ef should copy ee to create branch ef' '
507 git checkout -b ee &&
508 git reflog exists refs/heads/ee &&
509 git config branch.ee.dummy Hello &&
510 git branch -c ee ef &&
511 git reflog exists refs/heads/ee &&
512 git reflog exists refs/heads/ef &&
513 test $(git config branch.ee.dummy) = Hello &&
514 test $(git config branch.ef.dummy) = Hello &&
515 test $(git rev-parse --abbrev-ref HEAD) = ee
518 test_expect_success 'git branch -c f/f g/g should work' '
519 git branch --create-reflog f/f &&
520 git reflog exists refs/heads/f/f &&
521 git config branch.f/f.dummy Hello &&
522 git branch -c f/f g/g &&
523 git reflog exists refs/heads/f/f &&
524 git reflog exists refs/heads/g/g &&
525 test $(git config branch.f/f.dummy) = Hello &&
526 test $(git config branch.g/g.dummy) = Hello
529 test_expect_success 'git branch -c m2 m2 should work' '
530 git branch --create-reflog m2 &&
531 git reflog exists refs/heads/m2 &&
532 git config branch.m2.dummy Hello &&
533 git branch -c m2 m2 &&
534 git reflog exists refs/heads/m2 &&
535 test $(git config branch.m2.dummy) = Hello
538 test_expect_success 'git branch -c zz zz/zz should fail' '
539 git branch --create-reflog zz &&
540 git reflog exists refs/heads/zz &&
541 test_must_fail git branch -c zz zz/zz
544 test_expect_success 'git branch -c b/b b should fail' '
545 git branch --create-reflog b/b &&
546 test_must_fail git branch -c b/b b
549 test_expect_success 'git branch -C o/q o/p should work when o/p exists' '
550 git branch --create-reflog o/q &&
551 git reflog exists refs/heads/o/q &&
552 git reflog exists refs/heads/o/p &&
553 git branch -C o/q o/p
556 test_expect_success 'git branch -c -f o/q o/p should work when o/p exists' '
557 git reflog exists refs/heads/o/q &&
558 git reflog exists refs/heads/o/p &&
559 git branch -c -f o/q o/p
562 test_expect_success 'git branch -c qq rr/qq should fail when rr exists' '
563 git branch qq &&
564 git branch rr &&
565 test_must_fail git branch -c qq rr/qq
568 test_expect_success 'git branch -C b1 b2 should fail when b2 is checked out' '
569 git branch b1 &&
570 git checkout -b b2 &&
571 test_must_fail git branch -C b1 b2
574 test_expect_success 'git branch -C c1 c2 should succeed when c1 is checked out' '
575 git checkout -b c1 &&
576 git branch c2 &&
577 git branch -C c1 c2 &&
578 test $(git rev-parse --abbrev-ref HEAD) = c1
581 test_expect_success 'git branch -C c1 c2 should never touch HEAD' '
582 msg="Branch: copied refs/heads/c1 to refs/heads/c2" &&
583 ! grep "$msg$" .git/logs/HEAD
586 test_expect_success 'git branch -C master should work when master is checked out' '
587 git checkout master &&
588 git branch -C master
591 test_expect_success 'git branch -C master master should work when master is checked out' '
592 git checkout master &&
593 git branch -C master master
596 test_expect_success 'git branch -C master5 master5 should work when master is checked out' '
597 git checkout master &&
598 git branch master5 &&
599 git branch -C master5 master5
602 test_expect_success 'git branch -C ab cd should overwrite existing config for cd' '
603 git branch --create-reflog cd &&
604 git reflog exists refs/heads/cd &&
605 git config branch.cd.dummy CD &&
606 git branch --create-reflog ab &&
607 git reflog exists refs/heads/ab &&
608 git config branch.ab.dummy AB &&
609 git branch -C ab cd &&
610 git reflog exists refs/heads/ab &&
611 git reflog exists refs/heads/cd &&
612 test $(git config branch.ab.dummy) = AB &&
613 test $(git config branch.cd.dummy) = AB
616 test_expect_success 'git branch -c correctly copies multiple config sections' '
617 FOO=1 &&
618 export FOO &&
619 test_when_finished "git checkout master" &&
620 git checkout -b source2 master &&
622 # Assert that a config file with multiple config sections has
623 # those sections preserved...
624 cat >expect <<-\EOF &&
625 branch.source2.key1=value1
626 branch.dest2.key1=value1
627 more.gar.b=age
628 branch.source2.key2=value2
629 branch.dest2.key2=value2
631 cat >config.branch <<\EOF &&
632 ;; Note the lack of -\EOF above & mixed indenting here. This is
633 ;; intentional, we are also testing that the formatting of copied
634 ;; sections is preserved.
636 ;; Comment for source2. Tabs
637 [branch "source2"]
638 ;; Comment for the source2 value
639 key1 = value1
640 ;; Comment for more.gar. Spaces
641 [more "gar"]
642 ;; Comment for the more.gar value
643 b = age
644 ;; Comment for source2, again. Mixed tabs/spaces.
645 [branch "source2"]
646 ;; Comment for the source2 value, again
647 key2 = value2
649 cat config.branch >>.git/config &&
650 git branch -c source2 dest2 &&
651 git config -f .git/config -l | grep -F -e source2 -e dest2 -e more.gar >actual &&
652 test_cmp expect actual &&
654 # ...and that the comments and formatting for those sections
655 # is also preserved.
656 cat >expect <<\EOF &&
657 ;; Comment for source2. Tabs
658 [branch "source2"]
659 ;; Comment for the source2 value
660 key1 = value1
661 ;; Comment for more.gar. Spaces
662 [branch "dest2"]
663 ;; Comment for the source2 value
664 key1 = value1
665 ;; Comment for more.gar. Spaces
666 [more "gar"]
667 ;; Comment for the more.gar value
668 b = age
669 ;; Comment for source2, again. Mixed tabs/spaces.
670 [branch "source2"]
671 ;; Comment for the source2 value, again
672 key2 = value2
673 [branch "dest2"]
674 ;; Comment for the source2 value, again
675 key2 = value2
677 sed -n -e "/Comment for source2/,\$p" .git/config >actual &&
678 test_cmp expect actual
681 test_expect_success 'deleting a symref' '
682 git branch target &&
683 git symbolic-ref refs/heads/symref refs/heads/target &&
684 echo "Deleted branch symref (was refs/heads/target)." >expect &&
685 git branch -d symref >actual &&
686 test_path_is_file .git/refs/heads/target &&
687 test_path_is_missing .git/refs/heads/symref &&
688 test_i18ncmp expect actual
691 test_expect_success 'deleting a dangling symref' '
692 git symbolic-ref refs/heads/dangling-symref nowhere &&
693 test_path_is_file .git/refs/heads/dangling-symref &&
694 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
695 git branch -d dangling-symref >actual &&
696 test_path_is_missing .git/refs/heads/dangling-symref &&
697 test_i18ncmp expect actual
700 test_expect_success 'deleting a self-referential symref' '
701 git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
702 test_path_is_file .git/refs/heads/self-reference &&
703 echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
704 git branch -d self-reference >actual &&
705 test_path_is_missing .git/refs/heads/self-reference &&
706 test_i18ncmp expect actual
709 test_expect_success 'renaming a symref is not allowed' '
710 git symbolic-ref refs/heads/master2 refs/heads/master &&
711 test_must_fail git branch -m master2 master3 &&
712 git symbolic-ref refs/heads/master2 &&
713 test_path_is_file .git/refs/heads/master &&
714 test_path_is_missing .git/refs/heads/master3
717 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
718 git branch --create-reflog u &&
719 mv .git/logs/refs/heads/u real-u &&
720 ln -s real-u .git/logs/refs/heads/u &&
721 test_must_fail git branch -m u v
724 test_expect_success 'test tracking setup via --track' '
725 git config remote.local.url . &&
726 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
727 (git show-ref -q refs/remotes/local/master || git fetch local) &&
728 git branch --track my1 local/master &&
729 test $(git config branch.my1.remote) = local &&
730 test $(git config branch.my1.merge) = refs/heads/master
733 test_expect_success 'test tracking setup (non-wildcard, matching)' '
734 git config remote.local.url . &&
735 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
736 (git show-ref -q refs/remotes/local/master || git fetch local) &&
737 git branch --track my4 local/master &&
738 test $(git config branch.my4.remote) = local &&
739 test $(git config branch.my4.merge) = refs/heads/master
742 test_expect_success 'tracking setup fails on non-matching refspec' '
743 git config remote.local.url . &&
744 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
745 (git show-ref -q refs/remotes/local/master || git fetch local) &&
746 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
747 test_must_fail git branch --track my5 local/master &&
748 test_must_fail git config branch.my5.remote &&
749 test_must_fail git config branch.my5.merge
752 test_expect_success 'test tracking setup via config' '
753 git config branch.autosetupmerge true &&
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/master || git fetch local) &&
757 git branch my3 local/master &&
758 test $(git config branch.my3.remote) = local &&
759 test $(git config branch.my3.merge) = refs/heads/master
762 test_expect_success 'test overriding tracking setup via --no-track' '
763 git config branch.autosetupmerge true &&
764 git config remote.local.url . &&
765 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
766 (git show-ref -q refs/remotes/local/master || git fetch local) &&
767 git branch --no-track my2 local/master &&
768 git config branch.autosetupmerge false &&
769 ! test "$(git config branch.my2.remote)" = local &&
770 ! test "$(git config branch.my2.merge)" = refs/heads/master
773 test_expect_success 'no tracking without .fetch entries' '
774 git config branch.autosetupmerge true &&
775 git branch my6 s &&
776 git config branch.autosetupmerge false &&
777 test -z "$(git config branch.my6.remote)" &&
778 test -z "$(git config branch.my6.merge)"
781 test_expect_success 'test tracking setup via --track but deeper' '
782 git config remote.local.url . &&
783 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
784 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
785 git branch --track my7 local/o/o &&
786 test "$(git config branch.my7.remote)" = local &&
787 test "$(git config branch.my7.merge)" = refs/heads/o/o
790 test_expect_success 'test deleting branch deletes branch config' '
791 git branch -d my7 &&
792 test -z "$(git config branch.my7.remote)" &&
793 test -z "$(git config branch.my7.merge)"
796 test_expect_success 'test deleting branch without config' '
797 git branch my7 s &&
798 sha1=$(git rev-parse my7 | cut -c 1-7) &&
799 echo "Deleted branch my7 (was $sha1)." >expect &&
800 git branch -d my7 >actual 2>&1 &&
801 test_i18ncmp expect actual
804 test_expect_success 'deleting currently checked out branch fails' '
805 git worktree add -b my7 my7 &&
806 test_must_fail git -C my7 branch -d my7 &&
807 test_must_fail git branch -d my7
810 test_expect_success 'test --track without .fetch entries' '
811 git branch --track my8 &&
812 test "$(git config branch.my8.remote)" &&
813 test "$(git config branch.my8.merge)"
816 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
817 git config branch.autosetupmerge always &&
818 git branch my9 HEAD^ &&
819 git config branch.autosetupmerge false
822 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
823 test_must_fail git branch --track my10 HEAD^
826 test_expect_success 'branch from tag w/--track causes failure' '
827 git tag foobar &&
828 test_must_fail git branch --track my11 foobar
831 test_expect_success '--set-upstream-to fails on multiple branches' '
832 test_must_fail git branch --set-upstream-to master a b c
835 test_expect_success '--set-upstream-to fails on detached HEAD' '
836 git checkout HEAD^{} &&
837 test_must_fail git branch --set-upstream-to master &&
838 git checkout -
841 test_expect_success '--set-upstream-to fails on a missing dst branch' '
842 test_must_fail git branch --set-upstream-to master does-not-exist
845 test_expect_success '--set-upstream-to fails on a missing src branch' '
846 test_must_fail git branch --set-upstream-to does-not-exist master
849 test_expect_success '--set-upstream-to fails on a non-ref' '
850 test_must_fail git branch --set-upstream-to HEAD^{}
853 test_expect_success '--set-upstream-to fails on locked config' '
854 test_when_finished "rm -f .git/config.lock" &&
855 >.git/config.lock &&
856 git branch locked &&
857 test_must_fail git branch --set-upstream-to locked
860 test_expect_success 'use --set-upstream-to modify HEAD' '
861 test_config branch.master.remote foo &&
862 test_config branch.master.merge foo &&
863 git branch my12 &&
864 git branch --set-upstream-to my12 &&
865 test "$(git config branch.master.remote)" = "." &&
866 test "$(git config branch.master.merge)" = "refs/heads/my12"
869 test_expect_success 'use --set-upstream-to modify a particular branch' '
870 git branch my13 &&
871 git branch --set-upstream-to master my13 &&
872 test_when_finished "git branch --unset-upstream my13" &&
873 test "$(git config branch.my13.remote)" = "." &&
874 test "$(git config branch.my13.merge)" = "refs/heads/master"
877 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
878 test_must_fail git branch --unset-upstream i-dont-exist
881 test_expect_success '--unset-upstream should fail if config is locked' '
882 test_when_finished "rm -f .git/config.lock" &&
883 git branch --set-upstream-to locked &&
884 >.git/config.lock &&
885 test_must_fail git branch --unset-upstream
888 test_expect_success 'test --unset-upstream on HEAD' '
889 git branch my14 &&
890 test_config branch.master.remote foo &&
891 test_config branch.master.merge foo &&
892 git branch --set-upstream-to my14 &&
893 git branch --unset-upstream &&
894 test_must_fail git config branch.master.remote &&
895 test_must_fail git config branch.master.merge &&
896 # fail for a branch without upstream set
897 test_must_fail git branch --unset-upstream
900 test_expect_success '--unset-upstream should fail on multiple branches' '
901 test_must_fail git branch --unset-upstream a b c
904 test_expect_success '--unset-upstream should fail on detached HEAD' '
905 git checkout HEAD^{} &&
906 test_must_fail git branch --unset-upstream &&
907 git checkout -
910 test_expect_success 'test --unset-upstream on a particular branch' '
911 git branch my15 &&
912 git branch --set-upstream-to master my14 &&
913 git branch --unset-upstream my14 &&
914 test_must_fail git config branch.my14.remote &&
915 test_must_fail git config branch.my14.merge
918 test_expect_success 'disabled option --set-upstream fails' '
919 test_must_fail git branch --set-upstream origin/master
922 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
923 git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
924 cat >expected <<-\EOF &&
925 warning: Not setting branch my13 as its own upstream.
927 test_expect_code 1 git config branch.my13.remote &&
928 test_expect_code 1 git config branch.my13.merge &&
929 test_i18ncmp expected actual
932 # Keep this test last, as it changes the current branch
933 cat >expect <<EOF
934 $ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
936 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
937 GIT_COMMITTER_DATE="2005-05-26 23:30" \
938 git checkout -b g/h/i -l master &&
939 test_path_is_file .git/refs/heads/g/h/i &&
940 test_path_is_file .git/logs/refs/heads/g/h/i &&
941 test_cmp expect .git/logs/refs/heads/g/h/i
944 test_expect_success 'checkout -b makes reflog by default' '
945 git checkout master &&
946 git config --unset core.logAllRefUpdates &&
947 git checkout -b alpha &&
948 git rev-parse --verify alpha@{0}
951 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
952 git checkout master &&
953 git config core.logAllRefUpdates false &&
954 git checkout -b beta &&
955 test_must_fail git rev-parse --verify beta@{0}
958 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
959 git checkout master &&
960 git checkout -lb gamma &&
961 git config --unset core.logAllRefUpdates &&
962 git rev-parse --verify gamma@{0}
965 test_expect_success 'avoid ambiguous track' '
966 git config branch.autosetupmerge true &&
967 git config remote.ambi1.url lalala &&
968 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
969 git config remote.ambi2.url lilili &&
970 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
971 test_must_fail git branch all1 master &&
972 test -z "$(git config branch.all1.merge)"
975 test_expect_success 'autosetuprebase local on a tracked local branch' '
976 git config remote.local.url . &&
977 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
978 git config branch.autosetuprebase local &&
979 (git show-ref -q refs/remotes/local/o || git fetch local) &&
980 git branch mybase &&
981 git branch --track myr1 mybase &&
982 test "$(git config branch.myr1.remote)" = . &&
983 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
984 test "$(git config branch.myr1.rebase)" = true
987 test_expect_success 'autosetuprebase always on a tracked local branch' '
988 git config remote.local.url . &&
989 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
990 git config branch.autosetuprebase always &&
991 (git show-ref -q refs/remotes/local/o || git fetch local) &&
992 git branch mybase2 &&
993 git branch --track myr2 mybase &&
994 test "$(git config branch.myr2.remote)" = . &&
995 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
996 test "$(git config branch.myr2.rebase)" = true
999 test_expect_success 'autosetuprebase remote on a tracked local branch' '
1000 git config remote.local.url . &&
1001 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1002 git config branch.autosetuprebase remote &&
1003 (git show-ref -q refs/remotes/local/o || git fetch local) &&
1004 git branch mybase3 &&
1005 git branch --track myr3 mybase2 &&
1006 test "$(git config branch.myr3.remote)" = . &&
1007 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
1008 ! test "$(git config branch.myr3.rebase)" = true
1011 test_expect_success 'autosetuprebase never on a tracked local branch' '
1012 git config remote.local.url . &&
1013 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1014 git config branch.autosetuprebase never &&
1015 (git show-ref -q refs/remotes/local/o || git fetch local) &&
1016 git branch mybase4 &&
1017 git branch --track myr4 mybase2 &&
1018 test "$(git config branch.myr4.remote)" = . &&
1019 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
1020 ! test "$(git config branch.myr4.rebase)" = true
1023 test_expect_success 'autosetuprebase local on a tracked remote branch' '
1024 git config remote.local.url . &&
1025 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1026 git config branch.autosetuprebase local &&
1027 (git show-ref -q refs/remotes/local/master || git fetch local) &&
1028 git branch --track myr5 local/master &&
1029 test "$(git config branch.myr5.remote)" = local &&
1030 test "$(git config branch.myr5.merge)" = refs/heads/master &&
1031 ! test "$(git config branch.myr5.rebase)" = true
1034 test_expect_success 'autosetuprebase never on a tracked remote branch' '
1035 git config remote.local.url . &&
1036 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1037 git config branch.autosetuprebase never &&
1038 (git show-ref -q refs/remotes/local/master || git fetch local) &&
1039 git branch --track myr6 local/master &&
1040 test "$(git config branch.myr6.remote)" = local &&
1041 test "$(git config branch.myr6.merge)" = refs/heads/master &&
1042 ! test "$(git config branch.myr6.rebase)" = true
1045 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
1046 git config remote.local.url . &&
1047 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1048 git config branch.autosetuprebase remote &&
1049 (git show-ref -q refs/remotes/local/master || git fetch local) &&
1050 git branch --track myr7 local/master &&
1051 test "$(git config branch.myr7.remote)" = local &&
1052 test "$(git config branch.myr7.merge)" = refs/heads/master &&
1053 test "$(git config branch.myr7.rebase)" = true
1056 test_expect_success 'autosetuprebase always on a tracked remote branch' '
1057 git config remote.local.url . &&
1058 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1059 git config branch.autosetuprebase remote &&
1060 (git show-ref -q refs/remotes/local/master || git fetch local) &&
1061 git branch --track myr8 local/master &&
1062 test "$(git config branch.myr8.remote)" = local &&
1063 test "$(git config branch.myr8.merge)" = refs/heads/master &&
1064 test "$(git config branch.myr8.rebase)" = true
1067 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
1068 git config --unset branch.autosetuprebase &&
1069 git config remote.local.url . &&
1070 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1071 (git show-ref -q refs/remotes/local/master || git fetch local) &&
1072 git branch --track myr9 local/master &&
1073 test "$(git config branch.myr9.remote)" = local &&
1074 test "$(git config branch.myr9.merge)" = refs/heads/master &&
1075 test "z$(git config branch.myr9.rebase)" = z
1078 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
1079 git config remote.local.url . &&
1080 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1081 (git show-ref -q refs/remotes/local/o || git fetch local) &&
1082 git branch mybase10 &&
1083 git branch --track myr10 mybase2 &&
1084 test "$(git config branch.myr10.remote)" = . &&
1085 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
1086 test "z$(git config branch.myr10.rebase)" = z
1089 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
1090 git config remote.local.url . &&
1091 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1092 (git show-ref -q refs/remotes/local/master || git fetch local) &&
1093 git branch --no-track myr11 mybase2 &&
1094 test "z$(git config branch.myr11.remote)" = z &&
1095 test "z$(git config branch.myr11.merge)" = z &&
1096 test "z$(git config branch.myr11.rebase)" = z
1099 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
1100 git config remote.local.url . &&
1101 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1102 (git show-ref -q refs/remotes/local/master || git fetch local) &&
1103 git branch --no-track myr12 local/master &&
1104 test "z$(git config branch.myr12.remote)" = z &&
1105 test "z$(git config branch.myr12.merge)" = z &&
1106 test "z$(git config branch.myr12.rebase)" = z
1109 test_expect_success 'autosetuprebase never on an untracked local branch' '
1110 git config branch.autosetuprebase never &&
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/master || git fetch local) &&
1114 git branch --no-track myr13 mybase2 &&
1115 test "z$(git config branch.myr13.remote)" = z &&
1116 test "z$(git config branch.myr13.merge)" = z &&
1117 test "z$(git config branch.myr13.rebase)" = z
1120 test_expect_success 'autosetuprebase local on an untracked local branch' '
1121 git config branch.autosetuprebase local &&
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/master || git fetch local) &&
1125 git branch --no-track myr14 mybase2 &&
1126 test "z$(git config branch.myr14.remote)" = z &&
1127 test "z$(git config branch.myr14.merge)" = z &&
1128 test "z$(git config branch.myr14.rebase)" = z
1131 test_expect_success 'autosetuprebase remote on an untracked local branch' '
1132 git config branch.autosetuprebase remote &&
1133 git config remote.local.url . &&
1134 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1135 (git show-ref -q refs/remotes/local/master || git fetch local) &&
1136 git branch --no-track myr15 mybase2 &&
1137 test "z$(git config branch.myr15.remote)" = z &&
1138 test "z$(git config branch.myr15.merge)" = z &&
1139 test "z$(git config branch.myr15.rebase)" = z
1142 test_expect_success 'autosetuprebase always on an untracked local branch' '
1143 git config branch.autosetuprebase always &&
1144 git config remote.local.url . &&
1145 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1146 (git show-ref -q refs/remotes/local/master || git fetch local) &&
1147 git branch --no-track myr16 mybase2 &&
1148 test "z$(git config branch.myr16.remote)" = z &&
1149 test "z$(git config branch.myr16.merge)" = z &&
1150 test "z$(git config branch.myr16.rebase)" = z
1153 test_expect_success 'autosetuprebase never on an untracked remote branch' '
1154 git config branch.autosetuprebase never &&
1155 git config remote.local.url . &&
1156 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1157 (git show-ref -q refs/remotes/local/master || git fetch local) &&
1158 git branch --no-track myr17 local/master &&
1159 test "z$(git config branch.myr17.remote)" = z &&
1160 test "z$(git config branch.myr17.merge)" = z &&
1161 test "z$(git config branch.myr17.rebase)" = z
1164 test_expect_success 'autosetuprebase local on an untracked remote branch' '
1165 git config branch.autosetuprebase local &&
1166 git config remote.local.url . &&
1167 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1168 (git show-ref -q refs/remotes/local/master || git fetch local) &&
1169 git branch --no-track myr18 local/master &&
1170 test "z$(git config branch.myr18.remote)" = z &&
1171 test "z$(git config branch.myr18.merge)" = z &&
1172 test "z$(git config branch.myr18.rebase)" = z
1175 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
1176 git config branch.autosetuprebase remote &&
1177 git config remote.local.url . &&
1178 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1179 (git show-ref -q refs/remotes/local/master || git fetch local) &&
1180 git branch --no-track myr19 local/master &&
1181 test "z$(git config branch.myr19.remote)" = z &&
1182 test "z$(git config branch.myr19.merge)" = z &&
1183 test "z$(git config branch.myr19.rebase)" = z
1186 test_expect_success 'autosetuprebase always on an untracked remote branch' '
1187 git config branch.autosetuprebase always &&
1188 git config remote.local.url . &&
1189 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1190 (git show-ref -q refs/remotes/local/master || git fetch local) &&
1191 git branch --no-track myr20 local/master &&
1192 test "z$(git config branch.myr20.remote)" = z &&
1193 test "z$(git config branch.myr20.merge)" = z &&
1194 test "z$(git config branch.myr20.rebase)" = z
1197 test_expect_success 'autosetuprebase always on detached HEAD' '
1198 git config branch.autosetupmerge always &&
1199 test_when_finished git checkout master &&
1200 git checkout HEAD^0 &&
1201 git branch my11 &&
1202 test -z "$(git config branch.my11.remote)" &&
1203 test -z "$(git config branch.my11.merge)"
1206 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
1207 git config branch.autosetuprebase garbage &&
1208 test_must_fail git branch
1211 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
1212 git config --unset branch.autosetuprebase &&
1213 echo "[branch] autosetuprebase" >>.git/config &&
1214 test_must_fail git branch &&
1215 git config --unset branch.autosetuprebase
1218 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
1219 git checkout my9 &&
1220 git config --unset branch.my8.merge &&
1221 test_must_fail git branch -d my8
1224 test_expect_success 'attempt to delete a branch merged to its base' '
1225 # we are on my9 which is the initial commit; traditionally
1226 # we would not have allowed deleting my8 that is not merged
1227 # to my9, but it is set to track master that already has my8
1228 git config branch.my8.merge refs/heads/master &&
1229 git branch -d my8
1232 test_expect_success 'attempt to delete a branch merged to its base' '
1233 git checkout master &&
1234 echo Third >>A &&
1235 git commit -m "Third commit" A &&
1236 git branch -t my10 my9 &&
1237 git branch -f my10 HEAD^ &&
1238 # we are on master which is at the third commit, and my10
1239 # is behind us, so traditionally we would have allowed deleting
1240 # it; but my10 is set to track my9 that is further behind.
1241 test_must_fail git branch -d my10
1244 test_expect_success 'use --edit-description' '
1245 write_script editor <<-\EOF &&
1246 echo "New contents" >"$1"
1248 EDITOR=./editor git branch --edit-description &&
1249 write_script editor <<-\EOF &&
1250 git stripspace -s <"$1" >"EDITOR_OUTPUT"
1252 EDITOR=./editor git branch --edit-description &&
1253 echo "New contents" >expect &&
1254 test_cmp expect EDITOR_OUTPUT
1257 test_expect_success 'detect typo in branch name when using --edit-description' '
1258 write_script editor <<-\EOF &&
1259 echo "New contents" >"$1"
1261 test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
1264 test_expect_success 'refuse --edit-description on unborn branch for now' '
1265 write_script editor <<-\EOF &&
1266 echo "New contents" >"$1"
1268 git checkout --orphan unborn &&
1269 test_must_fail env EDITOR=./editor git branch --edit-description
1272 test_expect_success '--merged catches invalid object names' '
1273 test_must_fail git branch --merged 0000000000000000000000000000000000000000
1276 test_expect_success '--merged is incompatible with --no-merged' '
1277 test_must_fail git branch --merged HEAD --no-merged HEAD
1280 test_expect_success '--list during rebase' '
1281 test_when_finished "reset_rebase" &&
1282 git checkout master &&
1283 FAKE_LINES="1 edit 2" &&
1284 export FAKE_LINES &&
1285 set_fake_editor &&
1286 git rebase -i HEAD~2 &&
1287 git branch --list >actual &&
1288 test_i18ngrep "rebasing master" actual
1291 test_expect_success '--list during rebase from detached HEAD' '
1292 test_when_finished "reset_rebase && git checkout master" &&
1293 git checkout master^0 &&
1294 oid=$(git rev-parse --short HEAD) &&
1295 FAKE_LINES="1 edit 2" &&
1296 export FAKE_LINES &&
1297 set_fake_editor &&
1298 git rebase -i HEAD~2 &&
1299 git branch --list >actual &&
1300 test_i18ngrep "rebasing detached HEAD $oid" actual
1303 test_expect_success 'tracking with unexpected .fetch refspec' '
1304 rm -rf a b c d &&
1305 git init a &&
1307 cd a &&
1308 test_commit a
1309 ) &&
1310 git init b &&
1312 cd b &&
1313 test_commit b
1314 ) &&
1315 git init c &&
1317 cd c &&
1318 test_commit c &&
1319 git remote add a ../a &&
1320 git remote add b ../b &&
1321 git fetch --all
1322 ) &&
1323 git init d &&
1325 cd d &&
1326 git remote add c ../c &&
1327 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
1328 git fetch c &&
1329 git branch --track local/a/master remotes/a/master &&
1330 test "$(git config branch.local/a/master.remote)" = "c" &&
1331 test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
1332 git rev-parse --verify a >expect &&
1333 git rev-parse --verify local/a/master >actual &&
1334 test_cmp expect actual
1338 test_expect_success 'configured committerdate sort' '
1339 git init sort &&
1341 cd sort &&
1342 git config branch.sort committerdate &&
1343 test_commit initial &&
1344 git checkout -b a &&
1345 test_commit a &&
1346 git checkout -b c &&
1347 test_commit c &&
1348 git checkout -b b &&
1349 test_commit b &&
1350 git branch >actual &&
1351 cat >expect <<-\EOF &&
1352 master
1357 test_cmp expect actual
1361 test_expect_success 'option override configured sort' '
1363 cd sort &&
1364 git config branch.sort committerdate &&
1365 git branch --sort=refname >actual &&
1366 cat >expect <<-\EOF &&
1370 master
1372 test_cmp expect actual
1376 test_expect_success 'invalid sort parameter in configuration' '
1378 cd sort &&
1379 git config branch.sort "v:notvalid" &&
1380 test_must_fail git branch
1384 test_done