tgupdate: merge release into t/config/highlight-exts base
[git/gitweb.git] / t / t3200-branch.sh
blob8a833f354e331966f5f927ae94ac8686dd6d166f
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 succeed when baz is checked out as linked working tree' '
143 git checkout master &&
144 git worktree add -b baz bazdir &&
145 git worktree add -f bazdir2 baz &&
146 git branch -M baz bam &&
147 test $(git -C bazdir rev-parse --abbrev-ref HEAD) = bam &&
148 test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam
151 test_expect_success 'git branch -M baz bam should succeed within a worktree in which baz is checked out' '
152 git checkout -b baz &&
153 git worktree add -f bazdir3 baz &&
155 cd bazdir3 &&
156 git branch -M baz bam &&
157 test $(git rev-parse --abbrev-ref HEAD) = bam
158 ) &&
159 test $(git rev-parse --abbrev-ref HEAD) = bam
162 test_expect_success 'git branch -M master should work when master is checked out' '
163 git checkout master &&
164 git branch -M master
167 test_expect_success 'git branch -M master master should work when master is checked out' '
168 git checkout master &&
169 git branch -M master master
172 test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
173 git checkout master &&
174 git branch master2 &&
175 git branch -M master2 master2
178 test_expect_success 'git branch -v -d t should work' '
179 git branch t &&
180 test_path_is_file .git/refs/heads/t &&
181 git branch -v -d t &&
182 test_path_is_missing .git/refs/heads/t
185 test_expect_success 'git branch -v -m t s should work' '
186 git branch t &&
187 test_path_is_file .git/refs/heads/t &&
188 git branch -v -m t s &&
189 test_path_is_missing .git/refs/heads/t &&
190 test_path_is_file .git/refs/heads/s &&
191 git branch -d s
194 test_expect_success 'git branch -m -d t s should fail' '
195 git branch t &&
196 test_path_is_file .git/refs/heads/t &&
197 test_must_fail git branch -m -d t s &&
198 git branch -d t &&
199 test_path_is_missing .git/refs/heads/t
202 test_expect_success 'git branch --list -d t should fail' '
203 git branch t &&
204 test_path_is_file .git/refs/heads/t &&
205 test_must_fail git branch --list -d t &&
206 git branch -d t &&
207 test_path_is_missing .git/refs/heads/t
210 test_expect_success 'git branch --column' '
211 COLUMNS=81 git branch --column=column >actual &&
212 cat >expected <<\EOF &&
213 a/b/c bam foo l * master n o/p r
214 abc bar j/k m/m master2 o/o q
216 test_cmp expected actual
219 test_expect_success 'git branch --column with an extremely long branch name' '
220 long=this/is/a/part/of/long/branch/name &&
221 long=z$long/$long/$long/$long &&
222 test_when_finished "git branch -d $long" &&
223 git branch $long &&
224 COLUMNS=80 git branch --column=column >actual &&
225 cat >expected <<EOF &&
226 a/b/c
234 * master
235 master2
241 $long
243 test_cmp expected actual
246 test_expect_success 'git branch with column.*' '
247 git config column.ui column &&
248 git config column.branch "dense" &&
249 COLUMNS=80 git branch >actual &&
250 git config --unset column.branch &&
251 git config --unset column.ui &&
252 cat >expected <<\EOF &&
253 a/b/c bam foo l * master n o/p r
254 abc bar j/k m/m master2 o/o q
256 test_cmp expected actual
259 test_expect_success 'git branch --column -v should fail' '
260 test_must_fail git branch --column -v
263 test_expect_success 'git branch -v with column.ui ignored' '
264 git config column.ui column &&
265 COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
266 git config --unset column.ui &&
267 cat >expected <<\EOF &&
268 a/b/c
276 * master
277 master2
284 test_cmp expected actual
287 mv .git/config .git/config-saved
289 test_expect_success 'git branch -m q q2 without config should succeed' '
290 git branch -m q q2 &&
291 git branch -m q2 q
294 mv .git/config-saved .git/config
296 git config branch.s/s.dummy Hello
298 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
299 git branch -l s/s &&
300 git reflog exists refs/heads/s/s &&
301 git branch -l s/t &&
302 git reflog exists refs/heads/s/t &&
303 git branch -d s/t &&
304 git branch -m s/s s &&
305 git reflog exists refs/heads/s
308 test_expect_success 'config information was renamed, too' '
309 test $(git config branch.s.dummy) = Hello &&
310 test_must_fail git config branch.s/s/dummy
313 test_expect_success 'deleting a symref' '
314 git branch target &&
315 git symbolic-ref refs/heads/symref refs/heads/target &&
316 echo "Deleted branch symref (was refs/heads/target)." >expect &&
317 git branch -d symref >actual &&
318 test_path_is_file .git/refs/heads/target &&
319 test_path_is_missing .git/refs/heads/symref &&
320 test_i18ncmp expect actual
323 test_expect_success 'deleting a dangling symref' '
324 git symbolic-ref refs/heads/dangling-symref nowhere &&
325 test_path_is_file .git/refs/heads/dangling-symref &&
326 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
327 git branch -d dangling-symref >actual &&
328 test_path_is_missing .git/refs/heads/dangling-symref &&
329 test_i18ncmp expect actual
332 test_expect_success 'deleting a self-referential symref' '
333 git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
334 test_path_is_file .git/refs/heads/self-reference &&
335 echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
336 git branch -d self-reference >actual &&
337 test_path_is_missing .git/refs/heads/self-reference &&
338 test_i18ncmp expect actual
341 test_expect_success 'renaming a symref is not allowed' '
342 git symbolic-ref refs/heads/master2 refs/heads/master &&
343 test_must_fail git branch -m master2 master3 &&
344 git symbolic-ref refs/heads/master2 &&
345 test_path_is_file .git/refs/heads/master &&
346 test_path_is_missing .git/refs/heads/master3
349 test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
350 git branch -l u &&
351 mv .git/logs/refs/heads/u real-u &&
352 ln -s real-u .git/logs/refs/heads/u &&
353 test_must_fail git branch -m u v
356 test_expect_success 'test tracking setup via --track' '
357 git config remote.local.url . &&
358 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
359 (git show-ref -q refs/remotes/local/master || git fetch local) &&
360 git branch --track my1 local/master &&
361 test $(git config branch.my1.remote) = local &&
362 test $(git config branch.my1.merge) = refs/heads/master
365 test_expect_success 'test tracking setup (non-wildcard, matching)' '
366 git config remote.local.url . &&
367 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
368 (git show-ref -q refs/remotes/local/master || git fetch local) &&
369 git branch --track my4 local/master &&
370 test $(git config branch.my4.remote) = local &&
371 test $(git config branch.my4.merge) = refs/heads/master
374 test_expect_success 'tracking setup fails on non-matching refspec' '
375 git config remote.local.url . &&
376 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
377 (git show-ref -q refs/remotes/local/master || git fetch local) &&
378 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
379 test_must_fail git branch --track my5 local/master &&
380 test_must_fail git config branch.my5.remote &&
381 test_must_fail git config branch.my5.merge
384 test_expect_success 'test tracking setup via config' '
385 git config branch.autosetupmerge true &&
386 git config remote.local.url . &&
387 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
388 (git show-ref -q refs/remotes/local/master || git fetch local) &&
389 git branch my3 local/master &&
390 test $(git config branch.my3.remote) = local &&
391 test $(git config branch.my3.merge) = refs/heads/master
394 test_expect_success 'test overriding tracking setup via --no-track' '
395 git config branch.autosetupmerge true &&
396 git config remote.local.url . &&
397 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
398 (git show-ref -q refs/remotes/local/master || git fetch local) &&
399 git branch --no-track my2 local/master &&
400 git config branch.autosetupmerge false &&
401 ! test "$(git config branch.my2.remote)" = local &&
402 ! test "$(git config branch.my2.merge)" = refs/heads/master
405 test_expect_success 'no tracking without .fetch entries' '
406 git config branch.autosetupmerge true &&
407 git branch my6 s &&
408 git config branch.autosetupmerge false &&
409 test -z "$(git config branch.my6.remote)" &&
410 test -z "$(git config branch.my6.merge)"
413 test_expect_success 'test tracking setup via --track but deeper' '
414 git config remote.local.url . &&
415 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
416 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
417 git branch --track my7 local/o/o &&
418 test "$(git config branch.my7.remote)" = local &&
419 test "$(git config branch.my7.merge)" = refs/heads/o/o
422 test_expect_success 'test deleting branch deletes branch config' '
423 git branch -d my7 &&
424 test -z "$(git config branch.my7.remote)" &&
425 test -z "$(git config branch.my7.merge)"
428 test_expect_success 'test deleting branch without config' '
429 git branch my7 s &&
430 sha1=$(git rev-parse my7 | cut -c 1-7) &&
431 echo "Deleted branch my7 (was $sha1)." >expect &&
432 git branch -d my7 >actual 2>&1 &&
433 test_i18ncmp expect actual
436 test_expect_success 'deleting currently checked out branch fails' '
437 git worktree add -b my7 my7 &&
438 test_must_fail git -C my7 branch -d my7 &&
439 test_must_fail git branch -d my7
442 test_expect_success 'test --track without .fetch entries' '
443 git branch --track my8 &&
444 test "$(git config branch.my8.remote)" &&
445 test "$(git config branch.my8.merge)"
448 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
449 git config branch.autosetupmerge always &&
450 git branch my9 HEAD^ &&
451 git config branch.autosetupmerge false
454 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
455 test_must_fail git branch --track my10 HEAD^
458 test_expect_success 'branch from tag w/--track causes failure' '
459 git tag foobar &&
460 test_must_fail git branch --track my11 foobar
463 test_expect_success '--set-upstream-to fails on multiple branches' '
464 test_must_fail git branch --set-upstream-to master a b c
467 test_expect_success '--set-upstream-to fails on detached HEAD' '
468 git checkout HEAD^{} &&
469 test_must_fail git branch --set-upstream-to master &&
470 git checkout -
473 test_expect_success '--set-upstream-to fails on a missing dst branch' '
474 test_must_fail git branch --set-upstream-to master does-not-exist
477 test_expect_success '--set-upstream-to fails on a missing src branch' '
478 test_must_fail git branch --set-upstream-to does-not-exist master
481 test_expect_success '--set-upstream-to fails on a non-ref' '
482 test_must_fail git branch --set-upstream-to HEAD^{}
485 test_expect_success '--set-upstream-to fails on locked config' '
486 test_when_finished "rm -f .git/config.lock" &&
487 >.git/config.lock &&
488 git branch locked &&
489 test_must_fail git branch --set-upstream-to locked
492 test_expect_success 'use --set-upstream-to modify HEAD' '
493 test_config branch.master.remote foo &&
494 test_config branch.master.merge foo &&
495 git branch my12 &&
496 git branch --set-upstream-to my12 &&
497 test "$(git config branch.master.remote)" = "." &&
498 test "$(git config branch.master.merge)" = "refs/heads/my12"
501 test_expect_success 'use --set-upstream-to modify a particular branch' '
502 git branch my13 &&
503 git branch --set-upstream-to master my13 &&
504 test "$(git config branch.my13.remote)" = "." &&
505 test "$(git config branch.my13.merge)" = "refs/heads/master"
508 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
509 test_must_fail git branch --unset-upstream i-dont-exist
512 test_expect_success '--unset-upstream should fail if config is locked' '
513 test_when_finished "rm -f .git/config.lock" &&
514 git branch --set-upstream-to locked &&
515 >.git/config.lock &&
516 test_must_fail git branch --unset-upstream
519 test_expect_success 'test --unset-upstream on HEAD' '
520 git branch my14 &&
521 test_config branch.master.remote foo &&
522 test_config branch.master.merge foo &&
523 git branch --set-upstream-to my14 &&
524 git branch --unset-upstream &&
525 test_must_fail git config branch.master.remote &&
526 test_must_fail git config branch.master.merge &&
527 # fail for a branch without upstream set
528 test_must_fail git branch --unset-upstream
531 test_expect_success '--unset-upstream should fail on multiple branches' '
532 test_must_fail git branch --unset-upstream a b c
535 test_expect_success '--unset-upstream should fail on detached HEAD' '
536 git checkout HEAD^{} &&
537 test_must_fail git branch --unset-upstream &&
538 git checkout -
541 test_expect_success 'test --unset-upstream on a particular branch' '
542 git branch my15 &&
543 git branch --set-upstream-to master my14 &&
544 git branch --unset-upstream my14 &&
545 test_must_fail git config branch.my14.remote &&
546 test_must_fail git config branch.my14.merge
549 test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
550 git update-ref refs/remotes/origin/master HEAD &&
551 git branch --set-upstream origin/master 2>actual &&
552 test_when_finished git update-ref -d refs/remotes/origin/master &&
553 test_when_finished git branch -d origin/master &&
554 cat >expected <<EOF &&
555 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
557 If you wanted to make '"'master'"' track '"'origin/master'"', do this:
559 git branch -d origin/master
560 git branch --set-upstream-to origin/master
562 test_i18ncmp expected actual
565 test_expect_success '--set-upstream with two args only shows the deprecation message' '
566 git branch --set-upstream master my13 2>actual &&
567 test_when_finished git branch --unset-upstream master &&
568 cat >expected <<EOF &&
569 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
571 test_i18ncmp expected actual
574 test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
575 git branch --set-upstream my13 2>actual &&
576 test_when_finished git branch --unset-upstream my13 &&
577 cat >expected <<EOF &&
578 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
580 test_i18ncmp expected actual
583 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
584 git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
585 cat >expected <<-\EOF &&
586 warning: Not setting branch my13 as its own upstream.
588 test_expect_code 1 git config branch.my13.remote &&
589 test_expect_code 1 git config branch.my13.merge &&
590 test_i18ncmp expected actual
593 # Keep this test last, as it changes the current branch
594 cat >expect <<EOF
595 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
597 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
598 GIT_COMMITTER_DATE="2005-05-26 23:30" \
599 git checkout -b g/h/i -l master &&
600 test_path_is_file .git/refs/heads/g/h/i &&
601 test_path_is_file .git/logs/refs/heads/g/h/i &&
602 test_cmp expect .git/logs/refs/heads/g/h/i
605 test_expect_success 'checkout -b makes reflog by default' '
606 git checkout master &&
607 git config --unset core.logAllRefUpdates &&
608 git checkout -b alpha &&
609 git rev-parse --verify alpha@{0}
612 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
613 git checkout master &&
614 git config core.logAllRefUpdates false &&
615 git checkout -b beta &&
616 test_must_fail git rev-parse --verify beta@{0}
619 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
620 git checkout master &&
621 git checkout -lb gamma &&
622 git config --unset core.logAllRefUpdates &&
623 git rev-parse --verify gamma@{0}
626 test_expect_success 'avoid ambiguous track' '
627 git config branch.autosetupmerge true &&
628 git config remote.ambi1.url lalala &&
629 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
630 git config remote.ambi2.url lilili &&
631 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
632 test_must_fail git branch all1 master &&
633 test -z "$(git config branch.all1.merge)"
636 test_expect_success 'autosetuprebase local on a tracked local branch' '
637 git config remote.local.url . &&
638 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
639 git config branch.autosetuprebase local &&
640 (git show-ref -q refs/remotes/local/o || git fetch local) &&
641 git branch mybase &&
642 git branch --track myr1 mybase &&
643 test "$(git config branch.myr1.remote)" = . &&
644 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
645 test "$(git config branch.myr1.rebase)" = true
648 test_expect_success 'autosetuprebase always on a tracked local branch' '
649 git config remote.local.url . &&
650 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
651 git config branch.autosetuprebase always &&
652 (git show-ref -q refs/remotes/local/o || git fetch local) &&
653 git branch mybase2 &&
654 git branch --track myr2 mybase &&
655 test "$(git config branch.myr2.remote)" = . &&
656 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
657 test "$(git config branch.myr2.rebase)" = true
660 test_expect_success 'autosetuprebase remote on a tracked local branch' '
661 git config remote.local.url . &&
662 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
663 git config branch.autosetuprebase remote &&
664 (git show-ref -q refs/remotes/local/o || git fetch local) &&
665 git branch mybase3 &&
666 git branch --track myr3 mybase2 &&
667 test "$(git config branch.myr3.remote)" = . &&
668 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
669 ! test "$(git config branch.myr3.rebase)" = true
672 test_expect_success 'autosetuprebase never on a tracked local branch' '
673 git config remote.local.url . &&
674 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
675 git config branch.autosetuprebase never &&
676 (git show-ref -q refs/remotes/local/o || git fetch local) &&
677 git branch mybase4 &&
678 git branch --track myr4 mybase2 &&
679 test "$(git config branch.myr4.remote)" = . &&
680 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
681 ! test "$(git config branch.myr4.rebase)" = true
684 test_expect_success 'autosetuprebase local on a tracked remote branch' '
685 git config remote.local.url . &&
686 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
687 git config branch.autosetuprebase local &&
688 (git show-ref -q refs/remotes/local/master || git fetch local) &&
689 git branch --track myr5 local/master &&
690 test "$(git config branch.myr5.remote)" = local &&
691 test "$(git config branch.myr5.merge)" = refs/heads/master &&
692 ! test "$(git config branch.myr5.rebase)" = true
695 test_expect_success 'autosetuprebase never on a tracked remote branch' '
696 git config remote.local.url . &&
697 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
698 git config branch.autosetuprebase never &&
699 (git show-ref -q refs/remotes/local/master || git fetch local) &&
700 git branch --track myr6 local/master &&
701 test "$(git config branch.myr6.remote)" = local &&
702 test "$(git config branch.myr6.merge)" = refs/heads/master &&
703 ! test "$(git config branch.myr6.rebase)" = true
706 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
707 git config remote.local.url . &&
708 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
709 git config branch.autosetuprebase remote &&
710 (git show-ref -q refs/remotes/local/master || git fetch local) &&
711 git branch --track myr7 local/master &&
712 test "$(git config branch.myr7.remote)" = local &&
713 test "$(git config branch.myr7.merge)" = refs/heads/master &&
714 test "$(git config branch.myr7.rebase)" = true
717 test_expect_success 'autosetuprebase always on a tracked remote branch' '
718 git config remote.local.url . &&
719 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
720 git config branch.autosetuprebase remote &&
721 (git show-ref -q refs/remotes/local/master || git fetch local) &&
722 git branch --track myr8 local/master &&
723 test "$(git config branch.myr8.remote)" = local &&
724 test "$(git config branch.myr8.merge)" = refs/heads/master &&
725 test "$(git config branch.myr8.rebase)" = true
728 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
729 git config --unset branch.autosetuprebase &&
730 git config remote.local.url . &&
731 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
732 (git show-ref -q refs/remotes/local/master || git fetch local) &&
733 git branch --track myr9 local/master &&
734 test "$(git config branch.myr9.remote)" = local &&
735 test "$(git config branch.myr9.merge)" = refs/heads/master &&
736 test "z$(git config branch.myr9.rebase)" = z
739 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
740 git config remote.local.url . &&
741 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
742 (git show-ref -q refs/remotes/local/o || git fetch local) &&
743 git branch mybase10 &&
744 git branch --track myr10 mybase2 &&
745 test "$(git config branch.myr10.remote)" = . &&
746 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
747 test "z$(git config branch.myr10.rebase)" = z
750 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
751 git config remote.local.url . &&
752 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
753 (git show-ref -q refs/remotes/local/master || git fetch local) &&
754 git branch --no-track myr11 mybase2 &&
755 test "z$(git config branch.myr11.remote)" = z &&
756 test "z$(git config branch.myr11.merge)" = z &&
757 test "z$(git config branch.myr11.rebase)" = z
760 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
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 --no-track myr12 local/master &&
765 test "z$(git config branch.myr12.remote)" = z &&
766 test "z$(git config branch.myr12.merge)" = z &&
767 test "z$(git config branch.myr12.rebase)" = z
770 test_expect_success 'autosetuprebase never on an untracked local branch' '
771 git config branch.autosetuprebase never &&
772 git config remote.local.url . &&
773 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
774 (git show-ref -q refs/remotes/local/master || git fetch local) &&
775 git branch --no-track myr13 mybase2 &&
776 test "z$(git config branch.myr13.remote)" = z &&
777 test "z$(git config branch.myr13.merge)" = z &&
778 test "z$(git config branch.myr13.rebase)" = z
781 test_expect_success 'autosetuprebase local on an untracked local branch' '
782 git config branch.autosetuprebase local &&
783 git config remote.local.url . &&
784 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
785 (git show-ref -q refs/remotes/local/master || git fetch local) &&
786 git branch --no-track myr14 mybase2 &&
787 test "z$(git config branch.myr14.remote)" = z &&
788 test "z$(git config branch.myr14.merge)" = z &&
789 test "z$(git config branch.myr14.rebase)" = z
792 test_expect_success 'autosetuprebase remote on an untracked local branch' '
793 git config branch.autosetuprebase remote &&
794 git config remote.local.url . &&
795 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
796 (git show-ref -q refs/remotes/local/master || git fetch local) &&
797 git branch --no-track myr15 mybase2 &&
798 test "z$(git config branch.myr15.remote)" = z &&
799 test "z$(git config branch.myr15.merge)" = z &&
800 test "z$(git config branch.myr15.rebase)" = z
803 test_expect_success 'autosetuprebase always on an untracked local branch' '
804 git config branch.autosetuprebase always &&
805 git config remote.local.url . &&
806 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
807 (git show-ref -q refs/remotes/local/master || git fetch local) &&
808 git branch --no-track myr16 mybase2 &&
809 test "z$(git config branch.myr16.remote)" = z &&
810 test "z$(git config branch.myr16.merge)" = z &&
811 test "z$(git config branch.myr16.rebase)" = z
814 test_expect_success 'autosetuprebase never on an untracked remote branch' '
815 git config branch.autosetuprebase never &&
816 git config remote.local.url . &&
817 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
818 (git show-ref -q refs/remotes/local/master || git fetch local) &&
819 git branch --no-track myr17 local/master &&
820 test "z$(git config branch.myr17.remote)" = z &&
821 test "z$(git config branch.myr17.merge)" = z &&
822 test "z$(git config branch.myr17.rebase)" = z
825 test_expect_success 'autosetuprebase local on an untracked remote branch' '
826 git config branch.autosetuprebase local &&
827 git config remote.local.url . &&
828 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
829 (git show-ref -q refs/remotes/local/master || git fetch local) &&
830 git branch --no-track myr18 local/master &&
831 test "z$(git config branch.myr18.remote)" = z &&
832 test "z$(git config branch.myr18.merge)" = z &&
833 test "z$(git config branch.myr18.rebase)" = z
836 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
837 git config branch.autosetuprebase remote &&
838 git config remote.local.url . &&
839 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
840 (git show-ref -q refs/remotes/local/master || git fetch local) &&
841 git branch --no-track myr19 local/master &&
842 test "z$(git config branch.myr19.remote)" = z &&
843 test "z$(git config branch.myr19.merge)" = z &&
844 test "z$(git config branch.myr19.rebase)" = z
847 test_expect_success 'autosetuprebase always on an untracked remote branch' '
848 git config branch.autosetuprebase always &&
849 git config remote.local.url . &&
850 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
851 (git show-ref -q refs/remotes/local/master || git fetch local) &&
852 git branch --no-track myr20 local/master &&
853 test "z$(git config branch.myr20.remote)" = z &&
854 test "z$(git config branch.myr20.merge)" = z &&
855 test "z$(git config branch.myr20.rebase)" = z
858 test_expect_success 'autosetuprebase always on detached HEAD' '
859 git config branch.autosetupmerge always &&
860 test_when_finished git checkout master &&
861 git checkout HEAD^0 &&
862 git branch my11 &&
863 test -z "$(git config branch.my11.remote)" &&
864 test -z "$(git config branch.my11.merge)"
867 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
868 git config branch.autosetuprebase garbage &&
869 test_must_fail git branch
872 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
873 git config --unset branch.autosetuprebase &&
874 echo "[branch] autosetuprebase" >>.git/config &&
875 test_must_fail git branch &&
876 git config --unset branch.autosetuprebase
879 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
880 git checkout my9 &&
881 git config --unset branch.my8.merge &&
882 test_must_fail git branch -d my8
885 test_expect_success 'attempt to delete a branch merged to its base' '
886 # we are on my9 which is the initial commit; traditionally
887 # we would not have allowed deleting my8 that is not merged
888 # to my9, but it is set to track master that already has my8
889 git config branch.my8.merge refs/heads/master &&
890 git branch -d my8
893 test_expect_success 'attempt to delete a branch merged to its base' '
894 git checkout master &&
895 echo Third >>A &&
896 git commit -m "Third commit" A &&
897 git branch -t my10 my9 &&
898 git branch -f my10 HEAD^ &&
899 # we are on master which is at the third commit, and my10
900 # is behind us, so traditionally we would have allowed deleting
901 # it; but my10 is set to track my9 that is further behind.
902 test_must_fail git branch -d my10
905 test_expect_success 'use set-upstream on the current branch' '
906 git checkout master &&
907 git --bare init myupstream.git &&
908 git push myupstream.git master:refs/heads/frotz &&
909 git remote add origin myupstream.git &&
910 git fetch &&
911 git branch --set-upstream master origin/frotz &&
913 test "z$(git config branch.master.remote)" = "zorigin" &&
914 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
918 test_expect_success 'use --edit-description' '
919 write_script editor <<-\EOF &&
920 echo "New contents" >"$1"
922 EDITOR=./editor git branch --edit-description &&
923 write_script editor <<-\EOF &&
924 git stripspace -s <"$1" >"EDITOR_OUTPUT"
926 EDITOR=./editor git branch --edit-description &&
927 echo "New contents" >expect &&
928 test_cmp EDITOR_OUTPUT expect
931 test_expect_success 'detect typo in branch name when using --edit-description' '
932 write_script editor <<-\EOF &&
933 echo "New contents" >"$1"
935 test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
938 test_expect_success 'refuse --edit-description on unborn branch for now' '
939 write_script editor <<-\EOF &&
940 echo "New contents" >"$1"
942 git checkout --orphan unborn &&
943 test_must_fail env EDITOR=./editor git branch --edit-description
946 test_expect_success '--merged catches invalid object names' '
947 test_must_fail git branch --merged 0000000000000000000000000000000000000000
950 test_expect_success 'tracking with unexpected .fetch refspec' '
951 rm -rf a b c d &&
952 git init a &&
954 cd a &&
955 test_commit a
956 ) &&
957 git init b &&
959 cd b &&
960 test_commit b
961 ) &&
962 git init c &&
964 cd c &&
965 test_commit c &&
966 git remote add a ../a &&
967 git remote add b ../b &&
968 git fetch --all
969 ) &&
970 git init d &&
972 cd d &&
973 git remote add c ../c &&
974 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
975 git fetch c &&
976 git branch --track local/a/master remotes/a/master &&
977 test "$(git config branch.local/a/master.remote)" = "c" &&
978 test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
979 git rev-parse --verify a >expect &&
980 git rev-parse --verify local/a/master >actual &&
981 test_cmp expect actual
985 test_done