]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3200-branch.sh
help: reuse print_columns() for help -a
[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
01ebb9dc
GB
163mv .git/config .git/config-saved
164
08b984fb 165test_expect_success 'git branch -m q q2 without config should succeed' '
5be60078
JH
166 git branch -m q q2 &&
167 git branch -m q2 q
01ebb9dc
GB
168'
169
170mv .git/config-saved .git/config
171
5be60078 172git config branch.s/s.dummy Hello
dc81c58c 173
c976d415
LH
174test_expect_success \
175 'git branch -m s/s s should work when s/t is deleted' \
5be60078 176 'git branch -l s/s &&
376eb14a 177 test_path_is_file .git/logs/refs/heads/s/s &&
5be60078 178 git branch -l s/t &&
376eb14a 179 test_path_is_file .git/logs/refs/heads/s/t &&
5be60078
JH
180 git branch -d s/t &&
181 git branch -m s/s s &&
376eb14a 182 test_path_is_file .git/logs/refs/heads/s'
c976d415 183
dc81c58c 184test_expect_success 'config information was renamed, too' \
5be60078 185 "test $(git config branch.s.dummy) = Hello &&
d492b31c 186 test_must_fail git config branch.s/s/dummy"
dc81c58c 187
fa58186c 188test_expect_success 'renaming a symref is not allowed' \
eca35a25
MV
189'
190 git symbolic-ref refs/heads/master2 refs/heads/master &&
fa58186c
MV
191 test_must_fail git branch -m master2 master3 &&
192 git symbolic-ref refs/heads/master2 &&
376eb14a
JK
193 test_path_is_file .git/refs/heads/master &&
194 test_path_is_missing .git/refs/heads/master3
eca35a25
MV
195'
196
704a3143 197test_expect_success SYMLINKS \
41ac414e
JH
198 'git branch -m u v should fail when the reflog for u is a symlink' '
199 git branch -l u &&
16c2bfbb
LH
200 mv .git/logs/refs/heads/u real-u &&
201 ln -s real-u .git/logs/refs/heads/u &&
d492b31c 202 test_must_fail git branch -m u v
41ac414e 203'
16c2bfbb 204
0746d19a 205test_expect_success 'test tracking setup via --track' \
5be60078
JH
206 'git config remote.local.url . &&
207 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 208 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
209 git branch --track my1 local/master &&
210 test $(git config branch.my1.remote) = local &&
211 test $(git config branch.my1.merge) = refs/heads/master'
0746d19a
PB
212
213test_expect_success 'test tracking setup (non-wildcard, matching)' \
5be60078
JH
214 'git config remote.local.url . &&
215 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
0cb0e143 216 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
217 git branch --track my4 local/master &&
218 test $(git config branch.my4.remote) = local &&
219 test $(git config branch.my4.merge) = refs/heads/master'
0746d19a
PB
220
221test_expect_success 'test tracking setup (non-wildcard, not matching)' \
5be60078
JH
222 'git config remote.local.url . &&
223 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
0cb0e143 224 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
225 git branch --track my5 local/master &&
226 ! test "$(git config branch.my5.remote)" = local &&
227 ! test "$(git config branch.my5.merge)" = refs/heads/master'
0746d19a
PB
228
229test_expect_success 'test tracking setup via config' \
5be60078
JH
230 'git config branch.autosetupmerge true &&
231 git config remote.local.url . &&
232 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 233 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
234 git branch my3 local/master &&
235 test $(git config branch.my3.remote) = local &&
236 test $(git config branch.my3.merge) = refs/heads/master'
0746d19a
PB
237
238test_expect_success 'test overriding tracking setup via --no-track' \
5be60078
JH
239 'git config branch.autosetupmerge true &&
240 git config remote.local.url . &&
241 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 242 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
243 git branch --no-track my2 local/master &&
244 git config branch.autosetupmerge false &&
245 ! test "$(git config branch.my2.remote)" = local &&
246 ! test "$(git config branch.my2.merge)" = refs/heads/master'
0746d19a 247
6f084a56 248test_expect_success 'no tracking without .fetch entries' \
9ed36cfa
JS
249 'git config branch.autosetupmerge true &&
250 git branch my6 s &&
251 git config branch.automsetupmerge false &&
6f084a56
JS
252 test -z "$(git config branch.my6.remote)" &&
253 test -z "$(git config branch.my6.merge)"'
9debc324 254
11f68d90 255test_expect_success 'test tracking setup via --track but deeper' \
5be60078
JH
256 'git config remote.local.url . &&
257 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 258 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
5be60078
JH
259 git branch --track my7 local/o/o &&
260 test "$(git config branch.my7.remote)" = local &&
261 test "$(git config branch.my7.merge)" = refs/heads/o/o'
11f68d90 262
f1eccbab 263test_expect_success 'test deleting branch deletes branch config' \
5be60078 264 'git branch -d my7 &&
6f084a56
JS
265 test -z "$(git config branch.my7.remote)" &&
266 test -z "$(git config branch.my7.merge)"'
f1eccbab 267
f2c8c800 268test_expect_success 'test deleting branch without config' \
5be60078 269 'git branch my7 s &&
a126ed0a 270 sha1=$(git rev-parse my7 | cut -c 1-7) &&
f2c8c800
JH
271 echo "Deleted branch my7 (was $sha1)." >expect &&
272 git branch -d my7 >actual 2>&1 &&
273 test_i18ncmp expect actual'
f1eccbab 274
9ed36cfa
JS
275test_expect_success 'test --track without .fetch entries' \
276 'git branch --track my8 &&
277 test "$(git config branch.my8.remote)" &&
278 test "$(git config branch.my8.merge)"'
279
280test_expect_success \
281 'branch from non-branch HEAD w/autosetupmerge=always' \
282 'git config branch.autosetupmerge always &&
283 git branch my9 HEAD^ &&
284 git config branch.autosetupmerge false'
285
286test_expect_success \
287 'branch from non-branch HEAD w/--track causes failure' \
03b9dfb1 288 'test_must_fail git branch --track my10 HEAD^'
9ed36cfa 289
21b5b1e8
JH
290test_expect_success \
291 'branch from tag w/--track causes failure' \
292 'git tag foobar &&
293 test_must_fail git branch --track my11 foobar'
294
0746d19a
PB
295# Keep this test last, as it changes the current branch
296cat >expect <<EOF
3749fde5 297$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
0746d19a
PB
298EOF
299test_expect_success \
300 'git checkout -b g/h/i -l should create a branch and a log' \
301 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
0cb0e143 302 git checkout -b g/h/i -l master &&
376eb14a
JK
303 test_path_is_file .git/refs/heads/g/h/i &&
304 test_path_is_file .git/logs/refs/heads/g/h/i &&
4fdf71be 305 test_cmp expect .git/logs/refs/heads/g/h/i'
0746d19a 306
b2099957
EM
307test_expect_success 'checkout -b makes reflog by default' '
308 git checkout master &&
309 git config --unset core.logAllRefUpdates &&
310 git checkout -b alpha &&
6e6842e3 311 git rev-parse --verify alpha@{0}
b2099957
EM
312'
313
314test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
315 git checkout master &&
316 git config core.logAllRefUpdates false &&
317 git checkout -b beta &&
6e6842e3 318 test_must_fail git rev-parse --verify beta@{0}
b2099957
EM
319'
320
321test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
322 git checkout master &&
323 git checkout -lb gamma &&
324 git config --unset core.logAllRefUpdates &&
6e6842e3 325 git rev-parse --verify gamma@{0}
b2099957
EM
326'
327
1d0a694b
DB
328test_expect_success 'avoid ambiguous track' '
329 git config branch.autosetupmerge true &&
330 git config remote.ambi1.url lalala &&
331 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
332 git config remote.ambi2.url lilili &&
333 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
334 git branch all1 master &&
335 test -z "$(git config branch.all1.merge)"
336'
337
c998ae9b
DS
338test_expect_success 'autosetuprebase local on a tracked local branch' '
339 git config remote.local.url . &&
340 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
341 git config branch.autosetuprebase local &&
0cb0e143 342 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
343 git branch mybase &&
344 git branch --track myr1 mybase &&
345 test "$(git config branch.myr1.remote)" = . &&
346 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
347 test "$(git config branch.myr1.rebase)" = true
348'
349
350test_expect_success 'autosetuprebase always on a tracked local branch' '
351 git config remote.local.url . &&
352 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
353 git config branch.autosetuprebase always &&
0cb0e143 354 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
355 git branch mybase2 &&
356 git branch --track myr2 mybase &&
357 test "$(git config branch.myr2.remote)" = . &&
358 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
359 test "$(git config branch.myr2.rebase)" = true
360'
361
362test_expect_success 'autosetuprebase remote on a tracked local branch' '
363 git config remote.local.url . &&
364 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
365 git config branch.autosetuprebase remote &&
0cb0e143 366 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
367 git branch mybase3 &&
368 git branch --track myr3 mybase2 &&
369 test "$(git config branch.myr3.remote)" = . &&
370 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
371 ! test "$(git config branch.myr3.rebase)" = true
372'
373
374test_expect_success 'autosetuprebase never on a tracked local branch' '
375 git config remote.local.url . &&
376 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
377 git config branch.autosetuprebase never &&
0cb0e143 378 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
379 git branch mybase4 &&
380 git branch --track myr4 mybase2 &&
381 test "$(git config branch.myr4.remote)" = . &&
382 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
383 ! test "$(git config branch.myr4.rebase)" = true
384'
385
386test_expect_success 'autosetuprebase local on a tracked remote branch' '
387 git config remote.local.url . &&
388 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
389 git config branch.autosetuprebase local &&
0cb0e143 390 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
391 git branch --track myr5 local/master &&
392 test "$(git config branch.myr5.remote)" = local &&
393 test "$(git config branch.myr5.merge)" = refs/heads/master &&
394 ! test "$(git config branch.myr5.rebase)" = true
395'
396
397test_expect_success 'autosetuprebase never on a tracked remote branch' '
398 git config remote.local.url . &&
399 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
400 git config branch.autosetuprebase never &&
0cb0e143 401 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
402 git branch --track myr6 local/master &&
403 test "$(git config branch.myr6.remote)" = local &&
404 test "$(git config branch.myr6.merge)" = refs/heads/master &&
405 ! test "$(git config branch.myr6.rebase)" = true
406'
407
408test_expect_success 'autosetuprebase remote on a tracked remote branch' '
409 git config remote.local.url . &&
410 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
411 git config branch.autosetuprebase remote &&
0cb0e143 412 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
413 git branch --track myr7 local/master &&
414 test "$(git config branch.myr7.remote)" = local &&
415 test "$(git config branch.myr7.merge)" = refs/heads/master &&
416 test "$(git config branch.myr7.rebase)" = true
417'
418
419test_expect_success 'autosetuprebase always on a tracked remote branch' '
420 git config remote.local.url . &&
421 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
422 git config branch.autosetuprebase remote &&
0cb0e143 423 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
424 git branch --track myr8 local/master &&
425 test "$(git config branch.myr8.remote)" = local &&
426 test "$(git config branch.myr8.merge)" = refs/heads/master &&
427 test "$(git config branch.myr8.rebase)" = true
428'
429
430test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
431 git config --unset branch.autosetuprebase &&
432 git config remote.local.url . &&
433 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 434 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
435 git branch --track myr9 local/master &&
436 test "$(git config branch.myr9.remote)" = local &&
437 test "$(git config branch.myr9.merge)" = refs/heads/master &&
438 test "z$(git config branch.myr9.rebase)" = z
439'
440
441test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
442 git config remote.local.url . &&
443 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 444 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
445 git branch mybase10 &&
446 git branch --track myr10 mybase2 &&
447 test "$(git config branch.myr10.remote)" = . &&
448 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
449 test "z$(git config branch.myr10.rebase)" = z
450'
451
452test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
453 git config remote.local.url . &&
454 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 455 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
456 git branch --no-track myr11 mybase2 &&
457 test "z$(git config branch.myr11.remote)" = z &&
458 test "z$(git config branch.myr11.merge)" = z &&
459 test "z$(git config branch.myr11.rebase)" = z
460'
461
462test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
463 git config remote.local.url . &&
464 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 465 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
466 git branch --no-track myr12 local/master &&
467 test "z$(git config branch.myr12.remote)" = z &&
468 test "z$(git config branch.myr12.merge)" = z &&
469 test "z$(git config branch.myr12.rebase)" = z
470'
471
472test_expect_success 'autosetuprebase never on an untracked local branch' '
473 git config branch.autosetuprebase never &&
474 git config remote.local.url . &&
475 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 476 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
477 git branch --no-track myr13 mybase2 &&
478 test "z$(git config branch.myr13.remote)" = z &&
479 test "z$(git config branch.myr13.merge)" = z &&
480 test "z$(git config branch.myr13.rebase)" = z
481'
482
483test_expect_success 'autosetuprebase local on an untracked local branch' '
484 git config branch.autosetuprebase local &&
485 git config remote.local.url . &&
486 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 487 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
488 git branch --no-track myr14 mybase2 &&
489 test "z$(git config branch.myr14.remote)" = z &&
490 test "z$(git config branch.myr14.merge)" = z &&
491 test "z$(git config branch.myr14.rebase)" = z
492'
493
494test_expect_success 'autosetuprebase remote on an untracked local branch' '
495 git config branch.autosetuprebase remote &&
496 git config remote.local.url . &&
497 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 498 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
499 git branch --no-track myr15 mybase2 &&
500 test "z$(git config branch.myr15.remote)" = z &&
501 test "z$(git config branch.myr15.merge)" = z &&
502 test "z$(git config branch.myr15.rebase)" = z
503'
504
505test_expect_success 'autosetuprebase always on an untracked local branch' '
506 git config branch.autosetuprebase always &&
507 git config remote.local.url . &&
508 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 509 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
510 git branch --no-track myr16 mybase2 &&
511 test "z$(git config branch.myr16.remote)" = z &&
512 test "z$(git config branch.myr16.merge)" = z &&
513 test "z$(git config branch.myr16.rebase)" = z
514'
515
516test_expect_success 'autosetuprebase never on an untracked remote branch' '
517 git config branch.autosetuprebase never &&
518 git config remote.local.url . &&
519 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 520 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
521 git branch --no-track myr17 local/master &&
522 test "z$(git config branch.myr17.remote)" = z &&
523 test "z$(git config branch.myr17.merge)" = z &&
524 test "z$(git config branch.myr17.rebase)" = z
525'
526
527test_expect_success 'autosetuprebase local on an untracked remote branch' '
528 git config branch.autosetuprebase local &&
529 git config remote.local.url . &&
530 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 531 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
532 git branch --no-track myr18 local/master &&
533 test "z$(git config branch.myr18.remote)" = z &&
534 test "z$(git config branch.myr18.merge)" = z &&
535 test "z$(git config branch.myr18.rebase)" = z
536'
537
538test_expect_success 'autosetuprebase remote on an untracked remote branch' '
539 git config branch.autosetuprebase remote &&
540 git config remote.local.url . &&
541 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 542 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
543 git branch --no-track myr19 local/master &&
544 test "z$(git config branch.myr19.remote)" = z &&
545 test "z$(git config branch.myr19.merge)" = z &&
546 test "z$(git config branch.myr19.rebase)" = z
547'
548
549test_expect_success 'autosetuprebase always on an untracked remote branch' '
550 git config branch.autosetuprebase always &&
551 git config remote.local.url . &&
552 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 553 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
554 git branch --no-track myr20 local/master &&
555 test "z$(git config branch.myr20.remote)" = z &&
556 test "z$(git config branch.myr20.merge)" = z &&
557 test "z$(git config branch.myr20.rebase)" = z
558'
559
21b5b1e8
JH
560test_expect_success 'autosetuprebase always on detached HEAD' '
561 git config branch.autosetupmerge always &&
562 test_when_finished git checkout master &&
563 git checkout HEAD^0 &&
564 git branch my11 &&
565 test -z "$(git config branch.my11.remote)" &&
566 test -z "$(git config branch.my11.merge)"
567'
568
c998ae9b
DS
569test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
570 git config branch.autosetuprebase garbage &&
571 test_must_fail git branch
572'
573
574test_expect_success 'detect misconfigured autosetuprebase (no value)' '
575 git config --unset branch.autosetuprebase &&
576 echo "[branch] autosetuprebase" >> .git/config &&
577 test_must_fail git branch &&
578 git config --unset branch.autosetuprebase
579'
580
99c419c9
JH
581test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
582 git checkout my9 &&
583 git config --unset branch.my8.merge &&
584 test_must_fail git branch -d my8
585'
586
587test_expect_success 'attempt to delete a branch merged to its base' '
588 # we are on my9 which is the initial commit; traditionally
589 # we would not have allowed deleting my8 that is not merged
590 # to my9, but it is set to track master that already has my8
591 git config branch.my8.merge refs/heads/master &&
592 git branch -d my8
593'
594
595test_expect_success 'attempt to delete a branch merged to its base' '
596 git checkout master &&
597 echo Third >>A &&
598 git commit -m "Third commit" A &&
599 git branch -t my10 my9 &&
600 git branch -f my10 HEAD^ &&
601 # we are on master which is at the third commit, and my10
602 # is behind us, so traditionally we would have allowed deleting
603 # it; but my10 is set to track my9 that is further behind.
604 test_must_fail git branch -d my10
605'
606
fa799376
JH
607test_expect_success 'use set-upstream on the current branch' '
608 git checkout master &&
609 git --bare init myupstream.git &&
610 git push myupstream.git master:refs/heads/frotz &&
611 git remote add origin myupstream.git &&
612 git fetch &&
613 git branch --set-upstream master origin/frotz &&
614
615 test "z$(git config branch.master.remote)" = "zorigin" &&
616 test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
617
618'
619
c2d17ba3
JH
620test_expect_success 'use --edit-description' '
621 write_script editor <<-\EOF &&
622 echo "New contents" >"$1"
623 EOF
624 EDITOR=./editor git branch --edit-description &&
625 write_script editor <<-\EOF &&
626 git stripspace -s <"$1" >"EDITOR_OUTPUT"
627 EOF
628 EDITOR=./editor git branch --edit-description &&
629 echo "New contents" >expect &&
630 test_cmp EDITOR_OUTPUT expect
631'
632
633test_expect_success 'detect typo in branch name when using --edit-description' '
634 write_script editor <<-\EOF &&
635 echo "New contents" >"$1"
636 EOF
637 (
638 EDITOR=./editor &&
639 export EDITOR &&
640 test_must_fail git branch --edit-description no-such-branch
641 )
642'
643
644test_expect_success 'refuse --edit-description on unborn branch for now' '
645 write_script editor <<-\EOF &&
646 echo "New contents" >"$1"
647 EOF
648 git checkout --orphan unborn &&
649 (
650 EDITOR=./editor &&
651 export EDITOR &&
652 test_must_fail git branch --edit-description
653 )
654'
655
a3b427b9 656test_done