]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3200-branch.sh
tests: teach callers of test_i18ngrep to use test_grep
[thirdparty/git.git] / t / t3200-branch.sh
CommitLineData
a3b427b9
AW
1#!/bin/sh
2#
3# Copyright (c) 2005 Amos Waterland
4#
5
c2d17ba3 6test_description='git branch assorted tests'
a3b427b9 7
d6c6b108 8GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
9export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
80d32e84 11TEST_PASSES_SANITIZE_LEAK=true
a3b427b9 12. ./test-lib.sh
1f537be3 13. "$TEST_DIRECTORY"/lib-rebase.sh
a3b427b9 14
0d158ebb
RR
15test_expect_success 'prepare a trivial repository' '
16 echo Hello >A &&
17 git update-index --add A &&
18 git commit -m "Initial commit." &&
ec9779bc 19 git branch -M main &&
0d158ebb
RR
20 echo World >>A &&
21 git update-index --add A &&
22 git commit -m "Second commit." &&
140cd845
FC
23 HEAD=$(git rev-parse --verify HEAD)
24'
0d158ebb
RR
25
26test_expect_success 'git branch --help should not have created a bogus branch' '
01e8d327 27 test_might_fail git branch --man --help </dev/null >/dev/null 2>&1 &&
0d158ebb 28 test_path_is_missing .git/refs/heads/--help
41ac414e 29'
a3b427b9 30
1dacfbcf
NTND
31test_expect_success 'branch -h in broken repository' '
32 mkdir broken &&
33 (
34 cd broken &&
ec9779bc
JS
35 git init -b main &&
36 >.git/refs/heads/main &&
1dacfbcf
NTND
37 test_expect_code 129 git branch -h >usage 2>&1
38 ) &&
6789275d 39 test_grep "[Uu]sage" broken/usage
1dacfbcf
NTND
40'
41
0d158ebb
RR
42test_expect_success 'git branch abc should create a branch' '
43 git branch abc && test_path_is_file .git/refs/heads/abc
44'
08db81a9 45
bc0893cf
GC
46test_expect_success 'git branch abc should fail when abc exists' '
47 test_must_fail git branch abc
48'
49
50test_expect_success 'git branch --force abc should fail when abc is checked out' '
51 test_when_finished git switch main &&
52 git switch abc &&
53 test_must_fail git branch --force abc HEAD~1
54'
55
56test_expect_success 'git branch --force abc should succeed when abc exists' '
57 git rev-parse HEAD~1 >expect &&
58 git branch --force abc HEAD~1 &&
59 git rev-parse abc >actual &&
60 test_cmp expect actual
61'
62
0d158ebb
RR
63test_expect_success 'git branch a/b/c should create a branch' '
64 git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c
65'
08db81a9 66
ec9779bc
JS
67test_expect_success 'git branch mb main... should create a branch' '
68 git branch mb main... && test_path_is_file .git/refs/heads/mb
e3d6539d
DL
69'
70
0cb24fe8
JH
71test_expect_success 'git branch HEAD should fail' '
72 test_must_fail git branch HEAD
73'
8efb8899 74
d7fb7a37 75cat >expect <<EOF
ec9779bc 76$ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from main
d7fb7a37 77EOF
7687f19e 78test_expect_success 'git branch --create-reflog d/e/f should create a branch and a log' '
0d158ebb 79 GIT_COMMITTER_DATE="2005-05-26 23:30" \
7687f19e 80 git -c core.logallrefupdates=false branch --create-reflog d/e/f &&
0d158ebb
RR
81 test_path_is_file .git/refs/heads/d/e/f &&
82 test_path_is_file .git/logs/refs/heads/d/e/f &&
83 test_cmp expect .git/logs/refs/heads/d/e/f
84'
85
86test_expect_success 'git branch -d d/e/f should delete a branch and a log' '
87 git branch -d d/e/f &&
88 test_path_is_missing .git/refs/heads/d/e/f &&
d0ab0584 89 test_must_fail git reflog exists refs/heads/d/e/f
0d158ebb
RR
90'
91
92test_expect_success 'git branch j/k should work after branch j has been deleted' '
93 git branch j &&
94 git branch -d j &&
95 git branch j/k
96'
97
98test_expect_success 'git branch l should work after branch l/m has been deleted' '
99 git branch l/m &&
100 git branch -d l/m &&
101 git branch l
102'
103
104test_expect_success 'git branch -m dumps usage' '
105 test_expect_code 128 git branch -m 2>err &&
6789275d 106 test_grep "branch name required" err
0d158ebb
RR
107'
108
12fd3496
DT
109test_expect_success 'git branch -m m broken_symref should work' '
110 test_when_finished "git branch -D broken_symref" &&
7687f19e 111 git branch --create-reflog m &&
12fd3496
DT
112 git symbolic-ref refs/heads/broken_symref refs/heads/i_am_broken &&
113 git branch -m m broken_symref &&
114 git reflog exists refs/heads/broken_symref &&
115 test_must_fail git reflog exists refs/heads/i_am_broken
116'
117
0d158ebb 118test_expect_success 'git branch -m m m/m should work' '
7687f19e 119 git branch --create-reflog m &&
0d158ebb 120 git branch -m m m/m &&
d0ab0584 121 git reflog exists refs/heads/m/m
0d158ebb
RR
122'
123
124test_expect_success 'git branch -m n/n n should work' '
7687f19e 125 git branch --create-reflog n/n &&
2f139044 126 git branch -m n/n n &&
d0ab0584 127 git reflog exists refs/heads/n
0d158ebb 128'
c976d415 129
bb8efa17
SD
130# The topmost entry in reflog for branch bbb is about branch creation.
131# Hence, we compare bbb@{1} (instead of bbb@{0}) with aaa@{0}.
132
133test_expect_success 'git branch -m bbb should rename checked out branch' '
134 test_when_finished git branch -D bbb &&
ec9779bc 135 test_when_finished git checkout main &&
bb8efa17
SD
136 git checkout -b aaa &&
137 git commit --allow-empty -m "a new commit" &&
138 git rev-parse aaa@{0} >expect &&
139 git branch -m bbb &&
140 git rev-parse bbb@{1} >actual &&
141 test_cmp expect actual &&
142 git symbolic-ref HEAD >actual &&
143 echo refs/heads/bbb >expect &&
144 test_cmp expect actual
145'
146
a1c1d817
JK
147test_expect_success 'renaming checked out branch works with d/f conflict' '
148 test_when_finished "git branch -D foo/bar || git branch -D foo" &&
ec9779bc 149 test_when_finished git checkout main &&
a1c1d817
JK
150 git checkout -b foo &&
151 git branch -m foo/bar &&
152 git symbolic-ref HEAD >actual &&
153 echo refs/heads/foo/bar >expect &&
154 test_cmp expect actual
155'
156
41ac414e
JH
157test_expect_success 'git branch -m o/o o should fail when o/p exists' '
158 git branch o/o &&
0d158ebb 159 git branch o/p &&
d492b31c 160 test_must_fail git branch -m o/o o
41ac414e 161'
c976d415 162
ff7aa81f
MG
163test_expect_success 'git branch -m o/q o/p should fail when o/p exists' '
164 git branch o/q &&
165 test_must_fail git branch -m o/q o/p
166'
167
168test_expect_success 'git branch -M o/q o/p should work when o/p exists' '
169 git branch -M o/q o/p
170'
171
356e91f2
MG
172test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '
173 git branch o/q &&
174 git branch -m -f o/q o/p
175'
176
41ac414e
JH
177test_expect_success 'git branch -m q r/q should fail when r exists' '
178 git branch q &&
179 git branch r &&
d492b31c 180 test_must_fail git branch -m q r/q
41ac414e 181'
c976d415 182
55c4a673
CI
183test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
184 git branch bar &&
185 git checkout -b foo &&
186 test_must_fail git branch -M bar foo
187'
188
593a2a5d
AK
189test_expect_success 'git branch -M foo bar should fail when bar is checked out in worktree' '
190 git branch -f bar &&
191 test_when_finished "git worktree remove wt && git branch -D wt" &&
192 git worktree add wt &&
193 test_must_fail git branch -M bar wt
194'
195
55c4a673
CI
196test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
197 git checkout -b baz &&
198 git branch bam &&
70999e9c
KY
199 git branch -M baz bam &&
200 test $(git rev-parse --abbrev-ref HEAD) = bam
201'
202
39ee4c6c 203test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' '
893dbf5b 204 msg="Branch: renamed refs/heads/baz to refs/heads/bam" &&
a764c37b
ĐTCD
205 grep " $ZERO_OID.*$msg$" .git/logs/HEAD &&
206 grep "^$ZERO_OID.*$msg$" .git/logs/HEAD
893dbf5b
KM
207'
208
31824d18 209test_expect_success 'git branch -M should leave orphaned HEAD alone' '
ec9779bc 210 git init -b main orphan &&
31824d18
NTND
211 (
212 cd orphan &&
213 test_commit initial &&
214 git checkout --orphan lonely &&
215 grep lonely .git/HEAD &&
216 test_path_is_missing .git/refs/head/lonely &&
ec9779bc 217 git branch -M main mistress &&
31824d18
NTND
218 grep lonely .git/HEAD
219 )
220'
221
2272d3e5
JK
222test_expect_success 'resulting reflog can be shown by log -g' '
223 oid=$(git rev-parse HEAD) &&
224 cat >expect <<-EOF &&
225 HEAD@{0} $oid $msg
2272d3e5
JK
226 HEAD@{2} $oid checkout: moving from foo to baz
227 EOF
d08565bf 228 git log -g --format="%gd %H %gs" -2 HEAD >actual &&
2272d3e5
JK
229 test_cmp expect actual
230'
231
70999e9c 232test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' '
ec9779bc 233 git checkout main &&
70999e9c
KY
234 git worktree add -b baz bazdir &&
235 git worktree add -f bazdir2 baz &&
236 git branch -M baz bam &&
237 test $(git -C bazdir rev-parse --abbrev-ref HEAD) = bam &&
ab313814
NB
238 test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam &&
239 rm -r bazdir bazdir2 &&
240 git worktree prune
70999e9c
KY
241'
242
2e8af499
RJ
243test_expect_success 'git branch -M fails if updating any linked working tree fails' '
244 git worktree add -b baz bazdir1 &&
245 git worktree add -f bazdir2 baz &&
246 touch .git/worktrees/bazdir1/HEAD.lock &&
247 test_must_fail git branch -M baz bam &&
248 test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam &&
249 git branch -M bam baz &&
250 rm .git/worktrees/bazdir1/HEAD.lock &&
251 touch .git/worktrees/bazdir2/HEAD.lock &&
252 test_must_fail git branch -M baz bam &&
253 test $(git -C bazdir1 rev-parse --abbrev-ref HEAD) = bam &&
254 rm -rf bazdir1 bazdir2 &&
255 git worktree prune
256'
257
70999e9c
KY
258test_expect_success 'git branch -M baz bam should succeed within a worktree in which baz is checked out' '
259 git checkout -b baz &&
ab313814 260 git worktree add -f bazdir baz &&
70999e9c 261 (
ab313814 262 cd bazdir &&
70999e9c 263 git branch -M baz bam &&
0cd1a881
ÆAB
264 echo bam >expect &&
265 git rev-parse --abbrev-ref HEAD >actual &&
266 test_cmp expect actual
70999e9c 267 ) &&
0cd1a881
ÆAB
268 echo bam >expect &&
269 git rev-parse --abbrev-ref HEAD >actual &&
270 test_cmp expect actual &&
ab313814
NB
271 rm -r bazdir &&
272 git worktree prune
55c4a673
CI
273'
274
ec9779bc
JS
275test_expect_success 'git branch -M main should work when main is checked out' '
276 git checkout main &&
277 git branch -M main
3f59481e
JN
278'
279
ec9779bc
JS
280test_expect_success 'git branch -M main main should work when main is checked out' '
281 git checkout main &&
282 git branch -M main main
3f59481e
JN
283'
284
ec9779bc
JS
285test_expect_success 'git branch -M topic topic should work when main is checked out' '
286 git checkout main &&
432f5e63
JS
287 git branch topic &&
288 git branch -M topic topic
3f59481e
JN
289'
290
77e7267e
RJ
291test_expect_success 'git branch -M and -C fail on detached HEAD' '
292 git checkout HEAD^{} &&
293 test_when_finished git checkout - &&
294 echo "fatal: cannot rename the current branch while not on any." >expect &&
295 test_must_fail git branch -M must-fail 2>err &&
296 test_cmp expect err &&
297 echo "fatal: cannot copy the current branch while not on any." >expect &&
298 test_must_fail git branch -C must-fail 2>err &&
299 test_cmp expect err
300'
301
a675ad17
RJ
302test_expect_success 'git branch -m should work with orphan branches' '
303 test_when_finished git checkout - &&
304 test_when_finished git worktree remove -f wt &&
305 git worktree add wt --detach &&
306 # rename orphan in another worktreee
307 git -C wt checkout --orphan orphan-foo-wt &&
308 git branch -m orphan-foo-wt orphan-bar-wt &&
309 test orphan-bar-wt=$(git -C orphan-worktree branch --show-current) &&
310 # rename orphan in the current worktree
311 git checkout --orphan orphan-foo &&
312 git branch -m orphan-foo orphan-bar &&
313 test orphan-bar=$(git branch --show-current)
314'
315
eb20e63f
JK
316test_expect_success 'git branch -d on orphan HEAD (merged)' '
317 test_when_finished git checkout main &&
318 git checkout --orphan orphan &&
319 test_when_finished "rm -rf .git/objects/commit-graph*" &&
320 git commit-graph write --reachable &&
321 git branch --track to-delete main &&
322 git branch -d to-delete
323'
324
325test_expect_success 'git branch -d on orphan HEAD (merged, graph)' '
326 test_when_finished git checkout main &&
327 git checkout --orphan orphan &&
328 git branch --track to-delete main &&
329 git branch -d to-delete
330'
331
332test_expect_success 'git branch -d on orphan HEAD (unmerged)' '
333 test_when_finished git checkout main &&
334 git checkout --orphan orphan &&
335 test_when_finished "git branch -D to-delete" &&
336 git branch to-delete main &&
337 test_must_fail git branch -d to-delete 2>err &&
338 grep "not fully merged" err
339'
340
341test_expect_success 'git branch -d on orphan HEAD (unmerged, graph)' '
342 test_when_finished git checkout main &&
343 git checkout --orphan orphan &&
344 test_when_finished "git branch -D to-delete" &&
345 git branch to-delete main &&
346 test_when_finished "rm -rf .git/objects/commit-graph*" &&
347 git commit-graph write --reachable &&
348 test_must_fail git branch -d to-delete 2>err &&
349 grep "not fully merged" err
350'
351
cddd127b
MG
352test_expect_success 'git branch -v -d t should work' '
353 git branch t &&
cbc5cf7c 354 git rev-parse --verify refs/heads/t &&
cddd127b 355 git branch -v -d t &&
cbc5cf7c 356 test_must_fail git rev-parse --verify refs/heads/t
cddd127b
MG
357'
358
359test_expect_success 'git branch -v -m t s should work' '
360 git branch t &&
cbc5cf7c 361 git rev-parse --verify refs/heads/t &&
cddd127b 362 git branch -v -m t s &&
cbc5cf7c
DT
363 test_must_fail git rev-parse --verify refs/heads/t &&
364 git rev-parse --verify refs/heads/s &&
cddd127b
MG
365 git branch -d s
366'
367
368test_expect_success 'git branch -m -d t s should fail' '
369 git branch t &&
cbc5cf7c 370 git rev-parse refs/heads/t &&
cddd127b
MG
371 test_must_fail git branch -m -d t s &&
372 git branch -d t &&
cbc5cf7c 373 test_must_fail git rev-parse refs/heads/t
cddd127b
MG
374'
375
376test_expect_success 'git branch --list -d t should fail' '
377 git branch t &&
cbc5cf7c 378 git rev-parse refs/heads/t &&
cddd127b
MG
379 test_must_fail git branch --list -d t &&
380 git branch -d t &&
cbc5cf7c 381 test_must_fail git rev-parse refs/heads/t
cddd127b
MG
382'
383
f3534c98
JT
384test_expect_success 'deleting checked-out branch from repo that is a submodule' '
385 test_when_finished "rm -rf repo1 repo2" &&
386
387 git init repo1 &&
388 git init repo1/sub &&
389 test_commit -C repo1/sub x &&
f8d510ed 390 test_config_global protocol.file.allow always &&
f3534c98
JT
391 git -C repo1 submodule add ./sub &&
392 git -C repo1 commit -m "adding sub" &&
393
394 git clone --recurse-submodules repo1 repo2 &&
395 git -C repo2/sub checkout -b work &&
396 test_must_fail git -C repo2/sub branch -D work
397'
398
399test_expect_success 'bare main worktree has HEAD at branch deleted by secondary worktree' '
400 test_when_finished "rm -rf nonbare base secondary" &&
401
ec9779bc 402 git init -b main nonbare &&
f3534c98
JT
403 test_commit -C nonbare x &&
404 git clone --bare nonbare bare &&
ec9779bc
JS
405 git -C bare worktree add --detach ../secondary main &&
406 git -C secondary branch -D main
f3534c98
JT
407'
408
ac5bbc02
JH
409test_expect_success 'git branch --list -v with --abbrev' '
410 test_when_finished "git branch -D t" &&
411 git branch t &&
412 git branch -v --list t >actual.default &&
413 git branch -v --list --abbrev t >actual.abbrev &&
414 test_cmp actual.default actual.abbrev &&
415
416 git branch -v --list --no-abbrev t >actual.noabbrev &&
417 git branch -v --list --abbrev=0 t >actual.0abbrev &&
a9ecaa06 418 git -c core.abbrev=no branch -v --list t >actual.noabbrev-conf &&
ac5bbc02 419 test_cmp actual.noabbrev actual.0abbrev &&
a9ecaa06 420 test_cmp actual.noabbrev actual.noabbrev-conf &&
ac5bbc02
JH
421
422 git branch -v --list --abbrev=36 t >actual.36abbrev &&
423 # how many hexdigits are used?
424 read name objdefault rest <actual.abbrev &&
425 read name obj36 rest <actual.36abbrev &&
426 objfull=$(git rev-parse --verify t) &&
427
428 # are we really getting abbreviations?
429 test "$obj36" != "$objdefault" &&
430 expr "$obj36" : "$objdefault" >/dev/null &&
431 test "$objfull" != "$obj36" &&
432 expr "$objfull" : "$obj36" >/dev/null
433
434'
435
ec9779bc 436test_expect_success 'git branch --column' '
ebe31ef2 437 COLUMNS=81 git branch --column=column >actual &&
6d504d5b 438 cat >expect <<\EOF &&
66713e84
JS
439 a/b/c bam foo l * main n o/p r
440 abc bar j/k m/m mb o/o q topic
ebe31ef2 441EOF
6d504d5b 442 test_cmp expect actual
ebe31ef2
NTND
443'
444
445test_expect_success 'git branch --column with an extremely long branch name' '
446 long=this/is/a/part/of/long/branch/name &&
447 long=z$long/$long/$long/$long &&
448 test_when_finished "git branch -d $long" &&
449 git branch $long &&
450 COLUMNS=80 git branch --column=column >actual &&
6d504d5b 451 cat >expect <<EOF &&
ebe31ef2
NTND
452 a/b/c
453 abc
454 bam
455 bar
456 foo
457 j/k
458 l
459 m/m
ec9779bc 460* main
e3d6539d 461 mb
ebe31ef2
NTND
462 n
463 o/o
464 o/p
465 q
466 r
432f5e63 467 topic
ebe31ef2
NTND
468 $long
469EOF
6d504d5b 470 test_cmp expect actual
ebe31ef2
NTND
471'
472
ec9779bc 473test_expect_success 'git branch with column.*' '
ebe31ef2
NTND
474 git config column.ui column &&
475 git config column.branch "dense" &&
476 COLUMNS=80 git branch >actual &&
477 git config --unset column.branch &&
478 git config --unset column.ui &&
6d504d5b 479 cat >expect <<\EOF &&
66713e84
JS
480 a/b/c bam foo l * main n o/p r
481 abc bar j/k m/m mb o/o q topic
ebe31ef2 482EOF
6d504d5b 483 test_cmp expect actual
ebe31ef2
NTND
484'
485
486test_expect_success 'git branch --column -v should fail' '
487 test_must_fail git branch --column -v
488'
489
ec9779bc 490test_expect_success 'git branch -v with column.ui ignored' '
ebe31ef2 491 git config column.ui column &&
56300ff3 492 COLUMNS=80 git branch -v | cut -c -8 | sed "s/ *$//" >actual &&
ebe31ef2 493 git config --unset column.ui &&
6d504d5b 494 cat >expect <<\EOF &&
ebe31ef2
NTND
495 a/b/c
496 abc
497 bam
498 bar
499 foo
500 j/k
501 l
502 m/m
ec9779bc 503* main
e3d6539d 504 mb
ebe31ef2
NTND
505 n
506 o/o
507 o/p
508 q
509 r
432f5e63 510 topic
ebe31ef2 511EOF
6d504d5b 512 test_cmp expect actual
ebe31ef2
NTND
513'
514
01ebb9dc
GB
515mv .git/config .git/config-saved
516
49c9a2ff 517test_expect_success SHA1 'git branch -m q q2 without config should succeed' '
5be60078
JH
518 git branch -m q q2 &&
519 git branch -m q2 q
01ebb9dc
GB
520'
521
522mv .git/config-saved .git/config
523
5be60078 524git config branch.s/s.dummy Hello
dc81c58c 525
0d158ebb 526test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
7687f19e 527 git branch --create-reflog s/s &&
d0ab0584 528 git reflog exists refs/heads/s/s &&
7687f19e 529 git branch --create-reflog s/t &&
d0ab0584 530 git reflog exists refs/heads/s/t &&
0d158ebb
RR
531 git branch -d s/t &&
532 git branch -m s/s s &&
d0ab0584 533 git reflog exists refs/heads/s
0d158ebb 534'
c976d415 535
0d158ebb
RR
536test_expect_success 'config information was renamed, too' '
537 test $(git config branch.s.dummy) = Hello &&
b8f354f2 538 test_must_fail git config branch.s/s.dummy
0d158ebb 539'
dc81c58c 540
c8b2cec0 541test_expect_success 'git branch -m correctly renames multiple config sections' '
ec9779bc
JS
542 test_when_finished "git checkout main" &&
543 git checkout -b source main &&
c8b2cec0
ÆAB
544
545 # Assert that a config file with multiple config sections has
546 # those sections preserved...
547 cat >expect <<-\EOF &&
548 branch.dest.key1=value1
549 some.gar.b=age
550 branch.dest.key2=value2
551 EOF
552 cat >config.branch <<\EOF &&
553;; Note the lack of -\EOF above & mixed indenting here. This is
554;; intentional, we are also testing that the formatting of copied
555;; sections is preserved.
556
557;; Comment for source. Tabs
558[branch "source"]
559 ;; Comment for the source value
560 key1 = value1
561;; Comment for some.gar. Spaces
562[some "gar"]
563 ;; Comment for the some.gar value
564 b = age
565;; Comment for source, again. Mixed tabs/spaces.
566[branch "source"]
567 ;; Comment for the source value, again
568 key2 = value2
569EOF
570 cat config.branch >>.git/config &&
571 git branch -m source dest &&
572 git config -f .git/config -l | grep -F -e source -e dest -e some.gar >actual &&
573 test_cmp expect actual &&
574
575 # ...and that the comments for those sections are also
576 # preserved.
577 cat config.branch | sed "s/\"source\"/\"dest\"/" >expect &&
578 sed -n -e "/Note the lack/,\$p" .git/config >actual &&
579 test_cmp expect actual
580'
581
52d59cc6
SD
582test_expect_success 'git branch -c dumps usage' '
583 test_expect_code 128 git branch -c 2>err &&
6789275d 584 test_grep "branch name required" err
52d59cc6
SD
585'
586
587test_expect_success 'git branch --copy dumps usage' '
588 test_expect_code 128 git branch --copy 2>err &&
6789275d 589 test_grep "branch name required" err
52d59cc6
SD
590'
591
592test_expect_success 'git branch -c d e should work' '
7687f19e 593 git branch --create-reflog d &&
52d59cc6
SD
594 git reflog exists refs/heads/d &&
595 git config branch.d.dummy Hello &&
596 git branch -c d e &&
597 git reflog exists refs/heads/d &&
598 git reflog exists refs/heads/e &&
599 echo Hello >expect &&
600 git config branch.e.dummy >actual &&
601 test_cmp expect actual &&
602 echo Hello >expect &&
603 git config branch.d.dummy >actual &&
604 test_cmp expect actual
605'
606
607test_expect_success 'git branch --copy is a synonym for -c' '
7687f19e 608 git branch --create-reflog copy &&
52d59cc6
SD
609 git reflog exists refs/heads/copy &&
610 git config branch.copy.dummy Hello &&
611 git branch --copy copy copy-to &&
612 git reflog exists refs/heads/copy &&
613 git reflog exists refs/heads/copy-to &&
614 echo Hello >expect &&
615 git config branch.copy.dummy >actual &&
616 test_cmp expect actual &&
617 echo Hello >expect &&
618 git config branch.copy-to.dummy >actual &&
619 test_cmp expect actual
620'
621
e5435ff1 622test_expect_success 'git branch -c ee ef should copy ee to create branch ef' '
52d59cc6
SD
623 git checkout -b ee &&
624 git reflog exists refs/heads/ee &&
625 git config branch.ee.dummy Hello &&
626 git branch -c ee ef &&
627 git reflog exists refs/heads/ee &&
628 git reflog exists refs/heads/ef &&
629 test $(git config branch.ee.dummy) = Hello &&
630 test $(git config branch.ef.dummy) = Hello &&
e5435ff1 631 test $(git rev-parse --abbrev-ref HEAD) = ee
52d59cc6
SD
632'
633
634test_expect_success 'git branch -c f/f g/g should work' '
7687f19e 635 git branch --create-reflog f/f &&
52d59cc6
SD
636 git reflog exists refs/heads/f/f &&
637 git config branch.f/f.dummy Hello &&
638 git branch -c f/f g/g &&
639 git reflog exists refs/heads/f/f &&
640 git reflog exists refs/heads/g/g &&
641 test $(git config branch.f/f.dummy) = Hello &&
642 test $(git config branch.g/g.dummy) = Hello
643'
644
645test_expect_success 'git branch -c m2 m2 should work' '
7687f19e 646 git branch --create-reflog m2 &&
52d59cc6
SD
647 git reflog exists refs/heads/m2 &&
648 git config branch.m2.dummy Hello &&
649 git branch -c m2 m2 &&
650 git reflog exists refs/heads/m2 &&
651 test $(git config branch.m2.dummy) = Hello
652'
653
654test_expect_success 'git branch -c zz zz/zz should fail' '
7687f19e 655 git branch --create-reflog zz &&
52d59cc6
SD
656 git reflog exists refs/heads/zz &&
657 test_must_fail git branch -c zz zz/zz
658'
659
660test_expect_success 'git branch -c b/b b should fail' '
7687f19e 661 git branch --create-reflog b/b &&
52d59cc6
SD
662 test_must_fail git branch -c b/b b
663'
664
665test_expect_success 'git branch -C o/q o/p should work when o/p exists' '
7687f19e 666 git branch --create-reflog o/q &&
52d59cc6
SD
667 git reflog exists refs/heads/o/q &&
668 git reflog exists refs/heads/o/p &&
669 git branch -C o/q o/p
670'
671
672test_expect_success 'git branch -c -f o/q o/p should work when o/p exists' '
673 git reflog exists refs/heads/o/q &&
674 git reflog exists refs/heads/o/p &&
675 git branch -c -f o/q o/p
676'
677
40c17eb1 678test_expect_success 'git branch -c qq rr/qq should fail when rr exists' '
52d59cc6
SD
679 git branch qq &&
680 git branch rr &&
681 test_must_fail git branch -c qq rr/qq
682'
683
684test_expect_success 'git branch -C b1 b2 should fail when b2 is checked out' '
685 git branch b1 &&
686 git checkout -b b2 &&
687 test_must_fail git branch -C b1 b2
688'
689
690test_expect_success 'git branch -C c1 c2 should succeed when c1 is checked out' '
691 git checkout -b c1 &&
692 git branch c2 &&
693 git branch -C c1 c2 &&
e5435ff1 694 test $(git rev-parse --abbrev-ref HEAD) = c1
52d59cc6
SD
695'
696
e5435ff1 697test_expect_success 'git branch -C c1 c2 should never touch HEAD' '
52d59cc6 698 msg="Branch: copied refs/heads/c1 to refs/heads/c2" &&
e5435ff1 699 ! grep "$msg$" .git/logs/HEAD
52d59cc6
SD
700'
701
ec9779bc
JS
702test_expect_success 'git branch -C main should work when main is checked out' '
703 git checkout main &&
704 git branch -C main
52d59cc6
SD
705'
706
ec9779bc
JS
707test_expect_success 'git branch -C main main should work when main is checked out' '
708 git checkout main &&
709 git branch -C main main
52d59cc6
SD
710'
711
ec9779bc
JS
712test_expect_success 'git branch -C main5 main5 should work when main is checked out' '
713 git checkout main &&
432f5e63
JS
714 git branch main5 &&
715 git branch -C main5 main5
52d59cc6
SD
716'
717
718test_expect_success 'git branch -C ab cd should overwrite existing config for cd' '
7687f19e 719 git branch --create-reflog cd &&
52d59cc6
SD
720 git reflog exists refs/heads/cd &&
721 git config branch.cd.dummy CD &&
7687f19e 722 git branch --create-reflog ab &&
52d59cc6
SD
723 git reflog exists refs/heads/ab &&
724 git config branch.ab.dummy AB &&
725 git branch -C ab cd &&
726 git reflog exists refs/heads/ab &&
727 git reflog exists refs/heads/cd &&
728 test $(git config branch.ab.dummy) = AB &&
729 test $(git config branch.cd.dummy) = AB
730'
731
732test_expect_success 'git branch -c correctly copies multiple config sections' '
733 FOO=1 &&
734 export FOO &&
ec9779bc
JS
735 test_when_finished "git checkout main" &&
736 git checkout -b source2 main &&
52d59cc6
SD
737
738 # Assert that a config file with multiple config sections has
739 # those sections preserved...
740 cat >expect <<-\EOF &&
741 branch.source2.key1=value1
742 branch.dest2.key1=value1
743 more.gar.b=age
744 branch.source2.key2=value2
745 branch.dest2.key2=value2
746 EOF
747 cat >config.branch <<\EOF &&
748;; Note the lack of -\EOF above & mixed indenting here. This is
749;; intentional, we are also testing that the formatting of copied
750;; sections is preserved.
751
752;; Comment for source2. Tabs
753[branch "source2"]
754 ;; Comment for the source2 value
755 key1 = value1
756;; Comment for more.gar. Spaces
757[more "gar"]
758 ;; Comment for the more.gar value
759 b = age
760;; Comment for source2, again. Mixed tabs/spaces.
761[branch "source2"]
762 ;; Comment for the source2 value, again
763 key2 = value2
764EOF
765 cat config.branch >>.git/config &&
766 git branch -c source2 dest2 &&
767 git config -f .git/config -l | grep -F -e source2 -e dest2 -e more.gar >actual &&
768 test_cmp expect actual &&
769
770 # ...and that the comments and formatting for those sections
771 # is also preserved.
772 cat >expect <<\EOF &&
773;; Comment for source2. Tabs
774[branch "source2"]
775 ;; Comment for the source2 value
776 key1 = value1
777;; Comment for more.gar. Spaces
778[branch "dest2"]
779 ;; Comment for the source2 value
780 key1 = value1
781;; Comment for more.gar. Spaces
782[more "gar"]
783 ;; Comment for the more.gar value
784 b = age
785;; Comment for source2, again. Mixed tabs/spaces.
786[branch "source2"]
787 ;; Comment for the source2 value, again
788 key2 = value2
789[branch "dest2"]
790 ;; Comment for the source2 value, again
791 key2 = value2
792EOF
793 sed -n -e "/Comment for source2/,\$p" .git/config >actual &&
794 test_cmp expect actual
795'
796
566c7707
RS
797test_expect_success 'deleting a symref' '
798 git branch target &&
799 git symbolic-ref refs/heads/symref refs/heads/target &&
13baa9fe 800 echo "Deleted branch symref (was refs/heads/target)." >expect &&
566c7707
RS
801 git branch -d symref >actual &&
802 test_path_is_file .git/refs/heads/target &&
803 test_path_is_missing .git/refs/heads/symref &&
1108cea7 804 test_cmp expect actual
566c7707
RS
805'
806
0fe700e3
RS
807test_expect_success 'deleting a dangling symref' '
808 git symbolic-ref refs/heads/dangling-symref nowhere &&
809 test_path_is_file .git/refs/heads/dangling-symref &&
13baa9fe 810 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
0fe700e3
RS
811 git branch -d dangling-symref >actual &&
812 test_path_is_missing .git/refs/heads/dangling-symref &&
1108cea7 813 test_cmp expect actual
0fe700e3
RS
814'
815
62a2d525
JN
816test_expect_success 'deleting a self-referential symref' '
817 git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
818 test_path_is_file .git/refs/heads/self-reference &&
819 echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
820 git branch -d self-reference >actual &&
821 test_path_is_missing .git/refs/heads/self-reference &&
1108cea7 822 test_cmp expect actual
62a2d525
JN
823'
824
0d158ebb 825test_expect_success 'renaming a symref is not allowed' '
ec9779bc 826 git symbolic-ref refs/heads/topic refs/heads/main &&
432f5e63
JS
827 test_must_fail git branch -m topic new-topic &&
828 git symbolic-ref refs/heads/topic &&
ec9779bc 829 test_path_is_file .git/refs/heads/main &&
432f5e63 830 test_path_is_missing .git/refs/heads/new-topic
eca35a25
MV
831'
832
0d158ebb 833test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
7687f19e 834 git branch --create-reflog u &&
0d158ebb
RR
835 mv .git/logs/refs/heads/u real-u &&
836 ln -s real-u .git/logs/refs/heads/u &&
837 test_must_fail git branch -m u v
838'
839
aa30fe14
HWN
840test_expect_success SYMLINKS 'git branch -m with symlinked .git/refs' '
841 test_when_finished "rm -rf subdir" &&
842 git init --bare subdir &&
843
844 rm -rfv subdir/refs subdir/objects subdir/packed-refs &&
845 ln -s ../.git/refs subdir/refs &&
846 ln -s ../.git/objects subdir/objects &&
847 ln -s ../.git/packed-refs subdir/packed-refs &&
848
849 git -C subdir rev-parse --absolute-git-dir >subdir.dir &&
850 git rev-parse --absolute-git-dir >our.dir &&
851 ! test_cmp subdir.dir our.dir &&
852
853 git -C subdir log &&
854 git -C subdir branch rename-src &&
855 git rev-parse rename-src >expect &&
856 git -C subdir branch -m rename-src rename-dest &&
857 git rev-parse rename-dest >actual &&
858 test_cmp expect actual &&
859 git branch -D rename-dest
860'
861
0d158ebb
RR
862test_expect_success 'test tracking setup via --track' '
863 git config remote.local.url . &&
864 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc
JS
865 (git show-ref -q refs/remotes/local/main || git fetch local) &&
866 git branch --track my1 local/main &&
0d158ebb 867 test $(git config branch.my1.remote) = local &&
ec9779bc 868 test $(git config branch.my1.merge) = refs/heads/main
0d158ebb
RR
869'
870
871test_expect_success 'test tracking setup (non-wildcard, matching)' '
872 git config remote.local.url . &&
ec9779bc
JS
873 git config remote.local.fetch refs/heads/main:refs/remotes/local/main &&
874 (git show-ref -q refs/remotes/local/main || git fetch local) &&
875 git branch --track my4 local/main &&
0d158ebb 876 test $(git config branch.my4.remote) = local &&
ec9779bc 877 test $(git config branch.my4.merge) = refs/heads/main
0d158ebb
RR
878'
879
41c21f22 880test_expect_success 'tracking setup fails on non-matching refspec' '
0d158ebb 881 git config remote.local.url . &&
81f339dc 882 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc 883 (git show-ref -q refs/remotes/local/main || git fetch local) &&
81f339dc 884 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
ec9779bc 885 test_must_fail git branch --track my5 local/main &&
9c9cd39a
JH
886 test_must_fail git config branch.my5.remote &&
887 test_must_fail git config branch.my5.merge
0d158ebb
RR
888'
889
890test_expect_success 'test tracking setup via config' '
891 git config branch.autosetupmerge true &&
892 git config remote.local.url . &&
893 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc
JS
894 (git show-ref -q refs/remotes/local/main || git fetch local) &&
895 git branch my3 local/main &&
0d158ebb 896 test $(git config branch.my3.remote) = local &&
ec9779bc 897 test $(git config branch.my3.merge) = refs/heads/main
0d158ebb
RR
898'
899
900test_expect_success 'test overriding tracking setup via --no-track' '
901 git config branch.autosetupmerge true &&
902 git config remote.local.url . &&
903 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc
JS
904 (git show-ref -q refs/remotes/local/main || git fetch local) &&
905 git branch --no-track my2 local/main &&
0d158ebb
RR
906 git config branch.autosetupmerge false &&
907 ! test "$(git config branch.my2.remote)" = local &&
ec9779bc 908 ! test "$(git config branch.my2.merge)" = refs/heads/main
0d158ebb
RR
909'
910
911test_expect_success 'no tracking without .fetch entries' '
912 git config branch.autosetupmerge true &&
913 git branch my6 s &&
002ba037 914 git config branch.autosetupmerge false &&
0d158ebb
RR
915 test -z "$(git config branch.my6.remote)" &&
916 test -z "$(git config branch.my6.merge)"
917'
918
919test_expect_success 'test tracking setup via --track but deeper' '
920 git config remote.local.url . &&
921 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
922 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
923 git branch --track my7 local/o/o &&
924 test "$(git config branch.my7.remote)" = local &&
925 test "$(git config branch.my7.merge)" = refs/heads/o/o
926'
927
928test_expect_success 'test deleting branch deletes branch config' '
929 git branch -d my7 &&
930 test -z "$(git config branch.my7.remote)" &&
931 test -z "$(git config branch.my7.merge)"
932'
933
934test_expect_success 'test deleting branch without config' '
935 git branch my7 s &&
936 sha1=$(git rev-parse my7 | cut -c 1-7) &&
937 echo "Deleted branch my7 (was $sha1)." >expect &&
938 git branch -d my7 >actual 2>&1 &&
1108cea7 939 test_cmp expect actual
0d158ebb
RR
940'
941
f292244c
KY
942test_expect_success 'deleting currently checked out branch fails' '
943 git worktree add -b my7 my7 &&
944 test_must_fail git -C my7 branch -d my7 &&
ab313814
NB
945 test_must_fail git branch -d my7 &&
946 rm -r my7 &&
947 git worktree prune
f292244c
KY
948'
949
0d158ebb
RR
950test_expect_success 'test --track without .fetch entries' '
951 git branch --track my8 &&
952 test "$(git config branch.my8.remote)" &&
953 test "$(git config branch.my8.merge)"
954'
955
956test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
957 git config branch.autosetupmerge always &&
958 git branch my9 HEAD^ &&
959 git config branch.autosetupmerge false
960'
961
962test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
963 test_must_fail git branch --track my10 HEAD^
964'
965
966test_expect_success 'branch from tag w/--track causes failure' '
967 git tag foobar &&
968 test_must_fail git branch --track my11 foobar
969'
970
bdaf1dfa
TK
971test_expect_success 'simple tracking works when remote branch name matches' '
972 test_when_finished "rm -rf otherserver" &&
973 git init otherserver &&
974 test_commit -C otherserver my_commit 1 &&
975 git -C otherserver branch feature &&
976 test_config branch.autosetupmerge simple &&
977 test_config remote.otherserver.url otherserver &&
978 test_config remote.otherserver.fetch refs/heads/*:refs/remotes/otherserver/* &&
979 git fetch otherserver &&
980 git branch feature otherserver/feature &&
981 test_cmp_config otherserver branch.feature.remote &&
982 test_cmp_config refs/heads/feature branch.feature.merge
983'
984
985test_expect_success 'simple tracking skips when remote branch name does not match' '
986 test_config branch.autosetupmerge simple &&
987 test_config remote.local.url . &&
988 test_config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
989 git fetch local &&
990 git branch my-other local/main &&
991 test_cmp_config "" --default "" branch.my-other.remote &&
992 test_cmp_config "" --default "" branch.my-other.merge
993'
994
995test_expect_success 'simple tracking skips when remote ref is not a branch' '
996 test_config branch.autosetupmerge simple &&
997 test_config remote.localtags.url . &&
998 test_config remote.localtags.fetch refs/tags/*:refs/remotes/localtags/* &&
999 git tag mytag12 main &&
1000 git fetch localtags &&
1001 git branch mytag12 localtags/mytag12 &&
1002 test_cmp_config "" --default "" branch.mytag12.remote &&
1003 test_cmp_config "" --default "" branch.mytag12.merge
1004'
1005
0cb24fe8 1006test_expect_success '--set-upstream-to fails on multiple branches' '
6b709306 1007 echo "fatal: too many arguments to set new upstream" >expect &&
ec9779bc 1008 test_must_fail git branch --set-upstream-to main a b c 2>err &&
1108cea7 1009 test_cmp expect err
0cb24fe8
JH
1010'
1011
1012test_expect_success '--set-upstream-to fails on detached HEAD' '
1013 git checkout HEAD^{} &&
6b709306 1014 test_when_finished git checkout - &&
ec9779bc
JS
1015 echo "fatal: could not set upstream of HEAD to main when it does not point to any branch." >expect &&
1016 test_must_fail git branch --set-upstream-to main 2>err &&
1108cea7 1017 test_cmp expect err
0cb24fe8
JH
1018'
1019
8a3e5ecd 1020test_expect_success '--set-upstream-to fails on a missing dst branch' '
6b709306 1021 echo "fatal: branch '"'"'does-not-exist'"'"' does not exist" >expect &&
ec9779bc 1022 test_must_fail git branch --set-upstream-to main does-not-exist 2>err &&
1108cea7 1023 test_cmp expect err
8a3e5ecd
JK
1024'
1025
1026test_expect_success '--set-upstream-to fails on a missing src branch' '
ec9779bc 1027 test_must_fail git branch --set-upstream-to does-not-exist main 2>err &&
6789275d 1028 test_grep "the requested upstream branch '"'"'does-not-exist'"'"' does not exist" err
8a3e5ecd
JK
1029'
1030
1031test_expect_success '--set-upstream-to fails on a non-ref' '
7435e7e2 1032 echo "fatal: cannot set up tracking information; starting point '"'"'HEAD^{}'"'"' is not a branch" >expect &&
6b709306 1033 test_must_fail git branch --set-upstream-to HEAD^{} 2>err &&
1108cea7 1034 test_cmp expect err
8a3e5ecd
JK
1035'
1036
27852b2c
PS
1037test_expect_success '--set-upstream-to fails on locked config' '
1038 test_when_finished "rm -f .git/config.lock" &&
1039 >.git/config.lock &&
1040 git branch locked &&
6b709306 1041 test_must_fail git branch --set-upstream-to locked 2>err &&
6789275d 1042 test_grep "could not lock config file .git/config" err
27852b2c
PS
1043'
1044
0d158ebb 1045test_expect_success 'use --set-upstream-to modify HEAD' '
ec9779bc
JS
1046 test_config branch.main.remote foo &&
1047 test_config branch.main.merge foo &&
d0423ddd 1048 git branch my12 &&
0d158ebb 1049 git branch --set-upstream-to my12 &&
ec9779bc
JS
1050 test "$(git config branch.main.remote)" = "." &&
1051 test "$(git config branch.main.merge)" = "refs/heads/my12"
0d158ebb
RR
1052'
1053
1054test_expect_success 'use --set-upstream-to modify a particular branch' '
d0423ddd 1055 git branch my13 &&
ec9779bc 1056 git branch --set-upstream-to main my13 &&
93a6b3f2 1057 test_when_finished "git branch --unset-upstream my13" &&
0d158ebb 1058 test "$(git config branch.my13.remote)" = "." &&
ec9779bc 1059 test "$(git config branch.my13.merge)" = "refs/heads/main"
0d158ebb
RR
1060'
1061
1062test_expect_success '--unset-upstream should fail if given a non-existent branch' '
6b709306
DL
1063 echo "fatal: Branch '"'"'i-dont-exist'"'"' has no upstream information" >expect &&
1064 test_must_fail git branch --unset-upstream i-dont-exist 2>err &&
1108cea7 1065 test_cmp expect err
0d158ebb
RR
1066'
1067
b81842cb
PS
1068test_expect_success '--unset-upstream should fail if config is locked' '
1069 test_when_finished "rm -f .git/config.lock" &&
1070 git branch --set-upstream-to locked &&
1071 >.git/config.lock &&
6b709306 1072 test_must_fail git branch --unset-upstream 2>err &&
6789275d 1073 test_grep "could not lock config file .git/config" err
b81842cb
PS
1074'
1075
0d158ebb 1076test_expect_success 'test --unset-upstream on HEAD' '
d0423ddd 1077 git branch my14 &&
ec9779bc
JS
1078 test_config branch.main.remote foo &&
1079 test_config branch.main.merge foo &&
0d158ebb
RR
1080 git branch --set-upstream-to my14 &&
1081 git branch --unset-upstream &&
ec9779bc
JS
1082 test_must_fail git config branch.main.remote &&
1083 test_must_fail git config branch.main.merge &&
0d158ebb 1084 # fail for a branch without upstream set
ec9779bc 1085 echo "fatal: Branch '"'"'main'"'"' has no upstream information" >expect &&
6b709306 1086 test_must_fail git branch --unset-upstream 2>err &&
1108cea7 1087 test_cmp expect err
0d158ebb
RR
1088'
1089
0cb24fe8 1090test_expect_success '--unset-upstream should fail on multiple branches' '
6b709306
DL
1091 echo "fatal: too many arguments to unset upstream" >expect &&
1092 test_must_fail git branch --unset-upstream a b c 2>err &&
1108cea7 1093 test_cmp expect err
0cb24fe8
JH
1094'
1095
1096test_expect_success '--unset-upstream should fail on detached HEAD' '
1097 git checkout HEAD^{} &&
6b709306
DL
1098 test_when_finished git checkout - &&
1099 echo "fatal: could not unset upstream of HEAD when it does not point to any branch." >expect &&
1100 test_must_fail git branch --unset-upstream 2>err &&
1108cea7 1101 test_cmp expect err
0cb24fe8
JH
1102'
1103
0d158ebb 1104test_expect_success 'test --unset-upstream on a particular branch' '
d0423ddd 1105 git branch my15 &&
ec9779bc 1106 git branch --set-upstream-to main my14 &&
0d158ebb
RR
1107 git branch --unset-upstream my14 &&
1108 test_must_fail git config branch.my14.remote &&
1109 test_must_fail git config branch.my14.merge
1110'
1111
cf317877 1112test_expect_success 'disabled option --set-upstream fails' '
ec9779bc 1113 test_must_fail git branch --set-upstream origin/main
b347d06b
CMN
1114'
1115
a3f40ec4 1116test_expect_success '--set-upstream-to notices an error to set branch as own upstream' "
95052d1f 1117 git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
6d504d5b 1118 cat >expect <<-\EOF &&
0669bdf4 1119 warning: not setting branch 'my13' as its own upstream
95052d1f
BG
1120 EOF
1121 test_expect_code 1 git config branch.my13.remote &&
1122 test_expect_code 1 git config branch.my13.merge &&
1108cea7 1123 test_cmp expect actual
a3f40ec4 1124"
95052d1f 1125
0746d19a
PB
1126# Keep this test last, as it changes the current branch
1127cat >expect <<EOF
ec9779bc 1128$ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from main
0746d19a 1129EOF
0d158ebb
RR
1130test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
1131 GIT_COMMITTER_DATE="2005-05-26 23:30" \
ec9779bc 1132 git checkout -b g/h/i -l main &&
0d158ebb
RR
1133 test_path_is_file .git/refs/heads/g/h/i &&
1134 test_path_is_file .git/logs/refs/heads/g/h/i &&
1135 test_cmp expect .git/logs/refs/heads/g/h/i
1136'
0746d19a 1137
b2099957 1138test_expect_success 'checkout -b makes reflog by default' '
ec9779bc 1139 git checkout main &&
b2099957
EM
1140 git config --unset core.logAllRefUpdates &&
1141 git checkout -b alpha &&
6e6842e3 1142 git rev-parse --verify alpha@{0}
b2099957
EM
1143'
1144
1145test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
ec9779bc 1146 git checkout main &&
b2099957
EM
1147 git config core.logAllRefUpdates false &&
1148 git checkout -b beta &&
6e6842e3 1149 test_must_fail git rev-parse --verify beta@{0}
b2099957
EM
1150'
1151
1152test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
ec9779bc 1153 git checkout main &&
b2099957
EM
1154 git checkout -lb gamma &&
1155 git config --unset core.logAllRefUpdates &&
6e6842e3 1156 git rev-parse --verify gamma@{0}
b2099957
EM
1157'
1158
e4921d87 1159test_expect_success 'avoid ambiguous track and advise' '
1d0a694b
DB
1160 git config branch.autosetupmerge true &&
1161 git config remote.ambi1.url lalala &&
ec9779bc 1162 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/main &&
1d0a694b 1163 git config remote.ambi2.url lilili &&
ec9779bc 1164 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/main &&
e4921d87
TK
1165 cat <<-EOF >expected &&
1166 fatal: not tracking: ambiguous information for ref '\''refs/heads/main'\''
1167 hint: There are multiple remotes whose fetch refspecs map to the remote
1168 hint: tracking ref '\''refs/heads/main'\'':
1169 hint: ambi1
1170 hint: ambi2
1171 hint: ''
1172 hint: This is typically a configuration error.
1173 hint: ''
1174 hint: To support setting up tracking branches, ensure that
1175 hint: different remotes'\'' fetch refspecs map into different
1176 hint: tracking namespaces.
1177 EOF
1178 test_must_fail git branch all1 main 2>actual &&
1179 test_cmp expected actual &&
1d0a694b
DB
1180 test -z "$(git config branch.all1.merge)"
1181'
1182
c998ae9b
DS
1183test_expect_success 'autosetuprebase local on a tracked local branch' '
1184 git config remote.local.url . &&
1185 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1186 git config branch.autosetuprebase local &&
0cb0e143 1187 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
1188 git branch mybase &&
1189 git branch --track myr1 mybase &&
1190 test "$(git config branch.myr1.remote)" = . &&
1191 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
1192 test "$(git config branch.myr1.rebase)" = true
1193'
1194
1195test_expect_success 'autosetuprebase always on a tracked local branch' '
1196 git config remote.local.url . &&
1197 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1198 git config branch.autosetuprebase always &&
0cb0e143 1199 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
1200 git branch mybase2 &&
1201 git branch --track myr2 mybase &&
1202 test "$(git config branch.myr2.remote)" = . &&
1203 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
1204 test "$(git config branch.myr2.rebase)" = true
1205'
1206
1207test_expect_success 'autosetuprebase remote on a tracked local branch' '
1208 git config remote.local.url . &&
1209 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1210 git config branch.autosetuprebase remote &&
0cb0e143 1211 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
1212 git branch mybase3 &&
1213 git branch --track myr3 mybase2 &&
1214 test "$(git config branch.myr3.remote)" = . &&
1215 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
1216 ! test "$(git config branch.myr3.rebase)" = true
1217'
1218
1219test_expect_success 'autosetuprebase never on a tracked local branch' '
1220 git config remote.local.url . &&
1221 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1222 git config branch.autosetuprebase never &&
0cb0e143 1223 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
1224 git branch mybase4 &&
1225 git branch --track myr4 mybase2 &&
1226 test "$(git config branch.myr4.remote)" = . &&
1227 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
1228 ! test "$(git config branch.myr4.rebase)" = true
1229'
1230
1231test_expect_success 'autosetuprebase local on a tracked remote branch' '
1232 git config remote.local.url . &&
1233 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1234 git config branch.autosetuprebase local &&
ec9779bc
JS
1235 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1236 git branch --track myr5 local/main &&
c998ae9b 1237 test "$(git config branch.myr5.remote)" = local &&
ec9779bc 1238 test "$(git config branch.myr5.merge)" = refs/heads/main &&
c998ae9b
DS
1239 ! test "$(git config branch.myr5.rebase)" = true
1240'
1241
1242test_expect_success 'autosetuprebase never on a tracked remote branch' '
1243 git config remote.local.url . &&
1244 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1245 git config branch.autosetuprebase never &&
ec9779bc
JS
1246 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1247 git branch --track myr6 local/main &&
c998ae9b 1248 test "$(git config branch.myr6.remote)" = local &&
ec9779bc 1249 test "$(git config branch.myr6.merge)" = refs/heads/main &&
c998ae9b
DS
1250 ! test "$(git config branch.myr6.rebase)" = true
1251'
1252
1253test_expect_success 'autosetuprebase remote on a tracked remote branch' '
1254 git config remote.local.url . &&
1255 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1256 git config branch.autosetuprebase remote &&
ec9779bc
JS
1257 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1258 git branch --track myr7 local/main &&
c998ae9b 1259 test "$(git config branch.myr7.remote)" = local &&
ec9779bc 1260 test "$(git config branch.myr7.merge)" = refs/heads/main &&
c998ae9b
DS
1261 test "$(git config branch.myr7.rebase)" = true
1262'
1263
1264test_expect_success 'autosetuprebase always on a tracked remote branch' '
1265 git config remote.local.url . &&
1266 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1267 git config branch.autosetuprebase remote &&
ec9779bc
JS
1268 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1269 git branch --track myr8 local/main &&
c998ae9b 1270 test "$(git config branch.myr8.remote)" = local &&
ec9779bc 1271 test "$(git config branch.myr8.merge)" = refs/heads/main &&
c998ae9b
DS
1272 test "$(git config branch.myr8.rebase)" = true
1273'
1274
1275test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
1276 git config --unset branch.autosetuprebase &&
1277 git config remote.local.url . &&
1278 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc
JS
1279 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1280 git branch --track myr9 local/main &&
c998ae9b 1281 test "$(git config branch.myr9.remote)" = local &&
ec9779bc 1282 test "$(git config branch.myr9.merge)" = refs/heads/main &&
c998ae9b
DS
1283 test "z$(git config branch.myr9.rebase)" = z
1284'
1285
1286test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
1287 git config remote.local.url . &&
1288 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 1289 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
1290 git branch mybase10 &&
1291 git branch --track myr10 mybase2 &&
1292 test "$(git config branch.myr10.remote)" = . &&
1293 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
1294 test "z$(git config branch.myr10.rebase)" = z
1295'
1296
1297test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
1298 git config remote.local.url . &&
1299 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc 1300 (git show-ref -q refs/remotes/local/main || git fetch local) &&
c998ae9b
DS
1301 git branch --no-track myr11 mybase2 &&
1302 test "z$(git config branch.myr11.remote)" = z &&
1303 test "z$(git config branch.myr11.merge)" = z &&
1304 test "z$(git config branch.myr11.rebase)" = z
1305'
1306
1307test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
1308 git config remote.local.url . &&
1309 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc
JS
1310 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1311 git branch --no-track myr12 local/main &&
c998ae9b
DS
1312 test "z$(git config branch.myr12.remote)" = z &&
1313 test "z$(git config branch.myr12.merge)" = z &&
1314 test "z$(git config branch.myr12.rebase)" = z
1315'
1316
1317test_expect_success 'autosetuprebase never on an untracked local branch' '
1318 git config branch.autosetuprebase never &&
1319 git config remote.local.url . &&
1320 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc 1321 (git show-ref -q refs/remotes/local/main || git fetch local) &&
c998ae9b
DS
1322 git branch --no-track myr13 mybase2 &&
1323 test "z$(git config branch.myr13.remote)" = z &&
1324 test "z$(git config branch.myr13.merge)" = z &&
1325 test "z$(git config branch.myr13.rebase)" = z
1326'
1327
1328test_expect_success 'autosetuprebase local on an untracked local branch' '
1329 git config branch.autosetuprebase local &&
1330 git config remote.local.url . &&
1331 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc 1332 (git show-ref -q refs/remotes/local/main || git fetch local) &&
c998ae9b
DS
1333 git branch --no-track myr14 mybase2 &&
1334 test "z$(git config branch.myr14.remote)" = z &&
1335 test "z$(git config branch.myr14.merge)" = z &&
1336 test "z$(git config branch.myr14.rebase)" = z
1337'
1338
1339test_expect_success 'autosetuprebase remote on an untracked local branch' '
1340 git config branch.autosetuprebase remote &&
1341 git config remote.local.url . &&
1342 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc 1343 (git show-ref -q refs/remotes/local/main || git fetch local) &&
c998ae9b
DS
1344 git branch --no-track myr15 mybase2 &&
1345 test "z$(git config branch.myr15.remote)" = z &&
1346 test "z$(git config branch.myr15.merge)" = z &&
1347 test "z$(git config branch.myr15.rebase)" = z
1348'
1349
1350test_expect_success 'autosetuprebase always on an untracked local branch' '
1351 git config branch.autosetuprebase always &&
1352 git config remote.local.url . &&
1353 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc 1354 (git show-ref -q refs/remotes/local/main || git fetch local) &&
c998ae9b
DS
1355 git branch --no-track myr16 mybase2 &&
1356 test "z$(git config branch.myr16.remote)" = z &&
1357 test "z$(git config branch.myr16.merge)" = z &&
1358 test "z$(git config branch.myr16.rebase)" = z
1359'
1360
1361test_expect_success 'autosetuprebase never on an untracked remote branch' '
1362 git config branch.autosetuprebase never &&
1363 git config remote.local.url . &&
1364 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc
JS
1365 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1366 git branch --no-track myr17 local/main &&
c998ae9b
DS
1367 test "z$(git config branch.myr17.remote)" = z &&
1368 test "z$(git config branch.myr17.merge)" = z &&
1369 test "z$(git config branch.myr17.rebase)" = z
1370'
1371
1372test_expect_success 'autosetuprebase local on an untracked remote branch' '
1373 git config branch.autosetuprebase local &&
1374 git config remote.local.url . &&
1375 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc
JS
1376 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1377 git branch --no-track myr18 local/main &&
c998ae9b
DS
1378 test "z$(git config branch.myr18.remote)" = z &&
1379 test "z$(git config branch.myr18.merge)" = z &&
1380 test "z$(git config branch.myr18.rebase)" = z
1381'
1382
1383test_expect_success 'autosetuprebase remote on an untracked remote branch' '
1384 git config branch.autosetuprebase remote &&
1385 git config remote.local.url . &&
1386 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc
JS
1387 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1388 git branch --no-track myr19 local/main &&
c998ae9b
DS
1389 test "z$(git config branch.myr19.remote)" = z &&
1390 test "z$(git config branch.myr19.merge)" = z &&
1391 test "z$(git config branch.myr19.rebase)" = z
1392'
1393
1394test_expect_success 'autosetuprebase always on an untracked remote branch' '
1395 git config branch.autosetuprebase always &&
1396 git config remote.local.url . &&
1397 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
ec9779bc
JS
1398 (git show-ref -q refs/remotes/local/main || git fetch local) &&
1399 git branch --no-track myr20 local/main &&
c998ae9b
DS
1400 test "z$(git config branch.myr20.remote)" = z &&
1401 test "z$(git config branch.myr20.merge)" = z &&
1402 test "z$(git config branch.myr20.rebase)" = z
1403'
1404
21b5b1e8
JH
1405test_expect_success 'autosetuprebase always on detached HEAD' '
1406 git config branch.autosetupmerge always &&
ec9779bc 1407 test_when_finished git checkout main &&
21b5b1e8
JH
1408 git checkout HEAD^0 &&
1409 git branch my11 &&
1410 test -z "$(git config branch.my11.remote)" &&
1411 test -z "$(git config branch.my11.merge)"
1412'
1413
c998ae9b
DS
1414test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
1415 git config branch.autosetuprebase garbage &&
1416 test_must_fail git branch
1417'
1418
1419test_expect_success 'detect misconfigured autosetuprebase (no value)' '
1420 git config --unset branch.autosetuprebase &&
0d158ebb 1421 echo "[branch] autosetuprebase" >>.git/config &&
c998ae9b
DS
1422 test_must_fail git branch &&
1423 git config --unset branch.autosetuprebase
1424'
1425
99c419c9
JH
1426test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
1427 git checkout my9 &&
1428 git config --unset branch.my8.merge &&
1429 test_must_fail git branch -d my8
1430'
1431
1432test_expect_success 'attempt to delete a branch merged to its base' '
1433 # we are on my9 which is the initial commit; traditionally
1434 # we would not have allowed deleting my8 that is not merged
ec9779bc
JS
1435 # to my9, but it is set to track main that already has my8
1436 git config branch.my8.merge refs/heads/main &&
99c419c9
JH
1437 git branch -d my8
1438'
1439
1440test_expect_success 'attempt to delete a branch merged to its base' '
ec9779bc 1441 git checkout main &&
99c419c9
JH
1442 echo Third >>A &&
1443 git commit -m "Third commit" A &&
1444 git branch -t my10 my9 &&
1445 git branch -f my10 HEAD^ &&
ec9779bc 1446 # we are on main which is at the third commit, and my10
99c419c9
JH
1447 # is behind us, so traditionally we would have allowed deleting
1448 # it; but my10 is set to track my9 that is further behind.
1449 test_must_fail git branch -d my10
1450'
1451
597a9774
RS
1452test_expect_success 'branch --delete --force removes dangling branch' '
1453 git checkout main &&
1454 test_commit unstable &&
1455 hash=$(git rev-parse HEAD) &&
1456 objpath=$(echo $hash | sed -e "s|^..|.git/objects/&/|") &&
1457 git branch --no-track dangling &&
1458 mv $objpath $objpath.x &&
1459 test_when_finished "mv $objpath.x $objpath" &&
1460 git branch --delete --force dangling &&
1461 git for-each-ref refs/heads/dangling >actual &&
1462 test_must_be_empty actual
1463'
1464
c2d17ba3 1465test_expect_success 'use --edit-description' '
e288b3de 1466 EDITOR=: git branch --edit-description &&
8f241151 1467 test_expect_code 1 git config branch.main.description &&
e288b3de 1468
c2d17ba3
JH
1469 write_script editor <<-\EOF &&
1470 echo "New contents" >"$1"
1471 EOF
1472 EDITOR=./editor git branch --edit-description &&
1473 write_script editor <<-\EOF &&
1474 git stripspace -s <"$1" >"EDITOR_OUTPUT"
1475 EOF
1476 EDITOR=./editor git branch --edit-description &&
1477 echo "New contents" >expect &&
dcbaa0b3 1478 test_cmp expect EDITOR_OUTPUT
c2d17ba3
JH
1479'
1480
1481test_expect_success 'detect typo in branch name when using --edit-description' '
1482 write_script editor <<-\EOF &&
1483 echo "New contents" >"$1"
1484 EOF
512477b1 1485 test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
c2d17ba3
JH
1486'
1487
1488test_expect_success 'refuse --edit-description on unborn branch for now' '
ec9779bc 1489 test_when_finished "git checkout main" &&
c2d17ba3
JH
1490 write_script editor <<-\EOF &&
1491 echo "New contents" >"$1"
1492 EOF
1493 git checkout --orphan unborn &&
512477b1 1494 test_must_fail env EDITOR=./editor git branch --edit-description
c2d17ba3
JH
1495'
1496
6c41e975
CMN
1497test_expect_success '--merged catches invalid object names' '
1498 test_must_fail git branch --merged 0000000000000000000000000000000000000000
1499'
1500
1f537be3
ES
1501test_expect_success '--list during rebase' '
1502 test_when_finished "reset_rebase" &&
ec9779bc 1503 git checkout main &&
1f537be3
ES
1504 FAKE_LINES="1 edit 2" &&
1505 export FAKE_LINES &&
1506 set_fake_editor &&
1507 git rebase -i HEAD~2 &&
1508 git branch --list >actual &&
6789275d 1509 test_grep "rebasing main" actual
1f537be3
ES
1510'
1511
1512test_expect_success '--list during rebase from detached HEAD' '
ec9779bc
JS
1513 test_when_finished "reset_rebase && git checkout main" &&
1514 git checkout main^0 &&
1f537be3
ES
1515 oid=$(git rev-parse --short HEAD) &&
1516 FAKE_LINES="1 edit 2" &&
1517 export FAKE_LINES &&
1518 set_fake_editor &&
1519 git rebase -i HEAD~2 &&
1520 git branch --list >actual &&
6789275d 1521 test_grep "rebasing detached HEAD $oid" actual
1f537be3
ES
1522'
1523
1d7358c5 1524test_expect_success 'tracking with unexpected .fetch refspec' '
b0f49ff1 1525 rm -rf a b c d &&
ec9779bc 1526 git init -b main a &&
62d94a3a
JH
1527 (
1528 cd a &&
1529 test_commit a
1530 ) &&
ec9779bc 1531 git init -b main b &&
62d94a3a
JH
1532 (
1533 cd b &&
1534 test_commit b
1535 ) &&
ec9779bc 1536 git init -b main c &&
62d94a3a
JH
1537 (
1538 cd c &&
1539 test_commit c &&
1540 git remote add a ../a &&
1541 git remote add b ../b &&
1542 git fetch --all
1543 ) &&
ec9779bc 1544 git init -b main d &&
62d94a3a
JH
1545 (
1546 cd d &&
1547 git remote add c ../c &&
1548 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
1549 git fetch c &&
ec9779bc
JS
1550 git branch --track local/a/main remotes/a/main &&
1551 test "$(git config branch.local/a/main.remote)" = "c" &&
1552 test "$(git config branch.local/a/main.merge)" = "refs/remotes/a/main" &&
62d94a3a 1553 git rev-parse --verify a >expect &&
ec9779bc 1554 git rev-parse --verify local/a/main >actual &&
62d94a3a
JH
1555 test_cmp expect actual
1556 )
1557'
1558
560ae1c1 1559test_expect_success 'configured committerdate sort' '
ec9779bc 1560 git init -b main sort &&
560ae1c1
SM
1561 (
1562 cd sort &&
1563 git config branch.sort committerdate &&
1564 test_commit initial &&
1565 git checkout -b a &&
1566 test_commit a &&
1567 git checkout -b c &&
1568 test_commit c &&
1569 git checkout -b b &&
1570 test_commit b &&
1571 git branch >actual &&
1572 cat >expect <<-\EOF &&
ec9779bc 1573 main
560ae1c1
SM
1574 a
1575 c
1576 * b
1577 EOF
1578 test_cmp expect actual
1579 )
1580'
1581
1582test_expect_success 'option override configured sort' '
1583 (
1584 cd sort &&
1585 git config branch.sort committerdate &&
1586 git branch --sort=refname >actual &&
1587 cat >expect <<-\EOF &&
1588 a
1589 * b
1590 c
ec9779bc 1591 main
560ae1c1
SM
1592 EOF
1593 test_cmp expect actual
1594 )
1595'
1596
1597test_expect_success 'invalid sort parameter in configuration' '
1598 (
1599 cd sort &&
1600 git config branch.sort "v:notvalid" &&
98e7ab6d
JH
1601
1602 # this works in the "listing" mode, so bad sort key
1603 # is a dying offence.
1604 test_must_fail git branch &&
1605
1606 # these do not need to use sorting, and should all
1607 # succeed
1608 git branch newone main &&
1609 git branch -c newone newerone &&
1610 git branch -m newone newestone &&
1611 git branch -d newerone newestone
560ae1c1
SM
1612 )
1613'
1614
d3115660
JS
1615test_expect_success 'tracking info copied with --track=inherit' '
1616 git branch --track=inherit foo2 my1 &&
1617 test_cmp_config local branch.foo2.remote &&
1618 test_cmp_config refs/heads/main branch.foo2.merge
1619'
1620
1621test_expect_success 'tracking info copied with autoSetupMerge=inherit' '
1622 test_unconfig branch.autoSetupMerge &&
1623 # default config does not copy tracking info
1624 git branch foo-no-inherit my1 &&
1625 test_cmp_config "" --default "" branch.foo-no-inherit.remote &&
1626 test_cmp_config "" --default "" branch.foo-no-inherit.merge &&
1627 # with autoSetupMerge=inherit, we copy tracking info from my1
1628 test_config branch.autoSetupMerge inherit &&
1629 git branch foo3 my1 &&
1630 test_cmp_config local branch.foo3.remote &&
1631 test_cmp_config refs/heads/main branch.foo3.merge &&
1632 # no tracking info to inherit from main
1633 git branch main2 main &&
1634 test_cmp_config "" --default "" branch.main2.remote &&
1635 test_cmp_config "" --default "" branch.main2.merge
1636'
1637
1638test_expect_success '--track overrides branch.autoSetupMerge' '
1639 test_config branch.autoSetupMerge inherit &&
1640 git branch --track=direct foo4 my1 &&
1641 test_cmp_config . branch.foo4.remote &&
1642 test_cmp_config refs/heads/my1 branch.foo4.merge &&
1643 git branch --no-track foo5 my1 &&
1644 test_cmp_config "" --default "" branch.foo5.remote &&
1645 test_cmp_config "" --default "" branch.foo5.merge
1646'
1647
a3b427b9 1648test_done