t0061: do not fail test if '.' is part of $PATH
[git/debian.git] / t / t3200-branch.sh
blob5fc2fb425b007c3fec736df5cf13782b8e881f58
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 # The topmost entry in reflog for branch bbb is about branch creation.
104 # Hence, we compare bbb@{1} (instead of bbb@{0}) with aaa@{0}.
106 test_expect_success 'git branch -m bbb should rename checked out branch' '
107 test_when_finished git branch -D bbb &&
108 test_when_finished git checkout master &&
109 git checkout -b aaa &&
110 git commit --allow-empty -m "a new commit" &&
111 git rev-parse aaa@{0} >expect &&
112 git branch -m bbb &&
113 git rev-parse bbb@{1} >actual &&
114 test_cmp expect actual &&
115 git symbolic-ref HEAD >actual &&
116 echo refs/heads/bbb >expect &&
117 test_cmp expect actual
120 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
121 git branch o/o &&
122 git branch o/p &&
123 test_must_fail git branch -m o/o o
126 test_expect_success 'git branch -m o/q o/p should fail when o/p exists' '
127 git branch o/q &&
128 test_must_fail git branch -m o/q o/p
131 test_expect_success 'git branch -M o/q o/p should work when o/p exists' '
132 git branch -M o/q o/p
135 test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '
136 git branch o/q &&
137 git branch -m -f o/q o/p
140 test_expect_success 'git branch -m q r/q should fail when r exists' '
141 git branch q &&
142 git branch r &&
143 test_must_fail git branch -m q r/q
146 test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
147 git branch bar &&
148 git checkout -b foo &&
149 test_must_fail git branch -M bar foo
152 test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
153 git checkout -b baz &&
154 git branch bam &&
155 git branch -M baz bam &&
156 test $(git rev-parse --abbrev-ref HEAD) = bam
159 test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' '
160 msg="Branch: renamed refs/heads/baz to refs/heads/bam" &&
161 grep " 0\{40\}.*$msg$" .git/logs/HEAD &&
162 grep "^0\{40\}.*$msg$" .git/logs/HEAD
165 test_expect_success 'git branch -M should leave orphaned HEAD alone' '
166 git init orphan &&
168 cd orphan &&
169 test_commit initial &&
170 git checkout --orphan lonely &&
171 grep lonely .git/HEAD &&
172 test_path_is_missing .git/refs/head/lonely &&
173 git branch -M master mistress &&
174 grep lonely .git/HEAD
178 test_expect_success 'resulting reflog can be shown by log -g' '
179 oid=$(git rev-parse HEAD) &&
180 cat >expect <<-EOF &&
181 HEAD@{0} $oid $msg
182 HEAD@{2} $oid checkout: moving from foo to baz
184 git log -g --format="%gd %H %gs" -2 HEAD >actual &&
185 test_cmp expect actual
188 test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' '
189 git checkout master &&
190 git worktree add -b baz bazdir &&
191 git worktree add -f bazdir2 baz &&
192 git branch -M baz bam &&
193 test $(git -C bazdir rev-parse --abbrev-ref HEAD) = bam &&
194 test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam
197 test_expect_success 'git branch -M baz bam should succeed within a worktree in which baz is checked out' '
198 git checkout -b baz &&
199 git worktree add -f bazdir3 baz &&
201 cd bazdir3 &&
202 git branch -M baz bam &&
203 test $(git rev-parse --abbrev-ref HEAD) = bam
204 ) &&
205 test $(git rev-parse --abbrev-ref HEAD) = bam
208 test_expect_success 'git branch -M master should work when master is checked out' '
209 git checkout master &&
210 git branch -M master
213 test_expect_success 'git branch -M master master should work when master is checked out' '
214 git checkout master &&
215 git branch -M master master
218 test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
219 git checkout master &&
220 git branch master2 &&
221 git branch -M master2 master2
224 test_expect_success 'git branch -v -d t should work' '
225 git branch t &&
226 test_path_is_file .git/refs/heads/t &&
227 git branch -v -d t &&
228 test_path_is_missing .git/refs/heads/t
231 test_expect_success 'git branch -v -m t s should work' '
232 git branch t &&
233 test_path_is_file .git/refs/heads/t &&
234 git branch -v -m t s &&
235 test_path_is_missing .git/refs/heads/t &&
236 test_path_is_file .git/refs/heads/s &&
237 git branch -d s
240 test_expect_success 'git branch -m -d t s should fail' '
241 git branch t &&
242 test_path_is_file .git/refs/heads/t &&
243 test_must_fail git branch -m -d t s &&
244 git branch -d t &&
245 test_path_is_missing .git/refs/heads/t
248 test_expect_success 'git branch --list -d t should fail' '
249 git branch t &&
250 test_path_is_file .git/refs/heads/t &&
251 test_must_fail git branch --list -d t &&
252 git branch -d t &&
253 test_path_is_missing .git/refs/heads/t
256 test_expect_success 'git branch --list -v with --abbrev' '
257 test_when_finished "git branch -D t" &&
258 git branch t &&
259 git branch -v --list t >actual.default &&
260 git branch -v --list --abbrev t >actual.abbrev &&
261 test_cmp actual.default actual.abbrev &&
263 git branch -v --list --no-abbrev t >actual.noabbrev &&
264 git branch -v --list --abbrev=0 t >actual.0abbrev &&
265 test_cmp actual.noabbrev actual.0abbrev &&
267 git branch -v --list --abbrev=36 t >actual.36abbrev &&
268 # how many hexdigits are used?
269 read name objdefault rest <actual.abbrev &&
270 read name obj36 rest <actual.36abbrev &&
271 objfull=$(git rev-parse --verify t) &&
273 # are we really getting abbreviations?
274 test "$obj36" != "$objdefault" &&
275 expr "$obj36" : "$objdefault" >/dev/null &&
276 test "$objfull" != "$obj36" &&
277 expr "$objfull" : "$obj36" >/dev/null
281 test_expect_success 'git branch --column' '
282 COLUMNS=81 git branch --column=column >actual &&
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 with an extremely long branch name' '
291 long=this/is/a/part/of/long/branch/name &&
292 long=z$long/$long/$long/$long &&
293 test_when_finished "git branch -d $long" &&
294 git branch $long &&
295 COLUMNS=80 git branch --column=column >actual &&
296 cat >expected <<EOF &&
297 a/b/c
305 * master
306 master2
312 $long
314 test_cmp expected actual
317 test_expect_success 'git branch with column.*' '
318 git config column.ui column &&
319 git config column.branch "dense" &&
320 COLUMNS=80 git branch >actual &&
321 git config --unset column.branch &&
322 git config --unset column.ui &&
323 cat >expected <<\EOF &&
324 a/b/c bam foo l * master n o/p r
325 abc bar j/k m/m master2 o/o q
327 test_cmp expected actual
330 test_expect_success 'git branch --column -v should fail' '
331 test_must_fail git branch --column -v
334 test_expect_success 'git branch -v with column.ui ignored' '
335 git config column.ui column &&
336 COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
337 git config --unset column.ui &&
338 cat >expected <<\EOF &&
339 a/b/c
347 * master
348 master2
355 test_cmp expected actual
358 mv .git/config .git/config-saved
360 test_expect_success 'git branch -m q q2 without config should succeed' '
361 git branch -m q q2 &&
362 git branch -m q2 q
365 mv .git/config-saved .git/config
367 git config branch.s/s.dummy Hello
369 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
370 git branch -l s/s &&
371 git reflog exists refs/heads/s/s &&
372 git branch -l s/t &&
373 git reflog exists refs/heads/s/t &&
374 git branch -d s/t &&
375 git branch -m s/s s &&
376 git reflog exists refs/heads/s
379 test_expect_success 'config information was renamed, too' '
380 test $(git config branch.s.dummy) = Hello &&
381 test_must_fail git config branch.s/s.dummy
384 test_expect_success 'deleting a symref' '
385 git branch target &&
386 git symbolic-ref refs/heads/symref refs/heads/target &&
387 echo "Deleted branch symref (was refs/heads/target)." >expect &&
388 git branch -d symref >actual &&
389 test_path_is_file .git/refs/heads/target &&
390 test_path_is_missing .git/refs/heads/symref &&
391 test_i18ncmp expect actual
394 test_expect_success 'deleting a dangling symref' '
395 git symbolic-ref refs/heads/dangling-symref nowhere &&
396 test_path_is_file .git/refs/heads/dangling-symref &&
397 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
398 git branch -d dangling-symref >actual &&
399 test_path_is_missing .git/refs/heads/dangling-symref &&
400 test_i18ncmp expect actual
403 test_expect_success 'deleting a self-referential symref' '
404 git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
405 test_path_is_file .git/refs/heads/self-reference &&
406 echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
407 git branch -d self-reference >actual &&
408 test_path_is_missing .git/refs/heads/self-reference &&
409 test_i18ncmp expect actual
412 test_expect_success 'renaming a symref is not allowed' '
413 git symbolic-ref refs/heads/master2 refs/heads/master &&
414 test_must_fail git branch -m master2 master3 &&
415 git symbolic-ref refs/heads/master2 &&
416 test_path_is_file .git/refs/heads/master &&
417 test_path_is_missing .git/refs/heads/master3
420 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
421 git branch -l u &&
422 mv .git/logs/refs/heads/u real-u &&
423 ln -s real-u .git/logs/refs/heads/u &&
424 test_must_fail git branch -m u v
427 test_expect_success 'test tracking setup via --track' '
428 git config remote.local.url . &&
429 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
430 (git show-ref -q refs/remotes/local/master || git fetch local) &&
431 git branch --track my1 local/master &&
432 test $(git config branch.my1.remote) = local &&
433 test $(git config branch.my1.merge) = refs/heads/master
436 test_expect_success 'test tracking setup (non-wildcard, matching)' '
437 git config remote.local.url . &&
438 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
439 (git show-ref -q refs/remotes/local/master || git fetch local) &&
440 git branch --track my4 local/master &&
441 test $(git config branch.my4.remote) = local &&
442 test $(git config branch.my4.merge) = refs/heads/master
445 test_expect_success 'tracking setup fails on non-matching refspec' '
446 git config remote.local.url . &&
447 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
448 (git show-ref -q refs/remotes/local/master || git fetch local) &&
449 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
450 test_must_fail git branch --track my5 local/master &&
451 test_must_fail git config branch.my5.remote &&
452 test_must_fail git config branch.my5.merge
455 test_expect_success 'test tracking setup via config' '
456 git config branch.autosetupmerge true &&
457 git config remote.local.url . &&
458 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
459 (git show-ref -q refs/remotes/local/master || git fetch local) &&
460 git branch my3 local/master &&
461 test $(git config branch.my3.remote) = local &&
462 test $(git config branch.my3.merge) = refs/heads/master
465 test_expect_success 'test overriding tracking setup via --no-track' '
466 git config branch.autosetupmerge true &&
467 git config remote.local.url . &&
468 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
469 (git show-ref -q refs/remotes/local/master || git fetch local) &&
470 git branch --no-track my2 local/master &&
471 git config branch.autosetupmerge false &&
472 ! test "$(git config branch.my2.remote)" = local &&
473 ! test "$(git config branch.my2.merge)" = refs/heads/master
476 test_expect_success 'no tracking without .fetch entries' '
477 git config branch.autosetupmerge true &&
478 git branch my6 s &&
479 git config branch.autosetupmerge false &&
480 test -z "$(git config branch.my6.remote)" &&
481 test -z "$(git config branch.my6.merge)"
484 test_expect_success 'test tracking setup via --track but deeper' '
485 git config remote.local.url . &&
486 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
487 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
488 git branch --track my7 local/o/o &&
489 test "$(git config branch.my7.remote)" = local &&
490 test "$(git config branch.my7.merge)" = refs/heads/o/o
493 test_expect_success 'test deleting branch deletes branch config' '
494 git branch -d my7 &&
495 test -z "$(git config branch.my7.remote)" &&
496 test -z "$(git config branch.my7.merge)"
499 test_expect_success 'test deleting branch without config' '
500 git branch my7 s &&
501 sha1=$(git rev-parse my7 | cut -c 1-7) &&
502 echo "Deleted branch my7 (was $sha1)." >expect &&
503 git branch -d my7 >actual 2>&1 &&
504 test_i18ncmp expect actual
507 test_expect_success 'deleting currently checked out branch fails' '
508 git worktree add -b my7 my7 &&
509 test_must_fail git -C my7 branch -d my7 &&
510 test_must_fail git branch -d my7
513 test_expect_success 'test --track without .fetch entries' '
514 git branch --track my8 &&
515 test "$(git config branch.my8.remote)" &&
516 test "$(git config branch.my8.merge)"
519 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
520 git config branch.autosetupmerge always &&
521 git branch my9 HEAD^ &&
522 git config branch.autosetupmerge false
525 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
526 test_must_fail git branch --track my10 HEAD^
529 test_expect_success 'branch from tag w/--track causes failure' '
530 git tag foobar &&
531 test_must_fail git branch --track my11 foobar
534 test_expect_success '--set-upstream-to fails on multiple branches' '
535 test_must_fail git branch --set-upstream-to master a b c
538 test_expect_success '--set-upstream-to fails on detached HEAD' '
539 git checkout HEAD^{} &&
540 test_must_fail git branch --set-upstream-to master &&
541 git checkout -
544 test_expect_success '--set-upstream-to fails on a missing dst branch' '
545 test_must_fail git branch --set-upstream-to master does-not-exist
548 test_expect_success '--set-upstream-to fails on a missing src branch' '
549 test_must_fail git branch --set-upstream-to does-not-exist master
552 test_expect_success '--set-upstream-to fails on a non-ref' '
553 test_must_fail git branch --set-upstream-to HEAD^{}
556 test_expect_success '--set-upstream-to fails on locked config' '
557 test_when_finished "rm -f .git/config.lock" &&
558 >.git/config.lock &&
559 git branch locked &&
560 test_must_fail git branch --set-upstream-to locked
563 test_expect_success 'use --set-upstream-to modify HEAD' '
564 test_config branch.master.remote foo &&
565 test_config branch.master.merge foo &&
566 git branch my12 &&
567 git branch --set-upstream-to my12 &&
568 test "$(git config branch.master.remote)" = "." &&
569 test "$(git config branch.master.merge)" = "refs/heads/my12"
572 test_expect_success 'use --set-upstream-to modify a particular branch' '
573 git branch my13 &&
574 git branch --set-upstream-to master my13 &&
575 test "$(git config branch.my13.remote)" = "." &&
576 test "$(git config branch.my13.merge)" = "refs/heads/master"
579 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
580 test_must_fail git branch --unset-upstream i-dont-exist
583 test_expect_success '--unset-upstream should fail if config is locked' '
584 test_when_finished "rm -f .git/config.lock" &&
585 git branch --set-upstream-to locked &&
586 >.git/config.lock &&
587 test_must_fail git branch --unset-upstream
590 test_expect_success 'test --unset-upstream on HEAD' '
591 git branch my14 &&
592 test_config branch.master.remote foo &&
593 test_config branch.master.merge foo &&
594 git branch --set-upstream-to my14 &&
595 git branch --unset-upstream &&
596 test_must_fail git config branch.master.remote &&
597 test_must_fail git config branch.master.merge &&
598 # fail for a branch without upstream set
599 test_must_fail git branch --unset-upstream
602 test_expect_success '--unset-upstream should fail on multiple branches' '
603 test_must_fail git branch --unset-upstream a b c
606 test_expect_success '--unset-upstream should fail on detached HEAD' '
607 git checkout HEAD^{} &&
608 test_must_fail git branch --unset-upstream &&
609 git checkout -
612 test_expect_success 'test --unset-upstream on a particular branch' '
613 git branch my15 &&
614 git branch --set-upstream-to master my14 &&
615 git branch --unset-upstream my14 &&
616 test_must_fail git config branch.my14.remote &&
617 test_must_fail git config branch.my14.merge
620 test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
621 git update-ref refs/remotes/origin/master HEAD &&
622 git branch --set-upstream origin/master 2>actual &&
623 test_when_finished git update-ref -d refs/remotes/origin/master &&
624 test_when_finished git branch -d origin/master &&
625 cat >expected <<EOF &&
626 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
628 If you wanted to make '"'master'"' track '"'origin/master'"', do this:
630 git branch -d origin/master
631 git branch --set-upstream-to origin/master
633 test_i18ncmp expected actual
636 test_expect_success '--set-upstream with two args only shows the deprecation message' '
637 git branch --set-upstream master my13 2>actual &&
638 test_when_finished git branch --unset-upstream master &&
639 cat >expected <<EOF &&
640 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
642 test_i18ncmp expected actual
645 test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
646 git branch --set-upstream my13 2>actual &&
647 test_when_finished git branch --unset-upstream my13 &&
648 cat >expected <<EOF &&
649 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
651 test_i18ncmp expected actual
654 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
655 git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
656 cat >expected <<-\EOF &&
657 warning: Not setting branch my13 as its own upstream.
659 test_expect_code 1 git config branch.my13.remote &&
660 test_expect_code 1 git config branch.my13.merge &&
661 test_i18ncmp expected actual
664 # Keep this test last, as it changes the current branch
665 cat >expect <<EOF
666 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
668 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
669 GIT_COMMITTER_DATE="2005-05-26 23:30" \
670 git checkout -b g/h/i -l master &&
671 test_path_is_file .git/refs/heads/g/h/i &&
672 test_path_is_file .git/logs/refs/heads/g/h/i &&
673 test_cmp expect .git/logs/refs/heads/g/h/i
676 test_expect_success 'checkout -b makes reflog by default' '
677 git checkout master &&
678 git config --unset core.logAllRefUpdates &&
679 git checkout -b alpha &&
680 git rev-parse --verify alpha@{0}
683 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
684 git checkout master &&
685 git config core.logAllRefUpdates false &&
686 git checkout -b beta &&
687 test_must_fail git rev-parse --verify beta@{0}
690 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
691 git checkout master &&
692 git checkout -lb gamma &&
693 git config --unset core.logAllRefUpdates &&
694 git rev-parse --verify gamma@{0}
697 test_expect_success 'avoid ambiguous track' '
698 git config branch.autosetupmerge true &&
699 git config remote.ambi1.url lalala &&
700 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
701 git config remote.ambi2.url lilili &&
702 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
703 test_must_fail git branch all1 master &&
704 test -z "$(git config branch.all1.merge)"
707 test_expect_success 'autosetuprebase local on a tracked local branch' '
708 git config remote.local.url . &&
709 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
710 git config branch.autosetuprebase local &&
711 (git show-ref -q refs/remotes/local/o || git fetch local) &&
712 git branch mybase &&
713 git branch --track myr1 mybase &&
714 test "$(git config branch.myr1.remote)" = . &&
715 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
716 test "$(git config branch.myr1.rebase)" = true
719 test_expect_success 'autosetuprebase always on a tracked local branch' '
720 git config remote.local.url . &&
721 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
722 git config branch.autosetuprebase always &&
723 (git show-ref -q refs/remotes/local/o || git fetch local) &&
724 git branch mybase2 &&
725 git branch --track myr2 mybase &&
726 test "$(git config branch.myr2.remote)" = . &&
727 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
728 test "$(git config branch.myr2.rebase)" = true
731 test_expect_success 'autosetuprebase remote on a tracked local branch' '
732 git config remote.local.url . &&
733 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
734 git config branch.autosetuprebase remote &&
735 (git show-ref -q refs/remotes/local/o || git fetch local) &&
736 git branch mybase3 &&
737 git branch --track myr3 mybase2 &&
738 test "$(git config branch.myr3.remote)" = . &&
739 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
740 ! test "$(git config branch.myr3.rebase)" = true
743 test_expect_success 'autosetuprebase never on a tracked local branch' '
744 git config remote.local.url . &&
745 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
746 git config branch.autosetuprebase never &&
747 (git show-ref -q refs/remotes/local/o || git fetch local) &&
748 git branch mybase4 &&
749 git branch --track myr4 mybase2 &&
750 test "$(git config branch.myr4.remote)" = . &&
751 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
752 ! test "$(git config branch.myr4.rebase)" = true
755 test_expect_success 'autosetuprebase local on a tracked remote branch' '
756 git config remote.local.url . &&
757 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
758 git config branch.autosetuprebase local &&
759 (git show-ref -q refs/remotes/local/master || git fetch local) &&
760 git branch --track myr5 local/master &&
761 test "$(git config branch.myr5.remote)" = local &&
762 test "$(git config branch.myr5.merge)" = refs/heads/master &&
763 ! test "$(git config branch.myr5.rebase)" = true
766 test_expect_success 'autosetuprebase never on a tracked remote branch' '
767 git config remote.local.url . &&
768 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
769 git config branch.autosetuprebase never &&
770 (git show-ref -q refs/remotes/local/master || git fetch local) &&
771 git branch --track myr6 local/master &&
772 test "$(git config branch.myr6.remote)" = local &&
773 test "$(git config branch.myr6.merge)" = refs/heads/master &&
774 ! test "$(git config branch.myr6.rebase)" = true
777 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
778 git config remote.local.url . &&
779 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
780 git config branch.autosetuprebase remote &&
781 (git show-ref -q refs/remotes/local/master || git fetch local) &&
782 git branch --track myr7 local/master &&
783 test "$(git config branch.myr7.remote)" = local &&
784 test "$(git config branch.myr7.merge)" = refs/heads/master &&
785 test "$(git config branch.myr7.rebase)" = true
788 test_expect_success 'autosetuprebase always on a tracked remote branch' '
789 git config remote.local.url . &&
790 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
791 git config branch.autosetuprebase remote &&
792 (git show-ref -q refs/remotes/local/master || git fetch local) &&
793 git branch --track myr8 local/master &&
794 test "$(git config branch.myr8.remote)" = local &&
795 test "$(git config branch.myr8.merge)" = refs/heads/master &&
796 test "$(git config branch.myr8.rebase)" = true
799 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
800 git config --unset branch.autosetuprebase &&
801 git config remote.local.url . &&
802 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
803 (git show-ref -q refs/remotes/local/master || git fetch local) &&
804 git branch --track myr9 local/master &&
805 test "$(git config branch.myr9.remote)" = local &&
806 test "$(git config branch.myr9.merge)" = refs/heads/master &&
807 test "z$(git config branch.myr9.rebase)" = z
810 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
811 git config remote.local.url . &&
812 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
813 (git show-ref -q refs/remotes/local/o || git fetch local) &&
814 git branch mybase10 &&
815 git branch --track myr10 mybase2 &&
816 test "$(git config branch.myr10.remote)" = . &&
817 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
818 test "z$(git config branch.myr10.rebase)" = z
821 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
822 git config remote.local.url . &&
823 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
824 (git show-ref -q refs/remotes/local/master || git fetch local) &&
825 git branch --no-track myr11 mybase2 &&
826 test "z$(git config branch.myr11.remote)" = z &&
827 test "z$(git config branch.myr11.merge)" = z &&
828 test "z$(git config branch.myr11.rebase)" = z
831 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
832 git config remote.local.url . &&
833 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
834 (git show-ref -q refs/remotes/local/master || git fetch local) &&
835 git branch --no-track myr12 local/master &&
836 test "z$(git config branch.myr12.remote)" = z &&
837 test "z$(git config branch.myr12.merge)" = z &&
838 test "z$(git config branch.myr12.rebase)" = z
841 test_expect_success 'autosetuprebase never on an untracked local branch' '
842 git config branch.autosetuprebase never &&
843 git config remote.local.url . &&
844 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
845 (git show-ref -q refs/remotes/local/master || git fetch local) &&
846 git branch --no-track myr13 mybase2 &&
847 test "z$(git config branch.myr13.remote)" = z &&
848 test "z$(git config branch.myr13.merge)" = z &&
849 test "z$(git config branch.myr13.rebase)" = z
852 test_expect_success 'autosetuprebase local on an untracked local branch' '
853 git config branch.autosetuprebase local &&
854 git config remote.local.url . &&
855 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
856 (git show-ref -q refs/remotes/local/master || git fetch local) &&
857 git branch --no-track myr14 mybase2 &&
858 test "z$(git config branch.myr14.remote)" = z &&
859 test "z$(git config branch.myr14.merge)" = z &&
860 test "z$(git config branch.myr14.rebase)" = z
863 test_expect_success 'autosetuprebase remote on an untracked local branch' '
864 git config branch.autosetuprebase remote &&
865 git config remote.local.url . &&
866 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
867 (git show-ref -q refs/remotes/local/master || git fetch local) &&
868 git branch --no-track myr15 mybase2 &&
869 test "z$(git config branch.myr15.remote)" = z &&
870 test "z$(git config branch.myr15.merge)" = z &&
871 test "z$(git config branch.myr15.rebase)" = z
874 test_expect_success 'autosetuprebase always on an untracked local branch' '
875 git config branch.autosetuprebase always &&
876 git config remote.local.url . &&
877 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
878 (git show-ref -q refs/remotes/local/master || git fetch local) &&
879 git branch --no-track myr16 mybase2 &&
880 test "z$(git config branch.myr16.remote)" = z &&
881 test "z$(git config branch.myr16.merge)" = z &&
882 test "z$(git config branch.myr16.rebase)" = z
885 test_expect_success 'autosetuprebase never on an untracked remote branch' '
886 git config branch.autosetuprebase never &&
887 git config remote.local.url . &&
888 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
889 (git show-ref -q refs/remotes/local/master || git fetch local) &&
890 git branch --no-track myr17 local/master &&
891 test "z$(git config branch.myr17.remote)" = z &&
892 test "z$(git config branch.myr17.merge)" = z &&
893 test "z$(git config branch.myr17.rebase)" = z
896 test_expect_success 'autosetuprebase local on an untracked remote branch' '
897 git config branch.autosetuprebase local &&
898 git config remote.local.url . &&
899 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
900 (git show-ref -q refs/remotes/local/master || git fetch local) &&
901 git branch --no-track myr18 local/master &&
902 test "z$(git config branch.myr18.remote)" = z &&
903 test "z$(git config branch.myr18.merge)" = z &&
904 test "z$(git config branch.myr18.rebase)" = z
907 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
908 git config branch.autosetuprebase remote &&
909 git config remote.local.url . &&
910 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
911 (git show-ref -q refs/remotes/local/master || git fetch local) &&
912 git branch --no-track myr19 local/master &&
913 test "z$(git config branch.myr19.remote)" = z &&
914 test "z$(git config branch.myr19.merge)" = z &&
915 test "z$(git config branch.myr19.rebase)" = z
918 test_expect_success 'autosetuprebase always on an untracked remote branch' '
919 git config branch.autosetuprebase always &&
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/master || git fetch local) &&
923 git branch --no-track myr20 local/master &&
924 test "z$(git config branch.myr20.remote)" = z &&
925 test "z$(git config branch.myr20.merge)" = z &&
926 test "z$(git config branch.myr20.rebase)" = z
929 test_expect_success 'autosetuprebase always on detached HEAD' '
930 git config branch.autosetupmerge always &&
931 test_when_finished git checkout master &&
932 git checkout HEAD^0 &&
933 git branch my11 &&
934 test -z "$(git config branch.my11.remote)" &&
935 test -z "$(git config branch.my11.merge)"
938 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
939 git config branch.autosetuprebase garbage &&
940 test_must_fail git branch
943 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
944 git config --unset branch.autosetuprebase &&
945 echo "[branch] autosetuprebase" >>.git/config &&
946 test_must_fail git branch &&
947 git config --unset branch.autosetuprebase
950 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
951 git checkout my9 &&
952 git config --unset branch.my8.merge &&
953 test_must_fail git branch -d my8
956 test_expect_success 'attempt to delete a branch merged to its base' '
957 # we are on my9 which is the initial commit; traditionally
958 # we would not have allowed deleting my8 that is not merged
959 # to my9, but it is set to track master that already has my8
960 git config branch.my8.merge refs/heads/master &&
961 git branch -d my8
964 test_expect_success 'attempt to delete a branch merged to its base' '
965 git checkout master &&
966 echo Third >>A &&
967 git commit -m "Third commit" A &&
968 git branch -t my10 my9 &&
969 git branch -f my10 HEAD^ &&
970 # we are on master which is at the third commit, and my10
971 # is behind us, so traditionally we would have allowed deleting
972 # it; but my10 is set to track my9 that is further behind.
973 test_must_fail git branch -d my10
976 test_expect_success 'use set-upstream on the current branch' '
977 git checkout master &&
978 git --bare init myupstream.git &&
979 git push myupstream.git master:refs/heads/frotz &&
980 git remote add origin myupstream.git &&
981 git fetch &&
982 git branch --set-upstream master origin/frotz &&
984 test "z$(git config branch.master.remote)" = "zorigin" &&
985 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
989 test_expect_success 'use --edit-description' '
990 write_script editor <<-\EOF &&
991 echo "New contents" >"$1"
993 EDITOR=./editor git branch --edit-description &&
994 write_script editor <<-\EOF &&
995 git stripspace -s <"$1" >"EDITOR_OUTPUT"
997 EDITOR=./editor git branch --edit-description &&
998 echo "New contents" >expect &&
999 test_cmp EDITOR_OUTPUT expect
1002 test_expect_success 'detect typo in branch name when using --edit-description' '
1003 write_script editor <<-\EOF &&
1004 echo "New contents" >"$1"
1006 test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
1009 test_expect_success 'refuse --edit-description on unborn branch for now' '
1010 write_script editor <<-\EOF &&
1011 echo "New contents" >"$1"
1013 git checkout --orphan unborn &&
1014 test_must_fail env EDITOR=./editor git branch --edit-description
1017 test_expect_success '--merged catches invalid object names' '
1018 test_must_fail git branch --merged 0000000000000000000000000000000000000000
1021 test_expect_success '--merged is incompatible with --no-merged' '
1022 test_must_fail git branch --merged HEAD --no-merged HEAD
1025 test_expect_success 'tracking with unexpected .fetch refspec' '
1026 rm -rf a b c d &&
1027 git init a &&
1029 cd a &&
1030 test_commit a
1031 ) &&
1032 git init b &&
1034 cd b &&
1035 test_commit b
1036 ) &&
1037 git init c &&
1039 cd c &&
1040 test_commit c &&
1041 git remote add a ../a &&
1042 git remote add b ../b &&
1043 git fetch --all
1044 ) &&
1045 git init d &&
1047 cd d &&
1048 git remote add c ../c &&
1049 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
1050 git fetch c &&
1051 git branch --track local/a/master remotes/a/master &&
1052 test "$(git config branch.local/a/master.remote)" = "c" &&
1053 test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
1054 git rev-parse --verify a >expect &&
1055 git rev-parse --verify local/a/master >actual &&
1056 test_cmp expect actual
1060 test_done