grep: add tests for --threads=N and grep.threads
[alt-git.git] / t / t3200-branch.sh
blobfe62e7c775da6a8fc191ed1dc6634d5285ddbc4b
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 'deleting a symref' '
345 git branch target &&
346 git symbolic-ref refs/heads/symref refs/heads/target &&
347 echo "Deleted branch symref (was refs/heads/target)." >expect &&
348 git branch -d symref >actual &&
349 test_path_is_file .git/refs/heads/target &&
350 test_path_is_missing .git/refs/heads/symref &&
351 test_i18ncmp expect actual
354 test_expect_success 'deleting a dangling symref' '
355 git symbolic-ref refs/heads/dangling-symref nowhere &&
356 test_path_is_file .git/refs/heads/dangling-symref &&
357 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
358 git branch -d dangling-symref >actual &&
359 test_path_is_missing .git/refs/heads/dangling-symref &&
360 test_i18ncmp expect actual
363 test_expect_success 'deleting a self-referential symref' '
364 git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
365 test_path_is_file .git/refs/heads/self-reference &&
366 echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
367 git branch -d self-reference >actual &&
368 test_path_is_missing .git/refs/heads/self-reference &&
369 test_i18ncmp expect actual
372 test_expect_success 'renaming a symref is not allowed' '
373 git symbolic-ref refs/heads/master2 refs/heads/master &&
374 test_must_fail git branch -m master2 master3 &&
375 git symbolic-ref refs/heads/master2 &&
376 test_path_is_file .git/refs/heads/master &&
377 test_path_is_missing .git/refs/heads/master3
380 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
381 git branch -l u &&
382 mv .git/logs/refs/heads/u real-u &&
383 ln -s real-u .git/logs/refs/heads/u &&
384 test_must_fail git branch -m u v
387 test_expect_success 'test tracking setup via --track' '
388 git config remote.local.url . &&
389 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
390 (git show-ref -q refs/remotes/local/master || git fetch local) &&
391 git branch --track my1 local/master &&
392 test $(git config branch.my1.remote) = local &&
393 test $(git config branch.my1.merge) = refs/heads/master
396 test_expect_success 'test tracking setup (non-wildcard, matching)' '
397 git config remote.local.url . &&
398 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
399 (git show-ref -q refs/remotes/local/master || git fetch local) &&
400 git branch --track my4 local/master &&
401 test $(git config branch.my4.remote) = local &&
402 test $(git config branch.my4.merge) = refs/heads/master
405 test_expect_success 'tracking setup fails on non-matching refspec' '
406 git config remote.local.url . &&
407 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
408 (git show-ref -q refs/remotes/local/master || git fetch local) &&
409 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
410 test_must_fail git branch --track my5 local/master &&
411 test_must_fail git config branch.my5.remote &&
412 test_must_fail git config branch.my5.merge
415 test_expect_success 'test tracking setup via config' '
416 git config branch.autosetupmerge true &&
417 git config remote.local.url . &&
418 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
419 (git show-ref -q refs/remotes/local/master || git fetch local) &&
420 git branch my3 local/master &&
421 test $(git config branch.my3.remote) = local &&
422 test $(git config branch.my3.merge) = refs/heads/master
425 test_expect_success 'test overriding tracking setup via --no-track' '
426 git config branch.autosetupmerge true &&
427 git config remote.local.url . &&
428 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
429 (git show-ref -q refs/remotes/local/master || git fetch local) &&
430 git branch --no-track my2 local/master &&
431 git config branch.autosetupmerge false &&
432 ! test "$(git config branch.my2.remote)" = local &&
433 ! test "$(git config branch.my2.merge)" = refs/heads/master
436 test_expect_success 'no tracking without .fetch entries' '
437 git config branch.autosetupmerge true &&
438 git branch my6 s &&
439 git config branch.autosetupmerge false &&
440 test -z "$(git config branch.my6.remote)" &&
441 test -z "$(git config branch.my6.merge)"
444 test_expect_success 'test tracking setup via --track but deeper' '
445 git config remote.local.url . &&
446 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
447 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
448 git branch --track my7 local/o/o &&
449 test "$(git config branch.my7.remote)" = local &&
450 test "$(git config branch.my7.merge)" = refs/heads/o/o
453 test_expect_success 'test deleting branch deletes branch config' '
454 git branch -d my7 &&
455 test -z "$(git config branch.my7.remote)" &&
456 test -z "$(git config branch.my7.merge)"
459 test_expect_success 'test deleting branch without config' '
460 git branch my7 s &&
461 sha1=$(git rev-parse my7 | cut -c 1-7) &&
462 echo "Deleted branch my7 (was $sha1)." >expect &&
463 git branch -d my7 >actual 2>&1 &&
464 test_i18ncmp expect actual
467 test_expect_success 'deleting currently checked out branch fails' '
468 git worktree add -b my7 my7 &&
469 test_must_fail git -C my7 branch -d my7 &&
470 test_must_fail git branch -d my7
473 test_expect_success 'test --track without .fetch entries' '
474 git branch --track my8 &&
475 test "$(git config branch.my8.remote)" &&
476 test "$(git config branch.my8.merge)"
479 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
480 git config branch.autosetupmerge always &&
481 git branch my9 HEAD^ &&
482 git config branch.autosetupmerge false
485 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
486 test_must_fail git branch --track my10 HEAD^
489 test_expect_success 'branch from tag w/--track causes failure' '
490 git tag foobar &&
491 test_must_fail git branch --track my11 foobar
494 test_expect_success '--set-upstream-to fails on multiple branches' '
495 test_must_fail git branch --set-upstream-to master a b c
498 test_expect_success '--set-upstream-to fails on detached HEAD' '
499 git checkout HEAD^{} &&
500 test_must_fail git branch --set-upstream-to master &&
501 git checkout -
504 test_expect_success '--set-upstream-to fails on a missing dst branch' '
505 test_must_fail git branch --set-upstream-to master does-not-exist
508 test_expect_success '--set-upstream-to fails on a missing src branch' '
509 test_must_fail git branch --set-upstream-to does-not-exist master
512 test_expect_success '--set-upstream-to fails on a non-ref' '
513 test_must_fail git branch --set-upstream-to HEAD^{}
516 test_expect_success '--set-upstream-to fails on locked config' '
517 test_when_finished "rm -f .git/config.lock" &&
518 >.git/config.lock &&
519 git branch locked &&
520 test_must_fail git branch --set-upstream-to locked
523 test_expect_success 'use --set-upstream-to modify HEAD' '
524 test_config branch.master.remote foo &&
525 test_config branch.master.merge foo &&
526 git branch my12 &&
527 git branch --set-upstream-to my12 &&
528 test "$(git config branch.master.remote)" = "." &&
529 test "$(git config branch.master.merge)" = "refs/heads/my12"
532 test_expect_success 'use --set-upstream-to modify a particular branch' '
533 git branch my13 &&
534 git branch --set-upstream-to master my13 &&
535 test "$(git config branch.my13.remote)" = "." &&
536 test "$(git config branch.my13.merge)" = "refs/heads/master"
539 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
540 test_must_fail git branch --unset-upstream i-dont-exist
543 test_expect_success '--unset-upstream should fail if config is locked' '
544 test_when_finished "rm -f .git/config.lock" &&
545 git branch --set-upstream-to locked &&
546 >.git/config.lock &&
547 test_must_fail git branch --unset-upstream
550 test_expect_success 'test --unset-upstream on HEAD' '
551 git branch my14 &&
552 test_config branch.master.remote foo &&
553 test_config branch.master.merge foo &&
554 git branch --set-upstream-to my14 &&
555 git branch --unset-upstream &&
556 test_must_fail git config branch.master.remote &&
557 test_must_fail git config branch.master.merge &&
558 # fail for a branch without upstream set
559 test_must_fail git branch --unset-upstream
562 test_expect_success '--unset-upstream should fail on multiple branches' '
563 test_must_fail git branch --unset-upstream a b c
566 test_expect_success '--unset-upstream should fail on detached HEAD' '
567 git checkout HEAD^{} &&
568 test_must_fail git branch --unset-upstream &&
569 git checkout -
572 test_expect_success 'test --unset-upstream on a particular branch' '
573 git branch my15 &&
574 git branch --set-upstream-to master my14 &&
575 git branch --unset-upstream my14 &&
576 test_must_fail git config branch.my14.remote &&
577 test_must_fail git config branch.my14.merge
580 test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
581 git update-ref refs/remotes/origin/master HEAD &&
582 git branch --set-upstream origin/master 2>actual &&
583 test_when_finished git update-ref -d refs/remotes/origin/master &&
584 test_when_finished git branch -d origin/master &&
585 cat >expected <<EOF &&
586 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
588 If you wanted to make '"'master'"' track '"'origin/master'"', do this:
590 git branch -d origin/master
591 git branch --set-upstream-to origin/master
593 test_i18ncmp expected actual
596 test_expect_success '--set-upstream with two args only shows the deprecation message' '
597 git branch --set-upstream master my13 2>actual &&
598 test_when_finished git branch --unset-upstream master &&
599 cat >expected <<EOF &&
600 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
602 test_i18ncmp expected actual
605 test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
606 git branch --set-upstream my13 2>actual &&
607 test_when_finished git branch --unset-upstream my13 &&
608 cat >expected <<EOF &&
609 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
611 test_i18ncmp expected actual
614 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
615 git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
616 cat >expected <<-\EOF &&
617 warning: Not setting branch my13 as its own upstream.
619 test_expect_code 1 git config branch.my13.remote &&
620 test_expect_code 1 git config branch.my13.merge &&
621 test_i18ncmp expected actual
624 # Keep this test last, as it changes the current branch
625 cat >expect <<EOF
626 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
628 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
629 GIT_COMMITTER_DATE="2005-05-26 23:30" \
630 git checkout -b g/h/i -l master &&
631 test_path_is_file .git/refs/heads/g/h/i &&
632 test_path_is_file .git/logs/refs/heads/g/h/i &&
633 test_cmp expect .git/logs/refs/heads/g/h/i
636 test_expect_success 'checkout -b makes reflog by default' '
637 git checkout master &&
638 git config --unset core.logAllRefUpdates &&
639 git checkout -b alpha &&
640 git rev-parse --verify alpha@{0}
643 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
644 git checkout master &&
645 git config core.logAllRefUpdates false &&
646 git checkout -b beta &&
647 test_must_fail git rev-parse --verify beta@{0}
650 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
651 git checkout master &&
652 git checkout -lb gamma &&
653 git config --unset core.logAllRefUpdates &&
654 git rev-parse --verify gamma@{0}
657 test_expect_success 'avoid ambiguous track' '
658 git config branch.autosetupmerge true &&
659 git config remote.ambi1.url lalala &&
660 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
661 git config remote.ambi2.url lilili &&
662 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
663 test_must_fail git branch all1 master &&
664 test -z "$(git config branch.all1.merge)"
667 test_expect_success 'autosetuprebase local on a tracked local branch' '
668 git config remote.local.url . &&
669 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
670 git config branch.autosetuprebase local &&
671 (git show-ref -q refs/remotes/local/o || git fetch local) &&
672 git branch mybase &&
673 git branch --track myr1 mybase &&
674 test "$(git config branch.myr1.remote)" = . &&
675 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
676 test "$(git config branch.myr1.rebase)" = true
679 test_expect_success 'autosetuprebase always on a tracked local branch' '
680 git config remote.local.url . &&
681 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
682 git config branch.autosetuprebase always &&
683 (git show-ref -q refs/remotes/local/o || git fetch local) &&
684 git branch mybase2 &&
685 git branch --track myr2 mybase &&
686 test "$(git config branch.myr2.remote)" = . &&
687 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
688 test "$(git config branch.myr2.rebase)" = true
691 test_expect_success 'autosetuprebase remote on a tracked local branch' '
692 git config remote.local.url . &&
693 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
694 git config branch.autosetuprebase remote &&
695 (git show-ref -q refs/remotes/local/o || git fetch local) &&
696 git branch mybase3 &&
697 git branch --track myr3 mybase2 &&
698 test "$(git config branch.myr3.remote)" = . &&
699 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
700 ! test "$(git config branch.myr3.rebase)" = true
703 test_expect_success 'autosetuprebase never on a tracked local branch' '
704 git config remote.local.url . &&
705 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
706 git config branch.autosetuprebase never &&
707 (git show-ref -q refs/remotes/local/o || git fetch local) &&
708 git branch mybase4 &&
709 git branch --track myr4 mybase2 &&
710 test "$(git config branch.myr4.remote)" = . &&
711 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
712 ! test "$(git config branch.myr4.rebase)" = true
715 test_expect_success 'autosetuprebase local on a tracked remote branch' '
716 git config remote.local.url . &&
717 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
718 git config branch.autosetuprebase local &&
719 (git show-ref -q refs/remotes/local/master || git fetch local) &&
720 git branch --track myr5 local/master &&
721 test "$(git config branch.myr5.remote)" = local &&
722 test "$(git config branch.myr5.merge)" = refs/heads/master &&
723 ! test "$(git config branch.myr5.rebase)" = true
726 test_expect_success 'autosetuprebase never on a tracked remote branch' '
727 git config remote.local.url . &&
728 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
729 git config branch.autosetuprebase never &&
730 (git show-ref -q refs/remotes/local/master || git fetch local) &&
731 git branch --track myr6 local/master &&
732 test "$(git config branch.myr6.remote)" = local &&
733 test "$(git config branch.myr6.merge)" = refs/heads/master &&
734 ! test "$(git config branch.myr6.rebase)" = true
737 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
738 git config remote.local.url . &&
739 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
740 git config branch.autosetuprebase remote &&
741 (git show-ref -q refs/remotes/local/master || git fetch local) &&
742 git branch --track myr7 local/master &&
743 test "$(git config branch.myr7.remote)" = local &&
744 test "$(git config branch.myr7.merge)" = refs/heads/master &&
745 test "$(git config branch.myr7.rebase)" = true
748 test_expect_success 'autosetuprebase always on a tracked remote branch' '
749 git config remote.local.url . &&
750 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
751 git config branch.autosetuprebase remote &&
752 (git show-ref -q refs/remotes/local/master || git fetch local) &&
753 git branch --track myr8 local/master &&
754 test "$(git config branch.myr8.remote)" = local &&
755 test "$(git config branch.myr8.merge)" = refs/heads/master &&
756 test "$(git config branch.myr8.rebase)" = true
759 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
760 git config --unset branch.autosetuprebase &&
761 git config remote.local.url . &&
762 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
763 (git show-ref -q refs/remotes/local/master || git fetch local) &&
764 git branch --track myr9 local/master &&
765 test "$(git config branch.myr9.remote)" = local &&
766 test "$(git config branch.myr9.merge)" = refs/heads/master &&
767 test "z$(git config branch.myr9.rebase)" = z
770 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
771 git config remote.local.url . &&
772 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
773 (git show-ref -q refs/remotes/local/o || git fetch local) &&
774 git branch mybase10 &&
775 git branch --track myr10 mybase2 &&
776 test "$(git config branch.myr10.remote)" = . &&
777 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
778 test "z$(git config branch.myr10.rebase)" = z
781 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
782 git config remote.local.url . &&
783 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
784 (git show-ref -q refs/remotes/local/master || git fetch local) &&
785 git branch --no-track myr11 mybase2 &&
786 test "z$(git config branch.myr11.remote)" = z &&
787 test "z$(git config branch.myr11.merge)" = z &&
788 test "z$(git config branch.myr11.rebase)" = z
791 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
792 git config remote.local.url . &&
793 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
794 (git show-ref -q refs/remotes/local/master || git fetch local) &&
795 git branch --no-track myr12 local/master &&
796 test "z$(git config branch.myr12.remote)" = z &&
797 test "z$(git config branch.myr12.merge)" = z &&
798 test "z$(git config branch.myr12.rebase)" = z
801 test_expect_success 'autosetuprebase never on an untracked local branch' '
802 git config branch.autosetuprebase never &&
803 git config remote.local.url . &&
804 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
805 (git show-ref -q refs/remotes/local/master || git fetch local) &&
806 git branch --no-track myr13 mybase2 &&
807 test "z$(git config branch.myr13.remote)" = z &&
808 test "z$(git config branch.myr13.merge)" = z &&
809 test "z$(git config branch.myr13.rebase)" = z
812 test_expect_success 'autosetuprebase local on an untracked local branch' '
813 git config branch.autosetuprebase local &&
814 git config remote.local.url . &&
815 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
816 (git show-ref -q refs/remotes/local/master || git fetch local) &&
817 git branch --no-track myr14 mybase2 &&
818 test "z$(git config branch.myr14.remote)" = z &&
819 test "z$(git config branch.myr14.merge)" = z &&
820 test "z$(git config branch.myr14.rebase)" = z
823 test_expect_success 'autosetuprebase remote on an untracked local branch' '
824 git config branch.autosetuprebase remote &&
825 git config remote.local.url . &&
826 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
827 (git show-ref -q refs/remotes/local/master || git fetch local) &&
828 git branch --no-track myr15 mybase2 &&
829 test "z$(git config branch.myr15.remote)" = z &&
830 test "z$(git config branch.myr15.merge)" = z &&
831 test "z$(git config branch.myr15.rebase)" = z
834 test_expect_success 'autosetuprebase always on an untracked local branch' '
835 git config branch.autosetuprebase always &&
836 git config remote.local.url . &&
837 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
838 (git show-ref -q refs/remotes/local/master || git fetch local) &&
839 git branch --no-track myr16 mybase2 &&
840 test "z$(git config branch.myr16.remote)" = z &&
841 test "z$(git config branch.myr16.merge)" = z &&
842 test "z$(git config branch.myr16.rebase)" = z
845 test_expect_success 'autosetuprebase never on an untracked remote branch' '
846 git config branch.autosetuprebase never &&
847 git config remote.local.url . &&
848 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
849 (git show-ref -q refs/remotes/local/master || git fetch local) &&
850 git branch --no-track myr17 local/master &&
851 test "z$(git config branch.myr17.remote)" = z &&
852 test "z$(git config branch.myr17.merge)" = z &&
853 test "z$(git config branch.myr17.rebase)" = z
856 test_expect_success 'autosetuprebase local on an untracked remote branch' '
857 git config branch.autosetuprebase local &&
858 git config remote.local.url . &&
859 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
860 (git show-ref -q refs/remotes/local/master || git fetch local) &&
861 git branch --no-track myr18 local/master &&
862 test "z$(git config branch.myr18.remote)" = z &&
863 test "z$(git config branch.myr18.merge)" = z &&
864 test "z$(git config branch.myr18.rebase)" = z
867 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
868 git config branch.autosetuprebase remote &&
869 git config remote.local.url . &&
870 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
871 (git show-ref -q refs/remotes/local/master || git fetch local) &&
872 git branch --no-track myr19 local/master &&
873 test "z$(git config branch.myr19.remote)" = z &&
874 test "z$(git config branch.myr19.merge)" = z &&
875 test "z$(git config branch.myr19.rebase)" = z
878 test_expect_success 'autosetuprebase always on an untracked remote branch' '
879 git config branch.autosetuprebase always &&
880 git config remote.local.url . &&
881 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
882 (git show-ref -q refs/remotes/local/master || git fetch local) &&
883 git branch --no-track myr20 local/master &&
884 test "z$(git config branch.myr20.remote)" = z &&
885 test "z$(git config branch.myr20.merge)" = z &&
886 test "z$(git config branch.myr20.rebase)" = z
889 test_expect_success 'autosetuprebase always on detached HEAD' '
890 git config branch.autosetupmerge always &&
891 test_when_finished git checkout master &&
892 git checkout HEAD^0 &&
893 git branch my11 &&
894 test -z "$(git config branch.my11.remote)" &&
895 test -z "$(git config branch.my11.merge)"
898 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
899 git config branch.autosetuprebase garbage &&
900 test_must_fail git branch
903 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
904 git config --unset branch.autosetuprebase &&
905 echo "[branch] autosetuprebase" >>.git/config &&
906 test_must_fail git branch &&
907 git config --unset branch.autosetuprebase
910 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
911 git checkout my9 &&
912 git config --unset branch.my8.merge &&
913 test_must_fail git branch -d my8
916 test_expect_success 'attempt to delete a branch merged to its base' '
917 # we are on my9 which is the initial commit; traditionally
918 # we would not have allowed deleting my8 that is not merged
919 # to my9, but it is set to track master that already has my8
920 git config branch.my8.merge refs/heads/master &&
921 git branch -d my8
924 test_expect_success 'attempt to delete a branch merged to its base' '
925 git checkout master &&
926 echo Third >>A &&
927 git commit -m "Third commit" A &&
928 git branch -t my10 my9 &&
929 git branch -f my10 HEAD^ &&
930 # we are on master which is at the third commit, and my10
931 # is behind us, so traditionally we would have allowed deleting
932 # it; but my10 is set to track my9 that is further behind.
933 test_must_fail git branch -d my10
936 test_expect_success 'use set-upstream on the current branch' '
937 git checkout master &&
938 git --bare init myupstream.git &&
939 git push myupstream.git master:refs/heads/frotz &&
940 git remote add origin myupstream.git &&
941 git fetch &&
942 git branch --set-upstream master origin/frotz &&
944 test "z$(git config branch.master.remote)" = "zorigin" &&
945 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
949 test_expect_success 'use --edit-description' '
950 write_script editor <<-\EOF &&
951 echo "New contents" >"$1"
953 EDITOR=./editor git branch --edit-description &&
954 write_script editor <<-\EOF &&
955 git stripspace -s <"$1" >"EDITOR_OUTPUT"
957 EDITOR=./editor git branch --edit-description &&
958 echo "New contents" >expect &&
959 test_cmp EDITOR_OUTPUT expect
962 test_expect_success 'detect typo in branch name when using --edit-description' '
963 write_script editor <<-\EOF &&
964 echo "New contents" >"$1"
966 test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
969 test_expect_success 'refuse --edit-description on unborn branch for now' '
970 write_script editor <<-\EOF &&
971 echo "New contents" >"$1"
973 git checkout --orphan unborn &&
974 test_must_fail env EDITOR=./editor git branch --edit-description
977 test_expect_success '--merged catches invalid object names' '
978 test_must_fail git branch --merged 0000000000000000000000000000000000000000
981 test_expect_success '--merged is incompatible with --no-merged' '
982 test_must_fail git branch --merged HEAD --no-merged HEAD
985 test_expect_success 'tracking with unexpected .fetch refspec' '
986 rm -rf a b c d &&
987 git init a &&
989 cd a &&
990 test_commit a
991 ) &&
992 git init b &&
994 cd b &&
995 test_commit b
996 ) &&
997 git init c &&
999 cd c &&
1000 test_commit c &&
1001 git remote add a ../a &&
1002 git remote add b ../b &&
1003 git fetch --all
1004 ) &&
1005 git init d &&
1007 cd d &&
1008 git remote add c ../c &&
1009 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
1010 git fetch c &&
1011 git branch --track local/a/master remotes/a/master &&
1012 test "$(git config branch.local/a/master.remote)" = "c" &&
1013 test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
1014 git rev-parse --verify a >expect &&
1015 git rev-parse --verify local/a/master >actual &&
1016 test_cmp expect actual
1020 test_done