branch: introduce --set-upstream-to
[git.git] / t / t3200-branch.sh
blobe9019ac9432f88500f26ffb08295daff67de8908
1 #!/bin/sh
3 # Copyright (c) 2005 Amos Waterland
6 test_description='git branch assorted tests'
8 . ./test-lib.sh
10 test_expect_success \
11 'prepare a trivial repository' \
12 'echo Hello > A &&
13 git update-index --add A &&
14 git commit -m "Initial commit." &&
15 echo World >> A &&
16 git update-index --add A &&
17 git commit -m "Second commit." &&
18 HEAD=$(git rev-parse --verify HEAD)'
20 test_expect_success \
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' '
27 mkdir broken &&
29 cd broken &&
30 git init &&
31 >.git/refs/heads/master &&
32 test_expect_code 129 git branch -h >usage 2>&1
33 ) &&
34 grep "[Uu]sage" broken/usage
37 test_expect_success \
38 'git branch abc should create a branch' \
39 'git branch abc && test_path_is_file .git/refs/heads/abc'
41 test_expect_success \
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'
45 cat >expect <<EOF
46 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
47 EOF
48 test_expect_success \
49 'git branch -l d/e/f should create a branch and a log' \
50 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
51 git branch -l d/e/f &&
52 test_path_is_file .git/refs/heads/d/e/f &&
53 test_path_is_file .git/logs/refs/heads/d/e/f &&
54 test_cmp expect .git/logs/refs/heads/d/e/f'
56 test_expect_success \
57 'git branch -d d/e/f should delete a branch and a log' \
58 'git branch -d d/e/f &&
59 test_path_is_missing .git/refs/heads/d/e/f &&
60 test_path_is_missing .git/logs/refs/heads/d/e/f'
62 test_expect_success \
63 'git branch j/k should work after branch j has been deleted' \
64 'git branch j &&
65 git branch -d j &&
66 git branch j/k'
68 test_expect_success \
69 'git branch l should work after branch l/m has been deleted' \
70 'git branch l/m &&
71 git branch -d l/m &&
72 git branch l'
74 test_expect_success \
75 'git branch -m dumps usage' \
76 'test_expect_code 129 git branch -m 2>err &&
77 grep "[Uu]sage: git branch" err'
79 test_expect_success \
80 'git branch -m m m/m should work' \
81 'git branch -l m &&
82 git branch -m m m/m &&
83 test_path_is_file .git/logs/refs/heads/m/m'
85 test_expect_success \
86 'git branch -m n/n n should work' \
87 'git branch -l n/n &&
88 git branch -m n/n n &&
89 test_path_is_file .git/logs/refs/heads/n'
91 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
92 git branch o/o &&
93 git branch o/p &&
94 test_must_fail git branch -m o/o o
97 test_expect_success 'git branch -m q r/q should fail when r exists' '
98 git branch q &&
99 git branch r &&
100 test_must_fail git branch -m q r/q
103 test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
104 git branch bar &&
105 git checkout -b foo &&
106 test_must_fail git branch -M bar foo
109 test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
110 git checkout -b baz &&
111 git branch bam &&
112 git branch -M baz bam
115 test_expect_success 'git branch -M master should work when master is checked out' '
116 git checkout master &&
117 git branch -M master
120 test_expect_success 'git branch -M master master should work when master is checked out' '
121 git checkout master &&
122 git branch -M master master
125 test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
126 git checkout master &&
127 git branch master2 &&
128 git branch -M master2 master2
131 test_expect_success 'git branch -v -d t should work' '
132 git branch t &&
133 test_path_is_file .git/refs/heads/t &&
134 git branch -v -d t &&
135 test_path_is_missing .git/refs/heads/t
138 test_expect_success 'git branch -v -m t s should work' '
139 git branch t &&
140 test_path_is_file .git/refs/heads/t &&
141 git branch -v -m t s &&
142 test_path_is_missing .git/refs/heads/t &&
143 test_path_is_file .git/refs/heads/s &&
144 git branch -d s
147 test_expect_success 'git branch -m -d t s should fail' '
148 git branch t &&
149 test_path_is_file .git/refs/heads/t &&
150 test_must_fail git branch -m -d t s &&
151 git branch -d t &&
152 test_path_is_missing .git/refs/heads/t
155 test_expect_success 'git branch --list -d t should fail' '
156 git branch t &&
157 test_path_is_file .git/refs/heads/t &&
158 test_must_fail git branch --list -d t &&
159 git branch -d t &&
160 test_path_is_missing .git/refs/heads/t
163 test_expect_success 'git branch --column' '
164 COLUMNS=81 git branch --column=column >actual &&
165 cat >expected <<\EOF &&
166 a/b/c bam foo l * master n o/p r
167 abc bar j/k m/m master2 o/o q
169 test_cmp expected actual
172 test_expect_success 'git branch --column with an extremely long branch name' '
173 long=this/is/a/part/of/long/branch/name &&
174 long=z$long/$long/$long/$long &&
175 test_when_finished "git branch -d $long" &&
176 git branch $long &&
177 COLUMNS=80 git branch --column=column >actual &&
178 cat >expected <<EOF &&
179 a/b/c
187 * master
188 master2
194 $long
196 test_cmp expected actual
199 test_expect_success 'git branch with column.*' '
200 git config column.ui column &&
201 git config column.branch "dense" &&
202 COLUMNS=80 git branch >actual &&
203 git config --unset column.branch &&
204 git config --unset column.ui &&
205 cat >expected <<\EOF &&
206 a/b/c bam foo l * master n o/p r
207 abc bar j/k m/m master2 o/o q
209 test_cmp expected actual
212 test_expect_success 'git branch --column -v should fail' '
213 test_must_fail git branch --column -v
216 test_expect_success 'git branch -v with column.ui ignored' '
217 git config column.ui column &&
218 COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
219 git config --unset column.ui &&
220 cat >expected <<\EOF &&
221 a/b/c
229 * master
230 master2
237 test_cmp expected actual
240 mv .git/config .git/config-saved
242 test_expect_success 'git branch -m q q2 without config should succeed' '
243 git branch -m q q2 &&
244 git branch -m q2 q
247 mv .git/config-saved .git/config
249 git config branch.s/s.dummy Hello
251 test_expect_success \
252 'git branch -m s/s s should work when s/t is deleted' \
253 'git branch -l s/s &&
254 test_path_is_file .git/logs/refs/heads/s/s &&
255 git branch -l s/t &&
256 test_path_is_file .git/logs/refs/heads/s/t &&
257 git branch -d s/t &&
258 git branch -m s/s s &&
259 test_path_is_file .git/logs/refs/heads/s'
261 test_expect_success 'config information was renamed, too' \
262 "test $(git config branch.s.dummy) = Hello &&
263 test_must_fail git config branch.s/s/dummy"
265 test_expect_success 'renaming a symref is not allowed' \
267 git symbolic-ref refs/heads/master2 refs/heads/master &&
268 test_must_fail git branch -m master2 master3 &&
269 git symbolic-ref refs/heads/master2 &&
270 test_path_is_file .git/refs/heads/master &&
271 test_path_is_missing .git/refs/heads/master3
274 test_expect_success SYMLINKS \
275 'git branch -m u v should fail when the reflog for u is a symlink' '
276 git branch -l u &&
277 mv .git/logs/refs/heads/u real-u &&
278 ln -s real-u .git/logs/refs/heads/u &&
279 test_must_fail git branch -m u v
282 test_expect_success 'test tracking setup via --track' \
283 'git config remote.local.url . &&
284 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
285 (git show-ref -q refs/remotes/local/master || git fetch local) &&
286 git branch --track my1 local/master &&
287 test $(git config branch.my1.remote) = local &&
288 test $(git config branch.my1.merge) = refs/heads/master'
290 test_expect_success 'test tracking setup (non-wildcard, matching)' \
291 'git config remote.local.url . &&
292 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
293 (git show-ref -q refs/remotes/local/master || git fetch local) &&
294 git branch --track my4 local/master &&
295 test $(git config branch.my4.remote) = local &&
296 test $(git config branch.my4.merge) = refs/heads/master'
298 test_expect_success 'test tracking setup (non-wildcard, not matching)' \
299 'git config remote.local.url . &&
300 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
301 (git show-ref -q refs/remotes/local/master || git fetch local) &&
302 git branch --track my5 local/master &&
303 ! test "$(git config branch.my5.remote)" = local &&
304 ! test "$(git config branch.my5.merge)" = refs/heads/master'
306 test_expect_success 'test tracking setup via config' \
307 'git config branch.autosetupmerge true &&
308 git config remote.local.url . &&
309 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
310 (git show-ref -q refs/remotes/local/master || git fetch local) &&
311 git branch my3 local/master &&
312 test $(git config branch.my3.remote) = local &&
313 test $(git config branch.my3.merge) = refs/heads/master'
315 test_expect_success 'test overriding tracking setup via --no-track' \
316 'git config branch.autosetupmerge true &&
317 git config remote.local.url . &&
318 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
319 (git show-ref -q refs/remotes/local/master || git fetch local) &&
320 git branch --no-track my2 local/master &&
321 git config branch.autosetupmerge false &&
322 ! test "$(git config branch.my2.remote)" = local &&
323 ! test "$(git config branch.my2.merge)" = refs/heads/master'
325 test_expect_success 'no tracking without .fetch entries' \
326 'git config branch.autosetupmerge true &&
327 git branch my6 s &&
328 git config branch.automsetupmerge false &&
329 test -z "$(git config branch.my6.remote)" &&
330 test -z "$(git config branch.my6.merge)"'
332 test_expect_success 'test tracking setup via --track but deeper' \
333 'git config remote.local.url . &&
334 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
335 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
336 git branch --track my7 local/o/o &&
337 test "$(git config branch.my7.remote)" = local &&
338 test "$(git config branch.my7.merge)" = refs/heads/o/o'
340 test_expect_success 'test deleting branch deletes branch config' \
341 'git branch -d my7 &&
342 test -z "$(git config branch.my7.remote)" &&
343 test -z "$(git config branch.my7.merge)"'
345 test_expect_success 'test deleting branch without config' \
346 'git branch my7 s &&
347 sha1=$(git rev-parse my7 | cut -c 1-7) &&
348 echo "Deleted branch my7 (was $sha1)." >expect &&
349 git branch -d my7 >actual 2>&1 &&
350 test_i18ncmp expect actual'
352 test_expect_success 'test --track without .fetch entries' \
353 'git branch --track my8 &&
354 test "$(git config branch.my8.remote)" &&
355 test "$(git config branch.my8.merge)"'
357 test_expect_success \
358 'branch from non-branch HEAD w/autosetupmerge=always' \
359 'git config branch.autosetupmerge always &&
360 git branch my9 HEAD^ &&
361 git config branch.autosetupmerge false'
363 test_expect_success \
364 'branch from non-branch HEAD w/--track causes failure' \
365 'test_must_fail git branch --track my10 HEAD^'
367 test_expect_success \
368 'branch from tag w/--track causes failure' \
369 'git tag foobar &&
370 test_must_fail git branch --track my11 foobar'
372 test_expect_success 'use --set-upstream-to modify HEAD' \
373 'test_config branch.master.remote foo &&
374 test_config branch.master.merge foo &&
375 git branch my12
376 git branch --set-upstream-to my12 &&
377 test "$(git config branch.master.remote)" = "." &&
378 test "$(git config branch.master.merge)" = "refs/heads/my12"'
380 test_expect_success 'use --set-upstream-to modify a particular branch' \
381 'git branch my13
382 git branch --set-upstream-to master my13 &&
383 test "$(git config branch.my13.remote)" = "." &&
384 test "$(git config branch.my13.merge)" = "refs/heads/master"'
386 # Keep this test last, as it changes the current branch
387 cat >expect <<EOF
388 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
390 test_expect_success \
391 'git checkout -b g/h/i -l should create a branch and a log' \
392 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
393 git checkout -b g/h/i -l master &&
394 test_path_is_file .git/refs/heads/g/h/i &&
395 test_path_is_file .git/logs/refs/heads/g/h/i &&
396 test_cmp expect .git/logs/refs/heads/g/h/i'
398 test_expect_success 'checkout -b makes reflog by default' '
399 git checkout master &&
400 git config --unset core.logAllRefUpdates &&
401 git checkout -b alpha &&
402 git rev-parse --verify alpha@{0}
405 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
406 git checkout master &&
407 git config core.logAllRefUpdates false &&
408 git checkout -b beta &&
409 test_must_fail git rev-parse --verify beta@{0}
412 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
413 git checkout master &&
414 git checkout -lb gamma &&
415 git config --unset core.logAllRefUpdates &&
416 git rev-parse --verify gamma@{0}
419 test_expect_success 'avoid ambiguous track' '
420 git config branch.autosetupmerge true &&
421 git config remote.ambi1.url lalala &&
422 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
423 git config remote.ambi2.url lilili &&
424 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
425 git branch all1 master &&
426 test -z "$(git config branch.all1.merge)"
429 test_expect_success 'autosetuprebase local on a tracked local branch' '
430 git config remote.local.url . &&
431 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
432 git config branch.autosetuprebase local &&
433 (git show-ref -q refs/remotes/local/o || git fetch local) &&
434 git branch mybase &&
435 git branch --track myr1 mybase &&
436 test "$(git config branch.myr1.remote)" = . &&
437 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
438 test "$(git config branch.myr1.rebase)" = true
441 test_expect_success 'autosetuprebase always on a tracked local branch' '
442 git config remote.local.url . &&
443 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
444 git config branch.autosetuprebase always &&
445 (git show-ref -q refs/remotes/local/o || git fetch local) &&
446 git branch mybase2 &&
447 git branch --track myr2 mybase &&
448 test "$(git config branch.myr2.remote)" = . &&
449 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
450 test "$(git config branch.myr2.rebase)" = true
453 test_expect_success 'autosetuprebase remote on a tracked local branch' '
454 git config remote.local.url . &&
455 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
456 git config branch.autosetuprebase remote &&
457 (git show-ref -q refs/remotes/local/o || git fetch local) &&
458 git branch mybase3 &&
459 git branch --track myr3 mybase2 &&
460 test "$(git config branch.myr3.remote)" = . &&
461 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
462 ! test "$(git config branch.myr3.rebase)" = true
465 test_expect_success 'autosetuprebase never on a tracked local branch' '
466 git config remote.local.url . &&
467 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
468 git config branch.autosetuprebase never &&
469 (git show-ref -q refs/remotes/local/o || git fetch local) &&
470 git branch mybase4 &&
471 git branch --track myr4 mybase2 &&
472 test "$(git config branch.myr4.remote)" = . &&
473 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
474 ! test "$(git config branch.myr4.rebase)" = true
477 test_expect_success 'autosetuprebase local on a tracked remote branch' '
478 git config remote.local.url . &&
479 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
480 git config branch.autosetuprebase local &&
481 (git show-ref -q refs/remotes/local/master || git fetch local) &&
482 git branch --track myr5 local/master &&
483 test "$(git config branch.myr5.remote)" = local &&
484 test "$(git config branch.myr5.merge)" = refs/heads/master &&
485 ! test "$(git config branch.myr5.rebase)" = true
488 test_expect_success 'autosetuprebase never on a tracked remote branch' '
489 git config remote.local.url . &&
490 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
491 git config branch.autosetuprebase never &&
492 (git show-ref -q refs/remotes/local/master || git fetch local) &&
493 git branch --track myr6 local/master &&
494 test "$(git config branch.myr6.remote)" = local &&
495 test "$(git config branch.myr6.merge)" = refs/heads/master &&
496 ! test "$(git config branch.myr6.rebase)" = true
499 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
500 git config remote.local.url . &&
501 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
502 git config branch.autosetuprebase remote &&
503 (git show-ref -q refs/remotes/local/master || git fetch local) &&
504 git branch --track myr7 local/master &&
505 test "$(git config branch.myr7.remote)" = local &&
506 test "$(git config branch.myr7.merge)" = refs/heads/master &&
507 test "$(git config branch.myr7.rebase)" = true
510 test_expect_success 'autosetuprebase always on a tracked remote branch' '
511 git config remote.local.url . &&
512 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
513 git config branch.autosetuprebase remote &&
514 (git show-ref -q refs/remotes/local/master || git fetch local) &&
515 git branch --track myr8 local/master &&
516 test "$(git config branch.myr8.remote)" = local &&
517 test "$(git config branch.myr8.merge)" = refs/heads/master &&
518 test "$(git config branch.myr8.rebase)" = true
521 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
522 git config --unset branch.autosetuprebase &&
523 git config remote.local.url . &&
524 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
525 (git show-ref -q refs/remotes/local/master || git fetch local) &&
526 git branch --track myr9 local/master &&
527 test "$(git config branch.myr9.remote)" = local &&
528 test "$(git config branch.myr9.merge)" = refs/heads/master &&
529 test "z$(git config branch.myr9.rebase)" = z
532 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
533 git config remote.local.url . &&
534 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
535 (git show-ref -q refs/remotes/local/o || git fetch local) &&
536 git branch mybase10 &&
537 git branch --track myr10 mybase2 &&
538 test "$(git config branch.myr10.remote)" = . &&
539 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
540 test "z$(git config branch.myr10.rebase)" = z
543 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
544 git config remote.local.url . &&
545 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
546 (git show-ref -q refs/remotes/local/master || git fetch local) &&
547 git branch --no-track myr11 mybase2 &&
548 test "z$(git config branch.myr11.remote)" = z &&
549 test "z$(git config branch.myr11.merge)" = z &&
550 test "z$(git config branch.myr11.rebase)" = z
553 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
554 git config remote.local.url . &&
555 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
556 (git show-ref -q refs/remotes/local/master || git fetch local) &&
557 git branch --no-track myr12 local/master &&
558 test "z$(git config branch.myr12.remote)" = z &&
559 test "z$(git config branch.myr12.merge)" = z &&
560 test "z$(git config branch.myr12.rebase)" = z
563 test_expect_success 'autosetuprebase never on an untracked local branch' '
564 git config branch.autosetuprebase never &&
565 git config remote.local.url . &&
566 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
567 (git show-ref -q refs/remotes/local/master || git fetch local) &&
568 git branch --no-track myr13 mybase2 &&
569 test "z$(git config branch.myr13.remote)" = z &&
570 test "z$(git config branch.myr13.merge)" = z &&
571 test "z$(git config branch.myr13.rebase)" = z
574 test_expect_success 'autosetuprebase local on an untracked local branch' '
575 git config branch.autosetuprebase local &&
576 git config remote.local.url . &&
577 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
578 (git show-ref -q refs/remotes/local/master || git fetch local) &&
579 git branch --no-track myr14 mybase2 &&
580 test "z$(git config branch.myr14.remote)" = z &&
581 test "z$(git config branch.myr14.merge)" = z &&
582 test "z$(git config branch.myr14.rebase)" = z
585 test_expect_success 'autosetuprebase remote on an untracked local branch' '
586 git config branch.autosetuprebase remote &&
587 git config remote.local.url . &&
588 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
589 (git show-ref -q refs/remotes/local/master || git fetch local) &&
590 git branch --no-track myr15 mybase2 &&
591 test "z$(git config branch.myr15.remote)" = z &&
592 test "z$(git config branch.myr15.merge)" = z &&
593 test "z$(git config branch.myr15.rebase)" = z
596 test_expect_success 'autosetuprebase always on an untracked local branch' '
597 git config branch.autosetuprebase always &&
598 git config remote.local.url . &&
599 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
600 (git show-ref -q refs/remotes/local/master || git fetch local) &&
601 git branch --no-track myr16 mybase2 &&
602 test "z$(git config branch.myr16.remote)" = z &&
603 test "z$(git config branch.myr16.merge)" = z &&
604 test "z$(git config branch.myr16.rebase)" = z
607 test_expect_success 'autosetuprebase never on an untracked remote branch' '
608 git config branch.autosetuprebase never &&
609 git config remote.local.url . &&
610 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
611 (git show-ref -q refs/remotes/local/master || git fetch local) &&
612 git branch --no-track myr17 local/master &&
613 test "z$(git config branch.myr17.remote)" = z &&
614 test "z$(git config branch.myr17.merge)" = z &&
615 test "z$(git config branch.myr17.rebase)" = z
618 test_expect_success 'autosetuprebase local on an untracked remote branch' '
619 git config branch.autosetuprebase local &&
620 git config remote.local.url . &&
621 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
622 (git show-ref -q refs/remotes/local/master || git fetch local) &&
623 git branch --no-track myr18 local/master &&
624 test "z$(git config branch.myr18.remote)" = z &&
625 test "z$(git config branch.myr18.merge)" = z &&
626 test "z$(git config branch.myr18.rebase)" = z
629 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
630 git config branch.autosetuprebase remote &&
631 git config remote.local.url . &&
632 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
633 (git show-ref -q refs/remotes/local/master || git fetch local) &&
634 git branch --no-track myr19 local/master &&
635 test "z$(git config branch.myr19.remote)" = z &&
636 test "z$(git config branch.myr19.merge)" = z &&
637 test "z$(git config branch.myr19.rebase)" = z
640 test_expect_success 'autosetuprebase always on an untracked remote branch' '
641 git config branch.autosetuprebase always &&
642 git config remote.local.url . &&
643 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
644 (git show-ref -q refs/remotes/local/master || git fetch local) &&
645 git branch --no-track myr20 local/master &&
646 test "z$(git config branch.myr20.remote)" = z &&
647 test "z$(git config branch.myr20.merge)" = z &&
648 test "z$(git config branch.myr20.rebase)" = z
651 test_expect_success 'autosetuprebase always on detached HEAD' '
652 git config branch.autosetupmerge always &&
653 test_when_finished git checkout master &&
654 git checkout HEAD^0 &&
655 git branch my11 &&
656 test -z "$(git config branch.my11.remote)" &&
657 test -z "$(git config branch.my11.merge)"
660 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
661 git config branch.autosetuprebase garbage &&
662 test_must_fail git branch
665 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
666 git config --unset branch.autosetuprebase &&
667 echo "[branch] autosetuprebase" >> .git/config &&
668 test_must_fail git branch &&
669 git config --unset branch.autosetuprebase
672 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
673 git checkout my9 &&
674 git config --unset branch.my8.merge &&
675 test_must_fail git branch -d my8
678 test_expect_success 'attempt to delete a branch merged to its base' '
679 # we are on my9 which is the initial commit; traditionally
680 # we would not have allowed deleting my8 that is not merged
681 # to my9, but it is set to track master that already has my8
682 git config branch.my8.merge refs/heads/master &&
683 git branch -d my8
686 test_expect_success 'attempt to delete a branch merged to its base' '
687 git checkout master &&
688 echo Third >>A &&
689 git commit -m "Third commit" A &&
690 git branch -t my10 my9 &&
691 git branch -f my10 HEAD^ &&
692 # we are on master which is at the third commit, and my10
693 # is behind us, so traditionally we would have allowed deleting
694 # it; but my10 is set to track my9 that is further behind.
695 test_must_fail git branch -d my10
698 test_expect_success 'use set-upstream on the current branch' '
699 git checkout master &&
700 git --bare init myupstream.git &&
701 git push myupstream.git master:refs/heads/frotz &&
702 git remote add origin myupstream.git &&
703 git fetch &&
704 git branch --set-upstream master origin/frotz &&
706 test "z$(git config branch.master.remote)" = "zorigin" &&
707 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
711 test_expect_success 'use --edit-description' '
712 write_script editor <<-\EOF &&
713 echo "New contents" >"$1"
715 EDITOR=./editor git branch --edit-description &&
716 write_script editor <<-\EOF &&
717 git stripspace -s <"$1" >"EDITOR_OUTPUT"
719 EDITOR=./editor git branch --edit-description &&
720 echo "New contents" >expect &&
721 test_cmp EDITOR_OUTPUT expect
724 test_expect_success 'detect typo in branch name when using --edit-description' '
725 write_script editor <<-\EOF &&
726 echo "New contents" >"$1"
729 EDITOR=./editor &&
730 export EDITOR &&
731 test_must_fail git branch --edit-description no-such-branch
735 test_expect_success 'refuse --edit-description on unborn branch for now' '
736 write_script editor <<-\EOF &&
737 echo "New contents" >"$1"
739 git checkout --orphan unborn &&
741 EDITOR=./editor &&
742 export EDITOR &&
743 test_must_fail git branch --edit-description
747 test_expect_success '--merged catches invalid object names' '
748 test_must_fail git branch --merged 0000000000000000000000000000000000000000
751 test_done