Merge branch 'cc/access-on-aix-workaround'
[git] / t / t3200-branch.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Amos Waterland
4 #
5
6 test_description='git branch assorted tests'
7
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/lib-rebase.sh
10
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)
19 '
20
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
24 '
25
26 test_expect_success 'branch -h in broken repository' '
27         mkdir broken &&
28         (
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
35 '
36
37 test_expect_success 'git branch abc should create a branch' '
38         git branch abc && test_path_is_file .git/refs/heads/abc
39 '
40
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
43 '
44
45 test_expect_success 'git branch HEAD should fail' '
46         test_must_fail git branch HEAD
47 '
48
49 cat >expect <<EOF
50 $ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000     branch: Created from master
51 EOF
52 test_expect_success 'git branch --create-reflog d/e/f should create a branch and a log' '
53         GIT_COMMITTER_DATE="2005-05-26 23:30" \
54         git -c core.logallrefupdates=false branch --create-reflog d/e/f &&
55         test_path_is_file .git/refs/heads/d/e/f &&
56         test_path_is_file .git/logs/refs/heads/d/e/f &&
57         test_cmp expect .git/logs/refs/heads/d/e/f
58 '
59
60 test_expect_success 'git branch -d d/e/f should delete a branch and a log' '
61         git branch -d d/e/f &&
62         test_path_is_missing .git/refs/heads/d/e/f &&
63         test_must_fail git reflog exists refs/heads/d/e/f
64 '
65
66 test_expect_success 'git branch j/k should work after branch j has been deleted' '
67         git branch j &&
68         git branch -d j &&
69         git branch j/k
70 '
71
72 test_expect_success 'git branch l should work after branch l/m has been deleted' '
73         git branch l/m &&
74         git branch -d l/m &&
75         git branch l
76 '
77
78 test_expect_success 'git branch -m dumps usage' '
79         test_expect_code 128 git branch -m 2>err &&
80         test_i18ngrep "branch name required" err
81 '
82
83 test_expect_success 'git branch -m m broken_symref should work' '
84         test_when_finished "git branch -D broken_symref" &&
85         git branch --create-reflog m &&
86         git symbolic-ref refs/heads/broken_symref refs/heads/i_am_broken &&
87         git branch -m m broken_symref &&
88         git reflog exists refs/heads/broken_symref &&
89         test_must_fail git reflog exists refs/heads/i_am_broken
90 '
91
92 test_expect_success 'git branch -m m m/m should work' '
93         git branch --create-reflog m &&
94         git branch -m m m/m &&
95         git reflog exists refs/heads/m/m
96 '
97
98 test_expect_success 'git branch -m n/n n should work' '
99         git branch --create-reflog n/n &&
100         git branch -m n/n n &&
101         git reflog exists refs/heads/n
102 '
103
104 # The topmost entry in reflog for branch bbb is about branch creation.
105 # Hence, we compare bbb@{1} (instead of bbb@{0}) with aaa@{0}.
106
107 test_expect_success 'git branch -m bbb should rename checked out branch' '
108         test_when_finished git branch -D bbb &&
109         test_when_finished git checkout master &&
110         git checkout -b aaa &&
111         git commit --allow-empty -m "a new commit" &&
112         git rev-parse aaa@{0} >expect &&
113         git branch -m bbb &&
114         git rev-parse bbb@{1} >actual &&
115         test_cmp expect actual &&
116         git symbolic-ref HEAD >actual &&
117         echo refs/heads/bbb >expect &&
118         test_cmp expect actual
119 '
120
121 test_expect_success 'renaming checked out branch works with d/f conflict' '
122         test_when_finished "git branch -D foo/bar || git branch -D foo" &&
123         test_when_finished git checkout master &&
124         git checkout -b foo &&
125         git branch -m foo/bar &&
126         git symbolic-ref HEAD >actual &&
127         echo refs/heads/foo/bar >expect &&
128         test_cmp expect actual
129 '
130
131 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
132         git branch o/o &&
133         git branch o/p &&
134         test_must_fail git branch -m o/o o
135 '
136
137 test_expect_success 'git branch -m o/q o/p should fail when o/p exists' '
138         git branch o/q &&
139         test_must_fail git branch -m o/q o/p
140 '
141
142 test_expect_success 'git branch -M o/q o/p should work when o/p exists' '
143         git branch -M o/q o/p
144 '
145
146 test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '
147         git branch o/q &&
148         git branch -m -f o/q o/p
149 '
150
151 test_expect_success 'git branch -m q r/q should fail when r exists' '
152         git branch q &&
153         git branch r &&
154         test_must_fail git branch -m q r/q
155 '
156
157 test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
158         git branch bar &&
159         git checkout -b foo &&
160         test_must_fail git branch -M bar foo
161 '
162
163 test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
164         git checkout -b baz &&
165         git branch bam &&
166         git branch -M baz bam &&
167         test $(git rev-parse --abbrev-ref HEAD) = bam
168 '
169
170 test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' '
171         msg="Branch: renamed refs/heads/baz to refs/heads/bam" &&
172         grep " 0\{40\}.*$msg$" .git/logs/HEAD &&
173         grep "^0\{40\}.*$msg$" .git/logs/HEAD
174 '
175
176 test_expect_success 'git branch -M should leave orphaned HEAD alone' '
177         git init orphan &&
178         (
179                 cd orphan &&
180                 test_commit initial &&
181                 git checkout --orphan lonely &&
182                 grep lonely .git/HEAD &&
183                 test_path_is_missing .git/refs/head/lonely &&
184                 git branch -M master mistress &&
185                 grep lonely .git/HEAD
186         )
187 '
188
189 test_expect_success 'resulting reflog can be shown by log -g' '
190         oid=$(git rev-parse HEAD) &&
191         cat >expect <<-EOF &&
192         HEAD@{0} $oid $msg
193         HEAD@{2} $oid checkout: moving from foo to baz
194         EOF
195         git log -g --format="%gd %H %gs" -2 HEAD >actual &&
196         test_cmp expect actual
197 '
198
199 test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' '
200         git checkout master &&
201         git worktree add -b baz bazdir &&
202         git worktree add -f bazdir2 baz &&
203         git branch -M baz bam &&
204         test $(git -C bazdir rev-parse --abbrev-ref HEAD) = bam &&
205         test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam
206 '
207
208 test_expect_success 'git branch -M baz bam should succeed within a worktree in which baz is checked out' '
209         git checkout -b baz &&
210         git worktree add -f bazdir3 baz &&
211         (
212                 cd bazdir3 &&
213                 git branch -M baz bam &&
214                 test $(git rev-parse --abbrev-ref HEAD) = bam
215         ) &&
216         test $(git rev-parse --abbrev-ref HEAD) = bam
217 '
218
219 test_expect_success 'git branch -M master should work when master is checked out' '
220         git checkout master &&
221         git branch -M master
222 '
223
224 test_expect_success 'git branch -M master master should work when master is checked out' '
225         git checkout master &&
226         git branch -M master master
227 '
228
229 test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
230         git checkout master &&
231         git branch master2 &&
232         git branch -M master2 master2
233 '
234
235 test_expect_success 'git branch -v -d t should work' '
236         git branch t &&
237         git rev-parse --verify refs/heads/t &&
238         git branch -v -d t &&
239         test_must_fail git rev-parse --verify refs/heads/t
240 '
241
242 test_expect_success 'git branch -v -m t s should work' '
243         git branch t &&
244         git rev-parse --verify refs/heads/t &&
245         git branch -v -m t s &&
246         test_must_fail git rev-parse --verify refs/heads/t &&
247         git rev-parse --verify refs/heads/s &&
248         git branch -d s
249 '
250
251 test_expect_success 'git branch -m -d t s should fail' '
252         git branch t &&
253         git rev-parse refs/heads/t &&
254         test_must_fail git branch -m -d t s &&
255         git branch -d t &&
256         test_must_fail git rev-parse refs/heads/t
257 '
258
259 test_expect_success 'git branch --list -d t should fail' '
260         git branch t &&
261         git rev-parse refs/heads/t &&
262         test_must_fail git branch --list -d t &&
263         git branch -d t &&
264         test_must_fail git rev-parse refs/heads/t
265 '
266
267 test_expect_success 'deleting checked-out branch from repo that is a submodule' '
268         test_when_finished "rm -rf repo1 repo2" &&
269
270         git init repo1 &&
271         git init repo1/sub &&
272         test_commit -C repo1/sub x &&
273         git -C repo1 submodule add ./sub &&
274         git -C repo1 commit -m "adding sub" &&
275
276         git clone --recurse-submodules repo1 repo2 &&
277         git -C repo2/sub checkout -b work &&
278         test_must_fail git -C repo2/sub branch -D work
279 '
280
281 test_expect_success 'bare main worktree has HEAD at branch deleted by secondary worktree' '
282         test_when_finished "rm -rf nonbare base secondary" &&
283
284         git init nonbare &&
285         test_commit -C nonbare x &&
286         git clone --bare nonbare bare &&
287         git -C bare worktree add --detach ../secondary master &&
288         git -C secondary branch -D master
289 '
290
291 test_expect_success 'git branch --list -v with --abbrev' '
292         test_when_finished "git branch -D t" &&
293         git branch t &&
294         git branch -v --list t >actual.default &&
295         git branch -v --list --abbrev t >actual.abbrev &&
296         test_cmp actual.default actual.abbrev &&
297
298         git branch -v --list --no-abbrev t >actual.noabbrev &&
299         git branch -v --list --abbrev=0 t >actual.0abbrev &&
300         test_cmp actual.noabbrev actual.0abbrev &&
301
302         git branch -v --list --abbrev=36 t >actual.36abbrev &&
303         # how many hexdigits are used?
304         read name objdefault rest <actual.abbrev &&
305         read name obj36 rest <actual.36abbrev &&
306         objfull=$(git rev-parse --verify t) &&
307
308         # are we really getting abbreviations?
309         test "$obj36" != "$objdefault" &&
310         expr "$obj36" : "$objdefault" >/dev/null &&
311         test "$objfull" != "$obj36" &&
312         expr "$objfull" : "$obj36" >/dev/null
313
314 '
315
316 test_expect_success 'git branch --column' '
317         COLUMNS=81 git branch --column=column >actual &&
318         cat >expected <<\EOF &&
319   a/b/c     bam       foo       l       * master    n         o/p       r
320   abc       bar       j/k       m/m       master2   o/o       q
321 EOF
322         test_cmp expected actual
323 '
324
325 test_expect_success 'git branch --column with an extremely long branch name' '
326         long=this/is/a/part/of/long/branch/name &&
327         long=z$long/$long/$long/$long &&
328         test_when_finished "git branch -d $long" &&
329         git branch $long &&
330         COLUMNS=80 git branch --column=column >actual &&
331         cat >expected <<EOF &&
332   a/b/c
333   abc
334   bam
335   bar
336   foo
337   j/k
338   l
339   m/m
340 * master
341   master2
342   n
343   o/o
344   o/p
345   q
346   r
347   $long
348 EOF
349         test_cmp expected actual
350 '
351
352 test_expect_success 'git branch with column.*' '
353         git config column.ui column &&
354         git config column.branch "dense" &&
355         COLUMNS=80 git branch >actual &&
356         git config --unset column.branch &&
357         git config --unset column.ui &&
358         cat >expected <<\EOF &&
359   a/b/c   bam   foo   l   * master    n     o/p   r
360   abc     bar   j/k   m/m   master2   o/o   q
361 EOF
362         test_cmp expected actual
363 '
364
365 test_expect_success 'git branch --column -v should fail' '
366         test_must_fail git branch --column -v
367 '
368
369 test_expect_success 'git branch -v with column.ui ignored' '
370         git config column.ui column &&
371         COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
372         git config --unset column.ui &&
373         cat >expected <<\EOF &&
374   a/b/c
375   abc
376   bam
377   bar
378   foo
379   j/k
380   l
381   m/m
382 * master
383   master2
384   n
385   o/o
386   o/p
387   q
388   r
389 EOF
390         test_cmp expected actual
391 '
392
393 mv .git/config .git/config-saved
394
395 test_expect_success 'git branch -m q q2 without config should succeed' '
396         git branch -m q q2 &&
397         git branch -m q2 q
398 '
399
400 mv .git/config-saved .git/config
401
402 git config branch.s/s.dummy Hello
403
404 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
405         git branch --create-reflog s/s &&
406         git reflog exists refs/heads/s/s &&
407         git branch --create-reflog s/t &&
408         git reflog exists refs/heads/s/t &&
409         git branch -d s/t &&
410         git branch -m s/s s &&
411         git reflog exists refs/heads/s
412 '
413
414 test_expect_success 'config information was renamed, too' '
415         test $(git config branch.s.dummy) = Hello &&
416         test_must_fail git config branch.s/s.dummy
417 '
418
419 test_expect_success 'git branch -m correctly renames multiple config sections' '
420         test_when_finished "git checkout master" &&
421         git checkout -b source master &&
422
423         # Assert that a config file with multiple config sections has
424         # those sections preserved...
425         cat >expect <<-\EOF &&
426         branch.dest.key1=value1
427         some.gar.b=age
428         branch.dest.key2=value2
429         EOF
430         cat >config.branch <<\EOF &&
431 ;; Note the lack of -\EOF above & mixed indenting here. This is
432 ;; intentional, we are also testing that the formatting of copied
433 ;; sections is preserved.
434
435 ;; Comment for source. Tabs
436 [branch "source"]
437         ;; Comment for the source value
438         key1 = value1
439 ;; Comment for some.gar. Spaces
440 [some "gar"]
441     ;; Comment for the some.gar value
442     b = age
443 ;; Comment for source, again. Mixed tabs/spaces.
444 [branch "source"]
445     ;; Comment for the source value, again
446         key2 = value2
447 EOF
448         cat config.branch >>.git/config &&
449         git branch -m source dest &&
450         git config -f .git/config -l | grep -F -e source -e dest -e some.gar >actual &&
451         test_cmp expect actual &&
452
453         # ...and that the comments for those sections are also
454         # preserved.
455         cat config.branch | sed "s/\"source\"/\"dest\"/" >expect &&
456         sed -n -e "/Note the lack/,\$p" .git/config >actual &&
457         test_cmp expect actual
458 '
459
460 test_expect_success 'git branch -c dumps usage' '
461         test_expect_code 128 git branch -c 2>err &&
462         test_i18ngrep "branch name required" err
463 '
464
465 test_expect_success 'git branch --copy dumps usage' '
466         test_expect_code 128 git branch --copy 2>err &&
467         test_i18ngrep "branch name required" err
468 '
469
470 test_expect_success 'git branch -c d e should work' '
471         git branch --create-reflog d &&
472         git reflog exists refs/heads/d &&
473         git config branch.d.dummy Hello &&
474         git branch -c d e &&
475         git reflog exists refs/heads/d &&
476         git reflog exists refs/heads/e &&
477         echo Hello >expect &&
478         git config branch.e.dummy >actual &&
479         test_cmp expect actual &&
480         echo Hello >expect &&
481         git config branch.d.dummy >actual &&
482         test_cmp expect actual
483 '
484
485 test_expect_success 'git branch --copy is a synonym for -c' '
486         git branch --create-reflog copy &&
487         git reflog exists refs/heads/copy &&
488         git config branch.copy.dummy Hello &&
489         git branch --copy copy copy-to &&
490         git reflog exists refs/heads/copy &&
491         git reflog exists refs/heads/copy-to &&
492         echo Hello >expect &&
493         git config branch.copy.dummy >actual &&
494         test_cmp expect actual &&
495         echo Hello >expect &&
496         git config branch.copy-to.dummy >actual &&
497         test_cmp expect actual
498 '
499
500 test_expect_success 'git branch -c ee ef should copy ee to create branch ef' '
501         git checkout -b ee &&
502         git reflog exists refs/heads/ee &&
503         git config branch.ee.dummy Hello &&
504         git branch -c ee ef &&
505         git reflog exists refs/heads/ee &&
506         git reflog exists refs/heads/ef &&
507         test $(git config branch.ee.dummy) = Hello &&
508         test $(git config branch.ef.dummy) = Hello &&
509         test $(git rev-parse --abbrev-ref HEAD) = ee
510 '
511
512 test_expect_success 'git branch -c f/f g/g should work' '
513         git branch --create-reflog f/f &&
514         git reflog exists refs/heads/f/f &&
515         git config branch.f/f.dummy Hello &&
516         git branch -c f/f g/g &&
517         git reflog exists refs/heads/f/f &&
518         git reflog exists refs/heads/g/g &&
519         test $(git config branch.f/f.dummy) = Hello &&
520         test $(git config branch.g/g.dummy) = Hello
521 '
522
523 test_expect_success 'git branch -c m2 m2 should work' '
524         git branch --create-reflog m2 &&
525         git reflog exists refs/heads/m2 &&
526         git config branch.m2.dummy Hello &&
527         git branch -c m2 m2 &&
528         git reflog exists refs/heads/m2 &&
529         test $(git config branch.m2.dummy) = Hello
530 '
531
532 test_expect_success 'git branch -c zz zz/zz should fail' '
533         git branch --create-reflog zz &&
534         git reflog exists refs/heads/zz &&
535         test_must_fail git branch -c zz zz/zz
536 '
537
538 test_expect_success 'git branch -c b/b b should fail' '
539         git branch --create-reflog b/b &&
540         test_must_fail git branch -c b/b b
541 '
542
543 test_expect_success 'git branch -C o/q o/p should work when o/p exists' '
544         git branch --create-reflog o/q &&
545         git reflog exists refs/heads/o/q &&
546         git reflog exists refs/heads/o/p &&
547         git branch -C o/q o/p
548 '
549
550 test_expect_success 'git branch -c -f o/q o/p should work when o/p exists' '
551         git reflog exists refs/heads/o/q &&
552         git reflog exists refs/heads/o/p &&
553         git branch -c -f o/q o/p
554 '
555
556 test_expect_success 'git branch -c qq rr/qq should fail when rr exists' '
557         git branch qq &&
558         git branch rr &&
559         test_must_fail git branch -c qq rr/qq
560 '
561
562 test_expect_success 'git branch -C b1 b2 should fail when b2 is checked out' '
563         git branch b1 &&
564         git checkout -b b2 &&
565         test_must_fail git branch -C b1 b2
566 '
567
568 test_expect_success 'git branch -C c1 c2 should succeed when c1 is checked out' '
569         git checkout -b c1 &&
570         git branch c2 &&
571         git branch -C c1 c2 &&
572         test $(git rev-parse --abbrev-ref HEAD) = c1
573 '
574
575 test_expect_success 'git branch -C c1 c2 should never touch HEAD' '
576         msg="Branch: copied refs/heads/c1 to refs/heads/c2" &&
577         ! grep "$msg$" .git/logs/HEAD
578 '
579
580 test_expect_success 'git branch -C master should work when master is checked out' '
581         git checkout master &&
582         git branch -C master
583 '
584
585 test_expect_success 'git branch -C master master should work when master is checked out' '
586         git checkout master &&
587         git branch -C master master
588 '
589
590 test_expect_success 'git branch -C master5 master5 should work when master is checked out' '
591         git checkout master &&
592         git branch master5 &&
593         git branch -C master5 master5
594 '
595
596 test_expect_success 'git branch -C ab cd should overwrite existing config for cd' '
597         git branch --create-reflog cd &&
598         git reflog exists refs/heads/cd &&
599         git config branch.cd.dummy CD &&
600         git branch --create-reflog ab &&
601         git reflog exists refs/heads/ab &&
602         git config branch.ab.dummy AB &&
603         git branch -C ab cd &&
604         git reflog exists refs/heads/ab &&
605         git reflog exists refs/heads/cd &&
606         test $(git config branch.ab.dummy) = AB &&
607         test $(git config branch.cd.dummy) = AB
608 '
609
610 test_expect_success 'git branch -c correctly copies multiple config sections' '
611         FOO=1 &&
612         export FOO &&
613         test_when_finished "git checkout master" &&
614         git checkout -b source2 master &&
615
616         # Assert that a config file with multiple config sections has
617         # those sections preserved...
618         cat >expect <<-\EOF &&
619         branch.source2.key1=value1
620         branch.dest2.key1=value1
621         more.gar.b=age
622         branch.source2.key2=value2
623         branch.dest2.key2=value2
624         EOF
625         cat >config.branch <<\EOF &&
626 ;; Note the lack of -\EOF above & mixed indenting here. This is
627 ;; intentional, we are also testing that the formatting of copied
628 ;; sections is preserved.
629
630 ;; Comment for source2. Tabs
631 [branch "source2"]
632         ;; Comment for the source2 value
633         key1 = value1
634 ;; Comment for more.gar. Spaces
635 [more "gar"]
636     ;; Comment for the more.gar value
637     b = age
638 ;; Comment for source2, again. Mixed tabs/spaces.
639 [branch "source2"]
640     ;; Comment for the source2 value, again
641         key2 = value2
642 EOF
643         cat config.branch >>.git/config &&
644         git branch -c source2 dest2 &&
645         git config -f .git/config -l | grep -F -e source2 -e dest2 -e more.gar >actual &&
646         test_cmp expect actual &&
647
648         # ...and that the comments and formatting for those sections
649         # is also preserved.
650         cat >expect <<\EOF &&
651 ;; Comment for source2. Tabs
652 [branch "source2"]
653         ;; Comment for the source2 value
654         key1 = value1
655 ;; Comment for more.gar. Spaces
656 [branch "dest2"]
657         ;; Comment for the source2 value
658         key1 = value1
659 ;; Comment for more.gar. Spaces
660 [more "gar"]
661     ;; Comment for the more.gar value
662     b = age
663 ;; Comment for source2, again. Mixed tabs/spaces.
664 [branch "source2"]
665     ;; Comment for the source2 value, again
666         key2 = value2
667 [branch "dest2"]
668     ;; Comment for the source2 value, again
669         key2 = value2
670 EOF
671         sed -n -e "/Comment for source2/,\$p" .git/config >actual &&
672         test_cmp expect actual
673 '
674
675 test_expect_success 'deleting a symref' '
676         git branch target &&
677         git symbolic-ref refs/heads/symref refs/heads/target &&
678         echo "Deleted branch symref (was refs/heads/target)." >expect &&
679         git branch -d symref >actual &&
680         test_path_is_file .git/refs/heads/target &&
681         test_path_is_missing .git/refs/heads/symref &&
682         test_i18ncmp expect actual
683 '
684
685 test_expect_success 'deleting a dangling symref' '
686         git symbolic-ref refs/heads/dangling-symref nowhere &&
687         test_path_is_file .git/refs/heads/dangling-symref &&
688         echo "Deleted branch dangling-symref (was nowhere)." >expect &&
689         git branch -d dangling-symref >actual &&
690         test_path_is_missing .git/refs/heads/dangling-symref &&
691         test_i18ncmp expect actual
692 '
693
694 test_expect_success 'deleting a self-referential symref' '
695         git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
696         test_path_is_file .git/refs/heads/self-reference &&
697         echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
698         git branch -d self-reference >actual &&
699         test_path_is_missing .git/refs/heads/self-reference &&
700         test_i18ncmp expect actual
701 '
702
703 test_expect_success 'renaming a symref is not allowed' '
704         git symbolic-ref refs/heads/master2 refs/heads/master &&
705         test_must_fail git branch -m master2 master3 &&
706         git symbolic-ref refs/heads/master2 &&
707         test_path_is_file .git/refs/heads/master &&
708         test_path_is_missing .git/refs/heads/master3
709 '
710
711 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
712         git branch --create-reflog u &&
713         mv .git/logs/refs/heads/u real-u &&
714         ln -s real-u .git/logs/refs/heads/u &&
715         test_must_fail git branch -m u v
716 '
717
718 test_expect_success 'test tracking setup via --track' '
719         git config remote.local.url . &&
720         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
721         (git show-ref -q refs/remotes/local/master || git fetch local) &&
722         git branch --track my1 local/master &&
723         test $(git config branch.my1.remote) = local &&
724         test $(git config branch.my1.merge) = refs/heads/master
725 '
726
727 test_expect_success 'test tracking setup (non-wildcard, matching)' '
728         git config remote.local.url . &&
729         git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
730         (git show-ref -q refs/remotes/local/master || git fetch local) &&
731         git branch --track my4 local/master &&
732         test $(git config branch.my4.remote) = local &&
733         test $(git config branch.my4.merge) = refs/heads/master
734 '
735
736 test_expect_success 'tracking setup fails on non-matching refspec' '
737         git config remote.local.url . &&
738         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
739         (git show-ref -q refs/remotes/local/master || git fetch local) &&
740         git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
741         test_must_fail git branch --track my5 local/master &&
742         test_must_fail git config branch.my5.remote &&
743         test_must_fail git config branch.my5.merge
744 '
745
746 test_expect_success 'test tracking setup via config' '
747         git config branch.autosetupmerge true &&
748         git config remote.local.url . &&
749         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
750         (git show-ref -q refs/remotes/local/master || git fetch local) &&
751         git branch my3 local/master &&
752         test $(git config branch.my3.remote) = local &&
753         test $(git config branch.my3.merge) = refs/heads/master
754 '
755
756 test_expect_success 'test overriding tracking setup via --no-track' '
757         git config branch.autosetupmerge true &&
758         git config remote.local.url . &&
759         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
760         (git show-ref -q refs/remotes/local/master || git fetch local) &&
761         git branch --no-track my2 local/master &&
762         git config branch.autosetupmerge false &&
763         ! test "$(git config branch.my2.remote)" = local &&
764         ! test "$(git config branch.my2.merge)" = refs/heads/master
765 '
766
767 test_expect_success 'no tracking without .fetch entries' '
768         git config branch.autosetupmerge true &&
769         git branch my6 s &&
770         git config branch.autosetupmerge false &&
771         test -z "$(git config branch.my6.remote)" &&
772         test -z "$(git config branch.my6.merge)"
773 '
774
775 test_expect_success 'test tracking setup via --track but deeper' '
776         git config remote.local.url . &&
777         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
778         (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
779         git branch --track my7 local/o/o &&
780         test "$(git config branch.my7.remote)" = local &&
781         test "$(git config branch.my7.merge)" = refs/heads/o/o
782 '
783
784 test_expect_success 'test deleting branch deletes branch config' '
785         git branch -d my7 &&
786         test -z "$(git config branch.my7.remote)" &&
787         test -z "$(git config branch.my7.merge)"
788 '
789
790 test_expect_success 'test deleting branch without config' '
791         git branch my7 s &&
792         sha1=$(git rev-parse my7 | cut -c 1-7) &&
793         echo "Deleted branch my7 (was $sha1)." >expect &&
794         git branch -d my7 >actual 2>&1 &&
795         test_i18ncmp expect actual
796 '
797
798 test_expect_success 'deleting currently checked out branch fails' '
799         git worktree add -b my7 my7 &&
800         test_must_fail git -C my7 branch -d my7 &&
801         test_must_fail git branch -d my7
802 '
803
804 test_expect_success 'test --track without .fetch entries' '
805         git branch --track my8 &&
806         test "$(git config branch.my8.remote)" &&
807         test "$(git config branch.my8.merge)"
808 '
809
810 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
811         git config branch.autosetupmerge always &&
812         git branch my9 HEAD^ &&
813         git config branch.autosetupmerge false
814 '
815
816 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
817         test_must_fail git branch --track my10 HEAD^
818 '
819
820 test_expect_success 'branch from tag w/--track causes failure' '
821         git tag foobar &&
822         test_must_fail git branch --track my11 foobar
823 '
824
825 test_expect_success '--set-upstream-to fails on multiple branches' '
826         test_must_fail git branch --set-upstream-to master a b c
827 '
828
829 test_expect_success '--set-upstream-to fails on detached HEAD' '
830         git checkout HEAD^{} &&
831         test_must_fail git branch --set-upstream-to master &&
832         git checkout -
833 '
834
835 test_expect_success '--set-upstream-to fails on a missing dst branch' '
836         test_must_fail git branch --set-upstream-to master does-not-exist
837 '
838
839 test_expect_success '--set-upstream-to fails on a missing src branch' '
840         test_must_fail git branch --set-upstream-to does-not-exist master
841 '
842
843 test_expect_success '--set-upstream-to fails on a non-ref' '
844         test_must_fail git branch --set-upstream-to HEAD^{}
845 '
846
847 test_expect_success '--set-upstream-to fails on locked config' '
848         test_when_finished "rm -f .git/config.lock" &&
849         >.git/config.lock &&
850         git branch locked &&
851         test_must_fail git branch --set-upstream-to locked
852 '
853
854 test_expect_success 'use --set-upstream-to modify HEAD' '
855         test_config branch.master.remote foo &&
856         test_config branch.master.merge foo &&
857         git branch my12 &&
858         git branch --set-upstream-to my12 &&
859         test "$(git config branch.master.remote)" = "." &&
860         test "$(git config branch.master.merge)" = "refs/heads/my12"
861 '
862
863 test_expect_success 'use --set-upstream-to modify a particular branch' '
864         git branch my13 &&
865         git branch --set-upstream-to master my13 &&
866         test_when_finished "git branch --unset-upstream my13" &&
867         test "$(git config branch.my13.remote)" = "." &&
868         test "$(git config branch.my13.merge)" = "refs/heads/master"
869 '
870
871 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
872         test_must_fail git branch --unset-upstream i-dont-exist
873 '
874
875 test_expect_success '--unset-upstream should fail if config is locked' '
876         test_when_finished "rm -f .git/config.lock" &&
877         git branch --set-upstream-to locked &&
878         >.git/config.lock &&
879         test_must_fail git branch --unset-upstream
880 '
881
882 test_expect_success 'test --unset-upstream on HEAD' '
883         git branch my14 &&
884         test_config branch.master.remote foo &&
885         test_config branch.master.merge foo &&
886         git branch --set-upstream-to my14 &&
887         git branch --unset-upstream &&
888         test_must_fail git config branch.master.remote &&
889         test_must_fail git config branch.master.merge &&
890         # fail for a branch without upstream set
891         test_must_fail git branch --unset-upstream
892 '
893
894 test_expect_success '--unset-upstream should fail on multiple branches' '
895         test_must_fail git branch --unset-upstream a b c
896 '
897
898 test_expect_success '--unset-upstream should fail on detached HEAD' '
899         git checkout HEAD^{} &&
900         test_must_fail git branch --unset-upstream &&
901         git checkout -
902 '
903
904 test_expect_success 'test --unset-upstream on a particular branch' '
905         git branch my15 &&
906         git branch --set-upstream-to master my14 &&
907         git branch --unset-upstream my14 &&
908         test_must_fail git config branch.my14.remote &&
909         test_must_fail git config branch.my14.merge
910 '
911
912 test_expect_success 'disabled option --set-upstream fails' '
913     test_must_fail git branch --set-upstream origin/master
914 '
915
916 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
917         git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
918         cat >expected <<-\EOF &&
919         warning: Not setting branch my13 as its own upstream.
920         EOF
921         test_expect_code 1 git config branch.my13.remote &&
922         test_expect_code 1 git config branch.my13.merge &&
923         test_i18ncmp expected actual
924 '
925
926 # Keep this test last, as it changes the current branch
927 cat >expect <<EOF
928 $ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000     branch: Created from master
929 EOF
930 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
931         GIT_COMMITTER_DATE="2005-05-26 23:30" \
932         git checkout -b g/h/i -l master &&
933         test_path_is_file .git/refs/heads/g/h/i &&
934         test_path_is_file .git/logs/refs/heads/g/h/i &&
935         test_cmp expect .git/logs/refs/heads/g/h/i
936 '
937
938 test_expect_success 'checkout -b makes reflog by default' '
939         git checkout master &&
940         git config --unset core.logAllRefUpdates &&
941         git checkout -b alpha &&
942         git rev-parse --verify alpha@{0}
943 '
944
945 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
946         git checkout master &&
947         git config core.logAllRefUpdates false &&
948         git checkout -b beta &&
949         test_must_fail git rev-parse --verify beta@{0}
950 '
951
952 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
953         git checkout master &&
954         git checkout -lb gamma &&
955         git config --unset core.logAllRefUpdates &&
956         git rev-parse --verify gamma@{0}
957 '
958
959 test_expect_success 'avoid ambiguous track' '
960         git config branch.autosetupmerge true &&
961         git config remote.ambi1.url lalala &&
962         git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
963         git config remote.ambi2.url lilili &&
964         git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
965         test_must_fail git branch all1 master &&
966         test -z "$(git config branch.all1.merge)"
967 '
968
969 test_expect_success 'autosetuprebase local on a tracked local branch' '
970         git config remote.local.url . &&
971         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
972         git config branch.autosetuprebase local &&
973         (git show-ref -q refs/remotes/local/o || git fetch local) &&
974         git branch mybase &&
975         git branch --track myr1 mybase &&
976         test "$(git config branch.myr1.remote)" = . &&
977         test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
978         test "$(git config branch.myr1.rebase)" = true
979 '
980
981 test_expect_success 'autosetuprebase always on a tracked local branch' '
982         git config remote.local.url . &&
983         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
984         git config branch.autosetuprebase always &&
985         (git show-ref -q refs/remotes/local/o || git fetch local) &&
986         git branch mybase2 &&
987         git branch --track myr2 mybase &&
988         test "$(git config branch.myr2.remote)" = . &&
989         test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
990         test "$(git config branch.myr2.rebase)" = true
991 '
992
993 test_expect_success 'autosetuprebase remote on a tracked local branch' '
994         git config remote.local.url . &&
995         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
996         git config branch.autosetuprebase remote &&
997         (git show-ref -q refs/remotes/local/o || git fetch local) &&
998         git branch mybase3 &&
999         git branch --track myr3 mybase2 &&
1000         test "$(git config branch.myr3.remote)" = . &&
1001         test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
1002         ! test "$(git config branch.myr3.rebase)" = true
1003 '
1004
1005 test_expect_success 'autosetuprebase never on a tracked local branch' '
1006         git config remote.local.url . &&
1007         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1008         git config branch.autosetuprebase never &&
1009         (git show-ref -q refs/remotes/local/o || git fetch local) &&
1010         git branch mybase4 &&
1011         git branch --track myr4 mybase2 &&
1012         test "$(git config branch.myr4.remote)" = . &&
1013         test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
1014         ! test "$(git config branch.myr4.rebase)" = true
1015 '
1016
1017 test_expect_success 'autosetuprebase local on a tracked remote branch' '
1018         git config remote.local.url . &&
1019         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1020         git config branch.autosetuprebase local &&
1021         (git show-ref -q refs/remotes/local/master || git fetch local) &&
1022         git branch --track myr5 local/master &&
1023         test "$(git config branch.myr5.remote)" = local &&
1024         test "$(git config branch.myr5.merge)" = refs/heads/master &&
1025         ! test "$(git config branch.myr5.rebase)" = true
1026 '
1027
1028 test_expect_success 'autosetuprebase never on a tracked remote branch' '
1029         git config remote.local.url . &&
1030         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1031         git config branch.autosetuprebase never &&
1032         (git show-ref -q refs/remotes/local/master || git fetch local) &&
1033         git branch --track myr6 local/master &&
1034         test "$(git config branch.myr6.remote)" = local &&
1035         test "$(git config branch.myr6.merge)" = refs/heads/master &&
1036         ! test "$(git config branch.myr6.rebase)" = true
1037 '
1038
1039 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
1040         git config remote.local.url . &&
1041         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1042         git config branch.autosetuprebase remote &&
1043         (git show-ref -q refs/remotes/local/master || git fetch local) &&
1044         git branch --track myr7 local/master &&
1045         test "$(git config branch.myr7.remote)" = local &&
1046         test "$(git config branch.myr7.merge)" = refs/heads/master &&
1047         test "$(git config branch.myr7.rebase)" = true
1048 '
1049
1050 test_expect_success 'autosetuprebase always 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 remote &&
1054         (git show-ref -q refs/remotes/local/master || git fetch local) &&
1055         git branch --track myr8 local/master &&
1056         test "$(git config branch.myr8.remote)" = local &&
1057         test "$(git config branch.myr8.merge)" = refs/heads/master &&
1058         test "$(git config branch.myr8.rebase)" = true
1059 '
1060
1061 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
1062         git config --unset branch.autosetuprebase &&
1063         git config remote.local.url . &&
1064         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1065         (git show-ref -q refs/remotes/local/master || git fetch local) &&
1066         git branch --track myr9 local/master &&
1067         test "$(git config branch.myr9.remote)" = local &&
1068         test "$(git config branch.myr9.merge)" = refs/heads/master &&
1069         test "z$(git config branch.myr9.rebase)" = z
1070 '
1071
1072 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
1073         git config remote.local.url . &&
1074         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1075         (git show-ref -q refs/remotes/local/o || git fetch local) &&
1076         git branch mybase10 &&
1077         git branch --track myr10 mybase2 &&
1078         test "$(git config branch.myr10.remote)" = . &&
1079         test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
1080         test "z$(git config branch.myr10.rebase)" = z
1081 '
1082
1083 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
1084         git config remote.local.url . &&
1085         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1086         (git show-ref -q refs/remotes/local/master || git fetch local) &&
1087         git branch --no-track myr11 mybase2 &&
1088         test "z$(git config branch.myr11.remote)" = z &&
1089         test "z$(git config branch.myr11.merge)" = z &&
1090         test "z$(git config branch.myr11.rebase)" = z
1091 '
1092
1093 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
1094         git config remote.local.url . &&
1095         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1096         (git show-ref -q refs/remotes/local/master || git fetch local) &&
1097         git branch --no-track myr12 local/master &&
1098         test "z$(git config branch.myr12.remote)" = z &&
1099         test "z$(git config branch.myr12.merge)" = z &&
1100         test "z$(git config branch.myr12.rebase)" = z
1101 '
1102
1103 test_expect_success 'autosetuprebase never on an untracked local branch' '
1104         git config branch.autosetuprebase never &&
1105         git config remote.local.url . &&
1106         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1107         (git show-ref -q refs/remotes/local/master || git fetch local) &&
1108         git branch --no-track myr13 mybase2 &&
1109         test "z$(git config branch.myr13.remote)" = z &&
1110         test "z$(git config branch.myr13.merge)" = z &&
1111         test "z$(git config branch.myr13.rebase)" = z
1112 '
1113
1114 test_expect_success 'autosetuprebase local on an untracked local branch' '
1115         git config branch.autosetuprebase local &&
1116         git config remote.local.url . &&
1117         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1118         (git show-ref -q refs/remotes/local/master || git fetch local) &&
1119         git branch --no-track myr14 mybase2 &&
1120         test "z$(git config branch.myr14.remote)" = z &&
1121         test "z$(git config branch.myr14.merge)" = z &&
1122         test "z$(git config branch.myr14.rebase)" = z
1123 '
1124
1125 test_expect_success 'autosetuprebase remote on an untracked local branch' '
1126         git config branch.autosetuprebase remote &&
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/master || git fetch local) &&
1130         git branch --no-track myr15 mybase2 &&
1131         test "z$(git config branch.myr15.remote)" = z &&
1132         test "z$(git config branch.myr15.merge)" = z &&
1133         test "z$(git config branch.myr15.rebase)" = z
1134 '
1135
1136 test_expect_success 'autosetuprebase always on an untracked local branch' '
1137         git config branch.autosetuprebase always &&
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/master || git fetch local) &&
1141         git branch --no-track myr16 mybase2 &&
1142         test "z$(git config branch.myr16.remote)" = z &&
1143         test "z$(git config branch.myr16.merge)" = z &&
1144         test "z$(git config branch.myr16.rebase)" = z
1145 '
1146
1147 test_expect_success 'autosetuprebase never on an untracked remote branch' '
1148         git config branch.autosetuprebase never &&
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/master || git fetch local) &&
1152         git branch --no-track myr17 local/master &&
1153         test "z$(git config branch.myr17.remote)" = z &&
1154         test "z$(git config branch.myr17.merge)" = z &&
1155         test "z$(git config branch.myr17.rebase)" = z
1156 '
1157
1158 test_expect_success 'autosetuprebase local on an untracked remote branch' '
1159         git config branch.autosetuprebase local &&
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/master || git fetch local) &&
1163         git branch --no-track myr18 local/master &&
1164         test "z$(git config branch.myr18.remote)" = z &&
1165         test "z$(git config branch.myr18.merge)" = z &&
1166         test "z$(git config branch.myr18.rebase)" = z
1167 '
1168
1169 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
1170         git config branch.autosetuprebase remote &&
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/master || git fetch local) &&
1174         git branch --no-track myr19 local/master &&
1175         test "z$(git config branch.myr19.remote)" = z &&
1176         test "z$(git config branch.myr19.merge)" = z &&
1177         test "z$(git config branch.myr19.rebase)" = z
1178 '
1179
1180 test_expect_success 'autosetuprebase always on an untracked remote branch' '
1181         git config branch.autosetuprebase always &&
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/master || git fetch local) &&
1185         git branch --no-track myr20 local/master &&
1186         test "z$(git config branch.myr20.remote)" = z &&
1187         test "z$(git config branch.myr20.merge)" = z &&
1188         test "z$(git config branch.myr20.rebase)" = z
1189 '
1190
1191 test_expect_success 'autosetuprebase always on detached HEAD' '
1192         git config branch.autosetupmerge always &&
1193         test_when_finished git checkout master &&
1194         git checkout HEAD^0 &&
1195         git branch my11 &&
1196         test -z "$(git config branch.my11.remote)" &&
1197         test -z "$(git config branch.my11.merge)"
1198 '
1199
1200 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
1201         git config branch.autosetuprebase garbage &&
1202         test_must_fail git branch
1203 '
1204
1205 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
1206         git config --unset branch.autosetuprebase &&
1207         echo "[branch] autosetuprebase" >>.git/config &&
1208         test_must_fail git branch &&
1209         git config --unset branch.autosetuprebase
1210 '
1211
1212 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
1213         git checkout my9 &&
1214         git config --unset branch.my8.merge &&
1215         test_must_fail git branch -d my8
1216 '
1217
1218 test_expect_success 'attempt to delete a branch merged to its base' '
1219         # we are on my9 which is the initial commit; traditionally
1220         # we would not have allowed deleting my8 that is not merged
1221         # to my9, but it is set to track master that already has my8
1222         git config branch.my8.merge refs/heads/master &&
1223         git branch -d my8
1224 '
1225
1226 test_expect_success 'attempt to delete a branch merged to its base' '
1227         git checkout master &&
1228         echo Third >>A &&
1229         git commit -m "Third commit" A &&
1230         git branch -t my10 my9 &&
1231         git branch -f my10 HEAD^ &&
1232         # we are on master which is at the third commit, and my10
1233         # is behind us, so traditionally we would have allowed deleting
1234         # it; but my10 is set to track my9 that is further behind.
1235         test_must_fail git branch -d my10
1236 '
1237
1238 test_expect_success 'use --edit-description' '
1239         write_script editor <<-\EOF &&
1240                 echo "New contents" >"$1"
1241         EOF
1242         EDITOR=./editor git branch --edit-description &&
1243                 write_script editor <<-\EOF &&
1244                 git stripspace -s <"$1" >"EDITOR_OUTPUT"
1245         EOF
1246         EDITOR=./editor git branch --edit-description &&
1247         echo "New contents" >expect &&
1248         test_cmp expect EDITOR_OUTPUT
1249 '
1250
1251 test_expect_success 'detect typo in branch name when using --edit-description' '
1252         write_script editor <<-\EOF &&
1253                 echo "New contents" >"$1"
1254         EOF
1255         test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
1256 '
1257
1258 test_expect_success 'refuse --edit-description on unborn branch for now' '
1259         write_script editor <<-\EOF &&
1260                 echo "New contents" >"$1"
1261         EOF
1262         git checkout --orphan unborn &&
1263         test_must_fail env EDITOR=./editor git branch --edit-description
1264 '
1265
1266 test_expect_success '--merged catches invalid object names' '
1267         test_must_fail git branch --merged 0000000000000000000000000000000000000000
1268 '
1269
1270 test_expect_success '--merged is incompatible with --no-merged' '
1271         test_must_fail git branch --merged HEAD --no-merged HEAD
1272 '
1273
1274 test_expect_success '--list during rebase' '
1275         test_when_finished "reset_rebase" &&
1276         git checkout master &&
1277         FAKE_LINES="1 edit 2" &&
1278         export FAKE_LINES &&
1279         set_fake_editor &&
1280         git rebase -i HEAD~2 &&
1281         git branch --list >actual &&
1282         test_i18ngrep "rebasing master" actual
1283 '
1284
1285 test_expect_success '--list during rebase from detached HEAD' '
1286         test_when_finished "reset_rebase && git checkout master" &&
1287         git checkout master^0 &&
1288         oid=$(git rev-parse --short HEAD) &&
1289         FAKE_LINES="1 edit 2" &&
1290         export FAKE_LINES &&
1291         set_fake_editor &&
1292         git rebase -i HEAD~2 &&
1293         git branch --list >actual &&
1294         test_i18ngrep "rebasing detached HEAD $oid" actual
1295 '
1296
1297 test_expect_success 'tracking with unexpected .fetch refspec' '
1298         rm -rf a b c d &&
1299         git init a &&
1300         (
1301                 cd a &&
1302                 test_commit a
1303         ) &&
1304         git init b &&
1305         (
1306                 cd b &&
1307                 test_commit b
1308         ) &&
1309         git init c &&
1310         (
1311                 cd c &&
1312                 test_commit c &&
1313                 git remote add a ../a &&
1314                 git remote add b ../b &&
1315                 git fetch --all
1316         ) &&
1317         git init d &&
1318         (
1319                 cd d &&
1320                 git remote add c ../c &&
1321                 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
1322                 git fetch c &&
1323                 git branch --track local/a/master remotes/a/master &&
1324                 test "$(git config branch.local/a/master.remote)" = "c" &&
1325                 test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
1326                 git rev-parse --verify a >expect &&
1327                 git rev-parse --verify local/a/master >actual &&
1328                 test_cmp expect actual
1329         )
1330 '
1331
1332 test_expect_success 'configured committerdate sort' '
1333         git init sort &&
1334         (
1335                 cd sort &&
1336                 git config branch.sort committerdate &&
1337                 test_commit initial &&
1338                 git checkout -b a &&
1339                 test_commit a &&
1340                 git checkout -b c &&
1341                 test_commit c &&
1342                 git checkout -b b &&
1343                 test_commit b &&
1344                 git branch >actual &&
1345                 cat >expect <<-\EOF &&
1346                   master
1347                   a
1348                   c
1349                 * b
1350                 EOF
1351                 test_cmp expect actual
1352         )
1353 '
1354
1355 test_expect_success 'option override configured sort' '
1356         (
1357                 cd sort &&
1358                 git config branch.sort committerdate &&
1359                 git branch --sort=refname >actual &&
1360                 cat >expect <<-\EOF &&
1361                   a
1362                 * b
1363                   c
1364                   master
1365                 EOF
1366                 test_cmp expect actual
1367         )
1368 '
1369
1370 test_expect_success 'invalid sort parameter in configuration' '
1371         (
1372                 cd sort &&
1373                 git config branch.sort "v:notvalid" &&
1374                 test_must_fail git branch
1375         )
1376 '
1377
1378 test_done