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