Merge branch 'tb/pretty-format-cd-date-format' into jch
[git/jrn.git] / t / t3200-branch.sh
blob64f5bf23791ef216c9ee5cbd696bfdd6fac46a31
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_path_is_missing .git/logs/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 m/m should work' '
83 git branch -l m &&
84 git branch -m m m/m &&
85 test_path_is_file .git/logs/refs/heads/m/m
88 test_expect_success 'git branch -m n/n n should work' '
89 git branch -l n/n &&
90 git branch -m n/n n &&
91 test_path_is_file .git/logs/refs/heads/n
94 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
95 git branch o/o &&
96 git branch o/p &&
97 test_must_fail git branch -m o/o o
100 test_expect_success 'git branch -m q r/q should fail when r exists' '
101 git branch q &&
102 git branch r &&
103 test_must_fail git branch -m q r/q
106 test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
107 git branch bar &&
108 git checkout -b foo &&
109 test_must_fail git branch -M bar foo
112 test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
113 git checkout -b baz &&
114 git branch bam &&
115 git branch -M baz bam
118 test_expect_success 'git branch -M master should work when master is checked out' '
119 git checkout master &&
120 git branch -M master
123 test_expect_success 'git branch -M master master should work when master is checked out' '
124 git checkout master &&
125 git branch -M master master
128 test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
129 git checkout master &&
130 git branch master2 &&
131 git branch -M master2 master2
134 test_expect_success 'git branch -v -d t should work' '
135 git branch t &&
136 test_path_is_file .git/refs/heads/t &&
137 git branch -v -d t &&
138 test_path_is_missing .git/refs/heads/t
141 test_expect_success 'git branch -v -m t s should work' '
142 git branch t &&
143 test_path_is_file .git/refs/heads/t &&
144 git branch -v -m t s &&
145 test_path_is_missing .git/refs/heads/t &&
146 test_path_is_file .git/refs/heads/s &&
147 git branch -d s
150 test_expect_success 'git branch -m -d t s should fail' '
151 git branch t &&
152 test_path_is_file .git/refs/heads/t &&
153 test_must_fail git branch -m -d t s &&
154 git branch -d t &&
155 test_path_is_missing .git/refs/heads/t
158 test_expect_success 'git branch --list -d t should fail' '
159 git branch t &&
160 test_path_is_file .git/refs/heads/t &&
161 test_must_fail git branch --list -d t &&
162 git branch -d t &&
163 test_path_is_missing .git/refs/heads/t
166 test_expect_success 'git branch --column' '
167 COLUMNS=81 git branch --column=column >actual &&
168 cat >expected <<\EOF &&
169 a/b/c bam foo l * master n o/p r
170 abc bar j/k m/m master2 o/o q
172 test_cmp expected actual
175 test_expect_success 'git branch --column with an extremely long branch name' '
176 long=this/is/a/part/of/long/branch/name &&
177 long=z$long/$long/$long/$long &&
178 test_when_finished "git branch -d $long" &&
179 git branch $long &&
180 COLUMNS=80 git branch --column=column >actual &&
181 cat >expected <<EOF &&
182 a/b/c
190 * master
191 master2
197 $long
199 test_cmp expected actual
202 test_expect_success 'git branch with column.*' '
203 git config column.ui column &&
204 git config column.branch "dense" &&
205 COLUMNS=80 git branch >actual &&
206 git config --unset column.branch &&
207 git config --unset column.ui &&
208 cat >expected <<\EOF &&
209 a/b/c bam foo l * master n o/p r
210 abc bar j/k m/m master2 o/o q
212 test_cmp expected actual
215 test_expect_success 'git branch --column -v should fail' '
216 test_must_fail git branch --column -v
219 test_expect_success 'git branch -v with column.ui ignored' '
220 git config column.ui column &&
221 COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
222 git config --unset column.ui &&
223 cat >expected <<\EOF &&
224 a/b/c
232 * master
233 master2
240 test_cmp expected actual
243 mv .git/config .git/config-saved
245 test_expect_success 'git branch -m q q2 without config should succeed' '
246 git branch -m q q2 &&
247 git branch -m q2 q
250 mv .git/config-saved .git/config
252 git config branch.s/s.dummy Hello
254 test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
255 git branch -l s/s &&
256 test_path_is_file .git/logs/refs/heads/s/s &&
257 git branch -l s/t &&
258 test_path_is_file .git/logs/refs/heads/s/t &&
259 git branch -d s/t &&
260 git branch -m s/s s &&
261 test_path_is_file .git/logs/refs/heads/s
264 test_expect_success 'config information was renamed, too' '
265 test $(git config branch.s.dummy) = Hello &&
266 test_must_fail git config branch.s/s/dummy
269 test_expect_success 'deleting a symref' '
270 git branch target &&
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' '
289 git symbolic-ref refs/heads/master2 refs/heads/master &&
290 test_must_fail git branch -m master2 master3 &&
291 git symbolic-ref refs/heads/master2 &&
292 test_path_is_file .git/refs/heads/master &&
293 test_path_is_missing .git/refs/heads/master3
296 test_expect_success 'test tracking setup via --track' '
297 git config remote.local.url . &&
298 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
299 (git show-ref -q refs/remotes/local/master || git fetch local) &&
300 git branch --track my1 local/master &&
301 test $(git config branch.my1.remote) = local &&
302 test $(git config branch.my1.merge) = refs/heads/master
305 test_expect_success 'test tracking setup (non-wildcard, matching)' '
306 git config remote.local.url . &&
307 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
308 (git show-ref -q refs/remotes/local/master || git fetch local) &&
309 git branch --track my4 local/master &&
310 test $(git config branch.my4.remote) = local &&
311 test $(git config branch.my4.merge) = refs/heads/master
314 test_expect_success 'tracking setup fails on non-matching refspec' '
315 git config remote.local.url . &&
316 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
317 (git show-ref -q refs/remotes/local/master || git fetch local) &&
318 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
319 test_must_fail git branch --track my5 local/master &&
320 test_must_fail git config branch.my5.remote &&
321 test_must_fail git config branch.my5.merge
324 test_expect_success 'test tracking setup via config' '
325 git config branch.autosetupmerge true &&
326 git config remote.local.url . &&
327 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
328 (git show-ref -q refs/remotes/local/master || git fetch local) &&
329 git branch my3 local/master &&
330 test $(git config branch.my3.remote) = local &&
331 test $(git config branch.my3.merge) = refs/heads/master
334 test_expect_success 'test overriding tracking setup via --no-track' '
335 git config branch.autosetupmerge true &&
336 git config remote.local.url . &&
337 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
338 (git show-ref -q refs/remotes/local/master || git fetch local) &&
339 git branch --no-track my2 local/master &&
340 git config branch.autosetupmerge false &&
341 ! test "$(git config branch.my2.remote)" = local &&
342 ! test "$(git config branch.my2.merge)" = refs/heads/master
345 test_expect_success 'no tracking without .fetch entries' '
346 git config branch.autosetupmerge true &&
347 git branch my6 s &&
348 git config branch.autosetupmerge false &&
349 test -z "$(git config branch.my6.remote)" &&
350 test -z "$(git config branch.my6.merge)"
353 test_expect_success 'test tracking setup via --track but deeper' '
354 git config remote.local.url . &&
355 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
356 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
357 git branch --track my7 local/o/o &&
358 test "$(git config branch.my7.remote)" = local &&
359 test "$(git config branch.my7.merge)" = refs/heads/o/o
362 test_expect_success 'test deleting branch deletes branch config' '
363 git branch -d my7 &&
364 test -z "$(git config branch.my7.remote)" &&
365 test -z "$(git config branch.my7.merge)"
368 test_expect_success 'test deleting branch without config' '
369 git branch my7 s &&
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
376 test_expect_success 'test --track without .fetch entries' '
377 git branch --track my8 &&
378 test "$(git config branch.my8.remote)" &&
379 test "$(git config branch.my8.merge)"
382 test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
383 git config branch.autosetupmerge always &&
384 git branch my9 HEAD^ &&
385 git config branch.autosetupmerge false
388 test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
389 test_must_fail git branch --track my10 HEAD^
392 test_expect_success 'branch from tag w/--track causes failure' '
393 git tag foobar &&
394 test_must_fail git branch --track my11 foobar
397 test_expect_success '--set-upstream-to fails on multiple branches' '
398 test_must_fail git branch --set-upstream-to master a b c
401 test_expect_success '--set-upstream-to fails on detached HEAD' '
402 git checkout HEAD^{} &&
403 test_must_fail git branch --set-upstream-to master &&
404 git checkout -
407 test_expect_success '--set-upstream-to fails on a missing dst branch' '
408 test_must_fail git branch --set-upstream-to master does-not-exist
411 test_expect_success '--set-upstream-to fails on a missing src branch' '
412 test_must_fail git branch --set-upstream-to does-not-exist master
415 test_expect_success '--set-upstream-to fails on a non-ref' '
416 test_must_fail git branch --set-upstream-to HEAD^{}
419 test_expect_success 'use --set-upstream-to modify HEAD' '
420 test_config branch.master.remote foo &&
421 test_config branch.master.merge foo &&
422 git branch my12 &&
423 git branch --set-upstream-to my12 &&
424 test "$(git config branch.master.remote)" = "." &&
425 test "$(git config branch.master.merge)" = "refs/heads/my12"
428 test_expect_success 'use --set-upstream-to modify a particular branch' '
429 git branch my13 &&
430 git branch --set-upstream-to master my13 &&
431 test "$(git config branch.my13.remote)" = "." &&
432 test "$(git config branch.my13.merge)" = "refs/heads/master"
435 test_expect_success '--unset-upstream should fail if given a non-existent branch' '
436 test_must_fail git branch --unset-upstream i-dont-exist
439 test_expect_success 'test --unset-upstream on HEAD' '
440 git branch my14 &&
441 test_config branch.master.remote foo &&
442 test_config branch.master.merge foo &&
443 git branch --set-upstream-to my14 &&
444 git branch --unset-upstream &&
445 test_must_fail git config branch.master.remote &&
446 test_must_fail git config branch.master.merge &&
447 # fail for a branch without upstream set
448 test_must_fail git branch --unset-upstream
451 test_expect_success '--unset-upstream should fail on multiple branches' '
452 test_must_fail git branch --unset-upstream a b c
455 test_expect_success '--unset-upstream should fail on detached HEAD' '
456 git checkout HEAD^{} &&
457 test_must_fail git branch --unset-upstream &&
458 git checkout -
461 test_expect_success 'test --unset-upstream on a particular branch' '
462 git branch my15 &&
463 git branch --set-upstream-to master my14 &&
464 git branch --unset-upstream my14 &&
465 test_must_fail git config branch.my14.remote &&
466 test_must_fail git config branch.my14.merge
469 test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
470 git update-ref refs/remotes/origin/master HEAD &&
471 git branch --set-upstream origin/master 2>actual &&
472 test_when_finished git update-ref -d refs/remotes/origin/master &&
473 test_when_finished git branch -d origin/master &&
474 cat >expected <<EOF &&
475 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
477 If you wanted to make '"'master'"' track '"'origin/master'"', do this:
479 git branch -d origin/master
480 git branch --set-upstream-to origin/master
482 test_cmp expected actual
485 test_expect_success '--set-upstream with two args only shows the deprecation message' '
486 git branch --set-upstream master my13 2>actual &&
487 test_when_finished git branch --unset-upstream master &&
488 cat >expected <<EOF &&
489 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
491 test_cmp expected actual
494 test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
495 git branch --set-upstream my13 2>actual &&
496 test_when_finished git branch --unset-upstream my13 &&
497 cat >expected <<EOF &&
498 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
500 test_cmp expected actual
503 test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
504 git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
505 cat >expected <<-\EOF &&
506 warning: Not setting branch my13 as its own upstream.
508 test_expect_code 1 git config branch.my13.remote &&
509 test_expect_code 1 git config branch.my13.merge &&
510 test_i18ncmp expected actual
513 # Keep this test last, as it changes the current branch
514 cat >expect <<EOF
515 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
517 test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
518 GIT_COMMITTER_DATE="2005-05-26 23:30" \
519 git checkout -b g/h/i -l master &&
520 test_path_is_file .git/refs/heads/g/h/i &&
521 test_path_is_file .git/logs/refs/heads/g/h/i &&
522 test_cmp expect .git/logs/refs/heads/g/h/i
525 test_expect_success 'checkout -b makes reflog by default' '
526 git checkout master &&
527 git config --unset core.logAllRefUpdates &&
528 git checkout -b alpha &&
529 git rev-parse --verify alpha@{0}
532 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
533 git checkout master &&
534 git config core.logAllRefUpdates false &&
535 git checkout -b beta &&
536 test_must_fail git rev-parse --verify beta@{0}
539 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
540 git checkout master &&
541 git checkout -lb gamma &&
542 git config --unset core.logAllRefUpdates &&
543 git rev-parse --verify gamma@{0}
546 test_expect_success 'avoid ambiguous track' '
547 git config branch.autosetupmerge true &&
548 git config remote.ambi1.url lalala &&
549 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
550 git config remote.ambi2.url lilili &&
551 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
552 git branch all1 master &&
553 test -z "$(git config branch.all1.merge)"
556 test_expect_success 'autosetuprebase local on a tracked local branch' '
557 git config remote.local.url . &&
558 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
559 git config branch.autosetuprebase local &&
560 (git show-ref -q refs/remotes/local/o || git fetch local) &&
561 git branch mybase &&
562 git branch --track myr1 mybase &&
563 test "$(git config branch.myr1.remote)" = . &&
564 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
565 test "$(git config branch.myr1.rebase)" = true
568 test_expect_success 'autosetuprebase always on a tracked local branch' '
569 git config remote.local.url . &&
570 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
571 git config branch.autosetuprebase always &&
572 (git show-ref -q refs/remotes/local/o || git fetch local) &&
573 git branch mybase2 &&
574 git branch --track myr2 mybase &&
575 test "$(git config branch.myr2.remote)" = . &&
576 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
577 test "$(git config branch.myr2.rebase)" = true
580 test_expect_success 'autosetuprebase remote on a tracked local branch' '
581 git config remote.local.url . &&
582 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
583 git config branch.autosetuprebase remote &&
584 (git show-ref -q refs/remotes/local/o || git fetch local) &&
585 git branch mybase3 &&
586 git branch --track myr3 mybase2 &&
587 test "$(git config branch.myr3.remote)" = . &&
588 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
589 ! test "$(git config branch.myr3.rebase)" = true
592 test_expect_success 'autosetuprebase never on a tracked local branch' '
593 git config remote.local.url . &&
594 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
595 git config branch.autosetuprebase never &&
596 (git show-ref -q refs/remotes/local/o || git fetch local) &&
597 git branch mybase4 &&
598 git branch --track myr4 mybase2 &&
599 test "$(git config branch.myr4.remote)" = . &&
600 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
601 ! test "$(git config branch.myr4.rebase)" = true
604 test_expect_success 'autosetuprebase local on a tracked remote branch' '
605 git config remote.local.url . &&
606 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
607 git config branch.autosetuprebase local &&
608 (git show-ref -q refs/remotes/local/master || git fetch local) &&
609 git branch --track myr5 local/master &&
610 test "$(git config branch.myr5.remote)" = local &&
611 test "$(git config branch.myr5.merge)" = refs/heads/master &&
612 ! test "$(git config branch.myr5.rebase)" = true
615 test_expect_success 'autosetuprebase never on a tracked remote branch' '
616 git config remote.local.url . &&
617 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
618 git config branch.autosetuprebase never &&
619 (git show-ref -q refs/remotes/local/master || git fetch local) &&
620 git branch --track myr6 local/master &&
621 test "$(git config branch.myr6.remote)" = local &&
622 test "$(git config branch.myr6.merge)" = refs/heads/master &&
623 ! test "$(git config branch.myr6.rebase)" = true
626 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
627 git config remote.local.url . &&
628 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
629 git config branch.autosetuprebase remote &&
630 (git show-ref -q refs/remotes/local/master || git fetch local) &&
631 git branch --track myr7 local/master &&
632 test "$(git config branch.myr7.remote)" = local &&
633 test "$(git config branch.myr7.merge)" = refs/heads/master &&
634 test "$(git config branch.myr7.rebase)" = true
637 test_expect_success 'autosetuprebase always on a tracked remote branch' '
638 git config remote.local.url . &&
639 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
640 git config branch.autosetuprebase remote &&
641 (git show-ref -q refs/remotes/local/master || git fetch local) &&
642 git branch --track myr8 local/master &&
643 test "$(git config branch.myr8.remote)" = local &&
644 test "$(git config branch.myr8.merge)" = refs/heads/master &&
645 test "$(git config branch.myr8.rebase)" = true
648 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
649 git config --unset branch.autosetuprebase &&
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 --track myr9 local/master &&
654 test "$(git config branch.myr9.remote)" = local &&
655 test "$(git config branch.myr9.merge)" = refs/heads/master &&
656 test "z$(git config branch.myr9.rebase)" = z
659 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
660 git config remote.local.url . &&
661 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
662 (git show-ref -q refs/remotes/local/o || git fetch local) &&
663 git branch mybase10 &&
664 git branch --track myr10 mybase2 &&
665 test "$(git config branch.myr10.remote)" = . &&
666 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
667 test "z$(git config branch.myr10.rebase)" = z
670 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
671 git config remote.local.url . &&
672 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
673 (git show-ref -q refs/remotes/local/master || git fetch local) &&
674 git branch --no-track myr11 mybase2 &&
675 test "z$(git config branch.myr11.remote)" = z &&
676 test "z$(git config branch.myr11.merge)" = z &&
677 test "z$(git config branch.myr11.rebase)" = z
680 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
681 git config remote.local.url . &&
682 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
683 (git show-ref -q refs/remotes/local/master || git fetch local) &&
684 git branch --no-track myr12 local/master &&
685 test "z$(git config branch.myr12.remote)" = z &&
686 test "z$(git config branch.myr12.merge)" = z &&
687 test "z$(git config branch.myr12.rebase)" = z
690 test_expect_success 'autosetuprebase never on an untracked local branch' '
691 git config branch.autosetuprebase never &&
692 git config remote.local.url . &&
693 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
694 (git show-ref -q refs/remotes/local/master || git fetch local) &&
695 git branch --no-track myr13 mybase2 &&
696 test "z$(git config branch.myr13.remote)" = z &&
697 test "z$(git config branch.myr13.merge)" = z &&
698 test "z$(git config branch.myr13.rebase)" = z
701 test_expect_success 'autosetuprebase local on an untracked local branch' '
702 git config branch.autosetuprebase local &&
703 git config remote.local.url . &&
704 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
705 (git show-ref -q refs/remotes/local/master || git fetch local) &&
706 git branch --no-track myr14 mybase2 &&
707 test "z$(git config branch.myr14.remote)" = z &&
708 test "z$(git config branch.myr14.merge)" = z &&
709 test "z$(git config branch.myr14.rebase)" = z
712 test_expect_success 'autosetuprebase remote on an untracked local branch' '
713 git config branch.autosetuprebase remote &&
714 git config remote.local.url . &&
715 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
716 (git show-ref -q refs/remotes/local/master || git fetch local) &&
717 git branch --no-track myr15 mybase2 &&
718 test "z$(git config branch.myr15.remote)" = z &&
719 test "z$(git config branch.myr15.merge)" = z &&
720 test "z$(git config branch.myr15.rebase)" = z
723 test_expect_success 'autosetuprebase always on an untracked local branch' '
724 git config branch.autosetuprebase always &&
725 git config remote.local.url . &&
726 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
727 (git show-ref -q refs/remotes/local/master || git fetch local) &&
728 git branch --no-track myr16 mybase2 &&
729 test "z$(git config branch.myr16.remote)" = z &&
730 test "z$(git config branch.myr16.merge)" = z &&
731 test "z$(git config branch.myr16.rebase)" = z
734 test_expect_success 'autosetuprebase never on an untracked remote branch' '
735 git config branch.autosetuprebase never &&
736 git config remote.local.url . &&
737 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
738 (git show-ref -q refs/remotes/local/master || git fetch local) &&
739 git branch --no-track myr17 local/master &&
740 test "z$(git config branch.myr17.remote)" = z &&
741 test "z$(git config branch.myr17.merge)" = z &&
742 test "z$(git config branch.myr17.rebase)" = z
745 test_expect_success 'autosetuprebase local on an untracked remote branch' '
746 git config branch.autosetuprebase local &&
747 git config remote.local.url . &&
748 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
749 (git show-ref -q refs/remotes/local/master || git fetch local) &&
750 git branch --no-track myr18 local/master &&
751 test "z$(git config branch.myr18.remote)" = z &&
752 test "z$(git config branch.myr18.merge)" = z &&
753 test "z$(git config branch.myr18.rebase)" = z
756 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
757 git config branch.autosetuprebase remote &&
758 git config remote.local.url . &&
759 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
760 (git show-ref -q refs/remotes/local/master || git fetch local) &&
761 git branch --no-track myr19 local/master &&
762 test "z$(git config branch.myr19.remote)" = z &&
763 test "z$(git config branch.myr19.merge)" = z &&
764 test "z$(git config branch.myr19.rebase)" = z
767 test_expect_success 'autosetuprebase always on an untracked remote branch' '
768 git config branch.autosetuprebase always &&
769 git config remote.local.url . &&
770 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
771 (git show-ref -q refs/remotes/local/master || git fetch local) &&
772 git branch --no-track myr20 local/master &&
773 test "z$(git config branch.myr20.remote)" = z &&
774 test "z$(git config branch.myr20.merge)" = z &&
775 test "z$(git config branch.myr20.rebase)" = z
778 test_expect_success 'autosetuprebase always on detached HEAD' '
779 git config branch.autosetupmerge always &&
780 test_when_finished git checkout master &&
781 git checkout HEAD^0 &&
782 git branch my11 &&
783 test -z "$(git config branch.my11.remote)" &&
784 test -z "$(git config branch.my11.merge)"
787 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
788 git config branch.autosetuprebase garbage &&
789 test_must_fail git branch
792 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
793 git config --unset branch.autosetuprebase &&
794 echo "[branch] autosetuprebase" >>.git/config &&
795 test_must_fail git branch &&
796 git config --unset branch.autosetuprebase
799 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
800 git checkout my9 &&
801 git config --unset branch.my8.merge &&
802 test_must_fail git branch -d my8
805 test_expect_success 'attempt to delete a branch merged to its base' '
806 # we are on my9 which is the initial commit; traditionally
807 # we would not have allowed deleting my8 that is not merged
808 # to my9, but it is set to track master that already has my8
809 git config branch.my8.merge refs/heads/master &&
810 git branch -d my8
813 test_expect_success 'attempt to delete a branch merged to its base' '
814 git checkout master &&
815 echo Third >>A &&
816 git commit -m "Third commit" A &&
817 git branch -t my10 my9 &&
818 git branch -f my10 HEAD^ &&
819 # we are on master which is at the third commit, and my10
820 # is behind us, so traditionally we would have allowed deleting
821 # it; but my10 is set to track my9 that is further behind.
822 test_must_fail git branch -d my10
825 test_expect_success 'use set-upstream on the current branch' '
826 git checkout master &&
827 git --bare init myupstream.git &&
828 git push myupstream.git master:refs/heads/frotz &&
829 git remote add origin myupstream.git &&
830 git fetch &&
831 git branch --set-upstream master origin/frotz &&
833 test "z$(git config branch.master.remote)" = "zorigin" &&
834 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
838 test_expect_success 'use --edit-description' '
839 write_script editor <<-\EOF &&
840 echo "New contents" >"$1"
842 EDITOR=./editor git branch --edit-description &&
843 write_script editor <<-\EOF &&
844 git stripspace -s <"$1" >"EDITOR_OUTPUT"
846 EDITOR=./editor git branch --edit-description &&
847 echo "New contents" >expect &&
848 test_cmp EDITOR_OUTPUT expect
851 test_expect_success 'detect typo in branch name when using --edit-description' '
852 write_script editor <<-\EOF &&
853 echo "New contents" >"$1"
855 test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
858 test_expect_success 'refuse --edit-description on unborn branch for now' '
859 write_script editor <<-\EOF &&
860 echo "New contents" >"$1"
862 git checkout --orphan unborn &&
863 test_must_fail env EDITOR=./editor git branch --edit-description
866 test_expect_success '--merged catches invalid object names' '
867 test_must_fail git branch --merged 0000000000000000000000000000000000000000
870 test_expect_success 'tracking with unexpected .fetch refspec' '
871 rm -rf a b c d &&
872 git init a &&
874 cd a &&
875 test_commit a
876 ) &&
877 git init b &&
879 cd b &&
880 test_commit b
881 ) &&
882 git init c &&
884 cd c &&
885 test_commit c &&
886 git remote add a ../a &&
887 git remote add b ../b &&
888 git fetch --all
889 ) &&
890 git init d &&
892 cd d &&
893 git remote add c ../c &&
894 git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
895 git fetch c &&
896 git branch --track local/a/master remotes/a/master &&
897 test "$(git config branch.local/a/master.remote)" = "c" &&
898 test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
899 git rev-parse --verify a >expect &&
900 git rev-parse --verify local/a/master >actual &&
901 test_cmp expect actual
905 test_done