3 # Copyright (c) 2005 Amos Waterland
6 test_description
='git branch assorted tests'
11 'prepare a trivial repository' \
13 git update-index --add A &&
14 git commit -m "Initial commit." &&
16 git update-index --add A &&
17 git commit -m "Second commit." &&
18 HEAD=$(git rev-parse --verify HEAD)'
21 'git branch --help should not have created a bogus branch' '
22 test_might_fail git branch --help </dev/null >/dev/null 2>/dev/null &&
23 test_path_is_missing .git/refs/heads/--help
26 test_expect_success
'branch -h in broken repository' '
31 >.git/refs/heads/master &&
32 test_expect_code 129 git branch -h >usage 2>&1
34 test_i18ngrep "[Uu]sage" broken/usage
38 'git branch abc should create a branch' \
39 'git branch abc && test_path_is_file .git/refs/heads/abc'
42 'git branch a/b/c should create a branch' \
43 'git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c'
46 'git branch HEAD should fail' \
47 'test_must_fail git branch HEAD'
50 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
53 'git branch -l d/e/f should create a branch and a log' \
54 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
55 git branch -l d/e/f &&
56 test_path_is_file .git/refs/heads/d/e/f &&
57 test_path_is_file .git/logs/refs/heads/d/e/f &&
58 test_cmp expect .git/logs/refs/heads/d/e/f'
61 'git branch -d d/e/f should delete a branch and a log' \
62 'git branch -d d/e/f &&
63 test_path_is_missing .git/refs/heads/d/e/f &&
64 test_path_is_missing .git/logs/refs/heads/d/e/f'
67 'git branch j/k should work after branch j has been deleted' \
73 'git branch l should work after branch l/m has been deleted' \
79 'git branch -m dumps usage' \
80 'test_expect_code 128 git branch -m 2>err &&
81 test_i18ngrep "too many branches for a rename operation" err'
84 'git branch -m m m/m should work' \
86 git branch -m m m/m &&
87 test_path_is_file .git/logs/refs/heads/m/m'
90 'git branch -m n/n n should work' \
92 git branch -m n/n n &&
93 test_path_is_file .git/logs/refs/heads/n'
95 test_expect_success
'git branch -m o/o o should fail when o/p exists' '
98 test_must_fail git branch -m o/o o
101 test_expect_success
'git branch -m q r/q should fail when r exists' '
104 test_must_fail git branch -m q r/q
107 test_expect_success
'git branch -M foo bar should fail when bar is checked out' '
109 git checkout -b foo &&
110 test_must_fail git branch -M bar foo
113 test_expect_success
'git branch -M baz bam should succeed when baz is checked out' '
114 git checkout -b baz &&
116 git branch -M baz bam
119 test_expect_success
'git branch -M master should work when master is checked out' '
120 git checkout master &&
124 test_expect_success
'git branch -M master master should work when master is checked out' '
125 git checkout master &&
126 git branch -M master master
129 test_expect_success
'git branch -M master2 master2 should work when master is checked out' '
130 git checkout master &&
131 git branch master2 &&
132 git branch -M master2 master2
135 test_expect_success
'git branch -v -d t should work' '
137 test_path_is_file .git/refs/heads/t &&
138 git branch -v -d t &&
139 test_path_is_missing .git/refs/heads/t
142 test_expect_success
'git branch -v -m t s should work' '
144 test_path_is_file .git/refs/heads/t &&
145 git branch -v -m t s &&
146 test_path_is_missing .git/refs/heads/t &&
147 test_path_is_file .git/refs/heads/s &&
151 test_expect_success
'git branch -m -d t s should fail' '
153 test_path_is_file .git/refs/heads/t &&
154 test_must_fail git branch -m -d t s &&
156 test_path_is_missing .git/refs/heads/t
159 test_expect_success
'git branch --list -d t should fail' '
161 test_path_is_file .git/refs/heads/t &&
162 test_must_fail git branch --list -d t &&
164 test_path_is_missing .git/refs/heads/t
167 test_expect_success
'git branch --column' '
168 COLUMNS=81 git branch --column=column >actual &&
169 cat >expected <<\EOF &&
170 a/b/c bam foo l * master n o/p r
171 abc bar j/k m/m master2 o/o q
173 test_cmp expected actual
176 test_expect_success
'git branch --column with an extremely long branch name' '
177 long=this/is/a/part/of/long/branch/name &&
178 long=z$long/$long/$long/$long &&
179 test_when_finished "git branch -d $long" &&
181 COLUMNS=80 git branch --column=column >actual &&
182 cat >expected <<EOF &&
200 test_cmp expected actual
203 test_expect_success
'git branch with column.*' '
204 git config column.ui column &&
205 git config column.branch "dense" &&
206 COLUMNS=80 git branch >actual &&
207 git config --unset column.branch &&
208 git config --unset column.ui &&
209 cat >expected <<\EOF &&
210 a/b/c bam foo l * master n o/p r
211 abc bar j/k m/m master2 o/o q
213 test_cmp expected actual
216 test_expect_success
'git branch --column -v should fail' '
217 test_must_fail git branch --column -v
220 test_expect_success
'git branch -v with column.ui ignored' '
221 git config column.ui column &&
222 COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
223 git config --unset column.ui &&
224 cat >expected <<\EOF &&
241 test_cmp expected actual
244 mv .git
/config .git
/config-saved
246 test_expect_success
'git branch -m q q2 without config should succeed' '
247 git branch -m q q2 &&
251 mv .git
/config-saved .git
/config
253 git config branch.s
/s.dummy Hello
255 test_expect_success \
256 'git branch -m s/s s should work when s/t is deleted' \
257 'git branch -l s/s &&
258 test_path_is_file .git/logs/refs/heads/s/s &&
260 test_path_is_file .git/logs/refs/heads/s/t &&
262 git branch -m s/s s &&
263 test_path_is_file .git/logs/refs/heads/s'
265 test_expect_success
'config information was renamed, too' \
266 "test $(git config branch.s.dummy) = Hello &&
267 test_must_fail git config branch.s/s/dummy"
269 test_expect_success
'deleting a symref' '
271 git symbolic-ref refs/heads/symref refs/heads/target &&
272 echo "Deleted branch symref (was refs/heads/target)." >expect &&
273 git branch -d symref >actual &&
274 test_path_is_file .git/refs/heads/target &&
275 test_path_is_missing .git/refs/heads/symref &&
276 test_i18ncmp expect actual
279 test_expect_success
'deleting a dangling symref' '
280 git symbolic-ref refs/heads/dangling-symref nowhere &&
281 test_path_is_file .git/refs/heads/dangling-symref &&
282 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
283 git branch -d dangling-symref >actual &&
284 test_path_is_missing .git/refs/heads/dangling-symref &&
285 test_i18ncmp expect actual
288 test_expect_success
'renaming a symref is not allowed' \
290 git symbolic-ref refs/heads/master2 refs/heads/master &&
291 test_must_fail git branch -m master2 master3 &&
292 git symbolic-ref refs/heads/master2 &&
293 test_path_is_file .git/refs/heads/master &&
294 test_path_is_missing .git/refs/heads/master3
297 test_expect_success SYMLINKS \
298 'git branch -m u v should fail when the reflog for u is a symlink' '
300 mv .git/logs/refs/heads/u real-u &&
301 ln -s real-u .git/logs/refs/heads/u &&
302 test_must_fail git branch -m u v
305 test_expect_success
'test tracking setup via --track' \
306 'git config remote.local.url . &&
307 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
308 (git show-ref -q refs/remotes/local/master || git fetch local) &&
309 git branch --track my1 local/master &&
310 test $(git config branch.my1.remote) = local &&
311 test $(git config branch.my1.merge) = refs/heads/master'
313 test_expect_success
'test tracking setup (non-wildcard, matching)' \
314 'git config remote.local.url . &&
315 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
316 (git show-ref -q refs/remotes/local/master || git fetch local) &&
317 git branch --track my4 local/master &&
318 test $(git config branch.my4.remote) = local &&
319 test $(git config branch.my4.merge) = refs/heads/master'
321 test_expect_success
'test tracking setup (non-wildcard, not matching)' \
322 'git config remote.local.url . &&
323 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
324 (git show-ref -q refs/remotes/local/master || git fetch local) &&
325 git branch --track my5 local/master &&
326 ! test "$(git config branch.my5.remote)" = local &&
327 ! test "$(git config branch.my5.merge)" = refs/heads/master'
329 test_expect_success
'test tracking setup via config' \
330 'git config branch.autosetupmerge true &&
331 git config remote.local.url . &&
332 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
333 (git show-ref -q refs/remotes/local/master || git fetch local) &&
334 git branch my3 local/master &&
335 test $(git config branch.my3.remote) = local &&
336 test $(git config branch.my3.merge) = refs/heads/master'
338 test_expect_success
'test overriding tracking setup via --no-track' \
339 'git config branch.autosetupmerge true &&
340 git config remote.local.url . &&
341 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
342 (git show-ref -q refs/remotes/local/master || git fetch local) &&
343 git branch --no-track my2 local/master &&
344 git config branch.autosetupmerge false &&
345 ! test "$(git config branch.my2.remote)" = local &&
346 ! test "$(git config branch.my2.merge)" = refs/heads/master'
348 test_expect_success
'no tracking without .fetch entries' \
349 'git config branch.autosetupmerge true &&
351 git config branch.automsetupmerge false &&
352 test -z "$(git config branch.my6.remote)" &&
353 test -z "$(git config branch.my6.merge)"'
355 test_expect_success
'test tracking setup via --track but deeper' \
356 'git config remote.local.url . &&
357 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
358 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
359 git branch --track my7 local/o/o &&
360 test "$(git config branch.my7.remote)" = local &&
361 test "$(git config branch.my7.merge)" = refs/heads/o/o'
363 test_expect_success
'test deleting branch deletes branch config' \
364 'git branch -d my7 &&
365 test -z "$(git config branch.my7.remote)" &&
366 test -z "$(git config branch.my7.merge)"'
368 test_expect_success
'test deleting branch without config' \
370 sha1=$(git rev-parse my7 | cut -c 1-7) &&
371 echo "Deleted branch my7 (was $sha1)." >expect &&
372 git branch -d my7 >actual 2>&1 &&
373 test_i18ncmp expect actual'
375 test_expect_success
'test --track without .fetch entries' \
376 'git branch --track my8 &&
377 test "$(git config branch.my8.remote)" &&
378 test "$(git config branch.my8.merge)"'
380 test_expect_success \
381 'branch from non-branch HEAD w/autosetupmerge=always' \
382 'git config branch.autosetupmerge always &&
383 git branch my9 HEAD^ &&
384 git config branch.autosetupmerge false'
386 test_expect_success \
387 'branch from non-branch HEAD w/--track causes failure' \
388 'test_must_fail git branch --track my10 HEAD^'
390 test_expect_success \
391 'branch from tag w/--track causes failure' \
393 test_must_fail git branch --track my11 foobar'
395 test_expect_success
'--set-upstream-to fails on multiple branches' \
396 'test_must_fail git branch --set-upstream-to master a b c'
398 test_expect_success
'--set-upstream-to fails on detached HEAD' \
399 'git checkout HEAD^{} &&
400 test_must_fail git branch --set-upstream-to master &&
403 test_expect_success
'use --set-upstream-to modify HEAD' \
404 'test_config branch.master.remote foo &&
405 test_config branch.master.merge foo &&
407 git branch --set-upstream-to my12 &&
408 test "$(git config branch.master.remote)" = "." &&
409 test "$(git config branch.master.merge)" = "refs/heads/my12"'
411 test_expect_success
'use --set-upstream-to modify a particular branch' \
413 git branch --set-upstream-to master my13 &&
414 test "$(git config branch.my13.remote)" = "." &&
415 test "$(git config branch.my13.merge)" = "refs/heads/master"'
417 test_expect_success
'--unset-upstream should fail if given a non-existent branch' \
418 'test_must_fail git branch --unset-upstream i-dont-exist'
420 test_expect_success
'test --unset-upstream on HEAD' \
422 test_config branch.master.remote foo &&
423 test_config branch.master.merge foo &&
424 git branch --set-upstream-to my14 &&
425 git branch --unset-upstream &&
426 test_must_fail git config branch.master.remote &&
427 test_must_fail git config branch.master.merge &&
428 # fail for a branch without upstream set
429 test_must_fail git branch --unset-upstream
432 test_expect_success
'--unset-upstream should fail on multiple branches' \
433 'test_must_fail git branch --unset-upstream a b c'
435 test_expect_success
'--unset-upstream should fail on detached HEAD' \
436 'git checkout HEAD^{} &&
437 test_must_fail git branch --unset-upstream &&
441 test_expect_success
'test --unset-upstream on a particular branch' \
443 git branch --set-upstream-to master my14 &&
444 git branch --unset-upstream my14 &&
445 test_must_fail git config branch.my14.remote &&
446 test_must_fail git config branch.my14.merge'
448 test_expect_success
'--set-upstream shows message when creating a new branch that exists as remote-tracking' \
449 'git update-ref refs/remotes/origin/master HEAD &&
450 git branch --set-upstream origin/master 2>actual &&
451 test_when_finished git update-ref -d refs/remotes/origin/master &&
452 test_when_finished git branch -d origin/master &&
453 cat >expected <<EOF &&
454 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
456 If you wanted to make '"'master'"' track '"'origin/master'"', do this:
458 git branch -d origin/master
459 git branch --set-upstream-to origin/master
461 test_cmp expected actual
464 test_expect_success
'--set-upstream with two args only shows the deprecation message' \
465 'git branch --set-upstream master my13 2>actual &&
466 test_when_finished git branch --unset-upstream master &&
467 cat >expected <<EOF &&
468 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
470 test_cmp expected actual
473 test_expect_success
'--set-upstream with one arg only shows the deprecation message if the branch existed' \
474 'git branch --set-upstream my13 2>actual &&
475 test_when_finished git branch --unset-upstream my13 &&
476 cat >expected <<EOF &&
477 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
479 test_cmp expected actual
482 # Keep this test last, as it changes the current branch
484 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
486 test_expect_success \
487 'git checkout -b g/h/i -l should create a branch and a log' \
488 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
489 git checkout -b g/h/i -l master &&
490 test_path_is_file .git/refs/heads/g/h/i &&
491 test_path_is_file .git/logs/refs/heads/g/h/i &&
492 test_cmp expect .git/logs/refs/heads/g/h/i'
494 test_expect_success
'checkout -b makes reflog by default' '
495 git checkout master &&
496 git config --unset core.logAllRefUpdates &&
497 git checkout -b alpha &&
498 git rev-parse --verify alpha@{0}
501 test_expect_success
'checkout -b does not make reflog when core.logAllRefUpdates = false' '
502 git checkout master &&
503 git config core.logAllRefUpdates false &&
504 git checkout -b beta &&
505 test_must_fail git rev-parse --verify beta@{0}
508 test_expect_success
'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
509 git checkout master &&
510 git checkout -lb gamma &&
511 git config --unset core.logAllRefUpdates &&
512 git rev-parse --verify gamma@{0}
515 test_expect_success
'avoid ambiguous track' '
516 git config branch.autosetupmerge true &&
517 git config remote.ambi1.url lalala &&
518 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
519 git config remote.ambi2.url lilili &&
520 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
521 git branch all1 master &&
522 test -z "$(git config branch.all1.merge)"
525 test_expect_success
'autosetuprebase local on a tracked local branch' '
526 git config remote.local.url . &&
527 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
528 git config branch.autosetuprebase local &&
529 (git show-ref -q refs/remotes/local/o || git fetch local) &&
531 git branch --track myr1 mybase &&
532 test "$(git config branch.myr1.remote)" = . &&
533 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
534 test "$(git config branch.myr1.rebase)" = true
537 test_expect_success
'autosetuprebase always on a tracked local branch' '
538 git config remote.local.url . &&
539 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
540 git config branch.autosetuprebase always &&
541 (git show-ref -q refs/remotes/local/o || git fetch local) &&
542 git branch mybase2 &&
543 git branch --track myr2 mybase &&
544 test "$(git config branch.myr2.remote)" = . &&
545 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
546 test "$(git config branch.myr2.rebase)" = true
549 test_expect_success
'autosetuprebase remote on a tracked local branch' '
550 git config remote.local.url . &&
551 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
552 git config branch.autosetuprebase remote &&
553 (git show-ref -q refs/remotes/local/o || git fetch local) &&
554 git branch mybase3 &&
555 git branch --track myr3 mybase2 &&
556 test "$(git config branch.myr3.remote)" = . &&
557 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
558 ! test "$(git config branch.myr3.rebase)" = true
561 test_expect_success
'autosetuprebase never on a tracked local branch' '
562 git config remote.local.url . &&
563 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
564 git config branch.autosetuprebase never &&
565 (git show-ref -q refs/remotes/local/o || git fetch local) &&
566 git branch mybase4 &&
567 git branch --track myr4 mybase2 &&
568 test "$(git config branch.myr4.remote)" = . &&
569 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
570 ! test "$(git config branch.myr4.rebase)" = true
573 test_expect_success
'autosetuprebase local on a tracked remote branch' '
574 git config remote.local.url . &&
575 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
576 git config branch.autosetuprebase local &&
577 (git show-ref -q refs/remotes/local/master || git fetch local) &&
578 git branch --track myr5 local/master &&
579 test "$(git config branch.myr5.remote)" = local &&
580 test "$(git config branch.myr5.merge)" = refs/heads/master &&
581 ! test "$(git config branch.myr5.rebase)" = true
584 test_expect_success
'autosetuprebase never on a tracked remote branch' '
585 git config remote.local.url . &&
586 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
587 git config branch.autosetuprebase never &&
588 (git show-ref -q refs/remotes/local/master || git fetch local) &&
589 git branch --track myr6 local/master &&
590 test "$(git config branch.myr6.remote)" = local &&
591 test "$(git config branch.myr6.merge)" = refs/heads/master &&
592 ! test "$(git config branch.myr6.rebase)" = true
595 test_expect_success
'autosetuprebase remote on a tracked remote branch' '
596 git config remote.local.url . &&
597 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
598 git config branch.autosetuprebase remote &&
599 (git show-ref -q refs/remotes/local/master || git fetch local) &&
600 git branch --track myr7 local/master &&
601 test "$(git config branch.myr7.remote)" = local &&
602 test "$(git config branch.myr7.merge)" = refs/heads/master &&
603 test "$(git config branch.myr7.rebase)" = true
606 test_expect_success
'autosetuprebase always on a tracked remote branch' '
607 git config remote.local.url . &&
608 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
609 git config branch.autosetuprebase remote &&
610 (git show-ref -q refs/remotes/local/master || git fetch local) &&
611 git branch --track myr8 local/master &&
612 test "$(git config branch.myr8.remote)" = local &&
613 test "$(git config branch.myr8.merge)" = refs/heads/master &&
614 test "$(git config branch.myr8.rebase)" = true
617 test_expect_success
'autosetuprebase unconfigured on a tracked remote branch' '
618 git config --unset branch.autosetuprebase &&
619 git config remote.local.url . &&
620 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
621 (git show-ref -q refs/remotes/local/master || git fetch local) &&
622 git branch --track myr9 local/master &&
623 test "$(git config branch.myr9.remote)" = local &&
624 test "$(git config branch.myr9.merge)" = refs/heads/master &&
625 test "z$(git config branch.myr9.rebase)" = z
628 test_expect_success
'autosetuprebase unconfigured on a tracked local branch' '
629 git config remote.local.url . &&
630 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
631 (git show-ref -q refs/remotes/local/o || git fetch local) &&
632 git branch mybase10 &&
633 git branch --track myr10 mybase2 &&
634 test "$(git config branch.myr10.remote)" = . &&
635 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
636 test "z$(git config branch.myr10.rebase)" = z
639 test_expect_success
'autosetuprebase unconfigured on untracked local branch' '
640 git config remote.local.url . &&
641 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
642 (git show-ref -q refs/remotes/local/master || git fetch local) &&
643 git branch --no-track myr11 mybase2 &&
644 test "z$(git config branch.myr11.remote)" = z &&
645 test "z$(git config branch.myr11.merge)" = z &&
646 test "z$(git config branch.myr11.rebase)" = z
649 test_expect_success
'autosetuprebase unconfigured on untracked remote branch' '
650 git config remote.local.url . &&
651 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
652 (git show-ref -q refs/remotes/local/master || git fetch local) &&
653 git branch --no-track myr12 local/master &&
654 test "z$(git config branch.myr12.remote)" = z &&
655 test "z$(git config branch.myr12.merge)" = z &&
656 test "z$(git config branch.myr12.rebase)" = z
659 test_expect_success
'autosetuprebase never on an untracked local branch' '
660 git config branch.autosetuprebase never &&
661 git config remote.local.url . &&
662 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
663 (git show-ref -q refs/remotes/local/master || git fetch local) &&
664 git branch --no-track myr13 mybase2 &&
665 test "z$(git config branch.myr13.remote)" = z &&
666 test "z$(git config branch.myr13.merge)" = z &&
667 test "z$(git config branch.myr13.rebase)" = z
670 test_expect_success
'autosetuprebase local on an untracked local branch' '
671 git config branch.autosetuprebase local &&
672 git config remote.local.url . &&
673 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
674 (git show-ref -q refs/remotes/local/master || git fetch local) &&
675 git branch --no-track myr14 mybase2 &&
676 test "z$(git config branch.myr14.remote)" = z &&
677 test "z$(git config branch.myr14.merge)" = z &&
678 test "z$(git config branch.myr14.rebase)" = z
681 test_expect_success
'autosetuprebase remote on an untracked local branch' '
682 git config branch.autosetuprebase remote &&
683 git config remote.local.url . &&
684 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
685 (git show-ref -q refs/remotes/local/master || git fetch local) &&
686 git branch --no-track myr15 mybase2 &&
687 test "z$(git config branch.myr15.remote)" = z &&
688 test "z$(git config branch.myr15.merge)" = z &&
689 test "z$(git config branch.myr15.rebase)" = z
692 test_expect_success
'autosetuprebase always on an untracked local branch' '
693 git config branch.autosetuprebase always &&
694 git config remote.local.url . &&
695 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
696 (git show-ref -q refs/remotes/local/master || git fetch local) &&
697 git branch --no-track myr16 mybase2 &&
698 test "z$(git config branch.myr16.remote)" = z &&
699 test "z$(git config branch.myr16.merge)" = z &&
700 test "z$(git config branch.myr16.rebase)" = z
703 test_expect_success
'autosetuprebase never on an untracked remote branch' '
704 git config branch.autosetuprebase never &&
705 git config remote.local.url . &&
706 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
707 (git show-ref -q refs/remotes/local/master || git fetch local) &&
708 git branch --no-track myr17 local/master &&
709 test "z$(git config branch.myr17.remote)" = z &&
710 test "z$(git config branch.myr17.merge)" = z &&
711 test "z$(git config branch.myr17.rebase)" = z
714 test_expect_success
'autosetuprebase local on an untracked remote branch' '
715 git config branch.autosetuprebase local &&
716 git config remote.local.url . &&
717 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
718 (git show-ref -q refs/remotes/local/master || git fetch local) &&
719 git branch --no-track myr18 local/master &&
720 test "z$(git config branch.myr18.remote)" = z &&
721 test "z$(git config branch.myr18.merge)" = z &&
722 test "z$(git config branch.myr18.rebase)" = z
725 test_expect_success
'autosetuprebase remote on an untracked remote branch' '
726 git config branch.autosetuprebase remote &&
727 git config remote.local.url . &&
728 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
729 (git show-ref -q refs/remotes/local/master || git fetch local) &&
730 git branch --no-track myr19 local/master &&
731 test "z$(git config branch.myr19.remote)" = z &&
732 test "z$(git config branch.myr19.merge)" = z &&
733 test "z$(git config branch.myr19.rebase)" = z
736 test_expect_success
'autosetuprebase always on an untracked remote branch' '
737 git config branch.autosetuprebase always &&
738 git config remote.local.url . &&
739 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
740 (git show-ref -q refs/remotes/local/master || git fetch local) &&
741 git branch --no-track myr20 local/master &&
742 test "z$(git config branch.myr20.remote)" = z &&
743 test "z$(git config branch.myr20.merge)" = z &&
744 test "z$(git config branch.myr20.rebase)" = z
747 test_expect_success
'autosetuprebase always on detached HEAD' '
748 git config branch.autosetupmerge always &&
749 test_when_finished git checkout master &&
750 git checkout HEAD^0 &&
752 test -z "$(git config branch.my11.remote)" &&
753 test -z "$(git config branch.my11.merge)"
756 test_expect_success
'detect misconfigured autosetuprebase (bad value)' '
757 git config branch.autosetuprebase garbage &&
758 test_must_fail git branch
761 test_expect_success
'detect misconfigured autosetuprebase (no value)' '
762 git config --unset branch.autosetuprebase &&
763 echo "[branch] autosetuprebase" >> .git/config &&
764 test_must_fail git branch &&
765 git config --unset branch.autosetuprebase
768 test_expect_success
'attempt to delete a branch without base and unmerged to HEAD' '
770 git config --unset branch.my8.merge &&
771 test_must_fail git branch -d my8
774 test_expect_success
'attempt to delete a branch merged to its base' '
775 # we are on my9 which is the initial commit; traditionally
776 # we would not have allowed deleting my8 that is not merged
777 # to my9, but it is set to track master that already has my8
778 git config branch.my8.merge refs/heads/master &&
782 test_expect_success
'attempt to delete a branch merged to its base' '
783 git checkout master &&
785 git commit -m "Third commit" A &&
786 git branch -t my10 my9 &&
787 git branch -f my10 HEAD^ &&
788 # we are on master which is at the third commit, and my10
789 # is behind us, so traditionally we would have allowed deleting
790 # it; but my10 is set to track my9 that is further behind.
791 test_must_fail git branch -d my10
794 test_expect_success
'use set-upstream on the current branch' '
795 git checkout master &&
796 git --bare init myupstream.git &&
797 git push myupstream.git master:refs/heads/frotz &&
798 git remote add origin myupstream.git &&
800 git branch --set-upstream master origin/frotz &&
802 test "z$(git config branch.master.remote)" = "zorigin" &&
803 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
807 test_expect_success
'use --edit-description' '
808 write_script editor <<-\EOF &&
809 echo "New contents" >"$1"
811 EDITOR=./editor git branch --edit-description &&
812 write_script editor <<-\EOF &&
813 git stripspace -s <"$1" >"EDITOR_OUTPUT"
815 EDITOR=./editor git branch --edit-description &&
816 echo "New contents" >expect &&
817 test_cmp EDITOR_OUTPUT expect
820 test_expect_success
'detect typo in branch name when using --edit-description' '
821 write_script editor <<-\EOF &&
822 echo "New contents" >"$1"
827 test_must_fail git branch --edit-description no-such-branch
831 test_expect_success
'refuse --edit-description on unborn branch for now' '
832 write_script editor <<-\EOF &&
833 echo "New contents" >"$1"
835 git checkout --orphan unborn &&
839 test_must_fail git branch --edit-description
843 test_expect_success
'--merged catches invalid object names' '
844 test_must_fail git branch --merged 0000000000000000000000000000000000000000