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