branch: add test for -m renaming multiple config sections
[git.git] / t / t3200-branch.sh
blob5eb752c516d74513b35c9adc92a805bf89b9e7e6
1 #!/bin/sh
3 # Copyright (c) 2005 Amos Waterland
6 test_description='git branch assorted tests'
8 . ./test-lib.sh
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)
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
25 test_expect_success 'branch -h in broken repository' '
26 mkdir broken &&
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
36 test_expect_success 'git branch abc should create a branch' '
37 git branch abc && test_path_is_file .git/refs/heads/abc
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
44 test_expect_success 'git branch HEAD should fail' '
45 test_must_fail git branch HEAD
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
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
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
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
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
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
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
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
103 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
104 git branch o/o &&
105 git branch o/p &&
106 test_must_fail git branch -m o/o o
109 test_expect_success 'git branch -m o/q o/p should fail when o/p exists' '
110 git branch o/q &&
111 test_must_fail git branch -m o/q o/p
114 test_expect_success 'git branch -M o/q o/p should work when o/p exists' '
115 git branch -M o/q o/p
118 test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '
119 git branch o/q &&
120 git branch -m -f o/q o/p
123 test_expect_success 'git branch -m q r/q should fail when r exists' '
124 git branch q &&
125 git branch r &&
126 test_must_fail git branch -m q r/q
129 test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
130 git branch bar &&
131 git checkout -b foo &&
132 test_must_fail git branch -M bar foo
135 test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
136 git checkout -b baz &&
137 git branch bam &&
138 git branch -M baz bam &&
139 test $(git rev-parse --abbrev-ref HEAD) = bam
142 test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' '
143 msg="Branch: renamed refs/heads/baz to refs/heads/bam" &&
144 grep " 0\{40\}.*$msg$" .git/logs/HEAD &&
145 grep "^0\{40\}.*$msg$" .git/logs/HEAD
148 test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' '
149 git checkout master &&
150 git worktree add -b baz bazdir &&
151 git worktree add -f bazdir2 baz &&
152 git branch -M baz bam &&
153 test $(git -C bazdir rev-parse --abbrev-ref HEAD) = bam &&
154 test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam
157 test_expect_success 'git branch -M baz bam should succeed within a worktree in which baz is checked out' '
158 git checkout -b baz &&
159 git worktree add -f bazdir3 baz &&
161 cd bazdir3 &&
162 git branch -M baz bam &&
163 test $(git rev-parse --abbrev-ref HEAD) = bam
164 ) &&
165 test $(git rev-parse --abbrev-ref HEAD) = bam
168 test_expect_success 'git branch -M master should work when master is checked out' '
169 git checkout master &&
170 git branch -M master
173 test_expect_success 'git branch -M master master should work when master is checked out' '
174 git checkout master &&
175 git branch -M master master
178 test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
179 git checkout master &&
180 git branch master2 &&
181 git branch -M master2 master2
184 test_expect_success 'git branch -v -d t should work' '
185 git branch t &&
186 test_path_is_file .git/refs/heads/t &&
187 git branch -v -d t &&
188 test_path_is_missing .git/refs/heads/t
191 test_expect_success 'git branch -v -m t s should work' '
192 git branch t &&
193 test_path_is_file .git/refs/heads/t &&
194 git branch -v -m t s &&
195 test_path_is_missing .git/refs/heads/t &&
196 test_path_is_file .git/refs/heads/s &&
197 git branch -d s
200 test_expect_success 'git branch -m -d t s should fail' '
201 git branch t &&
202 test_path_is_file .git/refs/heads/t &&
203 test_must_fail git branch -m -d t s &&
204 git branch -d t &&
205 test_path_is_missing .git/refs/heads/t
208 test_expect_success 'git branch --list -d t should fail' '
209 git branch t &&
210 test_path_is_file .git/refs/heads/t &&
211 test_must_fail git branch --list -d t &&
212 git branch -d t &&
213 test_path_is_missing .git/refs/heads/t
216 test_expect_success 'git branch --list -v with --abbrev' '
217 test_when_finished "git branch -D t" &&
218 git branch t &&
219 git branch -v --list t >actual.default &&
220 git branch -v --list --abbrev t >actual.abbrev &&
221 test_cmp actual.default actual.abbrev &&
223 git branch -v --list --no-abbrev t >actual.noabbrev &&
224 git branch -v --list --abbrev=0 t >actual.0abbrev &&
225 test_cmp actual.noabbrev actual.0abbrev &&
227 git branch -v --list --abbrev=36 t >actual.36abbrev &&
228 # how many hexdigits are used?
229 read name objdefault rest <actual.abbrev &&
230 read name obj36 rest <actual.36abbrev &&
231 objfull=$(git rev-parse --verify t) &&
233 # are we really getting abbreviations?
234 test "$obj36" != "$objdefault" &&
235 expr "$obj36" : "$objdefault" >/dev/null &&
236 test "$objfull" != "$obj36" &&
237 expr "$objfull" : "$obj36" >/dev/null
241 test_expect_success 'git branch --column' '
242 COLUMNS=81 git branch --column=column >actual &&
243 cat >expected <<\EOF &&
244 a/b/c bam foo l * master n o/p r
245 abc bar j/k m/m master2 o/o q
247 test_cmp expected actual
250 test_expect_success 'git branch --column with an extremely long branch name' '
251 long=this/is/a/part/of/long/branch/name &&
252 long=z$long/$long/$long/$long &&
253 test_when_finished "git branch -d $long" &&
254 git branch $long &&
255 COLUMNS=80 git branch --column=column >actual &&
256 cat >expected <<EOF &&
257 a/b/c
265 * master
266 master2
272 $long
274 test_cmp expected actual
277 test_expect_success 'git branch with column.*' '
278 git config column.ui column &&
279 git config column.branch "dense" &&
280 COLUMNS=80 git branch >actual &&
281 git config --unset column.branch &&
282 git config --unset column.ui &&
283 cat >expected <<\EOF &&
284 a/b/c bam foo l * master n o/p r
285 abc bar j/k m/m master2 o/o q
287 test_cmp expected actual
290 test_expect_success 'git branch --column -v should fail' '
291 test_must_fail git branch --column -v
294 test_expect_success 'git branch -v with column.ui ignored' '
295 git config column.ui column &&
296 COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
297 git config --unset column.ui &&
298 cat >expected <<\EOF &&
299 a/b/c
307 * master
308 master2
315 test_cmp expected actual
318 mv .git/config .git/config-saved
320 test_expect_success 'git branch -m q q2 without config should succeed' '
321 git branch -m q q2 &&
322 git branch -m q2 q
325 mv .git/config-saved .git/config
327 git config branch.s/s.dummy Hello
329 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
330 git branch -l s/s &&
331 git reflog exists refs/heads/s/s &&
332 git branch -l s/t &&
333 git reflog exists refs/heads/s/t &&
334 git branch -d s/t &&
335 git branch -m s/s s &&
336 git reflog exists refs/heads/s
339 test_expect_success 'config information was renamed, too' '
340 test $(git config branch.s.dummy) = Hello &&
341 test_must_fail git config branch.s/s.dummy
344 test_expect_success 'git branch -m correctly renames multiple config sections' '
345 test_when_finished "git checkout master" &&
346 git checkout -b source master &&
348 # Assert that a config file with multiple config sections has
349 # those sections preserved...
350 cat >expect <<-\EOF &&
351 branch.dest.key1=value1
352 some.gar.b=age
353 branch.dest.key2=value2
355 cat >config.branch <<\EOF &&
356 ;; Note the lack of -\EOF above & mixed indenting here. This is
357 ;; intentional, we are also testing that the formatting of copied
358 ;; sections is preserved.
360 ;; Comment for source. Tabs
361 [branch "source"]
362 ;; Comment for the source value
363 key1 = value1
364 ;; Comment for some.gar. Spaces
365 [some "gar"]
366 ;; Comment for the some.gar value
367 b = age
368 ;; Comment for source, again. Mixed tabs/spaces.
369 [branch "source"]
370 ;; Comment for the source value, again
371 key2 = value2
373 cat config.branch >>.git/config &&
374 git branch -m source dest &&
375 git config -f .git/config -l | grep -F -e source -e dest -e some.gar >actual &&
376 test_cmp expect actual &&
378 # ...and that the comments for those sections are also
379 # preserved.
380 cat config.branch | sed "s/\"source\"/\"dest\"/" >expect &&
381 sed -n -e "/Note the lack/,\$p" .git/config >actual &&
382 test_cmp expect actual
385 test_expect_success 'deleting a symref' '
386 git branch target &&
387 git symbolic-ref refs/heads/symref refs/heads/target &&
388 echo "Deleted branch symref (was refs/heads/target)." >expect &&
389 git branch -d symref >actual &&
390 test_path_is_file .git/refs/heads/target &&
391 test_path_is_missing .git/refs/heads/symref &&
392 test_i18ncmp expect actual
395 test_expect_success 'deleting a dangling symref' '
396 git symbolic-ref refs/heads/dangling-symref nowhere &&
397 test_path_is_file .git/refs/heads/dangling-symref &&
398 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
399 git branch -d dangling-symref >actual &&
400 test_path_is_missing .git/refs/heads/dangling-symref &&
401 test_i18ncmp expect actual
404 test_expect_success 'deleting a self-referential symref' '
405 git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
406 test_path_is_file .git/refs/heads/self-reference &&
407 echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
408 git branch -d self-reference >actual &&
409 test_path_is_missing .git/refs/heads/self-reference &&
410 test_i18ncmp expect actual
413 test_expect_success 'renaming a symref is not allowed' '
414 git symbolic-ref refs/heads/master2 refs/heads/master &&
415 test_must_fail git branch -m master2 master3 &&
416 git symbolic-ref refs/heads/master2 &&
417 test_path_is_file .git/refs/heads/master &&
418 test_path_is_missing .git/refs/heads/master3
421 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
422 git branch -l u &&
423 mv .git/logs/refs/heads/u real-u &&
424 ln -s real-u .git/logs/refs/heads/u &&
425 test_must_fail git branch -m u v
428 test_expect_success 'test tracking setup via --track' '
429 git config remote.local.url . &&
430 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
431 (git show-ref -q refs/remotes/local/master || git fetch local) &&
432 git branch --track my1 local/master &&
433 test $(git config branch.my1.remote) = local &&
434 test $(git config branch.my1.merge) = refs/heads/master
437 test_expect_success 'test tracking setup (non-wildcard, matching)' '
438 git config remote.local.url . &&
439 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
440 (git show-ref -q refs/remotes/local/master || git fetch local) &&
441 git branch --track my4 local/master &&
442 test $(git config branch.my4.remote) = local &&
443 test $(git config branch.my4.merge) = refs/heads/master
446 test_expect_success 'tracking setup fails on non-matching refspec' '
447 git config remote.local.url . &&
448 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
449 (git show-ref -q refs/remotes/local/master || git fetch local) &&
450 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
451 test_must_fail git branch --track my5 local/master &&
452 test_must_fail git config branch.my5.remote &&
453 test_must_fail git config branch.my5.merge
456 test_expect_success 'test tracking setup via config' '
457 git config branch.autosetupmerge true &&
458 git config remote.local.url . &&
459 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
460 (git show-ref -q refs/remotes/local/master || git fetch local) &&
461 git branch my3 local/master &&
462 test $(git config branch.my3.remote) = local &&
463 test $(git config branch.my3.merge) = refs/heads/master
466 test_expect_success 'test overriding tracking setup via --no-track' '
467 git config branch.autosetupmerge true &&
468 git config remote.local.url . &&
469 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
470 (git show-ref -q refs/remotes/local/master || git fetch local) &&
471 git branch --no-track my2 local/master &&
472 git config branch.autosetupmerge false &&
473 ! test "$(git config branch.my2.remote)" = local &&
474 ! test "$(git config branch.my2.merge)" = refs/heads/master
477 test_expect_success 'no tracking without .fetch entries' '
478 git config branch.autosetupmerge true &&
479 git branch my6 s &&
480 git config branch.autosetupmerge false &&
481 test -z "$(git config branch.my6.remote)" &&
482 test -z "$(git config branch.my6.merge)"
485 test_expect_success 'test tracking setup via --track but deeper' '
486 git config remote.local.url . &&
487 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
488 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
489 git branch --track my7 local/o/o &&
490 test "$(git config branch.my7.remote)" = local &&
491 test "$(git config branch.my7.merge)" = refs/heads/o/o
494 test_expect_success 'test deleting branch deletes branch config' '
495 git branch -d my7 &&
496 test -z "$(git config branch.my7.remote)" &&
497 test -z "$(git config branch.my7.merge)"
500 test_expect_success 'test deleting branch without config' '
501 git branch my7 s &&
502 sha1=$(git rev-parse my7 | cut -c 1-7) &&
503 echo "Deleted branch my7 (was $sha1)." >expect &&
504 git branch -d my7 >actual 2>&1 &&
505 test_i18ncmp expect actual
508 test_expect_success 'deleting currently checked out branch fails' '
509 git worktree add -b my7 my7 &&
510 test_must_fail git -C my7 branch -d my7 &&
511 test_must_fail git branch -d my7
514 test_expect_success 'test --track without .fetch entries' '
515 git branch --track my8 &&
516 test "$(git config branch.my8.remote)" &&
517 test "$(git config branch.my8.merge)"
520 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
521 git config branch.autosetupmerge always &&
522 git branch my9 HEAD^ &&
523 git config branch.autosetupmerge false
526 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
527 test_must_fail git branch --track my10 HEAD^
530 test_expect_success 'branch from tag w/--track causes failure' '
531 git tag foobar &&
532 test_must_fail git branch --track my11 foobar
535 test_expect_success '--set-upstream-to fails on multiple branches' '
536 test_must_fail git branch --set-upstream-to master a b c
539 test_expect_success '--set-upstream-to fails on detached HEAD' '
540 git checkout HEAD^{} &&
541 test_must_fail git branch --set-upstream-to master &&
542 git checkout -
545 test_expect_success '--set-upstream-to fails on a missing dst branch' '
546 test_must_fail git branch --set-upstream-to master does-not-exist
549 test_expect_success '--set-upstream-to fails on a missing src branch' '
550 test_must_fail git branch --set-upstream-to does-not-exist master
553 test_expect_success '--set-upstream-to fails on a non-ref' '
554 test_must_fail git branch --set-upstream-to HEAD^{}
557 test_expect_success '--set-upstream-to fails on locked config' '
558 test_when_finished "rm -f .git/config.lock" &&
559 >.git/config.lock &&
560 git branch locked &&
561 test_must_fail git branch --set-upstream-to locked
564 test_expect_success 'use --set-upstream-to modify HEAD' '
565 test_config branch.master.remote foo &&
566 test_config branch.master.merge foo &&
567 git branch my12 &&
568 git branch --set-upstream-to my12 &&
569 test "$(git config branch.master.remote)" = "." &&
570 test "$(git config branch.master.merge)" = "refs/heads/my12"
573 test_expect_success 'use --set-upstream-to modify a particular branch' '
574 git branch my13 &&
575 git branch --set-upstream-to master my13 &&
576 test "$(git config branch.my13.remote)" = "." &&
577 test "$(git config branch.my13.merge)" = "refs/heads/master"
580 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
581 test_must_fail git branch --unset-upstream i-dont-exist
584 test_expect_success '--unset-upstream should fail if config is locked' '
585 test_when_finished "rm -f .git/config.lock" &&
586 git branch --set-upstream-to locked &&
587 >.git/config.lock &&
588 test_must_fail git branch --unset-upstream
591 test_expect_success 'test --unset-upstream on HEAD' '
592 git branch my14 &&
593 test_config branch.master.remote foo &&
594 test_config branch.master.merge foo &&
595 git branch --set-upstream-to my14 &&
596 git branch --unset-upstream &&
597 test_must_fail git config branch.master.remote &&
598 test_must_fail git config branch.master.merge &&
599 # fail for a branch without upstream set
600 test_must_fail git branch --unset-upstream
603 test_expect_success '--unset-upstream should fail on multiple branches' '
604 test_must_fail git branch --unset-upstream a b c
607 test_expect_success '--unset-upstream should fail on detached HEAD' '
608 git checkout HEAD^{} &&
609 test_must_fail git branch --unset-upstream &&
610 git checkout -
613 test_expect_success 'test --unset-upstream on a particular branch' '
614 git branch my15 &&
615 git branch --set-upstream-to master my14 &&
616 git branch --unset-upstream my14 &&
617 test_must_fail git config branch.my14.remote &&
618 test_must_fail git config branch.my14.merge
621 test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
622 git update-ref refs/remotes/origin/master HEAD &&
623 git branch --set-upstream origin/master 2>actual &&
624 test_when_finished git update-ref -d refs/remotes/origin/master &&
625 test_when_finished git branch -d origin/master &&
626 cat >expected <<EOF &&
627 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
629 If you wanted to make '"'master'"' track '"'origin/master'"', do this:
631 git branch -d origin/master
632 git branch --set-upstream-to origin/master
634 test_i18ncmp expected actual
637 test_expect_success '--set-upstream with two args only shows the deprecation message' '
638 git branch --set-upstream master my13 2>actual &&
639 test_when_finished git branch --unset-upstream master &&
640 cat >expected <<EOF &&
641 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
643 test_i18ncmp expected actual
646 test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
647 git branch --set-upstream my13 2>actual &&
648 test_when_finished git branch --unset-upstream my13 &&
649 cat >expected <<EOF &&
650 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
652 test_i18ncmp expected actual
655 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
656 git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
657 cat >expected <<-\EOF &&
658 warning: Not setting branch my13 as its own upstream.
660 test_expect_code 1 git config branch.my13.remote &&
661 test_expect_code 1 git config branch.my13.merge &&
662 test_i18ncmp expected actual
665 # Keep this test last, as it changes the current branch
666 cat >expect <<EOF
667 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
669 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
670 GIT_COMMITTER_DATE="2005-05-26 23:30" \
671 git checkout -b g/h/i -l master &&
672 test_path_is_file .git/refs/heads/g/h/i &&
673 test_path_is_file .git/logs/refs/heads/g/h/i &&
674 test_cmp expect .git/logs/refs/heads/g/h/i
677 test_expect_success 'checkout -b makes reflog by default' '
678 git checkout master &&
679 git config --unset core.logAllRefUpdates &&
680 git checkout -b alpha &&
681 git rev-parse --verify alpha@{0}
684 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
685 git checkout master &&
686 git config core.logAllRefUpdates false &&
687 git checkout -b beta &&
688 test_must_fail git rev-parse --verify beta@{0}
691 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
692 git checkout master &&
693 git checkout -lb gamma &&
694 git config --unset core.logAllRefUpdates &&
695 git rev-parse --verify gamma@{0}
698 test_expect_success 'avoid ambiguous track' '
699 git config branch.autosetupmerge true &&
700 git config remote.ambi1.url lalala &&
701 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
702 git config remote.ambi2.url lilili &&
703 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
704 test_must_fail git branch all1 master &&
705 test -z "$(git config branch.all1.merge)"
708 test_expect_success 'autosetuprebase local on a tracked local branch' '
709 git config remote.local.url . &&
710 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
711 git config branch.autosetuprebase local &&
712 (git show-ref -q refs/remotes/local/o || git fetch local) &&
713 git branch mybase &&
714 git branch --track myr1 mybase &&
715 test "$(git config branch.myr1.remote)" = . &&
716 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
717 test "$(git config branch.myr1.rebase)" = true
720 test_expect_success 'autosetuprebase always on a tracked local branch' '
721 git config remote.local.url . &&
722 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
723 git config branch.autosetuprebase always &&
724 (git show-ref -q refs/remotes/local/o || git fetch local) &&
725 git branch mybase2 &&
726 git branch --track myr2 mybase &&
727 test "$(git config branch.myr2.remote)" = . &&
728 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
729 test "$(git config branch.myr2.rebase)" = true
732 test_expect_success 'autosetuprebase remote on a tracked local branch' '
733 git config remote.local.url . &&
734 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
735 git config branch.autosetuprebase remote &&
736 (git show-ref -q refs/remotes/local/o || git fetch local) &&
737 git branch mybase3 &&
738 git branch --track myr3 mybase2 &&
739 test "$(git config branch.myr3.remote)" = . &&
740 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
741 ! test "$(git config branch.myr3.rebase)" = true
744 test_expect_success 'autosetuprebase never on a tracked local branch' '
745 git config remote.local.url . &&
746 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
747 git config branch.autosetuprebase never &&
748 (git show-ref -q refs/remotes/local/o || git fetch local) &&
749 git branch mybase4 &&
750 git branch --track myr4 mybase2 &&
751 test "$(git config branch.myr4.remote)" = . &&
752 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
753 ! test "$(git config branch.myr4.rebase)" = true
756 test_expect_success 'autosetuprebase local on a tracked remote branch' '
757 git config remote.local.url . &&
758 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
759 git config branch.autosetuprebase local &&
760 (git show-ref -q refs/remotes/local/master || git fetch local) &&
761 git branch --track myr5 local/master &&
762 test "$(git config branch.myr5.remote)" = local &&
763 test "$(git config branch.myr5.merge)" = refs/heads/master &&
764 ! test "$(git config branch.myr5.rebase)" = true
767 test_expect_success 'autosetuprebase never on a tracked remote branch' '
768 git config remote.local.url . &&
769 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
770 git config branch.autosetuprebase never &&
771 (git show-ref -q refs/remotes/local/master || git fetch local) &&
772 git branch --track myr6 local/master &&
773 test "$(git config branch.myr6.remote)" = local &&
774 test "$(git config branch.myr6.merge)" = refs/heads/master &&
775 ! test "$(git config branch.myr6.rebase)" = true
778 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
779 git config remote.local.url . &&
780 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
781 git config branch.autosetuprebase remote &&
782 (git show-ref -q refs/remotes/local/master || git fetch local) &&
783 git branch --track myr7 local/master &&
784 test "$(git config branch.myr7.remote)" = local &&
785 test "$(git config branch.myr7.merge)" = refs/heads/master &&
786 test "$(git config branch.myr7.rebase)" = true
789 test_expect_success 'autosetuprebase always on a tracked remote branch' '
790 git config remote.local.url . &&
791 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
792 git config branch.autosetuprebase remote &&
793 (git show-ref -q refs/remotes/local/master || git fetch local) &&
794 git branch --track myr8 local/master &&
795 test "$(git config branch.myr8.remote)" = local &&
796 test "$(git config branch.myr8.merge)" = refs/heads/master &&
797 test "$(git config branch.myr8.rebase)" = true
800 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
801 git config --unset branch.autosetuprebase &&
802 git config remote.local.url . &&
803 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
804 (git show-ref -q refs/remotes/local/master || git fetch local) &&
805 git branch --track myr9 local/master &&
806 test "$(git config branch.myr9.remote)" = local &&
807 test "$(git config branch.myr9.merge)" = refs/heads/master &&
808 test "z$(git config branch.myr9.rebase)" = z
811 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
812 git config remote.local.url . &&
813 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
814 (git show-ref -q refs/remotes/local/o || git fetch local) &&
815 git branch mybase10 &&
816 git branch --track myr10 mybase2 &&
817 test "$(git config branch.myr10.remote)" = . &&
818 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
819 test "z$(git config branch.myr10.rebase)" = z
822 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
823 git config remote.local.url . &&
824 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
825 (git show-ref -q refs/remotes/local/master || git fetch local) &&
826 git branch --no-track myr11 mybase2 &&
827 test "z$(git config branch.myr11.remote)" = z &&
828 test "z$(git config branch.myr11.merge)" = z &&
829 test "z$(git config branch.myr11.rebase)" = z
832 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
833 git config remote.local.url . &&
834 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
835 (git show-ref -q refs/remotes/local/master || git fetch local) &&
836 git branch --no-track myr12 local/master &&
837 test "z$(git config branch.myr12.remote)" = z &&
838 test "z$(git config branch.myr12.merge)" = z &&
839 test "z$(git config branch.myr12.rebase)" = z
842 test_expect_success 'autosetuprebase never on an untracked local branch' '
843 git config branch.autosetuprebase never &&
844 git config remote.local.url . &&
845 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
846 (git show-ref -q refs/remotes/local/master || git fetch local) &&
847 git branch --no-track myr13 mybase2 &&
848 test "z$(git config branch.myr13.remote)" = z &&
849 test "z$(git config branch.myr13.merge)" = z &&
850 test "z$(git config branch.myr13.rebase)" = z
853 test_expect_success 'autosetuprebase local on an untracked local branch' '
854 git config branch.autosetuprebase local &&
855 git config remote.local.url . &&
856 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
857 (git show-ref -q refs/remotes/local/master || git fetch local) &&
858 git branch --no-track myr14 mybase2 &&
859 test "z$(git config branch.myr14.remote)" = z &&
860 test "z$(git config branch.myr14.merge)" = z &&
861 test "z$(git config branch.myr14.rebase)" = z
864 test_expect_success 'autosetuprebase remote on an untracked local branch' '
865 git config branch.autosetuprebase remote &&
866 git config remote.local.url . &&
867 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
868 (git show-ref -q refs/remotes/local/master || git fetch local) &&
869 git branch --no-track myr15 mybase2 &&
870 test "z$(git config branch.myr15.remote)" = z &&
871 test "z$(git config branch.myr15.merge)" = z &&
872 test "z$(git config branch.myr15.rebase)" = z
875 test_expect_success 'autosetuprebase always on an untracked local branch' '
876 git config branch.autosetuprebase always &&
877 git config remote.local.url . &&
878 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
879 (git show-ref -q refs/remotes/local/master || git fetch local) &&
880 git branch --no-track myr16 mybase2 &&
881 test "z$(git config branch.myr16.remote)" = z &&
882 test "z$(git config branch.myr16.merge)" = z &&
883 test "z$(git config branch.myr16.rebase)" = z
886 test_expect_success 'autosetuprebase never on an untracked remote branch' '
887 git config branch.autosetuprebase never &&
888 git config remote.local.url . &&
889 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
890 (git show-ref -q refs/remotes/local/master || git fetch local) &&
891 git branch --no-track myr17 local/master &&
892 test "z$(git config branch.myr17.remote)" = z &&
893 test "z$(git config branch.myr17.merge)" = z &&
894 test "z$(git config branch.myr17.rebase)" = z
897 test_expect_success 'autosetuprebase local on an untracked remote branch' '
898 git config branch.autosetuprebase local &&
899 git config remote.local.url . &&
900 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
901 (git show-ref -q refs/remotes/local/master || git fetch local) &&
902 git branch --no-track myr18 local/master &&
903 test "z$(git config branch.myr18.remote)" = z &&
904 test "z$(git config branch.myr18.merge)" = z &&
905 test "z$(git config branch.myr18.rebase)" = z
908 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
909 git config branch.autosetuprebase remote &&
910 git config remote.local.url . &&
911 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
912 (git show-ref -q refs/remotes/local/master || git fetch local) &&
913 git branch --no-track myr19 local/master &&
914 test "z$(git config branch.myr19.remote)" = z &&
915 test "z$(git config branch.myr19.merge)" = z &&
916 test "z$(git config branch.myr19.rebase)" = z
919 test_expect_success 'autosetuprebase always on an untracked remote branch' '
920 git config branch.autosetuprebase always &&
921 git config remote.local.url . &&
922 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
923 (git show-ref -q refs/remotes/local/master || git fetch local) &&
924 git branch --no-track myr20 local/master &&
925 test "z$(git config branch.myr20.remote)" = z &&
926 test "z$(git config branch.myr20.merge)" = z &&
927 test "z$(git config branch.myr20.rebase)" = z
930 test_expect_success 'autosetuprebase always on detached HEAD' '
931 git config branch.autosetupmerge always &&
932 test_when_finished git checkout master &&
933 git checkout HEAD^0 &&
934 git branch my11 &&
935 test -z "$(git config branch.my11.remote)" &&
936 test -z "$(git config branch.my11.merge)"
939 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
940 git config branch.autosetuprebase garbage &&
941 test_must_fail git branch
944 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
945 git config --unset branch.autosetuprebase &&
946 echo "[branch] autosetuprebase" >>.git/config &&
947 test_must_fail git branch &&
948 git config --unset branch.autosetuprebase
951 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
952 git checkout my9 &&
953 git config --unset branch.my8.merge &&
954 test_must_fail git branch -d my8
957 test_expect_success 'attempt to delete a branch merged to its base' '
958 # we are on my9 which is the initial commit; traditionally
959 # we would not have allowed deleting my8 that is not merged
960 # to my9, but it is set to track master that already has my8
961 git config branch.my8.merge refs/heads/master &&
962 git branch -d my8
965 test_expect_success 'attempt to delete a branch merged to its base' '
966 git checkout master &&
967 echo Third >>A &&
968 git commit -m "Third commit" A &&
969 git branch -t my10 my9 &&
970 git branch -f my10 HEAD^ &&
971 # we are on master which is at the third commit, and my10
972 # is behind us, so traditionally we would have allowed deleting
973 # it; but my10 is set to track my9 that is further behind.
974 test_must_fail git branch -d my10
977 test_expect_success 'use set-upstream on the current branch' '
978 git checkout master &&
979 git --bare init myupstream.git &&
980 git push myupstream.git master:refs/heads/frotz &&
981 git remote add origin myupstream.git &&
982 git fetch &&
983 git branch --set-upstream master origin/frotz &&
985 test "z$(git config branch.master.remote)" = "zorigin" &&
986 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
990 test_expect_success 'use --edit-description' '
991 write_script editor <<-\EOF &&
992 echo "New contents" >"$1"
994 EDITOR=./editor git branch --edit-description &&
995 write_script editor <<-\EOF &&
996 git stripspace -s <"$1" >"EDITOR_OUTPUT"
998 EDITOR=./editor git branch --edit-description &&
999 echo "New contents" >expect &&
1000 test_cmp EDITOR_OUTPUT expect
1003 test_expect_success 'detect typo in branch name when using --edit-description' '
1004 write_script editor <<-\EOF &&
1005 echo "New contents" >"$1"
1007 test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
1010 test_expect_success 'refuse --edit-description on unborn branch for now' '
1011 write_script editor <<-\EOF &&
1012 echo "New contents" >"$1"
1014 git checkout --orphan unborn &&
1015 test_must_fail env EDITOR=./editor git branch --edit-description
1018 test_expect_success '--merged catches invalid object names' '
1019 test_must_fail git branch --merged 0000000000000000000000000000000000000000
1022 test_expect_success '--merged is incompatible with --no-merged' '
1023 test_must_fail git branch --merged HEAD --no-merged HEAD
1026 test_expect_success 'tracking with unexpected .fetch refspec' '
1027 rm -rf a b c d &&
1028 git init a &&
1030 cd a &&
1031 test_commit a
1032 ) &&
1033 git init b &&
1035 cd b &&
1036 test_commit b
1037 ) &&
1038 git init c &&
1040 cd c &&
1041 test_commit c &&
1042 git remote add a ../a &&
1043 git remote add b ../b &&
1044 git fetch --all
1045 ) &&
1046 git init d &&
1048 cd d &&
1049 git remote add c ../c &&
1050 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
1051 git fetch c &&
1052 git branch --track local/a/master remotes/a/master &&
1053 test "$(git config branch.local/a/master.remote)" = "c" &&
1054 test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
1055 git rev-parse --verify a >expect &&
1056 git rev-parse --verify local/a/master >actual &&
1057 test_cmp expect actual
1061 test_done