]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3200-branch.sh
branch: -v does not automatically imply --list
[thirdparty/git.git] / t / t3200-branch.sh
CommitLineData
a3b427b9
AW
1#!/bin/sh
2#
3# Copyright (c) 2005 Amos Waterland
4#
5
6test_description='git branch --foo should not create bogus branch
7
8This test runs git branch --help and checks that the argument is properly
9handled. Specifically, that a bogus branch is not created.
10'
11. ./test-lib.sh
12
13test_expect_success \
4c84f0dc 14 'prepare a trivial repository' \
a3b427b9 15 'echo Hello > A &&
5be60078 16 git update-index --add A &&
0cb0e143 17 git commit -m "Initial commit." &&
9ed36cfa
JS
18 echo World >> A &&
19 git update-index --add A &&
0cb0e143 20 git commit -m "Second commit." &&
5be60078 21 HEAD=$(git rev-parse --verify HEAD)'
a3b427b9 22
41ac414e
JH
23test_expect_success \
24 'git branch --help should not have created a bogus branch' '
25 git branch --help </dev/null >/dev/null 2>/dev/null;
26 ! test -f .git/refs/heads/--help
27'
a3b427b9 28
1dacfbcf
NTND
29test_expect_success 'branch -h in broken repository' '
30 mkdir broken &&
31 (
32 cd broken &&
33 git init &&
34 >.git/refs/heads/master &&
35 test_expect_code 129 git branch -h >usage 2>&1
36 ) &&
37 grep "[Uu]sage" broken/usage
38'
39
08db81a9
AR
40test_expect_success \
41 'git branch abc should create a branch' \
5be60078 42 'git branch abc && test -f .git/refs/heads/abc'
08db81a9
AR
43
44test_expect_success \
45 'git branch a/b/c should create a branch' \
5be60078 46 'git branch a/b/c && test -f .git/refs/heads/a/b/c'
08db81a9 47
d7fb7a37 48cat >expect <<EOF
3749fde5 49$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
d7fb7a37
SP
50EOF
51test_expect_success \
52 'git branch -l d/e/f should create a branch and a log' \
53 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
5be60078 54 git branch -l d/e/f &&
d7fb7a37
SP
55 test -f .git/refs/heads/d/e/f &&
56 test -f .git/logs/refs/heads/d/e/f &&
4fdf71be 57 test_cmp expect .git/logs/refs/heads/d/e/f'
d7fb7a37
SP
58
59test_expect_success \
60 'git branch -d d/e/f should delete a branch and a log' \
5be60078 61 'git branch -d d/e/f &&
d7fb7a37
SP
62 test ! -f .git/refs/heads/d/e/f &&
63 test ! -f .git/logs/refs/heads/d/e/f'
64
9c7b0b3f
CC
65test_expect_success \
66 'git branch j/k should work after branch j has been deleted' \
5be60078
JH
67 'git branch j &&
68 git branch -d j &&
69 git branch j/k'
9c7b0b3f
CC
70
71test_expect_success \
72 'git branch l should work after branch l/m has been deleted' \
5be60078
JH
73 'git branch l/m &&
74 git branch -d l/m &&
75 git branch l'
9c7b0b3f 76
c976d415
LH
77test_expect_success \
78 'git branch -m m m/m should work' \
5be60078
JH
79 'git branch -l m &&
80 git branch -m m m/m &&
c976d415
LH
81 test -f .git/logs/refs/heads/m/m'
82
83test_expect_success \
84 'git branch -m n/n n should work' \
5be60078
JH
85 'git branch -l n/n &&
86 git branch -m n/n n
c976d415
LH
87 test -f .git/logs/refs/heads/n'
88
41ac414e
JH
89test_expect_success 'git branch -m o/o o should fail when o/p exists' '
90 git branch o/o &&
5be60078 91 git branch o/p &&
d492b31c 92 test_must_fail git branch -m o/o o
41ac414e 93'
c976d415 94
41ac414e
JH
95test_expect_success 'git branch -m q r/q should fail when r exists' '
96 git branch q &&
97 git branch r &&
d492b31c 98 test_must_fail git branch -m q r/q
41ac414e 99'
c976d415 100
cddd127b
MG
101test_expect_success 'git branch -v -d t should work' '
102 git branch t &&
103 test .git/refs/heads/t &&
104 git branch -v -d t &&
105 test ! -f .git/refs/heads/t
106'
107
108test_expect_success 'git branch -v -m t s should work' '
109 git branch t &&
110 test .git/refs/heads/t &&
111 git branch -v -m t s &&
112 test ! -f .git/refs/heads/t &&
113 test -f .git/refs/heads/s &&
114 git branch -d s
115'
116
117test_expect_success 'git branch -m -d t s should fail' '
118 git branch t &&
119 test .git/refs/heads/t &&
120 test_must_fail git branch -m -d t s &&
121 git branch -d t &&
122 test ! -f .git/refs/heads/t
123'
124
125test_expect_success 'git branch --list -d t should fail' '
126 git branch t &&
127 test .git/refs/heads/t &&
128 test_must_fail git branch --list -d t &&
129 git branch -d t &&
130 test ! -f .git/refs/heads/t
131'
132
01ebb9dc
GB
133mv .git/config .git/config-saved
134
08b984fb 135test_expect_success 'git branch -m q q2 without config should succeed' '
5be60078
JH
136 git branch -m q q2 &&
137 git branch -m q2 q
01ebb9dc
GB
138'
139
140mv .git/config-saved .git/config
141
5be60078 142git config branch.s/s.dummy Hello
dc81c58c 143
c976d415
LH
144test_expect_success \
145 'git branch -m s/s s should work when s/t is deleted' \
5be60078 146 'git branch -l s/s &&
c976d415 147 test -f .git/logs/refs/heads/s/s &&
5be60078 148 git branch -l s/t &&
c976d415 149 test -f .git/logs/refs/heads/s/t &&
5be60078
JH
150 git branch -d s/t &&
151 git branch -m s/s s &&
c976d415
LH
152 test -f .git/logs/refs/heads/s'
153
dc81c58c 154test_expect_success 'config information was renamed, too' \
5be60078 155 "test $(git config branch.s.dummy) = Hello &&
d492b31c 156 test_must_fail git config branch.s/s/dummy"
dc81c58c 157
fa58186c 158test_expect_success 'renaming a symref is not allowed' \
eca35a25
MV
159'
160 git symbolic-ref refs/heads/master2 refs/heads/master &&
fa58186c
MV
161 test_must_fail git branch -m master2 master3 &&
162 git symbolic-ref refs/heads/master2 &&
eca35a25 163 test -f .git/refs/heads/master &&
fa58186c 164 ! test -f .git/refs/heads/master3
eca35a25
MV
165'
166
704a3143 167test_expect_success SYMLINKS \
41ac414e
JH
168 'git branch -m u v should fail when the reflog for u is a symlink' '
169 git branch -l u &&
16c2bfbb
LH
170 mv .git/logs/refs/heads/u real-u &&
171 ln -s real-u .git/logs/refs/heads/u &&
d492b31c 172 test_must_fail git branch -m u v
41ac414e 173'
16c2bfbb 174
0746d19a 175test_expect_success 'test tracking setup via --track' \
5be60078
JH
176 'git config remote.local.url . &&
177 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 178 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
179 git branch --track my1 local/master &&
180 test $(git config branch.my1.remote) = local &&
181 test $(git config branch.my1.merge) = refs/heads/master'
0746d19a
PB
182
183test_expect_success 'test tracking setup (non-wildcard, matching)' \
5be60078
JH
184 'git config remote.local.url . &&
185 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
0cb0e143 186 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
187 git branch --track my4 local/master &&
188 test $(git config branch.my4.remote) = local &&
189 test $(git config branch.my4.merge) = refs/heads/master'
0746d19a
PB
190
191test_expect_success 'test tracking setup (non-wildcard, not matching)' \
5be60078
JH
192 'git config remote.local.url . &&
193 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
0cb0e143 194 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
195 git branch --track my5 local/master &&
196 ! test "$(git config branch.my5.remote)" = local &&
197 ! test "$(git config branch.my5.merge)" = refs/heads/master'
0746d19a
PB
198
199test_expect_success 'test tracking setup via config' \
5be60078
JH
200 'git config branch.autosetupmerge true &&
201 git config remote.local.url . &&
202 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 203 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
204 git branch my3 local/master &&
205 test $(git config branch.my3.remote) = local &&
206 test $(git config branch.my3.merge) = refs/heads/master'
0746d19a
PB
207
208test_expect_success 'test overriding tracking setup via --no-track' \
5be60078
JH
209 'git config branch.autosetupmerge true &&
210 git config remote.local.url . &&
211 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 212 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
213 git branch --no-track my2 local/master &&
214 git config branch.autosetupmerge false &&
215 ! test "$(git config branch.my2.remote)" = local &&
216 ! test "$(git config branch.my2.merge)" = refs/heads/master'
0746d19a 217
6f084a56 218test_expect_success 'no tracking without .fetch entries' \
9ed36cfa
JS
219 'git config branch.autosetupmerge true &&
220 git branch my6 s &&
221 git config branch.automsetupmerge false &&
6f084a56
JS
222 test -z "$(git config branch.my6.remote)" &&
223 test -z "$(git config branch.my6.merge)"'
9debc324 224
11f68d90 225test_expect_success 'test tracking setup via --track but deeper' \
5be60078
JH
226 'git config remote.local.url . &&
227 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 228 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
5be60078
JH
229 git branch --track my7 local/o/o &&
230 test "$(git config branch.my7.remote)" = local &&
231 test "$(git config branch.my7.merge)" = refs/heads/o/o'
11f68d90 232
f1eccbab 233test_expect_success 'test deleting branch deletes branch config' \
5be60078 234 'git branch -d my7 &&
6f084a56
JS
235 test -z "$(git config branch.my7.remote)" &&
236 test -z "$(git config branch.my7.merge)"'
f1eccbab 237
f2c8c800 238test_expect_success 'test deleting branch without config' \
5be60078 239 'git branch my7 s &&
a126ed0a 240 sha1=$(git rev-parse my7 | cut -c 1-7) &&
f2c8c800
JH
241 echo "Deleted branch my7 (was $sha1)." >expect &&
242 git branch -d my7 >actual 2>&1 &&
243 test_i18ncmp expect actual'
f1eccbab 244
9ed36cfa
JS
245test_expect_success 'test --track without .fetch entries' \
246 'git branch --track my8 &&
247 test "$(git config branch.my8.remote)" &&
248 test "$(git config branch.my8.merge)"'
249
250test_expect_success \
251 'branch from non-branch HEAD w/autosetupmerge=always' \
252 'git config branch.autosetupmerge always &&
253 git branch my9 HEAD^ &&
254 git config branch.autosetupmerge false'
255
256test_expect_success \
257 'branch from non-branch HEAD w/--track causes failure' \
03b9dfb1 258 'test_must_fail git branch --track my10 HEAD^'
9ed36cfa 259
21b5b1e8
JH
260test_expect_success \
261 'branch from tag w/--track causes failure' \
262 'git tag foobar &&
263 test_must_fail git branch --track my11 foobar'
264
0746d19a
PB
265# Keep this test last, as it changes the current branch
266cat >expect <<EOF
3749fde5 267$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
0746d19a
PB
268EOF
269test_expect_success \
270 'git checkout -b g/h/i -l should create a branch and a log' \
271 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
0cb0e143 272 git checkout -b g/h/i -l master &&
0746d19a
PB
273 test -f .git/refs/heads/g/h/i &&
274 test -f .git/logs/refs/heads/g/h/i &&
4fdf71be 275 test_cmp expect .git/logs/refs/heads/g/h/i'
0746d19a 276
b2099957
EM
277test_expect_success 'checkout -b makes reflog by default' '
278 git checkout master &&
279 git config --unset core.logAllRefUpdates &&
280 git checkout -b alpha &&
6e6842e3 281 git rev-parse --verify alpha@{0}
b2099957
EM
282'
283
284test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
285 git checkout master &&
286 git config core.logAllRefUpdates false &&
287 git checkout -b beta &&
6e6842e3 288 test_must_fail git rev-parse --verify beta@{0}
b2099957
EM
289'
290
291test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
292 git checkout master &&
293 git checkout -lb gamma &&
294 git config --unset core.logAllRefUpdates &&
6e6842e3 295 git rev-parse --verify gamma@{0}
b2099957
EM
296'
297
1d0a694b
DB
298test_expect_success 'avoid ambiguous track' '
299 git config branch.autosetupmerge true &&
300 git config remote.ambi1.url lalala &&
301 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
302 git config remote.ambi2.url lilili &&
303 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
304 git branch all1 master &&
305 test -z "$(git config branch.all1.merge)"
306'
307
c998ae9b
DS
308test_expect_success 'autosetuprebase local on a tracked local branch' '
309 git config remote.local.url . &&
310 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
311 git config branch.autosetuprebase local &&
0cb0e143 312 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
313 git branch mybase &&
314 git branch --track myr1 mybase &&
315 test "$(git config branch.myr1.remote)" = . &&
316 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
317 test "$(git config branch.myr1.rebase)" = true
318'
319
320test_expect_success 'autosetuprebase always on a tracked local branch' '
321 git config remote.local.url . &&
322 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
323 git config branch.autosetuprebase always &&
0cb0e143 324 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
325 git branch mybase2 &&
326 git branch --track myr2 mybase &&
327 test "$(git config branch.myr2.remote)" = . &&
328 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
329 test "$(git config branch.myr2.rebase)" = true
330'
331
332test_expect_success 'autosetuprebase remote on a tracked local branch' '
333 git config remote.local.url . &&
334 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
335 git config branch.autosetuprebase remote &&
0cb0e143 336 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
337 git branch mybase3 &&
338 git branch --track myr3 mybase2 &&
339 test "$(git config branch.myr3.remote)" = . &&
340 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
341 ! test "$(git config branch.myr3.rebase)" = true
342'
343
344test_expect_success 'autosetuprebase never on a tracked local branch' '
345 git config remote.local.url . &&
346 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
347 git config branch.autosetuprebase never &&
0cb0e143 348 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
349 git branch mybase4 &&
350 git branch --track myr4 mybase2 &&
351 test "$(git config branch.myr4.remote)" = . &&
352 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
353 ! test "$(git config branch.myr4.rebase)" = true
354'
355
356test_expect_success 'autosetuprebase local on a tracked remote branch' '
357 git config remote.local.url . &&
358 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
359 git config branch.autosetuprebase local &&
0cb0e143 360 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
361 git branch --track myr5 local/master &&
362 test "$(git config branch.myr5.remote)" = local &&
363 test "$(git config branch.myr5.merge)" = refs/heads/master &&
364 ! test "$(git config branch.myr5.rebase)" = true
365'
366
367test_expect_success 'autosetuprebase never on a tracked remote branch' '
368 git config remote.local.url . &&
369 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
370 git config branch.autosetuprebase never &&
0cb0e143 371 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
372 git branch --track myr6 local/master &&
373 test "$(git config branch.myr6.remote)" = local &&
374 test "$(git config branch.myr6.merge)" = refs/heads/master &&
375 ! test "$(git config branch.myr6.rebase)" = true
376'
377
378test_expect_success 'autosetuprebase remote on a tracked remote branch' '
379 git config remote.local.url . &&
380 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
381 git config branch.autosetuprebase remote &&
0cb0e143 382 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
383 git branch --track myr7 local/master &&
384 test "$(git config branch.myr7.remote)" = local &&
385 test "$(git config branch.myr7.merge)" = refs/heads/master &&
386 test "$(git config branch.myr7.rebase)" = true
387'
388
389test_expect_success 'autosetuprebase always on a tracked remote branch' '
390 git config remote.local.url . &&
391 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
392 git config branch.autosetuprebase remote &&
0cb0e143 393 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
394 git branch --track myr8 local/master &&
395 test "$(git config branch.myr8.remote)" = local &&
396 test "$(git config branch.myr8.merge)" = refs/heads/master &&
397 test "$(git config branch.myr8.rebase)" = true
398'
399
400test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
401 git config --unset branch.autosetuprebase &&
402 git config remote.local.url . &&
403 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 404 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
405 git branch --track myr9 local/master &&
406 test "$(git config branch.myr9.remote)" = local &&
407 test "$(git config branch.myr9.merge)" = refs/heads/master &&
408 test "z$(git config branch.myr9.rebase)" = z
409'
410
411test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
412 git config remote.local.url . &&
413 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 414 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
415 git branch mybase10 &&
416 git branch --track myr10 mybase2 &&
417 test "$(git config branch.myr10.remote)" = . &&
418 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
419 test "z$(git config branch.myr10.rebase)" = z
420'
421
422test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
423 git config remote.local.url . &&
424 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 425 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
426 git branch --no-track myr11 mybase2 &&
427 test "z$(git config branch.myr11.remote)" = z &&
428 test "z$(git config branch.myr11.merge)" = z &&
429 test "z$(git config branch.myr11.rebase)" = z
430'
431
432test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
433 git config remote.local.url . &&
434 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 435 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
436 git branch --no-track myr12 local/master &&
437 test "z$(git config branch.myr12.remote)" = z &&
438 test "z$(git config branch.myr12.merge)" = z &&
439 test "z$(git config branch.myr12.rebase)" = z
440'
441
442test_expect_success 'autosetuprebase never on an untracked local branch' '
443 git config branch.autosetuprebase never &&
444 git config remote.local.url . &&
445 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 446 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
447 git branch --no-track myr13 mybase2 &&
448 test "z$(git config branch.myr13.remote)" = z &&
449 test "z$(git config branch.myr13.merge)" = z &&
450 test "z$(git config branch.myr13.rebase)" = z
451'
452
453test_expect_success 'autosetuprebase local on an untracked local branch' '
454 git config branch.autosetuprebase local &&
455 git config remote.local.url . &&
456 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 457 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
458 git branch --no-track myr14 mybase2 &&
459 test "z$(git config branch.myr14.remote)" = z &&
460 test "z$(git config branch.myr14.merge)" = z &&
461 test "z$(git config branch.myr14.rebase)" = z
462'
463
464test_expect_success 'autosetuprebase remote on an untracked local branch' '
465 git config branch.autosetuprebase remote &&
466 git config remote.local.url . &&
467 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 468 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
469 git branch --no-track myr15 mybase2 &&
470 test "z$(git config branch.myr15.remote)" = z &&
471 test "z$(git config branch.myr15.merge)" = z &&
472 test "z$(git config branch.myr15.rebase)" = z
473'
474
475test_expect_success 'autosetuprebase always on an untracked local branch' '
476 git config branch.autosetuprebase always &&
477 git config remote.local.url . &&
478 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 479 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
480 git branch --no-track myr16 mybase2 &&
481 test "z$(git config branch.myr16.remote)" = z &&
482 test "z$(git config branch.myr16.merge)" = z &&
483 test "z$(git config branch.myr16.rebase)" = z
484'
485
486test_expect_success 'autosetuprebase never on an untracked remote branch' '
487 git config branch.autosetuprebase never &&
488 git config remote.local.url . &&
489 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 490 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
491 git branch --no-track myr17 local/master &&
492 test "z$(git config branch.myr17.remote)" = z &&
493 test "z$(git config branch.myr17.merge)" = z &&
494 test "z$(git config branch.myr17.rebase)" = z
495'
496
497test_expect_success 'autosetuprebase local on an untracked remote branch' '
498 git config branch.autosetuprebase local &&
499 git config remote.local.url . &&
500 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 501 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
502 git branch --no-track myr18 local/master &&
503 test "z$(git config branch.myr18.remote)" = z &&
504 test "z$(git config branch.myr18.merge)" = z &&
505 test "z$(git config branch.myr18.rebase)" = z
506'
507
508test_expect_success 'autosetuprebase remote on an untracked remote branch' '
509 git config branch.autosetuprebase remote &&
510 git config remote.local.url . &&
511 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 512 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
513 git branch --no-track myr19 local/master &&
514 test "z$(git config branch.myr19.remote)" = z &&
515 test "z$(git config branch.myr19.merge)" = z &&
516 test "z$(git config branch.myr19.rebase)" = z
517'
518
519test_expect_success 'autosetuprebase always on an untracked remote branch' '
520 git config branch.autosetuprebase always &&
521 git config remote.local.url . &&
522 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 523 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
524 git branch --no-track myr20 local/master &&
525 test "z$(git config branch.myr20.remote)" = z &&
526 test "z$(git config branch.myr20.merge)" = z &&
527 test "z$(git config branch.myr20.rebase)" = z
528'
529
21b5b1e8
JH
530test_expect_success 'autosetuprebase always on detached HEAD' '
531 git config branch.autosetupmerge always &&
532 test_when_finished git checkout master &&
533 git checkout HEAD^0 &&
534 git branch my11 &&
535 test -z "$(git config branch.my11.remote)" &&
536 test -z "$(git config branch.my11.merge)"
537'
538
c998ae9b
DS
539test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
540 git config branch.autosetuprebase garbage &&
541 test_must_fail git branch
542'
543
544test_expect_success 'detect misconfigured autosetuprebase (no value)' '
545 git config --unset branch.autosetuprebase &&
546 echo "[branch] autosetuprebase" >> .git/config &&
547 test_must_fail git branch &&
548 git config --unset branch.autosetuprebase
549'
550
99c419c9
JH
551test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
552 git checkout my9 &&
553 git config --unset branch.my8.merge &&
554 test_must_fail git branch -d my8
555'
556
557test_expect_success 'attempt to delete a branch merged to its base' '
558 # we are on my9 which is the initial commit; traditionally
559 # we would not have allowed deleting my8 that is not merged
560 # to my9, but it is set to track master that already has my8
561 git config branch.my8.merge refs/heads/master &&
562 git branch -d my8
563'
564
565test_expect_success 'attempt to delete a branch merged to its base' '
566 git checkout master &&
567 echo Third >>A &&
568 git commit -m "Third commit" A &&
569 git branch -t my10 my9 &&
570 git branch -f my10 HEAD^ &&
571 # we are on master which is at the third commit, and my10
572 # is behind us, so traditionally we would have allowed deleting
573 # it; but my10 is set to track my9 that is further behind.
574 test_must_fail git branch -d my10
575'
576
a3b427b9 577test_done