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