]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3200-branch.sh
Git 1.8.4
[thirdparty/git.git] / t / t3200-branch.sh
CommitLineData
a3b427b9
AW
1#!/bin/sh
2#
3# Copyright (c) 2005 Amos Waterland
4#
5
c2d17ba3 6test_description='git branch assorted tests'
a3b427b9 7
a3b427b9
AW
8. ./test-lib.sh
9
0d158ebb
RR
10test_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)'
18
19test_expect_success 'git branch --help should not have created a bogus branch' '
20 test_might_fail git branch --help </dev/null >/dev/null 2>/dev/null &&
21 test_path_is_missing .git/refs/heads/--help
41ac414e 22'
a3b427b9 23
1dacfbcf
NTND
24test_expect_success 'branch -h in broken repository' '
25 mkdir broken &&
26 (
27 cd broken &&
28 git init &&
29 >.git/refs/heads/master &&
30 test_expect_code 129 git branch -h >usage 2>&1
31 ) &&
9a001381 32 test_i18ngrep "[Uu]sage" broken/usage
1dacfbcf
NTND
33'
34
0d158ebb
RR
35test_expect_success 'git branch abc should create a branch' '
36 git branch abc && test_path_is_file .git/refs/heads/abc
37'
08db81a9 38
0d158ebb
RR
39test_expect_success 'git branch a/b/c should create a branch' '
40 git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c
41'
08db81a9 42
0cb24fe8
JH
43test_expect_success 'git branch HEAD should fail' '
44 test_must_fail git branch HEAD
45'
8efb8899 46
d7fb7a37 47cat >expect <<EOF
3749fde5 48$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
d7fb7a37 49EOF
0d158ebb
RR
50test_expect_success 'git branch -l d/e/f should create a branch and a log' '
51 GIT_COMMITTER_DATE="2005-05-26 23:30" \
52 git branch -l d/e/f &&
53 test_path_is_file .git/refs/heads/d/e/f &&
54 test_path_is_file .git/logs/refs/heads/d/e/f &&
55 test_cmp expect .git/logs/refs/heads/d/e/f
56'
57
58test_expect_success 'git branch -d d/e/f should delete a branch and a log' '
59 git branch -d d/e/f &&
60 test_path_is_missing .git/refs/heads/d/e/f &&
61 test_path_is_missing .git/logs/refs/heads/d/e/f
62'
63
64test_expect_success 'git branch j/k should work after branch j has been deleted' '
65 git branch j &&
66 git branch -d j &&
67 git branch j/k
68'
69
70test_expect_success 'git branch l should work after branch l/m has been deleted' '
71 git branch l/m &&
72 git branch -d l/m &&
73 git branch l
74'
75
76test_expect_success 'git branch -m dumps usage' '
77 test_expect_code 128 git branch -m 2>err &&
8054b9a6 78 test_i18ngrep "branch name required" err
0d158ebb
RR
79'
80
81test_expect_success 'git branch -m m m/m should work' '
82 git branch -l m &&
83 git branch -m m m/m &&
84 test_path_is_file .git/logs/refs/heads/m/m
85'
86
87test_expect_success 'git branch -m n/n n should work' '
88 git branch -l n/n &&
2f139044 89 git branch -m n/n n &&
0d158ebb
RR
90 test_path_is_file .git/logs/refs/heads/n
91'
c976d415 92
41ac414e
JH
93test_expect_success 'git branch -m o/o o should fail when o/p exists' '
94 git branch o/o &&
0d158ebb 95 git branch o/p &&
d492b31c 96 test_must_fail git branch -m o/o o
41ac414e 97'
c976d415 98
41ac414e
JH
99test_expect_success 'git branch -m q r/q should fail when r exists' '
100 git branch q &&
101 git branch r &&
d492b31c 102 test_must_fail git branch -m q r/q
41ac414e 103'
c976d415 104
55c4a673
CI
105test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
106 git branch bar &&
107 git checkout -b foo &&
108 test_must_fail git branch -M bar foo
109'
110
111test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
112 git checkout -b baz &&
113 git branch bam &&
114 git branch -M baz bam
115'
116
3f59481e
JN
117test_expect_success 'git branch -M master should work when master is checked out' '
118 git checkout master &&
119 git branch -M master
120'
121
122test_expect_success 'git branch -M master master should work when master is checked out' '
123 git checkout master &&
124 git branch -M master master
125'
126
127test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
128 git checkout master &&
129 git branch master2 &&
130 git branch -M master2 master2
131'
132
cddd127b
MG
133test_expect_success 'git branch -v -d t should work' '
134 git branch t &&
376eb14a 135 test_path_is_file .git/refs/heads/t &&
cddd127b 136 git branch -v -d t &&
376eb14a 137 test_path_is_missing .git/refs/heads/t
cddd127b
MG
138'
139
140test_expect_success 'git branch -v -m t s should work' '
141 git branch t &&
376eb14a 142 test_path_is_file .git/refs/heads/t &&
cddd127b 143 git branch -v -m t s &&
376eb14a
JK
144 test_path_is_missing .git/refs/heads/t &&
145 test_path_is_file .git/refs/heads/s &&
cddd127b
MG
146 git branch -d s
147'
148
149test_expect_success 'git branch -m -d t s should fail' '
150 git branch t &&
376eb14a 151 test_path_is_file .git/refs/heads/t &&
cddd127b
MG
152 test_must_fail git branch -m -d t s &&
153 git branch -d t &&
376eb14a 154 test_path_is_missing .git/refs/heads/t
cddd127b
MG
155'
156
157test_expect_success 'git branch --list -d t should fail' '
158 git branch t &&
376eb14a 159 test_path_is_file .git/refs/heads/t &&
cddd127b
MG
160 test_must_fail git branch --list -d t &&
161 git branch -d t &&
376eb14a 162 test_path_is_missing .git/refs/heads/t
cddd127b
MG
163'
164
ebe31ef2
NTND
165test_expect_success 'git branch --column' '
166 COLUMNS=81 git branch --column=column >actual &&
167 cat >expected <<\EOF &&
168 a/b/c bam foo l * master n o/p r
169 abc bar j/k m/m master2 o/o q
170EOF
171 test_cmp expected actual
172'
173
174test_expect_success 'git branch --column with an extremely long branch name' '
175 long=this/is/a/part/of/long/branch/name &&
176 long=z$long/$long/$long/$long &&
177 test_when_finished "git branch -d $long" &&
178 git branch $long &&
179 COLUMNS=80 git branch --column=column >actual &&
180 cat >expected <<EOF &&
181 a/b/c
182 abc
183 bam
184 bar
185 foo
186 j/k
187 l
188 m/m
189* master
190 master2
191 n
192 o/o
193 o/p
194 q
195 r
196 $long
197EOF
198 test_cmp expected actual
199'
200
201test_expect_success 'git branch with column.*' '
202 git config column.ui column &&
203 git config column.branch "dense" &&
204 COLUMNS=80 git branch >actual &&
205 git config --unset column.branch &&
206 git config --unset column.ui &&
207 cat >expected <<\EOF &&
208 a/b/c bam foo l * master n o/p r
209 abc bar j/k m/m master2 o/o q
210EOF
211 test_cmp expected actual
212'
213
214test_expect_success 'git branch --column -v should fail' '
215 test_must_fail git branch --column -v
216'
217
218test_expect_success 'git branch -v with column.ui ignored' '
219 git config column.ui column &&
220 COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
221 git config --unset column.ui &&
222 cat >expected <<\EOF &&
223 a/b/c
224 abc
225 bam
226 bar
227 foo
228 j/k
229 l
230 m/m
231* master
232 master2
233 n
234 o/o
235 o/p
236 q
237 r
238EOF
239 test_cmp expected actual
240'
241
01ebb9dc
GB
242mv .git/config .git/config-saved
243
08b984fb 244test_expect_success 'git branch -m q q2 without config should succeed' '
5be60078
JH
245 git branch -m q q2 &&
246 git branch -m q2 q
01ebb9dc
GB
247'
248
249mv .git/config-saved .git/config
250
5be60078 251git config branch.s/s.dummy Hello
dc81c58c 252
0d158ebb
RR
253test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
254 git branch -l s/s &&
376eb14a 255 test_path_is_file .git/logs/refs/heads/s/s &&
0d158ebb 256 git branch -l s/t &&
376eb14a 257 test_path_is_file .git/logs/refs/heads/s/t &&
0d158ebb
RR
258 git branch -d s/t &&
259 git branch -m s/s s &&
260 test_path_is_file .git/logs/refs/heads/s
261'
c976d415 262
0d158ebb
RR
263test_expect_success 'config information was renamed, too' '
264 test $(git config branch.s.dummy) = Hello &&
265 test_must_fail git config branch.s/s/dummy
266'
dc81c58c 267
566c7707
RS
268test_expect_success 'deleting a symref' '
269 git branch target &&
270 git symbolic-ref refs/heads/symref refs/heads/target &&
13baa9fe 271 echo "Deleted branch symref (was refs/heads/target)." >expect &&
566c7707
RS
272 git branch -d symref >actual &&
273 test_path_is_file .git/refs/heads/target &&
274 test_path_is_missing .git/refs/heads/symref &&
275 test_i18ncmp expect actual
276'
277
0fe700e3
RS
278test_expect_success 'deleting a dangling symref' '
279 git symbolic-ref refs/heads/dangling-symref nowhere &&
280 test_path_is_file .git/refs/heads/dangling-symref &&
13baa9fe 281 echo "Deleted branch dangling-symref (was nowhere)." >expect &&
0fe700e3
RS
282 git branch -d dangling-symref >actual &&
283 test_path_is_missing .git/refs/heads/dangling-symref &&
284 test_i18ncmp expect actual
285'
286
0d158ebb 287test_expect_success 'renaming a symref is not allowed' '
eca35a25 288 git symbolic-ref refs/heads/master2 refs/heads/master &&
fa58186c
MV
289 test_must_fail git branch -m master2 master3 &&
290 git symbolic-ref refs/heads/master2 &&
376eb14a
JK
291 test_path_is_file .git/refs/heads/master &&
292 test_path_is_missing .git/refs/heads/master3
eca35a25
MV
293'
294
0d158ebb
RR
295test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
296 git branch -l u &&
297 mv .git/logs/refs/heads/u real-u &&
298 ln -s real-u .git/logs/refs/heads/u &&
299 test_must_fail git branch -m u v
300'
301
302test_expect_success 'test tracking setup via --track' '
303 git config remote.local.url . &&
304 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
305 (git show-ref -q refs/remotes/local/master || git fetch local) &&
306 git branch --track my1 local/master &&
307 test $(git config branch.my1.remote) = local &&
308 test $(git config branch.my1.merge) = refs/heads/master
309'
310
311test_expect_success 'test tracking setup (non-wildcard, matching)' '
312 git config remote.local.url . &&
313 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
314 (git show-ref -q refs/remotes/local/master || git fetch local) &&
315 git branch --track my4 local/master &&
316 test $(git config branch.my4.remote) = local &&
317 test $(git config branch.my4.merge) = refs/heads/master
318'
319
41c21f22 320test_expect_success 'tracking setup fails on non-matching refspec' '
0d158ebb
RR
321 git config remote.local.url . &&
322 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
323 (git show-ref -q refs/remotes/local/master || git fetch local) &&
9c9cd39a
JH
324 test_must_fail git branch --track my5 local/master &&
325 test_must_fail git config branch.my5.remote &&
326 test_must_fail git config branch.my5.merge
0d158ebb
RR
327'
328
329test_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
337'
338
339test_expect_success 'test overriding tracking setup via --no-track' '
340 git config branch.autosetupmerge true &&
341 git config remote.local.url . &&
342 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
343 (git show-ref -q refs/remotes/local/master || git fetch local) &&
344 git branch --no-track my2 local/master &&
345 git config branch.autosetupmerge false &&
346 ! test "$(git config branch.my2.remote)" = local &&
347 ! test "$(git config branch.my2.merge)" = refs/heads/master
348'
349
350test_expect_success 'no tracking without .fetch entries' '
351 git config branch.autosetupmerge true &&
352 git branch my6 s &&
353 git config branch.automsetupmerge false &&
354 test -z "$(git config branch.my6.remote)" &&
355 test -z "$(git config branch.my6.merge)"
356'
357
358test_expect_success 'test tracking setup via --track but deeper' '
359 git config remote.local.url . &&
360 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
361 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
362 git branch --track my7 local/o/o &&
363 test "$(git config branch.my7.remote)" = local &&
364 test "$(git config branch.my7.merge)" = refs/heads/o/o
365'
366
367test_expect_success 'test deleting branch deletes branch config' '
368 git branch -d my7 &&
369 test -z "$(git config branch.my7.remote)" &&
370 test -z "$(git config branch.my7.merge)"
371'
372
373test_expect_success 'test deleting branch without config' '
374 git branch my7 s &&
375 sha1=$(git rev-parse my7 | cut -c 1-7) &&
376 echo "Deleted branch my7 (was $sha1)." >expect &&
377 git branch -d my7 >actual 2>&1 &&
378 test_i18ncmp expect actual
379'
380
381test_expect_success 'test --track without .fetch entries' '
382 git branch --track my8 &&
383 test "$(git config branch.my8.remote)" &&
384 test "$(git config branch.my8.merge)"
385'
386
387test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
388 git config branch.autosetupmerge always &&
389 git branch my9 HEAD^ &&
390 git config branch.autosetupmerge false
391'
392
393test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
394 test_must_fail git branch --track my10 HEAD^
395'
396
397test_expect_success 'branch from tag w/--track causes failure' '
398 git tag foobar &&
399 test_must_fail git branch --track my11 foobar
400'
401
0cb24fe8
JH
402test_expect_success '--set-upstream-to fails on multiple branches' '
403 test_must_fail git branch --set-upstream-to master a b c
404'
405
406test_expect_success '--set-upstream-to fails on detached HEAD' '
407 git checkout HEAD^{} &&
408 test_must_fail git branch --set-upstream-to master &&
409 git checkout -
410'
411
8a3e5ecd
JK
412test_expect_success '--set-upstream-to fails on a missing dst branch' '
413 test_must_fail git branch --set-upstream-to master does-not-exist
414'
415
416test_expect_success '--set-upstream-to fails on a missing src branch' '
417 test_must_fail git branch --set-upstream-to does-not-exist master
418'
419
420test_expect_success '--set-upstream-to fails on a non-ref' '
421 test_must_fail git branch --set-upstream-to HEAD^{}
422'
423
0d158ebb
RR
424test_expect_success 'use --set-upstream-to modify HEAD' '
425 test_config branch.master.remote foo &&
426 test_config branch.master.merge foo &&
427 git branch my12
428 git branch --set-upstream-to my12 &&
429 test "$(git config branch.master.remote)" = "." &&
430 test "$(git config branch.master.merge)" = "refs/heads/my12"
431'
432
433test_expect_success 'use --set-upstream-to modify a particular branch' '
434 git branch my13
435 git branch --set-upstream-to master my13 &&
436 test "$(git config branch.my13.remote)" = "." &&
437 test "$(git config branch.my13.merge)" = "refs/heads/master"
438'
439
440test_expect_success '--unset-upstream should fail if given a non-existent branch' '
441 test_must_fail git branch --unset-upstream i-dont-exist
442'
443
444test_expect_success 'test --unset-upstream on HEAD' '
445 git branch my14
446 test_config branch.master.remote foo &&
447 test_config branch.master.merge foo &&
448 git branch --set-upstream-to my14 &&
449 git branch --unset-upstream &&
450 test_must_fail git config branch.master.remote &&
451 test_must_fail git config branch.master.merge &&
452 # fail for a branch without upstream set
453 test_must_fail git branch --unset-upstream
454'
455
0cb24fe8
JH
456test_expect_success '--unset-upstream should fail on multiple branches' '
457 test_must_fail git branch --unset-upstream a b c
458'
459
460test_expect_success '--unset-upstream should fail on detached HEAD' '
461 git checkout HEAD^{} &&
462 test_must_fail git branch --unset-upstream &&
463 git checkout -
464'
465
0d158ebb
RR
466test_expect_success 'test --unset-upstream on a particular branch' '
467 git branch my15
468 git branch --set-upstream-to master my14 &&
469 git branch --unset-upstream my14 &&
470 test_must_fail git config branch.my14.remote &&
471 test_must_fail git config branch.my14.merge
472'
473
474test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
475 git update-ref refs/remotes/origin/master HEAD &&
476 git branch --set-upstream origin/master 2>actual &&
477 test_when_finished git update-ref -d refs/remotes/origin/master &&
478 test_when_finished git branch -d origin/master &&
479 cat >expected <<EOF &&
b347d06b
CMN
480The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
481
482If you wanted to make '"'master'"' track '"'origin/master'"', do this:
483
484 git branch -d origin/master
485 git branch --set-upstream-to origin/master
486EOF
0d158ebb 487 test_cmp expected actual
b347d06b
CMN
488'
489
0d158ebb
RR
490test_expect_success '--set-upstream with two args only shows the deprecation message' '
491 git branch --set-upstream master my13 2>actual &&
492 test_when_finished git branch --unset-upstream master &&
493 cat >expected <<EOF &&
b347d06b
CMN
494The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
495EOF
0d158ebb 496 test_cmp expected actual
b347d06b
CMN
497'
498
0d158ebb
RR
499test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
500 git branch --set-upstream my13 2>actual &&
501 test_when_finished git branch --unset-upstream my13 &&
502 cat >expected <<EOF &&
b347d06b
CMN
503The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
504EOF
0d158ebb 505 test_cmp expected actual
b347d06b
CMN
506'
507
0746d19a
PB
508# Keep this test last, as it changes the current branch
509cat >expect <<EOF
3749fde5 510$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
0746d19a 511EOF
0d158ebb
RR
512test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
513 GIT_COMMITTER_DATE="2005-05-26 23:30" \
514 git checkout -b g/h/i -l master &&
515 test_path_is_file .git/refs/heads/g/h/i &&
516 test_path_is_file .git/logs/refs/heads/g/h/i &&
517 test_cmp expect .git/logs/refs/heads/g/h/i
518'
0746d19a 519
b2099957
EM
520test_expect_success 'checkout -b makes reflog by default' '
521 git checkout master &&
522 git config --unset core.logAllRefUpdates &&
523 git checkout -b alpha &&
6e6842e3 524 git rev-parse --verify alpha@{0}
b2099957
EM
525'
526
527test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
528 git checkout master &&
529 git config core.logAllRefUpdates false &&
530 git checkout -b beta &&
6e6842e3 531 test_must_fail git rev-parse --verify beta@{0}
b2099957
EM
532'
533
534test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
535 git checkout master &&
536 git checkout -lb gamma &&
537 git config --unset core.logAllRefUpdates &&
6e6842e3 538 git rev-parse --verify gamma@{0}
b2099957
EM
539'
540
1d0a694b
DB
541test_expect_success 'avoid ambiguous track' '
542 git config branch.autosetupmerge true &&
543 git config remote.ambi1.url lalala &&
544 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
545 git config remote.ambi2.url lilili &&
546 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
547 git branch all1 master &&
548 test -z "$(git config branch.all1.merge)"
549'
550
c998ae9b
DS
551test_expect_success 'autosetuprebase local on a tracked local branch' '
552 git config remote.local.url . &&
553 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
554 git config branch.autosetuprebase local &&
0cb0e143 555 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
556 git branch mybase &&
557 git branch --track myr1 mybase &&
558 test "$(git config branch.myr1.remote)" = . &&
559 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
560 test "$(git config branch.myr1.rebase)" = true
561'
562
563test_expect_success 'autosetuprebase always on a tracked local branch' '
564 git config remote.local.url . &&
565 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
566 git config branch.autosetuprebase always &&
0cb0e143 567 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
568 git branch mybase2 &&
569 git branch --track myr2 mybase &&
570 test "$(git config branch.myr2.remote)" = . &&
571 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
572 test "$(git config branch.myr2.rebase)" = true
573'
574
575test_expect_success 'autosetuprebase remote on a tracked local branch' '
576 git config remote.local.url . &&
577 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
578 git config branch.autosetuprebase remote &&
0cb0e143 579 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
580 git branch mybase3 &&
581 git branch --track myr3 mybase2 &&
582 test "$(git config branch.myr3.remote)" = . &&
583 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
584 ! test "$(git config branch.myr3.rebase)" = true
585'
586
587test_expect_success 'autosetuprebase never on a tracked local branch' '
588 git config remote.local.url . &&
589 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
590 git config branch.autosetuprebase never &&
0cb0e143 591 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
592 git branch mybase4 &&
593 git branch --track myr4 mybase2 &&
594 test "$(git config branch.myr4.remote)" = . &&
595 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
596 ! test "$(git config branch.myr4.rebase)" = true
597'
598
599test_expect_success 'autosetuprebase local on a tracked remote branch' '
600 git config remote.local.url . &&
601 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
602 git config branch.autosetuprebase local &&
0cb0e143 603 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
604 git branch --track myr5 local/master &&
605 test "$(git config branch.myr5.remote)" = local &&
606 test "$(git config branch.myr5.merge)" = refs/heads/master &&
607 ! test "$(git config branch.myr5.rebase)" = true
608'
609
610test_expect_success 'autosetuprebase never on a tracked remote branch' '
611 git config remote.local.url . &&
612 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
613 git config branch.autosetuprebase never &&
0cb0e143 614 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
615 git branch --track myr6 local/master &&
616 test "$(git config branch.myr6.remote)" = local &&
617 test "$(git config branch.myr6.merge)" = refs/heads/master &&
618 ! test "$(git config branch.myr6.rebase)" = true
619'
620
621test_expect_success 'autosetuprebase remote on a tracked remote branch' '
622 git config remote.local.url . &&
623 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
624 git config branch.autosetuprebase remote &&
0cb0e143 625 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
626 git branch --track myr7 local/master &&
627 test "$(git config branch.myr7.remote)" = local &&
628 test "$(git config branch.myr7.merge)" = refs/heads/master &&
629 test "$(git config branch.myr7.rebase)" = true
630'
631
632test_expect_success 'autosetuprebase always on a tracked remote branch' '
633 git config remote.local.url . &&
634 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
635 git config branch.autosetuprebase remote &&
0cb0e143 636 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
637 git branch --track myr8 local/master &&
638 test "$(git config branch.myr8.remote)" = local &&
639 test "$(git config branch.myr8.merge)" = refs/heads/master &&
640 test "$(git config branch.myr8.rebase)" = true
641'
642
643test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
644 git config --unset branch.autosetuprebase &&
645 git config remote.local.url . &&
646 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 647 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
648 git branch --track myr9 local/master &&
649 test "$(git config branch.myr9.remote)" = local &&
650 test "$(git config branch.myr9.merge)" = refs/heads/master &&
651 test "z$(git config branch.myr9.rebase)" = z
652'
653
654test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
655 git config remote.local.url . &&
656 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 657 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
658 git branch mybase10 &&
659 git branch --track myr10 mybase2 &&
660 test "$(git config branch.myr10.remote)" = . &&
661 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
662 test "z$(git config branch.myr10.rebase)" = z
663'
664
665test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
666 git config remote.local.url . &&
667 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 668 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
669 git branch --no-track myr11 mybase2 &&
670 test "z$(git config branch.myr11.remote)" = z &&
671 test "z$(git config branch.myr11.merge)" = z &&
672 test "z$(git config branch.myr11.rebase)" = z
673'
674
675test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
676 git config remote.local.url . &&
677 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 678 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
679 git branch --no-track myr12 local/master &&
680 test "z$(git config branch.myr12.remote)" = z &&
681 test "z$(git config branch.myr12.merge)" = z &&
682 test "z$(git config branch.myr12.rebase)" = z
683'
684
685test_expect_success 'autosetuprebase never on an untracked local branch' '
686 git config branch.autosetuprebase never &&
687 git config remote.local.url . &&
688 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 689 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
690 git branch --no-track myr13 mybase2 &&
691 test "z$(git config branch.myr13.remote)" = z &&
692 test "z$(git config branch.myr13.merge)" = z &&
693 test "z$(git config branch.myr13.rebase)" = z
694'
695
696test_expect_success 'autosetuprebase local on an untracked local branch' '
697 git config branch.autosetuprebase local &&
698 git config remote.local.url . &&
699 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 700 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
701 git branch --no-track myr14 mybase2 &&
702 test "z$(git config branch.myr14.remote)" = z &&
703 test "z$(git config branch.myr14.merge)" = z &&
704 test "z$(git config branch.myr14.rebase)" = z
705'
706
707test_expect_success 'autosetuprebase remote on an untracked local branch' '
708 git config branch.autosetuprebase remote &&
709 git config remote.local.url . &&
710 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 711 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
712 git branch --no-track myr15 mybase2 &&
713 test "z$(git config branch.myr15.remote)" = z &&
714 test "z$(git config branch.myr15.merge)" = z &&
715 test "z$(git config branch.myr15.rebase)" = z
716'
717
718test_expect_success 'autosetuprebase always on an untracked local branch' '
719 git config branch.autosetuprebase always &&
720 git config remote.local.url . &&
721 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 722 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
723 git branch --no-track myr16 mybase2 &&
724 test "z$(git config branch.myr16.remote)" = z &&
725 test "z$(git config branch.myr16.merge)" = z &&
726 test "z$(git config branch.myr16.rebase)" = z
727'
728
729test_expect_success 'autosetuprebase never on an untracked remote branch' '
730 git config branch.autosetuprebase never &&
731 git config remote.local.url . &&
732 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 733 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
734 git branch --no-track myr17 local/master &&
735 test "z$(git config branch.myr17.remote)" = z &&
736 test "z$(git config branch.myr17.merge)" = z &&
737 test "z$(git config branch.myr17.rebase)" = z
738'
739
740test_expect_success 'autosetuprebase local on an untracked remote branch' '
741 git config branch.autosetuprebase local &&
742 git config remote.local.url . &&
743 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 744 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
745 git branch --no-track myr18 local/master &&
746 test "z$(git config branch.myr18.remote)" = z &&
747 test "z$(git config branch.myr18.merge)" = z &&
748 test "z$(git config branch.myr18.rebase)" = z
749'
750
751test_expect_success 'autosetuprebase remote on an untracked remote branch' '
752 git config branch.autosetuprebase remote &&
753 git config remote.local.url . &&
754 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 755 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
756 git branch --no-track myr19 local/master &&
757 test "z$(git config branch.myr19.remote)" = z &&
758 test "z$(git config branch.myr19.merge)" = z &&
759 test "z$(git config branch.myr19.rebase)" = z
760'
761
762test_expect_success 'autosetuprebase always on an untracked remote branch' '
763 git config branch.autosetuprebase always &&
764 git config remote.local.url . &&
765 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 766 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
767 git branch --no-track myr20 local/master &&
768 test "z$(git config branch.myr20.remote)" = z &&
769 test "z$(git config branch.myr20.merge)" = z &&
770 test "z$(git config branch.myr20.rebase)" = z
771'
772
21b5b1e8
JH
773test_expect_success 'autosetuprebase always on detached HEAD' '
774 git config branch.autosetupmerge always &&
775 test_when_finished git checkout master &&
776 git checkout HEAD^0 &&
777 git branch my11 &&
778 test -z "$(git config branch.my11.remote)" &&
779 test -z "$(git config branch.my11.merge)"
780'
781
c998ae9b
DS
782test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
783 git config branch.autosetuprebase garbage &&
784 test_must_fail git branch
785'
786
787test_expect_success 'detect misconfigured autosetuprebase (no value)' '
788 git config --unset branch.autosetuprebase &&
0d158ebb 789 echo "[branch] autosetuprebase" >>.git/config &&
c998ae9b
DS
790 test_must_fail git branch &&
791 git config --unset branch.autosetuprebase
792'
793
99c419c9
JH
794test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
795 git checkout my9 &&
796 git config --unset branch.my8.merge &&
797 test_must_fail git branch -d my8
798'
799
800test_expect_success 'attempt to delete a branch merged to its base' '
801 # we are on my9 which is the initial commit; traditionally
802 # we would not have allowed deleting my8 that is not merged
803 # to my9, but it is set to track master that already has my8
804 git config branch.my8.merge refs/heads/master &&
805 git branch -d my8
806'
807
808test_expect_success 'attempt to delete a branch merged to its base' '
809 git checkout master &&
810 echo Third >>A &&
811 git commit -m "Third commit" A &&
812 git branch -t my10 my9 &&
813 git branch -f my10 HEAD^ &&
814 # we are on master which is at the third commit, and my10
815 # is behind us, so traditionally we would have allowed deleting
816 # it; but my10 is set to track my9 that is further behind.
817 test_must_fail git branch -d my10
818'
819
fa799376
JH
820test_expect_success 'use set-upstream on the current branch' '
821 git checkout master &&
822 git --bare init myupstream.git &&
823 git push myupstream.git master:refs/heads/frotz &&
824 git remote add origin myupstream.git &&
825 git fetch &&
826 git branch --set-upstream master origin/frotz &&
827
828 test "z$(git config branch.master.remote)" = "zorigin" &&
829 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
830
831'
832
c2d17ba3
JH
833test_expect_success 'use --edit-description' '
834 write_script editor <<-\EOF &&
835 echo "New contents" >"$1"
836 EOF
837 EDITOR=./editor git branch --edit-description &&
838 write_script editor <<-\EOF &&
839 git stripspace -s <"$1" >"EDITOR_OUTPUT"
840 EOF
841 EDITOR=./editor git branch --edit-description &&
842 echo "New contents" >expect &&
843 test_cmp EDITOR_OUTPUT expect
844'
845
846test_expect_success 'detect typo in branch name when using --edit-description' '
847 write_script editor <<-\EOF &&
848 echo "New contents" >"$1"
849 EOF
850 (
851 EDITOR=./editor &&
852 export EDITOR &&
853 test_must_fail git branch --edit-description no-such-branch
854 )
855'
856
857test_expect_success 'refuse --edit-description on unborn branch for now' '
858 write_script editor <<-\EOF &&
859 echo "New contents" >"$1"
860 EOF
861 git checkout --orphan unborn &&
862 (
863 EDITOR=./editor &&
864 export EDITOR &&
865 test_must_fail git branch --edit-description
866 )
867'
868
6c41e975
CMN
869test_expect_success '--merged catches invalid object names' '
870 test_must_fail git branch --merged 0000000000000000000000000000000000000000
871'
872
a3b427b9 873test_done