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