Merge branch 'master' of git://repo.or.cz/alt-git
[git/dscho.git] / t / t3200-branch.sh
blobafc69238be36881124ca95a61b3c29fa35fccd9c
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 "$no_symlinks" || {
125 test_expect_success \
126 'git branch -m u v should fail when the reflog for u is a symlink' '
127 git branch -l u &&
128 mv .git/logs/refs/heads/u real-u &&
129 ln -s real-u .git/logs/refs/heads/u &&
130 test_must_fail git branch -m u v
134 test_expect_success 'test tracking setup via --track' \
135 'git config remote.local.url . &&
136 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
137 (git show-ref -q refs/remotes/local/master || git fetch local) &&
138 git branch --track my1 local/master &&
139 test $(git config branch.my1.remote) = local &&
140 test $(git config branch.my1.merge) = refs/heads/master'
142 test_expect_success 'test tracking setup (non-wildcard, matching)' \
143 'git config remote.local.url . &&
144 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
145 (git show-ref -q refs/remotes/local/master || git fetch local) &&
146 git branch --track my4 local/master &&
147 test $(git config branch.my4.remote) = local &&
148 test $(git config branch.my4.merge) = refs/heads/master'
150 test_expect_success 'test tracking setup (non-wildcard, not matching)' \
151 'git config remote.local.url . &&
152 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
153 (git show-ref -q refs/remotes/local/master || git fetch local) &&
154 git branch --track my5 local/master &&
155 ! test "$(git config branch.my5.remote)" = local &&
156 ! test "$(git config branch.my5.merge)" = refs/heads/master'
158 test_expect_success 'test tracking setup via config' \
159 'git config branch.autosetupmerge true &&
160 git config remote.local.url . &&
161 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
162 (git show-ref -q refs/remotes/local/master || git fetch local) &&
163 git branch my3 local/master &&
164 test $(git config branch.my3.remote) = local &&
165 test $(git config branch.my3.merge) = refs/heads/master'
167 test_expect_success 'test overriding tracking setup via --no-track' \
168 'git config branch.autosetupmerge true &&
169 git config remote.local.url . &&
170 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
171 (git show-ref -q refs/remotes/local/master || git fetch local) &&
172 git branch --no-track my2 local/master &&
173 git config branch.autosetupmerge false &&
174 ! test "$(git config branch.my2.remote)" = local &&
175 ! test "$(git config branch.my2.merge)" = refs/heads/master'
177 test_expect_success 'no tracking without .fetch entries' \
178 'git config branch.autosetupmerge true &&
179 git branch my6 s &&
180 git config branch.automsetupmerge false &&
181 test -z "$(git config branch.my6.remote)" &&
182 test -z "$(git config branch.my6.merge)"'
184 test_expect_success 'test tracking setup via --track but deeper' \
185 'git config remote.local.url . &&
186 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
187 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
188 git branch --track my7 local/o/o &&
189 test "$(git config branch.my7.remote)" = local &&
190 test "$(git config branch.my7.merge)" = refs/heads/o/o'
192 test_expect_success 'test deleting branch deletes branch config' \
193 'git branch -d my7 &&
194 test -z "$(git config branch.my7.remote)" &&
195 test -z "$(git config branch.my7.merge)"'
197 test_expect_success 'test deleting branch without config' \
198 'git branch my7 s &&
199 sha1=$(git rev-parse my7 | cut -c 1-7) &&
200 test "$(git branch -d my7 2>&1)" = "Deleted branch my7 ($sha1)."'
202 test_expect_success 'test --track without .fetch entries' \
203 'git branch --track my8 &&
204 test "$(git config branch.my8.remote)" &&
205 test "$(git config branch.my8.merge)"'
207 test_expect_success \
208 'branch from non-branch HEAD w/autosetupmerge=always' \
209 'git config branch.autosetupmerge always &&
210 git branch my9 HEAD^ &&
211 git config branch.autosetupmerge false'
213 test_expect_success \
214 'branch from non-branch HEAD w/--track causes failure' \
215 'test_must_fail git branch --track my10 HEAD^'
217 # Keep this test last, as it changes the current branch
218 cat >expect <<EOF
219 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
221 test_expect_success \
222 'git checkout -b g/h/i -l should create a branch and a log' \
223 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
224 git checkout -b g/h/i -l master &&
225 test -f .git/refs/heads/g/h/i &&
226 test -f .git/logs/refs/heads/g/h/i &&
227 diff expect .git/logs/refs/heads/g/h/i'
229 test_expect_success 'avoid ambiguous track' '
230 git config branch.autosetupmerge true &&
231 git config remote.ambi1.url lalala &&
232 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
233 git config remote.ambi2.url lilili &&
234 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
235 git branch all1 master &&
236 test -z "$(git config branch.all1.merge)"
239 test_expect_success 'autosetuprebase local on a tracked local branch' '
240 git config remote.local.url . &&
241 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
242 git config branch.autosetuprebase local &&
243 (git show-ref -q refs/remotes/local/o || git fetch local) &&
244 git branch mybase &&
245 git branch --track myr1 mybase &&
246 test "$(git config branch.myr1.remote)" = . &&
247 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
248 test "$(git config branch.myr1.rebase)" = true
251 test_expect_success 'autosetuprebase always on a tracked local branch' '
252 git config remote.local.url . &&
253 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
254 git config branch.autosetuprebase always &&
255 (git show-ref -q refs/remotes/local/o || git fetch local) &&
256 git branch mybase2 &&
257 git branch --track myr2 mybase &&
258 test "$(git config branch.myr2.remote)" = . &&
259 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
260 test "$(git config branch.myr2.rebase)" = true
263 test_expect_success 'autosetuprebase remote on a tracked local branch' '
264 git config remote.local.url . &&
265 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
266 git config branch.autosetuprebase remote &&
267 (git show-ref -q refs/remotes/local/o || git fetch local) &&
268 git branch mybase3 &&
269 git branch --track myr3 mybase2 &&
270 test "$(git config branch.myr3.remote)" = . &&
271 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
272 ! test "$(git config branch.myr3.rebase)" = true
275 test_expect_success 'autosetuprebase never on a tracked local branch' '
276 git config remote.local.url . &&
277 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
278 git config branch.autosetuprebase never &&
279 (git show-ref -q refs/remotes/local/o || git fetch local) &&
280 git branch mybase4 &&
281 git branch --track myr4 mybase2 &&
282 test "$(git config branch.myr4.remote)" = . &&
283 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
284 ! test "$(git config branch.myr4.rebase)" = true
287 test_expect_success 'autosetuprebase local on a tracked remote branch' '
288 git config remote.local.url . &&
289 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
290 git config branch.autosetuprebase local &&
291 (git show-ref -q refs/remotes/local/master || git fetch local) &&
292 git branch --track myr5 local/master &&
293 test "$(git config branch.myr5.remote)" = local &&
294 test "$(git config branch.myr5.merge)" = refs/heads/master &&
295 ! test "$(git config branch.myr5.rebase)" = true
298 test_expect_success 'autosetuprebase never on a tracked remote branch' '
299 git config remote.local.url . &&
300 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
301 git config branch.autosetuprebase never &&
302 (git show-ref -q refs/remotes/local/master || git fetch local) &&
303 git branch --track myr6 local/master &&
304 test "$(git config branch.myr6.remote)" = local &&
305 test "$(git config branch.myr6.merge)" = refs/heads/master &&
306 ! test "$(git config branch.myr6.rebase)" = true
309 test_expect_success 'autosetuprebase remote on a tracked remote branch' '
310 git config remote.local.url . &&
311 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
312 git config branch.autosetuprebase remote &&
313 (git show-ref -q refs/remotes/local/master || git fetch local) &&
314 git branch --track myr7 local/master &&
315 test "$(git config branch.myr7.remote)" = local &&
316 test "$(git config branch.myr7.merge)" = refs/heads/master &&
317 test "$(git config branch.myr7.rebase)" = true
320 test_expect_success 'autosetuprebase always on a tracked remote branch' '
321 git config remote.local.url . &&
322 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
323 git config branch.autosetuprebase remote &&
324 (git show-ref -q refs/remotes/local/master || git fetch local) &&
325 git branch --track myr8 local/master &&
326 test "$(git config branch.myr8.remote)" = local &&
327 test "$(git config branch.myr8.merge)" = refs/heads/master &&
328 test "$(git config branch.myr8.rebase)" = true
331 test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
332 git config --unset branch.autosetuprebase &&
333 git config remote.local.url . &&
334 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
335 (git show-ref -q refs/remotes/local/master || git fetch local) &&
336 git branch --track myr9 local/master &&
337 test "$(git config branch.myr9.remote)" = local &&
338 test "$(git config branch.myr9.merge)" = refs/heads/master &&
339 test "z$(git config branch.myr9.rebase)" = z
342 test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
343 git config remote.local.url . &&
344 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
345 (git show-ref -q refs/remotes/local/o || git fetch local) &&
346 git branch mybase10 &&
347 git branch --track myr10 mybase2 &&
348 test "$(git config branch.myr10.remote)" = . &&
349 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
350 test "z$(git config branch.myr10.rebase)" = z
353 test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
354 git config remote.local.url . &&
355 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
356 (git show-ref -q refs/remotes/local/master || git fetch local) &&
357 git branch --no-track myr11 mybase2 &&
358 test "z$(git config branch.myr11.remote)" = z &&
359 test "z$(git config branch.myr11.merge)" = z &&
360 test "z$(git config branch.myr11.rebase)" = z
363 test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
364 git config remote.local.url . &&
365 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
366 (git show-ref -q refs/remotes/local/master || git fetch local) &&
367 git branch --no-track myr12 local/master &&
368 test "z$(git config branch.myr12.remote)" = z &&
369 test "z$(git config branch.myr12.merge)" = z &&
370 test "z$(git config branch.myr12.rebase)" = z
373 test_expect_success 'autosetuprebase never on an untracked local branch' '
374 git config branch.autosetuprebase never &&
375 git config remote.local.url . &&
376 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
377 (git show-ref -q refs/remotes/local/master || git fetch local) &&
378 git branch --no-track myr13 mybase2 &&
379 test "z$(git config branch.myr13.remote)" = z &&
380 test "z$(git config branch.myr13.merge)" = z &&
381 test "z$(git config branch.myr13.rebase)" = z
384 test_expect_success 'autosetuprebase local on an untracked local branch' '
385 git config branch.autosetuprebase local &&
386 git config remote.local.url . &&
387 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
388 (git show-ref -q refs/remotes/local/master || git fetch local) &&
389 git branch --no-track myr14 mybase2 &&
390 test "z$(git config branch.myr14.remote)" = z &&
391 test "z$(git config branch.myr14.merge)" = z &&
392 test "z$(git config branch.myr14.rebase)" = z
395 test_expect_success 'autosetuprebase remote on an untracked local branch' '
396 git config branch.autosetuprebase remote &&
397 git config remote.local.url . &&
398 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
399 (git show-ref -q refs/remotes/local/master || git fetch local) &&
400 git branch --no-track myr15 mybase2 &&
401 test "z$(git config branch.myr15.remote)" = z &&
402 test "z$(git config branch.myr15.merge)" = z &&
403 test "z$(git config branch.myr15.rebase)" = z
406 test_expect_success 'autosetuprebase always on an untracked local branch' '
407 git config branch.autosetuprebase always &&
408 git config remote.local.url . &&
409 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
410 (git show-ref -q refs/remotes/local/master || git fetch local) &&
411 git branch --no-track myr16 mybase2 &&
412 test "z$(git config branch.myr16.remote)" = z &&
413 test "z$(git config branch.myr16.merge)" = z &&
414 test "z$(git config branch.myr16.rebase)" = z
417 test_expect_success 'autosetuprebase never on an untracked remote branch' '
418 git config branch.autosetuprebase never &&
419 git config remote.local.url . &&
420 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
421 (git show-ref -q refs/remotes/local/master || git fetch local) &&
422 git branch --no-track myr17 local/master &&
423 test "z$(git config branch.myr17.remote)" = z &&
424 test "z$(git config branch.myr17.merge)" = z &&
425 test "z$(git config branch.myr17.rebase)" = z
428 test_expect_success 'autosetuprebase local on an untracked remote branch' '
429 git config branch.autosetuprebase local &&
430 git config remote.local.url . &&
431 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
432 (git show-ref -q refs/remotes/local/master || git fetch local) &&
433 git branch --no-track myr18 local/master &&
434 test "z$(git config branch.myr18.remote)" = z &&
435 test "z$(git config branch.myr18.merge)" = z &&
436 test "z$(git config branch.myr18.rebase)" = z
439 test_expect_success 'autosetuprebase remote on an untracked remote branch' '
440 git config branch.autosetuprebase remote &&
441 git config remote.local.url . &&
442 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
443 (git show-ref -q refs/remotes/local/master || git fetch local) &&
444 git branch --no-track myr19 local/master &&
445 test "z$(git config branch.myr19.remote)" = z &&
446 test "z$(git config branch.myr19.merge)" = z &&
447 test "z$(git config branch.myr19.rebase)" = z
450 test_expect_success 'autosetuprebase always on an untracked remote branch' '
451 git config branch.autosetuprebase always &&
452 git config remote.local.url . &&
453 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
454 (git show-ref -q refs/remotes/local/master || git fetch local) &&
455 git branch --no-track myr20 local/master &&
456 test "z$(git config branch.myr20.remote)" = z &&
457 test "z$(git config branch.myr20.merge)" = z &&
458 test "z$(git config branch.myr20.rebase)" = z
461 test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
462 git config branch.autosetuprebase garbage &&
463 test_must_fail git branch
466 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
467 git config --unset branch.autosetuprebase &&
468 echo "[branch] autosetuprebase" >> .git/config &&
469 test_must_fail git branch &&
470 git config --unset branch.autosetuprebase
473 test_done