]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3200-branch.sh
GIT 1.6.0.3
[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
08db81a9
AR
29test_expect_success \
30 'git branch abc should create a branch' \
5be60078 31 'git branch abc && test -f .git/refs/heads/abc'
08db81a9
AR
32
33test_expect_success \
34 'git branch a/b/c should create a branch' \
5be60078 35 'git branch a/b/c && test -f .git/refs/heads/a/b/c'
08db81a9 36
d7fb7a37 37cat >expect <<EOF
5d9e8ee7 380000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
d7fb7a37
SP
39EOF
40test_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" \
5be60078 43 git branch -l d/e/f &&
d7fb7a37
SP
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'
47
48test_expect_success \
49 'git branch -d d/e/f should delete a branch and a log' \
5be60078 50 'git branch -d d/e/f &&
d7fb7a37
SP
51 test ! -f .git/refs/heads/d/e/f &&
52 test ! -f .git/logs/refs/heads/d/e/f'
53
9c7b0b3f
CC
54test_expect_success \
55 'git branch j/k should work after branch j has been deleted' \
5be60078
JH
56 'git branch j &&
57 git branch -d j &&
58 git branch j/k'
9c7b0b3f
CC
59
60test_expect_success \
61 'git branch l should work after branch l/m has been deleted' \
5be60078
JH
62 'git branch l/m &&
63 git branch -d l/m &&
64 git branch l'
9c7b0b3f 65
c976d415
LH
66test_expect_success \
67 'git branch -m m m/m should work' \
5be60078
JH
68 'git branch -l m &&
69 git branch -m m m/m &&
c976d415
LH
70 test -f .git/logs/refs/heads/m/m'
71
72test_expect_success \
73 'git branch -m n/n n should work' \
5be60078
JH
74 'git branch -l n/n &&
75 git branch -m n/n n
c976d415
LH
76 test -f .git/logs/refs/heads/n'
77
41ac414e
JH
78test_expect_success 'git branch -m o/o o should fail when o/p exists' '
79 git branch o/o &&
5be60078 80 git branch o/p &&
d492b31c 81 test_must_fail git branch -m o/o o
41ac414e 82'
c976d415 83
41ac414e
JH
84test_expect_success 'git branch -m q r/q should fail when r exists' '
85 git branch q &&
86 git branch r &&
d492b31c 87 test_must_fail git branch -m q r/q
41ac414e 88'
c976d415 89
01ebb9dc
GB
90mv .git/config .git/config-saved
91
08b984fb 92test_expect_success 'git branch -m q q2 without config should succeed' '
5be60078
JH
93 git branch -m q q2 &&
94 git branch -m q2 q
01ebb9dc
GB
95'
96
97mv .git/config-saved .git/config
98
5be60078 99git config branch.s/s.dummy Hello
dc81c58c 100
c976d415
LH
101test_expect_success \
102 'git branch -m s/s s should work when s/t is deleted' \
5be60078 103 'git branch -l s/s &&
c976d415 104 test -f .git/logs/refs/heads/s/s &&
5be60078 105 git branch -l s/t &&
c976d415 106 test -f .git/logs/refs/heads/s/t &&
5be60078
JH
107 git branch -d s/t &&
108 git branch -m s/s s &&
c976d415
LH
109 test -f .git/logs/refs/heads/s'
110
dc81c58c 111test_expect_success 'config information was renamed, too' \
5be60078 112 "test $(git config branch.s.dummy) = Hello &&
d492b31c 113 test_must_fail git config branch.s/s/dummy"
dc81c58c 114
41ac414e
JH
115test_expect_success \
116 'git branch -m u v should fail when the reflog for u is a symlink' '
117 git branch -l u &&
16c2bfbb
LH
118 mv .git/logs/refs/heads/u real-u &&
119 ln -s real-u .git/logs/refs/heads/u &&
d492b31c 120 test_must_fail git branch -m u v
41ac414e 121'
16c2bfbb 122
0746d19a 123test_expect_success 'test tracking setup via --track' \
5be60078
JH
124 'git config remote.local.url . &&
125 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 126 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
127 git branch --track my1 local/master &&
128 test $(git config branch.my1.remote) = local &&
129 test $(git config branch.my1.merge) = refs/heads/master'
0746d19a
PB
130
131test_expect_success 'test tracking setup (non-wildcard, matching)' \
5be60078
JH
132 'git config remote.local.url . &&
133 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
0cb0e143 134 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
135 git branch --track my4 local/master &&
136 test $(git config branch.my4.remote) = local &&
137 test $(git config branch.my4.merge) = refs/heads/master'
0746d19a
PB
138
139test_expect_success 'test tracking setup (non-wildcard, not matching)' \
5be60078
JH
140 'git config remote.local.url . &&
141 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
0cb0e143 142 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
143 git branch --track my5 local/master &&
144 ! test "$(git config branch.my5.remote)" = local &&
145 ! test "$(git config branch.my5.merge)" = refs/heads/master'
0746d19a
PB
146
147test_expect_success 'test tracking setup via config' \
5be60078
JH
148 'git config branch.autosetupmerge true &&
149 git config remote.local.url . &&
150 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 151 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
152 git branch my3 local/master &&
153 test $(git config branch.my3.remote) = local &&
154 test $(git config branch.my3.merge) = refs/heads/master'
0746d19a
PB
155
156test_expect_success 'test overriding tracking setup via --no-track' \
5be60078
JH
157 'git config branch.autosetupmerge true &&
158 git config remote.local.url . &&
159 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 160 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
161 git branch --no-track my2 local/master &&
162 git config branch.autosetupmerge false &&
163 ! test "$(git config branch.my2.remote)" = local &&
164 ! test "$(git config branch.my2.merge)" = refs/heads/master'
0746d19a 165
6f084a56 166test_expect_success 'no tracking without .fetch entries' \
9ed36cfa
JS
167 'git config branch.autosetupmerge true &&
168 git branch my6 s &&
169 git config branch.automsetupmerge false &&
6f084a56
JS
170 test -z "$(git config branch.my6.remote)" &&
171 test -z "$(git config branch.my6.merge)"'
9debc324 172
11f68d90 173test_expect_success 'test tracking setup via --track but deeper' \
5be60078
JH
174 'git config remote.local.url . &&
175 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 176 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
5be60078
JH
177 git branch --track my7 local/o/o &&
178 test "$(git config branch.my7.remote)" = local &&
179 test "$(git config branch.my7.merge)" = refs/heads/o/o'
11f68d90 180
f1eccbab 181test_expect_success 'test deleting branch deletes branch config' \
5be60078 182 'git branch -d my7 &&
6f084a56
JS
183 test -z "$(git config branch.my7.remote)" &&
184 test -z "$(git config branch.my7.merge)"'
f1eccbab
GP
185
186test_expect_success 'test deleting branch without config' \
5be60078
JH
187 'git branch my7 s &&
188 test "$(git branch -d my7 2>&1)" = "Deleted branch my7."'
f1eccbab 189
9ed36cfa
JS
190test_expect_success 'test --track without .fetch entries' \
191 'git branch --track my8 &&
192 test "$(git config branch.my8.remote)" &&
193 test "$(git config branch.my8.merge)"'
194
195test_expect_success \
196 'branch from non-branch HEAD w/autosetupmerge=always' \
197 'git config branch.autosetupmerge always &&
198 git branch my9 HEAD^ &&
199 git config branch.autosetupmerge false'
200
201test_expect_success \
202 'branch from non-branch HEAD w/--track causes failure' \
03b9dfb1 203 'test_must_fail git branch --track my10 HEAD^'
9ed36cfa 204
0746d19a
PB
205# Keep this test last, as it changes the current branch
206cat >expect <<EOF
2070000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
208EOF
209test_expect_success \
210 'git checkout -b g/h/i -l should create a branch and a log' \
211 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
0cb0e143 212 git checkout -b g/h/i -l master &&
0746d19a
PB
213 test -f .git/refs/heads/g/h/i &&
214 test -f .git/logs/refs/heads/g/h/i &&
215 diff expect .git/logs/refs/heads/g/h/i'
216
1d0a694b
DB
217test_expect_success 'avoid ambiguous track' '
218 git config branch.autosetupmerge true &&
219 git config remote.ambi1.url lalala &&
220 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
221 git config remote.ambi2.url lilili &&
222 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
223 git branch all1 master &&
224 test -z "$(git config branch.all1.merge)"
225'
226
c998ae9b
DS
227test_expect_success 'autosetuprebase local on a tracked local branch' '
228 git config remote.local.url . &&
229 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
230 git config branch.autosetuprebase local &&
0cb0e143 231 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
232 git branch mybase &&
233 git branch --track myr1 mybase &&
234 test "$(git config branch.myr1.remote)" = . &&
235 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
236 test "$(git config branch.myr1.rebase)" = true
237'
238
239test_expect_success 'autosetuprebase always 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 always &&
0cb0e143 243 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
244 git branch mybase2 &&
245 git branch --track myr2 mybase &&
246 test "$(git config branch.myr2.remote)" = . &&
247 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
248 test "$(git config branch.myr2.rebase)" = true
249'
250
251test_expect_success 'autosetuprebase remote 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 remote &&
0cb0e143 255 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
256 git branch mybase3 &&
257 git branch --track myr3 mybase2 &&
258 test "$(git config branch.myr3.remote)" = . &&
259 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
260 ! test "$(git config branch.myr3.rebase)" = true
261'
262
263test_expect_success 'autosetuprebase never 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 never &&
0cb0e143 267 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
268 git branch mybase4 &&
269 git branch --track myr4 mybase2 &&
270 test "$(git config branch.myr4.remote)" = . &&
271 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
272 ! test "$(git config branch.myr4.rebase)" = true
273'
274
275test_expect_success 'autosetuprebase local on a tracked remote branch' '
276 git config remote.local.url . &&
277 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
278 git config branch.autosetuprebase local &&
0cb0e143 279 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
280 git branch --track myr5 local/master &&
281 test "$(git config branch.myr5.remote)" = local &&
282 test "$(git config branch.myr5.merge)" = refs/heads/master &&
283 ! test "$(git config branch.myr5.rebase)" = true
284'
285
286test_expect_success 'autosetuprebase never on a tracked remote branch' '
287 git config remote.local.url . &&
288 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
289 git config branch.autosetuprebase never &&
0cb0e143 290 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
291 git branch --track myr6 local/master &&
292 test "$(git config branch.myr6.remote)" = local &&
293 test "$(git config branch.myr6.merge)" = refs/heads/master &&
294 ! test "$(git config branch.myr6.rebase)" = true
295'
296
297test_expect_success 'autosetuprebase remote on a tracked remote branch' '
298 git config remote.local.url . &&
299 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
300 git config branch.autosetuprebase remote &&
0cb0e143 301 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
302 git branch --track myr7 local/master &&
303 test "$(git config branch.myr7.remote)" = local &&
304 test "$(git config branch.myr7.merge)" = refs/heads/master &&
305 test "$(git config branch.myr7.rebase)" = true
306'
307
308test_expect_success 'autosetuprebase always on a tracked remote branch' '
309 git config remote.local.url . &&
310 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
311 git config branch.autosetuprebase remote &&
0cb0e143 312 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
313 git branch --track myr8 local/master &&
314 test "$(git config branch.myr8.remote)" = local &&
315 test "$(git config branch.myr8.merge)" = refs/heads/master &&
316 test "$(git config branch.myr8.rebase)" = true
317'
318
319test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
320 git config --unset branch.autosetuprebase &&
321 git config remote.local.url . &&
322 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 323 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
324 git branch --track myr9 local/master &&
325 test "$(git config branch.myr9.remote)" = local &&
326 test "$(git config branch.myr9.merge)" = refs/heads/master &&
327 test "z$(git config branch.myr9.rebase)" = z
328'
329
330test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
331 git config remote.local.url . &&
332 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 333 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
334 git branch mybase10 &&
335 git branch --track myr10 mybase2 &&
336 test "$(git config branch.myr10.remote)" = . &&
337 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
338 test "z$(git config branch.myr10.rebase)" = z
339'
340
341test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
342 git config remote.local.url . &&
343 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 344 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
345 git branch --no-track myr11 mybase2 &&
346 test "z$(git config branch.myr11.remote)" = z &&
347 test "z$(git config branch.myr11.merge)" = z &&
348 test "z$(git config branch.myr11.rebase)" = z
349'
350
351test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
352 git config remote.local.url . &&
353 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 354 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
355 git branch --no-track myr12 local/master &&
356 test "z$(git config branch.myr12.remote)" = z &&
357 test "z$(git config branch.myr12.merge)" = z &&
358 test "z$(git config branch.myr12.rebase)" = z
359'
360
361test_expect_success 'autosetuprebase never on an untracked local branch' '
362 git config branch.autosetuprebase never &&
363 git config remote.local.url . &&
364 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 365 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
366 git branch --no-track myr13 mybase2 &&
367 test "z$(git config branch.myr13.remote)" = z &&
368 test "z$(git config branch.myr13.merge)" = z &&
369 test "z$(git config branch.myr13.rebase)" = z
370'
371
372test_expect_success 'autosetuprebase local on an untracked local branch' '
373 git config branch.autosetuprebase local &&
374 git config remote.local.url . &&
375 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 376 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
377 git branch --no-track myr14 mybase2 &&
378 test "z$(git config branch.myr14.remote)" = z &&
379 test "z$(git config branch.myr14.merge)" = z &&
380 test "z$(git config branch.myr14.rebase)" = z
381'
382
383test_expect_success 'autosetuprebase remote on an untracked local branch' '
384 git config branch.autosetuprebase remote &&
385 git config remote.local.url . &&
386 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 387 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
388 git branch --no-track myr15 mybase2 &&
389 test "z$(git config branch.myr15.remote)" = z &&
390 test "z$(git config branch.myr15.merge)" = z &&
391 test "z$(git config branch.myr15.rebase)" = z
392'
393
394test_expect_success 'autosetuprebase always on an untracked local branch' '
395 git config branch.autosetuprebase always &&
396 git config remote.local.url . &&
397 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 398 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
399 git branch --no-track myr16 mybase2 &&
400 test "z$(git config branch.myr16.remote)" = z &&
401 test "z$(git config branch.myr16.merge)" = z &&
402 test "z$(git config branch.myr16.rebase)" = z
403'
404
405test_expect_success 'autosetuprebase never on an untracked remote branch' '
406 git config branch.autosetuprebase never &&
407 git config remote.local.url . &&
408 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 409 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
410 git branch --no-track myr17 local/master &&
411 test "z$(git config branch.myr17.remote)" = z &&
412 test "z$(git config branch.myr17.merge)" = z &&
413 test "z$(git config branch.myr17.rebase)" = z
414'
415
416test_expect_success 'autosetuprebase local on an untracked remote branch' '
417 git config branch.autosetuprebase local &&
418 git config remote.local.url . &&
419 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 420 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
421 git branch --no-track myr18 local/master &&
422 test "z$(git config branch.myr18.remote)" = z &&
423 test "z$(git config branch.myr18.merge)" = z &&
424 test "z$(git config branch.myr18.rebase)" = z
425'
426
427test_expect_success 'autosetuprebase remote on an untracked remote branch' '
428 git config branch.autosetuprebase remote &&
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/master || git fetch local) &&
c998ae9b
DS
432 git branch --no-track myr19 local/master &&
433 test "z$(git config branch.myr19.remote)" = z &&
434 test "z$(git config branch.myr19.merge)" = z &&
435 test "z$(git config branch.myr19.rebase)" = z
436'
437
438test_expect_success 'autosetuprebase always on an untracked remote branch' '
439 git config branch.autosetuprebase always &&
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 myr20 local/master &&
444 test "z$(git config branch.myr20.remote)" = z &&
445 test "z$(git config branch.myr20.merge)" = z &&
446 test "z$(git config branch.myr20.rebase)" = z
447'
448
449test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
450 git config branch.autosetuprebase garbage &&
451 test_must_fail git branch
452'
453
454test_expect_success 'detect misconfigured autosetuprebase (no value)' '
455 git config --unset branch.autosetuprebase &&
456 echo "[branch] autosetuprebase" >> .git/config &&
457 test_must_fail git branch &&
458 git config --unset branch.autosetuprebase
459'
460
a3b427b9 461test_done