git repack: keep commits hidden by a graft
[git/dscho.git] / t / t3200-branch.sh
blob5e23cf5d3299f5695a6c0960576ed86569341a6c
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 diff 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 diff expect .git/logs/refs/heads/g/h/i'
227 test_expect_success 'avoid ambiguous track' '
228 git config branch.autosetupmerge true &&
229 git config remote.ambi1.url lalala &&
230 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
231 git config remote.ambi2.url lilili &&
232 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
233 git branch all1 master &&
234 test -z "$(git config branch.all1.merge)"
236 test_expect_success 'test push setup' \
237 'git config branch.autosetupmerge true &&
238 git config branch.autosetuppush true &&
239 git config remote.local.url . &&
240 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
241 (git show-ref -q refs/remotes/local/master || git fetch local) &&
242 git branch my11 local/master &&
243 test $(git config branch.my11.remote) = local &&
244 test $(git config branch.my11.merge) = refs/heads/master
245 test $(git config remote.local.push) = refs/heads/my11:refs/heads/master
248 test_expect_success 'test multiple push setups' \
249 'git config remote.local.url . &&
250 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
251 (git show-ref -q refs/remotes/local/master || git fetch local) &&
252 git branch my12 local/master &&
253 test $(git config branch.my12.remote) = local &&
254 test $(git config branch.my12.merge) = refs/heads/master &&
255 (if git config remote.local.push; then exit 1; else test $? = 2; fi)
258 test_expect_success 'test push setup cleanup' \
259 'git config branch.autosetupmerge true &&
260 git config branch.autosetuppush true &&
261 git config remote.local.url . &&
262 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
263 (git show-ref -q refs/remotes/local/master || git fetch local) &&
264 (git branch my11 local/master || :) &&
265 (git branch my12 local/master || :) &&
266 git branch -d my11 &&
267 test $(git config remote.local.push) = refs/heads/my12:refs/heads/master &&
268 git branch -d my12 &&
269 test z$(git config remote.local.push) = z
272 test_expect_success 'autosetuprebase local on a tracked local branch' '
273 git config remote.local.url . &&
274 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
275 git config branch.autosetuprebase local &&
276 git config branch.autosetuppush false &&
277 (git show-ref -q refs/remotes/local/o || git fetch local) &&
278 git branch mybase &&
279 git branch --track myr1 mybase &&
280 test "$(git config branch.myr1.remote)" = . &&
281 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
282 test "$(git config branch.myr1.rebase)" = true
285 test_expect_success 'autosetuprebase always on a tracked local branch' '
286 git config remote.local.url . &&
287 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
288 git config branch.autosetuprebase always &&
289 (git show-ref -q refs/remotes/local/o || git fetch local) &&
290 git branch mybase2 &&
291 git branch --track myr2 mybase &&
292 test "$(git config branch.myr2.remote)" = . &&
293 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
294 test "$(git config branch.myr2.rebase)" = true
297 test_expect_success 'autosetuprebase remote on a tracked local branch' '
298 git config remote.local.url . &&
299 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
300 git config branch.autosetuprebase remote &&
301 (git show-ref -q refs/remotes/local/o || git fetch local) &&
302 git branch mybase3 &&
303 git branch --track myr3 mybase2 &&
304 test "$(git config branch.myr3.remote)" = . &&
305 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
306 ! test "$(git config branch.myr3.rebase)" = true
309 test_expect_success 'autosetuprebase never on a tracked local branch' '
310 git config remote.local.url . &&
311 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
312 git config branch.autosetuprebase never &&
313 (git show-ref -q refs/remotes/local/o || git fetch local) &&
314 git branch mybase4 &&
315 git branch --track myr4 mybase2 &&
316 test "$(git config branch.myr4.remote)" = . &&
317 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
318 ! test "$(git config branch.myr4.rebase)" = true
321 test_expect_success 'autosetuprebase local on a tracked remote branch' '
322 git config remote.local.url . &&
323 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
324 git config branch.autosetuprebase local &&
325 (git show-ref -q refs/remotes/local/master || git fetch local) &&
326 git branch --track myr5 local/master &&
327 test "$(git config branch.myr5.remote)" = local &&
328 test "$(git config branch.myr5.merge)" = refs/heads/master &&
329 ! test "$(git config branch.myr5.rebase)" = true
332 test_expect_success 'autosetuprebase never on a tracked remote branch' '
333 git config remote.local.url . &&
334 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
335 git config branch.autosetuprebase never &&
336 (git show-ref -q refs/remotes/local/master || git fetch local) &&
337 git branch --track myr6 local/master &&
338 test "$(git config branch.myr6.remote)" = local &&
339 test "$(git config branch.myr6.merge)" = refs/heads/master &&
340 ! test "$(git config branch.myr6.rebase)" = true
343 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
344 git config remote.local.url . &&
345 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
346 git config branch.autosetuprebase remote &&
347 (git show-ref -q refs/remotes/local/master || git fetch local) &&
348 git branch --track myr7 local/master &&
349 test "$(git config branch.myr7.remote)" = local &&
350 test "$(git config branch.myr7.merge)" = refs/heads/master &&
351 test "$(git config branch.myr7.rebase)" = true
354 test_expect_success 'autosetuprebase always on a tracked remote branch' '
355 git config remote.local.url . &&
356 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
357 git config branch.autosetuprebase remote &&
358 (git show-ref -q refs/remotes/local/master || git fetch local) &&
359 git branch --track myr8 local/master &&
360 test "$(git config branch.myr8.remote)" = local &&
361 test "$(git config branch.myr8.merge)" = refs/heads/master &&
362 test "$(git config branch.myr8.rebase)" = true
365 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
366 git config --unset branch.autosetuprebase &&
367 git config remote.local.url . &&
368 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
369 (git show-ref -q refs/remotes/local/master || git fetch local) &&
370 git branch --track myr9 local/master &&
371 test "$(git config branch.myr9.remote)" = local &&
372 test "$(git config branch.myr9.merge)" = refs/heads/master &&
373 test "z$(git config branch.myr9.rebase)" = z
376 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
377 git config remote.local.url . &&
378 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
379 (git show-ref -q refs/remotes/local/o || git fetch local) &&
380 git branch mybase10 &&
381 git branch --track myr10 mybase2 &&
382 test "$(git config branch.myr10.remote)" = . &&
383 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
384 test "z$(git config branch.myr10.rebase)" = z
387 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
388 git config remote.local.url . &&
389 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
390 (git show-ref -q refs/remotes/local/master || git fetch local) &&
391 git branch --no-track myr11 mybase2 &&
392 test "z$(git config branch.myr11.remote)" = z &&
393 test "z$(git config branch.myr11.merge)" = z &&
394 test "z$(git config branch.myr11.rebase)" = z
397 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
398 git config remote.local.url . &&
399 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
400 (git show-ref -q refs/remotes/local/master || git fetch local) &&
401 git branch --no-track myr12 local/master &&
402 test "z$(git config branch.myr12.remote)" = z &&
403 test "z$(git config branch.myr12.merge)" = z &&
404 test "z$(git config branch.myr12.rebase)" = z
407 test_expect_success 'autosetuprebase never on an untracked local branch' '
408 git config branch.autosetuprebase never &&
409 git config remote.local.url . &&
410 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
411 (git show-ref -q refs/remotes/local/master || git fetch local) &&
412 git branch --no-track myr13 mybase2 &&
413 test "z$(git config branch.myr13.remote)" = z &&
414 test "z$(git config branch.myr13.merge)" = z &&
415 test "z$(git config branch.myr13.rebase)" = z
418 test_expect_success 'autosetuprebase local on an untracked local branch' '
419 git config branch.autosetuprebase local &&
420 git config remote.local.url . &&
421 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
422 (git show-ref -q refs/remotes/local/master || git fetch local) &&
423 git branch --no-track myr14 mybase2 &&
424 test "z$(git config branch.myr14.remote)" = z &&
425 test "z$(git config branch.myr14.merge)" = z &&
426 test "z$(git config branch.myr14.rebase)" = z
429 test_expect_success 'autosetuprebase remote on an untracked local branch' '
430 git config branch.autosetuprebase remote &&
431 git config remote.local.url . &&
432 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
433 (git show-ref -q refs/remotes/local/master || git fetch local) &&
434 git branch --no-track myr15 mybase2 &&
435 test "z$(git config branch.myr15.remote)" = z &&
436 test "z$(git config branch.myr15.merge)" = z &&
437 test "z$(git config branch.myr15.rebase)" = z
440 test_expect_success 'autosetuprebase always on an untracked local branch' '
441 git config branch.autosetuprebase always &&
442 git config remote.local.url . &&
443 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
444 (git show-ref -q refs/remotes/local/master || git fetch local) &&
445 git branch --no-track myr16 mybase2 &&
446 test "z$(git config branch.myr16.remote)" = z &&
447 test "z$(git config branch.myr16.merge)" = z &&
448 test "z$(git config branch.myr16.rebase)" = z
451 test_expect_success 'autosetuprebase never on an untracked remote branch' '
452 git config branch.autosetuprebase never &&
453 git config remote.local.url . &&
454 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
455 (git show-ref -q refs/remotes/local/master || git fetch local) &&
456 git branch --no-track myr17 local/master &&
457 test "z$(git config branch.myr17.remote)" = z &&
458 test "z$(git config branch.myr17.merge)" = z &&
459 test "z$(git config branch.myr17.rebase)" = z
462 test_expect_success 'autosetuprebase local on an untracked remote branch' '
463 git config branch.autosetuprebase local &&
464 git config remote.local.url . &&
465 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
466 (git show-ref -q refs/remotes/local/master || git fetch local) &&
467 git branch --no-track myr18 local/master &&
468 test "z$(git config branch.myr18.remote)" = z &&
469 test "z$(git config branch.myr18.merge)" = z &&
470 test "z$(git config branch.myr18.rebase)" = z
473 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
474 git config branch.autosetuprebase remote &&
475 git config remote.local.url . &&
476 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
477 (git show-ref -q refs/remotes/local/master || git fetch local) &&
478 git branch --no-track myr19 local/master &&
479 test "z$(git config branch.myr19.remote)" = z &&
480 test "z$(git config branch.myr19.merge)" = z &&
481 test "z$(git config branch.myr19.rebase)" = z
484 test_expect_success 'autosetuprebase always on an untracked remote branch' '
485 git config branch.autosetuprebase always &&
486 git config remote.local.url . &&
487 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
488 (git show-ref -q refs/remotes/local/master || git fetch local) &&
489 git branch --no-track myr20 local/master &&
490 test "z$(git config branch.myr20.remote)" = z &&
491 test "z$(git config branch.myr20.merge)" = z &&
492 test "z$(git config branch.myr20.rebase)" = z
495 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
496 git config branch.autosetuprebase garbage &&
497 test_must_fail git branch
500 test_expect_success 'boolean value (no value) for autosetuprebase' '
501 git config --unset branch.autosetuprebase &&
502 echo "[branch] autosetuprebase" >> .git/config &&
503 git config remote.local.url . &&
504 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
505 (git show-ref -q refs/remotes/local/master || git fetch local) &&
506 git branch --track myr21 local/master &&
507 git branch --track myr22 myr21 &&
508 test "$(git config branch.myr21.remote)" = local &&
509 test "$(git config branch.myr21.merge)" = refs/heads/master &&
510 test "z$(git config branch.myr21.rebase)" = ztrue &&
511 test "$(git config branch.myr22.remote)" = . &&
512 test "$(git config branch.myr22.merge)" = refs/heads/myr21 &&
513 test "z$(git config branch.myr22.rebase)" = ztrue
515 test_expect_success 'tracking remote with branch.autosetupmerge = false' '
516 git config remote.local.autosetupmerge true &&
517 git config branch.autosetupmerge false &&
518 git config remote.local.url . &&
519 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
520 (git show-ref -q refs/remotes/local/master || git fetch local) &&
521 git branch myr23 local/master &&
522 test "$(git config branch.myr23.remote)" = local &&
523 test "$(git config branch.myr23.merge)" = refs/heads/master
526 test_expect_success 'non-tracking remote with branch.autosetupmerge = always' '
527 git config remote.local.autosetupmerge false &&
528 git config branch.autosetupmerge always &&
529 git branch myr24 local/master &&
530 test z"$(git config branch.myr24.remote)" = z &&
531 test z"$(git config branch.myr24.merge)" = z
534 test_expect_success 'tracking branch overriding remote configuration' '
535 git config remote.local.autosetupmerge false &&
536 git branch --track myr25 local/master &&
537 test "$(git config branch.myr25.remote)" = local &&
538 test "$(git config branch.myr25.merge)" = refs/heads/master
541 test_expect_success 'non-tracking branch overriding remote configuration' '
542 git config remote.local.autosetupmerge true &&
543 git branch --no-track myr26 local/master &&
544 test z"$(git config branch.myr26.remote)" = z &&
545 test z"$(git config branch.myr26.merge)" = z
548 test_expect_success '--no-track and multiple matches ' '
549 git config branch.autosetupmerge true &&
550 git config remote.local2.url . &&
551 git config remote.local2.fetch refs/heads/*:refs/remotes/local/* &&
552 git fetch local2 &&
553 git branch --no-track myr96 local/master
554 test z"$(git config branch.myr96.remote)" = z &&
555 test z"$(git config branch.myr96.merge)" = z
557 test_done