Code

Merge branch 'maint'
[git.git] / t / t3200-branch.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Amos Waterland
4 #
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
24 '
26 test_expect_success 'branch -h in broken repository' '
27         mkdir broken &&
28         (
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
35 '
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
95 '
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 mv .git/config .git/config-saved
165 test_expect_success 'git branch -m q q2 without config should succeed' '
166         git branch -m q q2 &&
167         git branch -m q2 q
170 mv .git/config-saved .git/config
172 git config branch.s/s.dummy Hello
174 test_expect_success \
175     'git branch -m s/s s should work when s/t is deleted' \
176        'git branch -l s/s &&
177         test_path_is_file .git/logs/refs/heads/s/s &&
178         git branch -l s/t &&
179         test_path_is_file .git/logs/refs/heads/s/t &&
180         git branch -d s/t &&
181         git branch -m s/s s &&
182         test_path_is_file .git/logs/refs/heads/s'
184 test_expect_success 'config information was renamed, too' \
185         "test $(git config branch.s.dummy) = Hello &&
186          test_must_fail git config branch.s/s/dummy"
188 test_expect_success 'renaming a symref is not allowed' \
190         git symbolic-ref refs/heads/master2 refs/heads/master &&
191         test_must_fail git branch -m master2 master3 &&
192         git symbolic-ref refs/heads/master2 &&
193         test_path_is_file .git/refs/heads/master &&
194         test_path_is_missing .git/refs/heads/master3
197 test_expect_success SYMLINKS \
198     'git branch -m u v should fail when the reflog for u is a symlink' '
199      git branch -l u &&
200      mv .git/logs/refs/heads/u real-u &&
201      ln -s real-u .git/logs/refs/heads/u &&
202      test_must_fail git branch -m u v
205 test_expect_success 'test tracking setup via --track' \
206     'git config remote.local.url . &&
207      git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
208      (git show-ref -q refs/remotes/local/master || git fetch local) &&
209      git branch --track my1 local/master &&
210      test $(git config branch.my1.remote) = local &&
211      test $(git config branch.my1.merge) = refs/heads/master'
213 test_expect_success 'test tracking setup (non-wildcard, matching)' \
214     'git config remote.local.url . &&
215      git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
216      (git show-ref -q refs/remotes/local/master || git fetch local) &&
217      git branch --track my4 local/master &&
218      test $(git config branch.my4.remote) = local &&
219      test $(git config branch.my4.merge) = refs/heads/master'
221 test_expect_success 'test tracking setup (non-wildcard, not matching)' \
222     'git config remote.local.url . &&
223      git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
224      (git show-ref -q refs/remotes/local/master || git fetch local) &&
225      git branch --track my5 local/master &&
226      ! test "$(git config branch.my5.remote)" = local &&
227      ! test "$(git config branch.my5.merge)" = refs/heads/master'
229 test_expect_success 'test tracking setup via config' \
230     'git config branch.autosetupmerge true &&
231      git config remote.local.url . &&
232      git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
233      (git show-ref -q refs/remotes/local/master || git fetch local) &&
234      git branch my3 local/master &&
235      test $(git config branch.my3.remote) = local &&
236      test $(git config branch.my3.merge) = refs/heads/master'
238 test_expect_success 'test overriding tracking setup via --no-track' \
239     'git config branch.autosetupmerge true &&
240      git config remote.local.url . &&
241      git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
242      (git show-ref -q refs/remotes/local/master || git fetch local) &&
243      git branch --no-track my2 local/master &&
244      git config branch.autosetupmerge false &&
245      ! test "$(git config branch.my2.remote)" = local &&
246      ! test "$(git config branch.my2.merge)" = refs/heads/master'
248 test_expect_success 'no tracking without .fetch entries' \
249     'git config branch.autosetupmerge true &&
250      git branch my6 s &&
251      git config branch.automsetupmerge false &&
252      test -z "$(git config branch.my6.remote)" &&
253      test -z "$(git config branch.my6.merge)"'
255 test_expect_success 'test tracking setup via --track but deeper' \
256     'git config remote.local.url . &&
257      git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
258      (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
259      git branch --track my7 local/o/o &&
260      test "$(git config branch.my7.remote)" = local &&
261      test "$(git config branch.my7.merge)" = refs/heads/o/o'
263 test_expect_success 'test deleting branch deletes branch config' \
264     'git branch -d my7 &&
265      test -z "$(git config branch.my7.remote)" &&
266      test -z "$(git config branch.my7.merge)"'
268 test_expect_success 'test deleting branch without config' \
269     'git branch my7 s &&
270      sha1=$(git rev-parse my7 | cut -c 1-7) &&
271      echo "Deleted branch my7 (was $sha1)." >expect &&
272      git branch -d my7 >actual 2>&1 &&
273      test_i18ncmp expect actual'
275 test_expect_success 'test --track without .fetch entries' \
276     'git branch --track my8 &&
277      test "$(git config branch.my8.remote)" &&
278      test "$(git config branch.my8.merge)"'
280 test_expect_success \
281     'branch from non-branch HEAD w/autosetupmerge=always' \
282     'git config branch.autosetupmerge always &&
283      git branch my9 HEAD^ &&
284      git config branch.autosetupmerge false'
286 test_expect_success \
287     'branch from non-branch HEAD w/--track causes failure' \
288     'test_must_fail git branch --track my10 HEAD^'
290 test_expect_success \
291     'branch from tag w/--track causes failure' \
292     'git tag foobar &&
293      test_must_fail git branch --track my11 foobar'
295 # Keep this test last, as it changes the current branch
296 cat >expect <<EOF
297 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
298 EOF
299 test_expect_success \
300     'git checkout -b g/h/i -l should create a branch and a log' \
301         'GIT_COMMITTER_DATE="2005-05-26 23:30" \
302      git checkout -b g/h/i -l master &&
303          test_path_is_file .git/refs/heads/g/h/i &&
304          test_path_is_file .git/logs/refs/heads/g/h/i &&
305          test_cmp expect .git/logs/refs/heads/g/h/i'
307 test_expect_success 'checkout -b makes reflog by default' '
308         git checkout master &&
309         git config --unset core.logAllRefUpdates &&
310         git checkout -b alpha &&
311         git rev-parse --verify alpha@{0}
314 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
315         git checkout master &&
316         git config core.logAllRefUpdates false &&
317         git checkout -b beta &&
318         test_must_fail git rev-parse --verify beta@{0}
321 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
322         git checkout master &&
323         git checkout -lb gamma &&
324         git config --unset core.logAllRefUpdates &&
325         git rev-parse --verify gamma@{0}
328 test_expect_success 'avoid ambiguous track' '
329         git config branch.autosetupmerge true &&
330         git config remote.ambi1.url lalala &&
331         git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
332         git config remote.ambi2.url lilili &&
333         git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
334         git branch all1 master &&
335         test -z "$(git config branch.all1.merge)"
338 test_expect_success 'autosetuprebase local on a tracked local branch' '
339         git config remote.local.url . &&
340         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
341         git config branch.autosetuprebase local &&
342         (git show-ref -q refs/remotes/local/o || git fetch local) &&
343         git branch mybase &&
344         git branch --track myr1 mybase &&
345         test "$(git config branch.myr1.remote)" = . &&
346         test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
347         test "$(git config branch.myr1.rebase)" = true
350 test_expect_success 'autosetuprebase always on a tracked local branch' '
351         git config remote.local.url . &&
352         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
353         git config branch.autosetuprebase always &&
354         (git show-ref -q refs/remotes/local/o || git fetch local) &&
355         git branch mybase2 &&
356         git branch --track myr2 mybase &&
357         test "$(git config branch.myr2.remote)" = . &&
358         test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
359         test "$(git config branch.myr2.rebase)" = true
362 test_expect_success 'autosetuprebase remote on a tracked local branch' '
363         git config remote.local.url . &&
364         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
365         git config branch.autosetuprebase remote &&
366         (git show-ref -q refs/remotes/local/o || git fetch local) &&
367         git branch mybase3 &&
368         git branch --track myr3 mybase2 &&
369         test "$(git config branch.myr3.remote)" = . &&
370         test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
371         ! test "$(git config branch.myr3.rebase)" = true
374 test_expect_success 'autosetuprebase never on a tracked local branch' '
375         git config remote.local.url . &&
376         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
377         git config branch.autosetuprebase never &&
378         (git show-ref -q refs/remotes/local/o || git fetch local) &&
379         git branch mybase4 &&
380         git branch --track myr4 mybase2 &&
381         test "$(git config branch.myr4.remote)" = . &&
382         test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
383         ! test "$(git config branch.myr4.rebase)" = true
386 test_expect_success 'autosetuprebase local on a tracked remote branch' '
387         git config remote.local.url . &&
388         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
389         git config branch.autosetuprebase local &&
390         (git show-ref -q refs/remotes/local/master || git fetch local) &&
391         git branch --track myr5 local/master &&
392         test "$(git config branch.myr5.remote)" = local &&
393         test "$(git config branch.myr5.merge)" = refs/heads/master &&
394         ! test "$(git config branch.myr5.rebase)" = true
397 test_expect_success 'autosetuprebase never on a tracked remote branch' '
398         git config remote.local.url . &&
399         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
400         git config branch.autosetuprebase never &&
401         (git show-ref -q refs/remotes/local/master || git fetch local) &&
402         git branch --track myr6 local/master &&
403         test "$(git config branch.myr6.remote)" = local &&
404         test "$(git config branch.myr6.merge)" = refs/heads/master &&
405         ! test "$(git config branch.myr6.rebase)" = true
408 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
409         git config remote.local.url . &&
410         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
411         git config branch.autosetuprebase remote &&
412         (git show-ref -q refs/remotes/local/master || git fetch local) &&
413         git branch --track myr7 local/master &&
414         test "$(git config branch.myr7.remote)" = local &&
415         test "$(git config branch.myr7.merge)" = refs/heads/master &&
416         test "$(git config branch.myr7.rebase)" = true
419 test_expect_success 'autosetuprebase always on a tracked remote branch' '
420         git config remote.local.url . &&
421         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
422         git config branch.autosetuprebase remote &&
423         (git show-ref -q refs/remotes/local/master || git fetch local) &&
424         git branch --track myr8 local/master &&
425         test "$(git config branch.myr8.remote)" = local &&
426         test "$(git config branch.myr8.merge)" = refs/heads/master &&
427         test "$(git config branch.myr8.rebase)" = true
430 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
431         git config --unset branch.autosetuprebase &&
432         git config remote.local.url . &&
433         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
434         (git show-ref -q refs/remotes/local/master || git fetch local) &&
435         git branch --track myr9 local/master &&
436         test "$(git config branch.myr9.remote)" = local &&
437         test "$(git config branch.myr9.merge)" = refs/heads/master &&
438         test "z$(git config branch.myr9.rebase)" = z
441 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
442         git config remote.local.url . &&
443         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
444         (git show-ref -q refs/remotes/local/o || git fetch local) &&
445         git branch mybase10 &&
446         git branch --track myr10 mybase2 &&
447         test "$(git config branch.myr10.remote)" = . &&
448         test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
449         test "z$(git config branch.myr10.rebase)" = z
452 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
453         git config remote.local.url . &&
454         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
455         (git show-ref -q refs/remotes/local/master || git fetch local) &&
456         git branch --no-track myr11 mybase2 &&
457         test "z$(git config branch.myr11.remote)" = z &&
458         test "z$(git config branch.myr11.merge)" = z &&
459         test "z$(git config branch.myr11.rebase)" = z
462 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
463         git config remote.local.url . &&
464         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
465         (git show-ref -q refs/remotes/local/master || git fetch local) &&
466         git branch --no-track myr12 local/master &&
467         test "z$(git config branch.myr12.remote)" = z &&
468         test "z$(git config branch.myr12.merge)" = z &&
469         test "z$(git config branch.myr12.rebase)" = z
472 test_expect_success 'autosetuprebase never on an untracked local branch' '
473         git config branch.autosetuprebase never &&
474         git config remote.local.url . &&
475         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
476         (git show-ref -q refs/remotes/local/master || git fetch local) &&
477         git branch --no-track myr13 mybase2 &&
478         test "z$(git config branch.myr13.remote)" = z &&
479         test "z$(git config branch.myr13.merge)" = z &&
480         test "z$(git config branch.myr13.rebase)" = z
483 test_expect_success 'autosetuprebase local on an untracked local branch' '
484         git config branch.autosetuprebase local &&
485         git config remote.local.url . &&
486         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
487         (git show-ref -q refs/remotes/local/master || git fetch local) &&
488         git branch --no-track myr14 mybase2 &&
489         test "z$(git config branch.myr14.remote)" = z &&
490         test "z$(git config branch.myr14.merge)" = z &&
491         test "z$(git config branch.myr14.rebase)" = z
494 test_expect_success 'autosetuprebase remote on an untracked local branch' '
495         git config branch.autosetuprebase remote &&
496         git config remote.local.url . &&
497         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
498         (git show-ref -q refs/remotes/local/master || git fetch local) &&
499         git branch --no-track myr15 mybase2 &&
500         test "z$(git config branch.myr15.remote)" = z &&
501         test "z$(git config branch.myr15.merge)" = z &&
502         test "z$(git config branch.myr15.rebase)" = z
505 test_expect_success 'autosetuprebase always on an untracked local branch' '
506         git config branch.autosetuprebase always &&
507         git config remote.local.url . &&
508         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
509         (git show-ref -q refs/remotes/local/master || git fetch local) &&
510         git branch --no-track myr16 mybase2 &&
511         test "z$(git config branch.myr16.remote)" = z &&
512         test "z$(git config branch.myr16.merge)" = z &&
513         test "z$(git config branch.myr16.rebase)" = z
516 test_expect_success 'autosetuprebase never on an untracked remote branch' '
517         git config branch.autosetuprebase never &&
518         git config remote.local.url . &&
519         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
520         (git show-ref -q refs/remotes/local/master || git fetch local) &&
521         git branch --no-track myr17 local/master &&
522         test "z$(git config branch.myr17.remote)" = z &&
523         test "z$(git config branch.myr17.merge)" = z &&
524         test "z$(git config branch.myr17.rebase)" = z
527 test_expect_success 'autosetuprebase local on an untracked remote branch' '
528         git config branch.autosetuprebase local &&
529         git config remote.local.url . &&
530         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
531         (git show-ref -q refs/remotes/local/master || git fetch local) &&
532         git branch --no-track myr18 local/master &&
533         test "z$(git config branch.myr18.remote)" = z &&
534         test "z$(git config branch.myr18.merge)" = z &&
535         test "z$(git config branch.myr18.rebase)" = z
538 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
539         git config branch.autosetuprebase remote &&
540         git config remote.local.url . &&
541         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
542         (git show-ref -q refs/remotes/local/master || git fetch local) &&
543         git branch --no-track myr19 local/master &&
544         test "z$(git config branch.myr19.remote)" = z &&
545         test "z$(git config branch.myr19.merge)" = z &&
546         test "z$(git config branch.myr19.rebase)" = z
549 test_expect_success 'autosetuprebase always on an untracked remote branch' '
550         git config branch.autosetuprebase always &&
551         git config remote.local.url . &&
552         git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
553         (git show-ref -q refs/remotes/local/master || git fetch local) &&
554         git branch --no-track myr20 local/master &&
555         test "z$(git config branch.myr20.remote)" = z &&
556         test "z$(git config branch.myr20.merge)" = z &&
557         test "z$(git config branch.myr20.rebase)" = z
560 test_expect_success 'autosetuprebase always on detached HEAD' '
561         git config branch.autosetupmerge always &&
562         test_when_finished git checkout master &&
563         git checkout HEAD^0 &&
564         git branch my11 &&
565         test -z "$(git config branch.my11.remote)" &&
566         test -z "$(git config branch.my11.merge)"
569 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
570         git config branch.autosetuprebase garbage &&
571         test_must_fail git branch
574 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
575         git config --unset branch.autosetuprebase &&
576         echo "[branch] autosetuprebase" >> .git/config &&
577         test_must_fail git branch &&
578         git config --unset branch.autosetuprebase
581 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
582         git checkout my9 &&
583         git config --unset branch.my8.merge &&
584         test_must_fail git branch -d my8
587 test_expect_success 'attempt to delete a branch merged to its base' '
588         # we are on my9 which is the initial commit; traditionally
589         # we would not have allowed deleting my8 that is not merged
590         # to my9, but it is set to track master that already has my8
591         git config branch.my8.merge refs/heads/master &&
592         git branch -d my8
595 test_expect_success 'attempt to delete a branch merged to its base' '
596         git checkout master &&
597         echo Third >>A &&
598         git commit -m "Third commit" A &&
599         git branch -t my10 my9 &&
600         git branch -f my10 HEAD^ &&
601         # we are on master which is at the third commit, and my10
602         # is behind us, so traditionally we would have allowed deleting
603         # it; but my10 is set to track my9 that is further behind.
604         test_must_fail git branch -d my10
607 test_expect_success 'use set-upstream on the current branch' '
608         git checkout master &&
609         git --bare init myupstream.git &&
610         git push myupstream.git master:refs/heads/frotz &&
611         git remote add origin myupstream.git &&
612         git fetch &&
613         git branch --set-upstream master origin/frotz &&
615         test "z$(git config branch.master.remote)" = "zorigin" &&
616         test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
620 test_expect_success 'use --edit-description' '
621         write_script editor <<-\EOF &&
622                 echo "New contents" >"$1"
623         EOF
624         EDITOR=./editor git branch --edit-description &&
625                 write_script editor <<-\EOF &&
626                 git stripspace -s <"$1" >"EDITOR_OUTPUT"
627         EOF
628         EDITOR=./editor git branch --edit-description &&
629         echo "New contents" >expect &&
630         test_cmp EDITOR_OUTPUT expect
633 test_expect_success 'detect typo in branch name when using --edit-description' '
634         write_script editor <<-\EOF &&
635                 echo "New contents" >"$1"
636         EOF
637         (
638                 EDITOR=./editor &&
639                 export EDITOR &&
640                 test_must_fail git branch --edit-description no-such-branch
641         )
644 test_expect_success 'refuse --edit-description on unborn branch for now' '
645         write_script editor <<-\EOF &&
646                 echo "New contents" >"$1"
647         EOF
648         git checkout --orphan unborn &&
649         (
650                 EDITOR=./editor &&
651                 export EDITOR &&
652                 test_must_fail git branch --edit-description
653         )
656 test_expect_success '--merged catches invalid object names' '
657         test_must_fail git branch --merged 0000000000000000000000000000000000000000
660 test_done