vcs-svn: Sharpen parsing of property lines
[alt-git.git] / t / t3200-branch.sh
blobf54a533456d74a3eb2f745dbc77c8ad5a5ae960f
1 #!/bin/sh
3 # Copyright (c) 2005 Amos Waterland
6 test_description='git branch --foo should not create bogus branch
8 This test runs git branch --help and checks that the argument is properly
9 handled. Specifically, that a bogus branch is not created.
11 . ./test-lib.sh
13 test_expect_success \
14 'prepare a trivial repository' \
15 'echo Hello > A &&
16 git update-index --add A &&
17 git commit -m "Initial commit." &&
18 echo World >> A &&
19 git update-index --add A &&
20 git commit -m "Second commit." &&
21 HEAD=$(git rev-parse --verify HEAD)'
23 test_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
29 test_expect_success \
30 'git branch abc should create a branch' \
31 'git branch abc && test -f .git/refs/heads/abc'
33 test_expect_success \
34 'git branch a/b/c should create a branch' \
35 'git branch a/b/c && test -f .git/refs/heads/a/b/c'
37 cat >expect <<EOF
38 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
39 EOF
40 test_expect_success \
41 'git branch -l d/e/f should create a branch and a log' \
42 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
43 git branch -l d/e/f &&
44 test -f .git/refs/heads/d/e/f &&
45 test -f .git/logs/refs/heads/d/e/f &&
46 test_cmp expect .git/logs/refs/heads/d/e/f'
48 test_expect_success \
49 'git branch -d d/e/f should delete a branch and a log' \
50 'git branch -d d/e/f &&
51 test ! -f .git/refs/heads/d/e/f &&
52 test ! -f .git/logs/refs/heads/d/e/f'
54 test_expect_success \
55 'git branch j/k should work after branch j has been deleted' \
56 'git branch j &&
57 git branch -d j &&
58 git branch j/k'
60 test_expect_success \
61 'git branch l should work after branch l/m has been deleted' \
62 'git branch l/m &&
63 git branch -d l/m &&
64 git branch l'
66 test_expect_success \
67 'git branch -m m m/m should work' \
68 'git branch -l m &&
69 git branch -m m m/m &&
70 test -f .git/logs/refs/heads/m/m'
72 test_expect_success \
73 'git branch -m n/n n should work' \
74 'git branch -l n/n &&
75 git branch -m n/n n
76 test -f .git/logs/refs/heads/n'
78 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
79 git branch o/o &&
80 git branch o/p &&
81 test_must_fail git branch -m o/o o
84 test_expect_success 'git branch -m q r/q should fail when r exists' '
85 git branch q &&
86 git branch r &&
87 test_must_fail git branch -m q r/q
90 mv .git/config .git/config-saved
92 test_expect_success 'git branch -m q q2 without config should succeed' '
93 git branch -m q q2 &&
94 git branch -m q2 q
97 mv .git/config-saved .git/config
99 git config branch.s/s.dummy Hello
101 test_expect_success \
102 'git branch -m s/s s should work when s/t is deleted' \
103 'git branch -l s/s &&
104 test -f .git/logs/refs/heads/s/s &&
105 git branch -l s/t &&
106 test -f .git/logs/refs/heads/s/t &&
107 git branch -d s/t &&
108 git branch -m s/s s &&
109 test -f .git/logs/refs/heads/s'
111 test_expect_success 'config information was renamed, too' \
112 "test $(git config branch.s.dummy) = Hello &&
113 test_must_fail git config branch.s/s/dummy"
115 test_expect_success 'renaming a symref is not allowed' \
117 git symbolic-ref refs/heads/master2 refs/heads/master &&
118 test_must_fail git branch -m master2 master3 &&
119 git symbolic-ref refs/heads/master2 &&
120 test -f .git/refs/heads/master &&
121 ! test -f .git/refs/heads/master3
124 test_expect_success SYMLINKS \
125 'git branch -m u v should fail when the reflog for u is a symlink' '
126 git branch -l u &&
127 mv .git/logs/refs/heads/u real-u &&
128 ln -s real-u .git/logs/refs/heads/u &&
129 test_must_fail git branch -m u v
132 test_expect_success 'test tracking setup via --track' \
133 'git config remote.local.url . &&
134 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
135 (git show-ref -q refs/remotes/local/master || git fetch local) &&
136 git branch --track my1 local/master &&
137 test $(git config branch.my1.remote) = local &&
138 test $(git config branch.my1.merge) = refs/heads/master'
140 test_expect_success 'test tracking setup (non-wildcard, matching)' \
141 'git config remote.local.url . &&
142 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
143 (git show-ref -q refs/remotes/local/master || git fetch local) &&
144 git branch --track my4 local/master &&
145 test $(git config branch.my4.remote) = local &&
146 test $(git config branch.my4.merge) = refs/heads/master'
148 test_expect_success 'test tracking setup (non-wildcard, not matching)' \
149 'git config remote.local.url . &&
150 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
151 (git show-ref -q refs/remotes/local/master || git fetch local) &&
152 git branch --track my5 local/master &&
153 ! test "$(git config branch.my5.remote)" = local &&
154 ! test "$(git config branch.my5.merge)" = refs/heads/master'
156 test_expect_success 'test tracking setup via config' \
157 'git config branch.autosetupmerge true &&
158 git config remote.local.url . &&
159 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
160 (git show-ref -q refs/remotes/local/master || git fetch local) &&
161 git branch my3 local/master &&
162 test $(git config branch.my3.remote) = local &&
163 test $(git config branch.my3.merge) = refs/heads/master'
165 test_expect_success 'test overriding tracking setup via --no-track' \
166 'git config branch.autosetupmerge true &&
167 git config remote.local.url . &&
168 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
169 (git show-ref -q refs/remotes/local/master || git fetch local) &&
170 git branch --no-track my2 local/master &&
171 git config branch.autosetupmerge false &&
172 ! test "$(git config branch.my2.remote)" = local &&
173 ! test "$(git config branch.my2.merge)" = refs/heads/master'
175 test_expect_success 'no tracking without .fetch entries' \
176 'git config branch.autosetupmerge true &&
177 git branch my6 s &&
178 git config branch.automsetupmerge false &&
179 test -z "$(git config branch.my6.remote)" &&
180 test -z "$(git config branch.my6.merge)"'
182 test_expect_success 'test tracking setup via --track but deeper' \
183 'git config remote.local.url . &&
184 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
185 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
186 git branch --track my7 local/o/o &&
187 test "$(git config branch.my7.remote)" = local &&
188 test "$(git config branch.my7.merge)" = refs/heads/o/o'
190 test_expect_success 'test deleting branch deletes branch config' \
191 'git branch -d my7 &&
192 test -z "$(git config branch.my7.remote)" &&
193 test -z "$(git config branch.my7.merge)"'
195 test_expect_success 'test deleting branch without config' \
196 'git branch my7 s &&
197 sha1=$(git rev-parse my7 | cut -c 1-7) &&
198 test "$(git branch -d my7 2>&1)" = "Deleted branch my7 (was $sha1)."'
200 test_expect_success 'test --track without .fetch entries' \
201 'git branch --track my8 &&
202 test "$(git config branch.my8.remote)" &&
203 test "$(git config branch.my8.merge)"'
205 test_expect_success \
206 'branch from non-branch HEAD w/autosetupmerge=always' \
207 'git config branch.autosetupmerge always &&
208 git branch my9 HEAD^ &&
209 git config branch.autosetupmerge false'
211 test_expect_success \
212 'branch from non-branch HEAD w/--track causes failure' \
213 'test_must_fail git branch --track my10 HEAD^'
215 # Keep this test last, as it changes the current branch
216 cat >expect <<EOF
217 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
219 test_expect_success \
220 'git checkout -b g/h/i -l should create a branch and a log' \
221 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
222 git checkout -b g/h/i -l master &&
223 test -f .git/refs/heads/g/h/i &&
224 test -f .git/logs/refs/heads/g/h/i &&
225 test_cmp expect .git/logs/refs/heads/g/h/i'
227 test_expect_success 'checkout -b makes reflog by default' '
228 git checkout master &&
229 git config --unset core.logAllRefUpdates &&
230 git checkout -b alpha &&
231 git rev-parse --verify alpha@{0}
234 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
235 git checkout master &&
236 git config core.logAllRefUpdates false &&
237 git checkout -b beta &&
238 test_must_fail git rev-parse --verify beta@{0}
241 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
242 git checkout master &&
243 git checkout -lb gamma &&
244 git config --unset core.logAllRefUpdates &&
245 git rev-parse --verify gamma@{0}
248 test_expect_success 'avoid ambiguous track' '
249 git config branch.autosetupmerge true &&
250 git config remote.ambi1.url lalala &&
251 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
252 git config remote.ambi2.url lilili &&
253 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
254 git branch all1 master &&
255 test -z "$(git config branch.all1.merge)"
258 test_expect_success 'autosetuprebase local on a tracked local branch' '
259 git config remote.local.url . &&
260 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
261 git config branch.autosetuprebase local &&
262 (git show-ref -q refs/remotes/local/o || git fetch local) &&
263 git branch mybase &&
264 git branch --track myr1 mybase &&
265 test "$(git config branch.myr1.remote)" = . &&
266 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
267 test "$(git config branch.myr1.rebase)" = true
270 test_expect_success 'autosetuprebase always on a tracked local branch' '
271 git config remote.local.url . &&
272 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
273 git config branch.autosetuprebase always &&
274 (git show-ref -q refs/remotes/local/o || git fetch local) &&
275 git branch mybase2 &&
276 git branch --track myr2 mybase &&
277 test "$(git config branch.myr2.remote)" = . &&
278 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
279 test "$(git config branch.myr2.rebase)" = true
282 test_expect_success 'autosetuprebase remote on a tracked local branch' '
283 git config remote.local.url . &&
284 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
285 git config branch.autosetuprebase remote &&
286 (git show-ref -q refs/remotes/local/o || git fetch local) &&
287 git branch mybase3 &&
288 git branch --track myr3 mybase2 &&
289 test "$(git config branch.myr3.remote)" = . &&
290 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
291 ! test "$(git config branch.myr3.rebase)" = true
294 test_expect_success 'autosetuprebase never on a tracked local branch' '
295 git config remote.local.url . &&
296 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
297 git config branch.autosetuprebase never &&
298 (git show-ref -q refs/remotes/local/o || git fetch local) &&
299 git branch mybase4 &&
300 git branch --track myr4 mybase2 &&
301 test "$(git config branch.myr4.remote)" = . &&
302 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
303 ! test "$(git config branch.myr4.rebase)" = true
306 test_expect_success 'autosetuprebase local on a tracked remote branch' '
307 git config remote.local.url . &&
308 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
309 git config branch.autosetuprebase local &&
310 (git show-ref -q refs/remotes/local/master || git fetch local) &&
311 git branch --track myr5 local/master &&
312 test "$(git config branch.myr5.remote)" = local &&
313 test "$(git config branch.myr5.merge)" = refs/heads/master &&
314 ! test "$(git config branch.myr5.rebase)" = true
317 test_expect_success 'autosetuprebase never on a tracked remote branch' '
318 git config remote.local.url . &&
319 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
320 git config branch.autosetuprebase never &&
321 (git show-ref -q refs/remotes/local/master || git fetch local) &&
322 git branch --track myr6 local/master &&
323 test "$(git config branch.myr6.remote)" = local &&
324 test "$(git config branch.myr6.merge)" = refs/heads/master &&
325 ! test "$(git config branch.myr6.rebase)" = true
328 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
329 git config remote.local.url . &&
330 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
331 git config branch.autosetuprebase remote &&
332 (git show-ref -q refs/remotes/local/master || git fetch local) &&
333 git branch --track myr7 local/master &&
334 test "$(git config branch.myr7.remote)" = local &&
335 test "$(git config branch.myr7.merge)" = refs/heads/master &&
336 test "$(git config branch.myr7.rebase)" = true
339 test_expect_success 'autosetuprebase always on a tracked remote branch' '
340 git config remote.local.url . &&
341 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
342 git config branch.autosetuprebase remote &&
343 (git show-ref -q refs/remotes/local/master || git fetch local) &&
344 git branch --track myr8 local/master &&
345 test "$(git config branch.myr8.remote)" = local &&
346 test "$(git config branch.myr8.merge)" = refs/heads/master &&
347 test "$(git config branch.myr8.rebase)" = true
350 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
351 git config --unset branch.autosetuprebase &&
352 git config remote.local.url . &&
353 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
354 (git show-ref -q refs/remotes/local/master || git fetch local) &&
355 git branch --track myr9 local/master &&
356 test "$(git config branch.myr9.remote)" = local &&
357 test "$(git config branch.myr9.merge)" = refs/heads/master &&
358 test "z$(git config branch.myr9.rebase)" = z
361 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
362 git config remote.local.url . &&
363 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
364 (git show-ref -q refs/remotes/local/o || git fetch local) &&
365 git branch mybase10 &&
366 git branch --track myr10 mybase2 &&
367 test "$(git config branch.myr10.remote)" = . &&
368 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
369 test "z$(git config branch.myr10.rebase)" = z
372 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
373 git config remote.local.url . &&
374 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
375 (git show-ref -q refs/remotes/local/master || git fetch local) &&
376 git branch --no-track myr11 mybase2 &&
377 test "z$(git config branch.myr11.remote)" = z &&
378 test "z$(git config branch.myr11.merge)" = z &&
379 test "z$(git config branch.myr11.rebase)" = z
382 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
383 git config remote.local.url . &&
384 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
385 (git show-ref -q refs/remotes/local/master || git fetch local) &&
386 git branch --no-track myr12 local/master &&
387 test "z$(git config branch.myr12.remote)" = z &&
388 test "z$(git config branch.myr12.merge)" = z &&
389 test "z$(git config branch.myr12.rebase)" = z
392 test_expect_success 'autosetuprebase never on an untracked local branch' '
393 git config branch.autosetuprebase never &&
394 git config remote.local.url . &&
395 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
396 (git show-ref -q refs/remotes/local/master || git fetch local) &&
397 git branch --no-track myr13 mybase2 &&
398 test "z$(git config branch.myr13.remote)" = z &&
399 test "z$(git config branch.myr13.merge)" = z &&
400 test "z$(git config branch.myr13.rebase)" = z
403 test_expect_success 'autosetuprebase local on an untracked local branch' '
404 git config branch.autosetuprebase local &&
405 git config remote.local.url . &&
406 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
407 (git show-ref -q refs/remotes/local/master || git fetch local) &&
408 git branch --no-track myr14 mybase2 &&
409 test "z$(git config branch.myr14.remote)" = z &&
410 test "z$(git config branch.myr14.merge)" = z &&
411 test "z$(git config branch.myr14.rebase)" = z
414 test_expect_success 'autosetuprebase remote on an untracked local branch' '
415 git config branch.autosetuprebase remote &&
416 git config remote.local.url . &&
417 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
418 (git show-ref -q refs/remotes/local/master || git fetch local) &&
419 git branch --no-track myr15 mybase2 &&
420 test "z$(git config branch.myr15.remote)" = z &&
421 test "z$(git config branch.myr15.merge)" = z &&
422 test "z$(git config branch.myr15.rebase)" = z
425 test_expect_success 'autosetuprebase always on an untracked local branch' '
426 git config branch.autosetuprebase always &&
427 git config remote.local.url . &&
428 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
429 (git show-ref -q refs/remotes/local/master || git fetch local) &&
430 git branch --no-track myr16 mybase2 &&
431 test "z$(git config branch.myr16.remote)" = z &&
432 test "z$(git config branch.myr16.merge)" = z &&
433 test "z$(git config branch.myr16.rebase)" = z
436 test_expect_success 'autosetuprebase never on an untracked remote branch' '
437 git config branch.autosetuprebase never &&
438 git config remote.local.url . &&
439 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
440 (git show-ref -q refs/remotes/local/master || git fetch local) &&
441 git branch --no-track myr17 local/master &&
442 test "z$(git config branch.myr17.remote)" = z &&
443 test "z$(git config branch.myr17.merge)" = z &&
444 test "z$(git config branch.myr17.rebase)" = z
447 test_expect_success 'autosetuprebase local on an untracked remote branch' '
448 git config branch.autosetuprebase local &&
449 git config remote.local.url . &&
450 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
451 (git show-ref -q refs/remotes/local/master || git fetch local) &&
452 git branch --no-track myr18 local/master &&
453 test "z$(git config branch.myr18.remote)" = z &&
454 test "z$(git config branch.myr18.merge)" = z &&
455 test "z$(git config branch.myr18.rebase)" = z
458 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
459 git config branch.autosetuprebase remote &&
460 git config remote.local.url . &&
461 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
462 (git show-ref -q refs/remotes/local/master || git fetch local) &&
463 git branch --no-track myr19 local/master &&
464 test "z$(git config branch.myr19.remote)" = z &&
465 test "z$(git config branch.myr19.merge)" = z &&
466 test "z$(git config branch.myr19.rebase)" = z
469 test_expect_success 'autosetuprebase always on an untracked remote branch' '
470 git config branch.autosetuprebase always &&
471 git config remote.local.url . &&
472 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
473 (git show-ref -q refs/remotes/local/master || git fetch local) &&
474 git branch --no-track myr20 local/master &&
475 test "z$(git config branch.myr20.remote)" = z &&
476 test "z$(git config branch.myr20.merge)" = z &&
477 test "z$(git config branch.myr20.rebase)" = z
480 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
481 git config branch.autosetuprebase garbage &&
482 test_must_fail git branch
485 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
486 git config --unset branch.autosetuprebase &&
487 echo "[branch] autosetuprebase" >> .git/config &&
488 test_must_fail git branch &&
489 git config --unset branch.autosetuprebase
492 test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
493 git checkout my9 &&
494 git config --unset branch.my8.merge &&
495 test_must_fail git branch -d my8
498 test_expect_success 'attempt to delete a branch merged to its base' '
499 # we are on my9 which is the initial commit; traditionally
500 # we would not have allowed deleting my8 that is not merged
501 # to my9, but it is set to track master that already has my8
502 git config branch.my8.merge refs/heads/master &&
503 git branch -d my8
506 test_expect_success 'attempt to delete a branch merged to its base' '
507 git checkout master &&
508 echo Third >>A &&
509 git commit -m "Third commit" A &&
510 git branch -t my10 my9 &&
511 git branch -f my10 HEAD^ &&
512 # we are on master which is at the third commit, and my10
513 # is behind us, so traditionally we would have allowed deleting
514 # it; but my10 is set to track my9 that is further behind.
515 test_must_fail git branch -d my10
518 test_done