]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3200-branch.sh
i18n: use test_i18ngrep in lib-httpd and t2019
[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
5d9e8ee7 490000000000000000000000000000000000000000 $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
01ebb9dc
GB
101mv .git/config .git/config-saved
102
08b984fb 103test_expect_success 'git branch -m q q2 without config should succeed' '
5be60078
JH
104 git branch -m q q2 &&
105 git branch -m q2 q
01ebb9dc
GB
106'
107
108mv .git/config-saved .git/config
109
5be60078 110git config branch.s/s.dummy Hello
dc81c58c 111
c976d415
LH
112test_expect_success \
113 'git branch -m s/s s should work when s/t is deleted' \
5be60078 114 'git branch -l s/s &&
c976d415 115 test -f .git/logs/refs/heads/s/s &&
5be60078 116 git branch -l s/t &&
c976d415 117 test -f .git/logs/refs/heads/s/t &&
5be60078
JH
118 git branch -d s/t &&
119 git branch -m s/s s &&
c976d415
LH
120 test -f .git/logs/refs/heads/s'
121
dc81c58c 122test_expect_success 'config information was renamed, too' \
5be60078 123 "test $(git config branch.s.dummy) = Hello &&
d492b31c 124 test_must_fail git config branch.s/s/dummy"
dc81c58c 125
fa58186c 126test_expect_success 'renaming a symref is not allowed' \
eca35a25
MV
127'
128 git symbolic-ref refs/heads/master2 refs/heads/master &&
fa58186c
MV
129 test_must_fail git branch -m master2 master3 &&
130 git symbolic-ref refs/heads/master2 &&
eca35a25 131 test -f .git/refs/heads/master &&
fa58186c 132 ! test -f .git/refs/heads/master3
eca35a25
MV
133'
134
704a3143 135test_expect_success SYMLINKS \
41ac414e
JH
136 'git branch -m u v should fail when the reflog for u is a symlink' '
137 git branch -l u &&
16c2bfbb
LH
138 mv .git/logs/refs/heads/u real-u &&
139 ln -s real-u .git/logs/refs/heads/u &&
d492b31c 140 test_must_fail git branch -m u v
41ac414e 141'
16c2bfbb 142
0746d19a 143test_expect_success 'test tracking setup via --track' \
5be60078
JH
144 'git config remote.local.url . &&
145 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 146 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
147 git branch --track my1 local/master &&
148 test $(git config branch.my1.remote) = local &&
149 test $(git config branch.my1.merge) = refs/heads/master'
0746d19a
PB
150
151test_expect_success 'test tracking setup (non-wildcard, matching)' \
5be60078
JH
152 'git config remote.local.url . &&
153 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
0cb0e143 154 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
155 git branch --track my4 local/master &&
156 test $(git config branch.my4.remote) = local &&
157 test $(git config branch.my4.merge) = refs/heads/master'
0746d19a
PB
158
159test_expect_success 'test tracking setup (non-wildcard, not matching)' \
5be60078
JH
160 'git config remote.local.url . &&
161 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
0cb0e143 162 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
163 git branch --track my5 local/master &&
164 ! test "$(git config branch.my5.remote)" = local &&
165 ! test "$(git config branch.my5.merge)" = refs/heads/master'
0746d19a
PB
166
167test_expect_success 'test tracking setup via config' \
5be60078
JH
168 'git config branch.autosetupmerge true &&
169 git config remote.local.url . &&
170 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 171 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
172 git branch my3 local/master &&
173 test $(git config branch.my3.remote) = local &&
174 test $(git config branch.my3.merge) = refs/heads/master'
0746d19a
PB
175
176test_expect_success 'test overriding tracking setup via --no-track' \
5be60078
JH
177 'git config branch.autosetupmerge true &&
178 git config remote.local.url . &&
179 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 180 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
181 git branch --no-track my2 local/master &&
182 git config branch.autosetupmerge false &&
183 ! test "$(git config branch.my2.remote)" = local &&
184 ! test "$(git config branch.my2.merge)" = refs/heads/master'
0746d19a 185
6f084a56 186test_expect_success 'no tracking without .fetch entries' \
9ed36cfa
JS
187 'git config branch.autosetupmerge true &&
188 git branch my6 s &&
189 git config branch.automsetupmerge false &&
6f084a56
JS
190 test -z "$(git config branch.my6.remote)" &&
191 test -z "$(git config branch.my6.merge)"'
9debc324 192
11f68d90 193test_expect_success 'test tracking setup via --track but deeper' \
5be60078
JH
194 'git config remote.local.url . &&
195 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 196 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
5be60078
JH
197 git branch --track my7 local/o/o &&
198 test "$(git config branch.my7.remote)" = local &&
199 test "$(git config branch.my7.merge)" = refs/heads/o/o'
11f68d90 200
f1eccbab 201test_expect_success 'test deleting branch deletes branch config' \
5be60078 202 'git branch -d my7 &&
6f084a56
JS
203 test -z "$(git config branch.my7.remote)" &&
204 test -z "$(git config branch.my7.merge)"'
f1eccbab 205
8af42b0f 206test_expect_success C_LOCALE_OUTPUT 'test deleting branch without config' \
5be60078 207 'git branch my7 s &&
a126ed0a 208 sha1=$(git rev-parse my7 | cut -c 1-7) &&
76aac715 209 test "$(git branch -d my7 2>&1)" = "Deleted branch my7 (was $sha1)."'
f1eccbab 210
9ed36cfa
JS
211test_expect_success 'test --track without .fetch entries' \
212 'git branch --track my8 &&
213 test "$(git config branch.my8.remote)" &&
214 test "$(git config branch.my8.merge)"'
215
216test_expect_success \
217 'branch from non-branch HEAD w/autosetupmerge=always' \
218 'git config branch.autosetupmerge always &&
219 git branch my9 HEAD^ &&
220 git config branch.autosetupmerge false'
221
222test_expect_success \
223 'branch from non-branch HEAD w/--track causes failure' \
03b9dfb1 224 'test_must_fail git branch --track my10 HEAD^'
9ed36cfa 225
21b5b1e8
JH
226test_expect_success \
227 'branch from tag w/--track causes failure' \
228 'git tag foobar &&
229 test_must_fail git branch --track my11 foobar'
230
0746d19a
PB
231# Keep this test last, as it changes the current branch
232cat >expect <<EOF
2330000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
234EOF
235test_expect_success \
236 'git checkout -b g/h/i -l should create a branch and a log' \
237 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
0cb0e143 238 git checkout -b g/h/i -l master &&
0746d19a
PB
239 test -f .git/refs/heads/g/h/i &&
240 test -f .git/logs/refs/heads/g/h/i &&
4fdf71be 241 test_cmp expect .git/logs/refs/heads/g/h/i'
0746d19a 242
b2099957
EM
243test_expect_success 'checkout -b makes reflog by default' '
244 git checkout master &&
245 git config --unset core.logAllRefUpdates &&
246 git checkout -b alpha &&
6e6842e3 247 git rev-parse --verify alpha@{0}
b2099957
EM
248'
249
250test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
251 git checkout master &&
252 git config core.logAllRefUpdates false &&
253 git checkout -b beta &&
6e6842e3 254 test_must_fail git rev-parse --verify beta@{0}
b2099957
EM
255'
256
257test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
258 git checkout master &&
259 git checkout -lb gamma &&
260 git config --unset core.logAllRefUpdates &&
6e6842e3 261 git rev-parse --verify gamma@{0}
b2099957
EM
262'
263
1d0a694b
DB
264test_expect_success 'avoid ambiguous track' '
265 git config branch.autosetupmerge true &&
266 git config remote.ambi1.url lalala &&
267 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
268 git config remote.ambi2.url lilili &&
269 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
270 git branch all1 master &&
271 test -z "$(git config branch.all1.merge)"
272'
273
c998ae9b
DS
274test_expect_success 'autosetuprebase local on a tracked local branch' '
275 git config remote.local.url . &&
276 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
277 git config branch.autosetuprebase local &&
0cb0e143 278 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
279 git branch mybase &&
280 git branch --track myr1 mybase &&
281 test "$(git config branch.myr1.remote)" = . &&
282 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
283 test "$(git config branch.myr1.rebase)" = true
284'
285
286test_expect_success 'autosetuprebase always on a tracked local branch' '
287 git config remote.local.url . &&
288 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
289 git config branch.autosetuprebase always &&
0cb0e143 290 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
291 git branch mybase2 &&
292 git branch --track myr2 mybase &&
293 test "$(git config branch.myr2.remote)" = . &&
294 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
295 test "$(git config branch.myr2.rebase)" = true
296'
297
298test_expect_success 'autosetuprebase remote on a tracked local branch' '
299 git config remote.local.url . &&
300 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
301 git config branch.autosetuprebase remote &&
0cb0e143 302 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
303 git branch mybase3 &&
304 git branch --track myr3 mybase2 &&
305 test "$(git config branch.myr3.remote)" = . &&
306 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
307 ! test "$(git config branch.myr3.rebase)" = true
308'
309
310test_expect_success 'autosetuprebase never on a tracked local branch' '
311 git config remote.local.url . &&
312 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
313 git config branch.autosetuprebase never &&
0cb0e143 314 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
315 git branch mybase4 &&
316 git branch --track myr4 mybase2 &&
317 test "$(git config branch.myr4.remote)" = . &&
318 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
319 ! test "$(git config branch.myr4.rebase)" = true
320'
321
322test_expect_success 'autosetuprebase local on a tracked remote branch' '
323 git config remote.local.url . &&
324 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
325 git config branch.autosetuprebase local &&
0cb0e143 326 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
327 git branch --track myr5 local/master &&
328 test "$(git config branch.myr5.remote)" = local &&
329 test "$(git config branch.myr5.merge)" = refs/heads/master &&
330 ! test "$(git config branch.myr5.rebase)" = true
331'
332
333test_expect_success 'autosetuprebase never on a tracked remote branch' '
334 git config remote.local.url . &&
335 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
336 git config branch.autosetuprebase never &&
0cb0e143 337 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
338 git branch --track myr6 local/master &&
339 test "$(git config branch.myr6.remote)" = local &&
340 test "$(git config branch.myr6.merge)" = refs/heads/master &&
341 ! test "$(git config branch.myr6.rebase)" = true
342'
343
344test_expect_success 'autosetuprebase remote on a tracked remote branch' '
345 git config remote.local.url . &&
346 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
347 git config branch.autosetuprebase remote &&
0cb0e143 348 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
349 git branch --track myr7 local/master &&
350 test "$(git config branch.myr7.remote)" = local &&
351 test "$(git config branch.myr7.merge)" = refs/heads/master &&
352 test "$(git config branch.myr7.rebase)" = true
353'
354
355test_expect_success 'autosetuprebase always on a tracked remote branch' '
356 git config remote.local.url . &&
357 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
358 git config branch.autosetuprebase remote &&
0cb0e143 359 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
360 git branch --track myr8 local/master &&
361 test "$(git config branch.myr8.remote)" = local &&
362 test "$(git config branch.myr8.merge)" = refs/heads/master &&
363 test "$(git config branch.myr8.rebase)" = true
364'
365
366test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
367 git config --unset branch.autosetuprebase &&
368 git config remote.local.url . &&
369 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 370 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
371 git branch --track myr9 local/master &&
372 test "$(git config branch.myr9.remote)" = local &&
373 test "$(git config branch.myr9.merge)" = refs/heads/master &&
374 test "z$(git config branch.myr9.rebase)" = z
375'
376
377test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
378 git config remote.local.url . &&
379 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 380 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
381 git branch mybase10 &&
382 git branch --track myr10 mybase2 &&
383 test "$(git config branch.myr10.remote)" = . &&
384 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
385 test "z$(git config branch.myr10.rebase)" = z
386'
387
388test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
389 git config remote.local.url . &&
390 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 391 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
392 git branch --no-track myr11 mybase2 &&
393 test "z$(git config branch.myr11.remote)" = z &&
394 test "z$(git config branch.myr11.merge)" = z &&
395 test "z$(git config branch.myr11.rebase)" = z
396'
397
398test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
399 git config remote.local.url . &&
400 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 401 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
402 git branch --no-track myr12 local/master &&
403 test "z$(git config branch.myr12.remote)" = z &&
404 test "z$(git config branch.myr12.merge)" = z &&
405 test "z$(git config branch.myr12.rebase)" = z
406'
407
408test_expect_success 'autosetuprebase never on an untracked local branch' '
409 git config branch.autosetuprebase never &&
410 git config remote.local.url . &&
411 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 412 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
413 git branch --no-track myr13 mybase2 &&
414 test "z$(git config branch.myr13.remote)" = z &&
415 test "z$(git config branch.myr13.merge)" = z &&
416 test "z$(git config branch.myr13.rebase)" = z
417'
418
419test_expect_success 'autosetuprebase local on an untracked local branch' '
420 git config branch.autosetuprebase local &&
421 git config remote.local.url . &&
422 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 423 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
424 git branch --no-track myr14 mybase2 &&
425 test "z$(git config branch.myr14.remote)" = z &&
426 test "z$(git config branch.myr14.merge)" = z &&
427 test "z$(git config branch.myr14.rebase)" = z
428'
429
430test_expect_success 'autosetuprebase remote on an untracked local branch' '
431 git config branch.autosetuprebase remote &&
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 --no-track myr15 mybase2 &&
436 test "z$(git config branch.myr15.remote)" = z &&
437 test "z$(git config branch.myr15.merge)" = z &&
438 test "z$(git config branch.myr15.rebase)" = z
439'
440
441test_expect_success 'autosetuprebase always on an untracked local branch' '
442 git config branch.autosetuprebase always &&
443 git config remote.local.url . &&
444 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 445 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
446 git branch --no-track myr16 mybase2 &&
447 test "z$(git config branch.myr16.remote)" = z &&
448 test "z$(git config branch.myr16.merge)" = z &&
449 test "z$(git config branch.myr16.rebase)" = z
450'
451
452test_expect_success 'autosetuprebase never on an untracked remote branch' '
453 git config branch.autosetuprebase never &&
454 git config remote.local.url . &&
455 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 456 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
457 git branch --no-track myr17 local/master &&
458 test "z$(git config branch.myr17.remote)" = z &&
459 test "z$(git config branch.myr17.merge)" = z &&
460 test "z$(git config branch.myr17.rebase)" = z
461'
462
463test_expect_success 'autosetuprebase local on an untracked remote branch' '
464 git config branch.autosetuprebase local &&
465 git config remote.local.url . &&
466 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 467 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
468 git branch --no-track myr18 local/master &&
469 test "z$(git config branch.myr18.remote)" = z &&
470 test "z$(git config branch.myr18.merge)" = z &&
471 test "z$(git config branch.myr18.rebase)" = z
472'
473
474test_expect_success 'autosetuprebase remote on an untracked remote branch' '
475 git config branch.autosetuprebase remote &&
476 git config remote.local.url . &&
477 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 478 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
479 git branch --no-track myr19 local/master &&
480 test "z$(git config branch.myr19.remote)" = z &&
481 test "z$(git config branch.myr19.merge)" = z &&
482 test "z$(git config branch.myr19.rebase)" = z
483'
484
485test_expect_success 'autosetuprebase always on an untracked remote branch' '
486 git config branch.autosetuprebase always &&
487 git config remote.local.url . &&
488 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 489 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
490 git branch --no-track myr20 local/master &&
491 test "z$(git config branch.myr20.remote)" = z &&
492 test "z$(git config branch.myr20.merge)" = z &&
493 test "z$(git config branch.myr20.rebase)" = z
494'
495
21b5b1e8
JH
496test_expect_success 'autosetuprebase always on detached HEAD' '
497 git config branch.autosetupmerge always &&
498 test_when_finished git checkout master &&
499 git checkout HEAD^0 &&
500 git branch my11 &&
501 test -z "$(git config branch.my11.remote)" &&
502 test -z "$(git config branch.my11.merge)"
503'
504
c998ae9b
DS
505test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
506 git config branch.autosetuprebase garbage &&
507 test_must_fail git branch
508'
509
510test_expect_success 'detect misconfigured autosetuprebase (no value)' '
511 git config --unset branch.autosetuprebase &&
512 echo "[branch] autosetuprebase" >> .git/config &&
513 test_must_fail git branch &&
514 git config --unset branch.autosetuprebase
515'
516
99c419c9
JH
517test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
518 git checkout my9 &&
519 git config --unset branch.my8.merge &&
520 test_must_fail git branch -d my8
521'
522
523test_expect_success 'attempt to delete a branch merged to its base' '
524 # we are on my9 which is the initial commit; traditionally
525 # we would not have allowed deleting my8 that is not merged
526 # to my9, but it is set to track master that already has my8
527 git config branch.my8.merge refs/heads/master &&
528 git branch -d my8
529'
530
531test_expect_success 'attempt to delete a branch merged to its base' '
532 git checkout master &&
533 echo Third >>A &&
534 git commit -m "Third commit" A &&
535 git branch -t my10 my9 &&
536 git branch -f my10 HEAD^ &&
537 # we are on master which is at the third commit, and my10
538 # is behind us, so traditionally we would have allowed deleting
539 # it; but my10 is set to track my9 that is further behind.
540 test_must_fail git branch -d my10
541'
542
a3b427b9 543test_done