]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3200-branch.sh
Fix git update-ref --no-deref -d.
[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
eca35a25
MV
115test_expect_success 'renaming a symref' \
116'
117 git symbolic-ref refs/heads/master2 refs/heads/master &&
118 git branch -m master2 master3 &&
119 git symbolic-ref refs/heads/master3 &&
120 test -f .git/refs/heads/master &&
121 ! test -f .git/refs/heads/master2
122'
123
41ac414e
JH
124test_expect_success \
125 'git branch -m u v should fail when the reflog for u is a symlink' '
126 git branch -l u &&
16c2bfbb
LH
127 mv .git/logs/refs/heads/u real-u &&
128 ln -s real-u .git/logs/refs/heads/u &&
d492b31c 129 test_must_fail git branch -m u v
41ac414e 130'
16c2bfbb 131
0746d19a 132test_expect_success 'test tracking setup via --track' \
5be60078
JH
133 'git config remote.local.url . &&
134 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 135 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
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'
0746d19a
PB
139
140test_expect_success 'test tracking setup (non-wildcard, matching)' \
5be60078
JH
141 'git config remote.local.url . &&
142 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
0cb0e143 143 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
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'
0746d19a
PB
147
148test_expect_success 'test tracking setup (non-wildcard, not matching)' \
5be60078
JH
149 'git config remote.local.url . &&
150 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
0cb0e143 151 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
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'
0746d19a
PB
155
156test_expect_success 'test tracking setup via config' \
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 my3 local/master &&
162 test $(git config branch.my3.remote) = local &&
163 test $(git config branch.my3.merge) = refs/heads/master'
0746d19a
PB
164
165test_expect_success 'test overriding tracking setup via --no-track' \
5be60078
JH
166 'git config branch.autosetupmerge true &&
167 git config remote.local.url . &&
168 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 169 (git show-ref -q refs/remotes/local/master || git fetch local) &&
5be60078
JH
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'
0746d19a 174
6f084a56 175test_expect_success 'no tracking without .fetch entries' \
9ed36cfa
JS
176 'git config branch.autosetupmerge true &&
177 git branch my6 s &&
178 git config branch.automsetupmerge false &&
6f084a56
JS
179 test -z "$(git config branch.my6.remote)" &&
180 test -z "$(git config branch.my6.merge)"'
9debc324 181
11f68d90 182test_expect_success 'test tracking setup via --track but deeper' \
5be60078
JH
183 'git config remote.local.url . &&
184 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 185 (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
5be60078
JH
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'
11f68d90 189
f1eccbab 190test_expect_success 'test deleting branch deletes branch config' \
5be60078 191 'git branch -d my7 &&
6f084a56
JS
192 test -z "$(git config branch.my7.remote)" &&
193 test -z "$(git config branch.my7.merge)"'
f1eccbab
GP
194
195test_expect_success 'test deleting branch without config' \
5be60078
JH
196 'git branch my7 s &&
197 test "$(git branch -d my7 2>&1)" = "Deleted branch my7."'
f1eccbab 198
9ed36cfa
JS
199test_expect_success 'test --track without .fetch entries' \
200 'git branch --track my8 &&
201 test "$(git config branch.my8.remote)" &&
202 test "$(git config branch.my8.merge)"'
203
204test_expect_success \
205 'branch from non-branch HEAD w/autosetupmerge=always' \
206 'git config branch.autosetupmerge always &&
207 git branch my9 HEAD^ &&
208 git config branch.autosetupmerge false'
209
210test_expect_success \
211 'branch from non-branch HEAD w/--track causes failure' \
03b9dfb1 212 'test_must_fail git branch --track my10 HEAD^'
9ed36cfa 213
0746d19a
PB
214# Keep this test last, as it changes the current branch
215cat >expect <<EOF
2160000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
217EOF
218test_expect_success \
219 'git checkout -b g/h/i -l should create a branch and a log' \
220 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
0cb0e143 221 git checkout -b g/h/i -l master &&
0746d19a
PB
222 test -f .git/refs/heads/g/h/i &&
223 test -f .git/logs/refs/heads/g/h/i &&
224 diff expect .git/logs/refs/heads/g/h/i'
225
1d0a694b
DB
226test_expect_success 'avoid ambiguous track' '
227 git config branch.autosetupmerge true &&
228 git config remote.ambi1.url lalala &&
229 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
230 git config remote.ambi2.url lilili &&
231 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
232 git branch all1 master &&
233 test -z "$(git config branch.all1.merge)"
234'
235
c998ae9b
DS
236test_expect_success 'autosetuprebase local on a tracked local branch' '
237 git config remote.local.url . &&
238 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
239 git config branch.autosetuprebase local &&
0cb0e143 240 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
241 git branch mybase &&
242 git branch --track myr1 mybase &&
243 test "$(git config branch.myr1.remote)" = . &&
244 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
245 test "$(git config branch.myr1.rebase)" = true
246'
247
248test_expect_success 'autosetuprebase always on a tracked local branch' '
249 git config remote.local.url . &&
250 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
251 git config branch.autosetuprebase always &&
0cb0e143 252 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
253 git branch mybase2 &&
254 git branch --track myr2 mybase &&
255 test "$(git config branch.myr2.remote)" = . &&
256 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
257 test "$(git config branch.myr2.rebase)" = true
258'
259
260test_expect_success 'autosetuprebase remote on a tracked local branch' '
261 git config remote.local.url . &&
262 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
263 git config branch.autosetuprebase remote &&
0cb0e143 264 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
265 git branch mybase3 &&
266 git branch --track myr3 mybase2 &&
267 test "$(git config branch.myr3.remote)" = . &&
268 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
269 ! test "$(git config branch.myr3.rebase)" = true
270'
271
272test_expect_success 'autosetuprebase never 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 never &&
0cb0e143 276 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
277 git branch mybase4 &&
278 git branch --track myr4 mybase2 &&
279 test "$(git config branch.myr4.remote)" = . &&
280 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
281 ! test "$(git config branch.myr4.rebase)" = true
282'
283
284test_expect_success 'autosetuprebase local on a tracked remote branch' '
285 git config remote.local.url . &&
286 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
287 git config branch.autosetuprebase local &&
0cb0e143 288 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
289 git branch --track myr5 local/master &&
290 test "$(git config branch.myr5.remote)" = local &&
291 test "$(git config branch.myr5.merge)" = refs/heads/master &&
292 ! test "$(git config branch.myr5.rebase)" = true
293'
294
295test_expect_success 'autosetuprebase never on a tracked remote branch' '
296 git config remote.local.url . &&
297 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
298 git config branch.autosetuprebase never &&
0cb0e143 299 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
300 git branch --track myr6 local/master &&
301 test "$(git config branch.myr6.remote)" = local &&
302 test "$(git config branch.myr6.merge)" = refs/heads/master &&
303 ! test "$(git config branch.myr6.rebase)" = true
304'
305
306test_expect_success 'autosetuprebase remote 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 remote &&
0cb0e143 310 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
311 git branch --track myr7 local/master &&
312 test "$(git config branch.myr7.remote)" = local &&
313 test "$(git config branch.myr7.merge)" = refs/heads/master &&
314 test "$(git config branch.myr7.rebase)" = true
315'
316
317test_expect_success 'autosetuprebase always 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 remote &&
0cb0e143 321 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
322 git branch --track myr8 local/master &&
323 test "$(git config branch.myr8.remote)" = local &&
324 test "$(git config branch.myr8.merge)" = refs/heads/master &&
325 test "$(git config branch.myr8.rebase)" = true
326'
327
328test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
329 git config --unset branch.autosetuprebase &&
330 git config remote.local.url . &&
331 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 332 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
333 git branch --track myr9 local/master &&
334 test "$(git config branch.myr9.remote)" = local &&
335 test "$(git config branch.myr9.merge)" = refs/heads/master &&
336 test "z$(git config branch.myr9.rebase)" = z
337'
338
339test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
340 git config remote.local.url . &&
341 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 342 (git show-ref -q refs/remotes/local/o || git fetch local) &&
c998ae9b
DS
343 git branch mybase10 &&
344 git branch --track myr10 mybase2 &&
345 test "$(git config branch.myr10.remote)" = . &&
346 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
347 test "z$(git config branch.myr10.rebase)" = z
348'
349
350test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
351 git config remote.local.url . &&
352 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 353 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
354 git branch --no-track myr11 mybase2 &&
355 test "z$(git config branch.myr11.remote)" = z &&
356 test "z$(git config branch.myr11.merge)" = z &&
357 test "z$(git config branch.myr11.rebase)" = z
358'
359
360test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
361 git config remote.local.url . &&
362 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 363 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
364 git branch --no-track myr12 local/master &&
365 test "z$(git config branch.myr12.remote)" = z &&
366 test "z$(git config branch.myr12.merge)" = z &&
367 test "z$(git config branch.myr12.rebase)" = z
368'
369
370test_expect_success 'autosetuprebase never on an untracked local branch' '
371 git config branch.autosetuprebase never &&
372 git config remote.local.url . &&
373 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 374 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
375 git branch --no-track myr13 mybase2 &&
376 test "z$(git config branch.myr13.remote)" = z &&
377 test "z$(git config branch.myr13.merge)" = z &&
378 test "z$(git config branch.myr13.rebase)" = z
379'
380
381test_expect_success 'autosetuprebase local on an untracked local branch' '
382 git config branch.autosetuprebase local &&
383 git config remote.local.url . &&
384 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 385 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
386 git branch --no-track myr14 mybase2 &&
387 test "z$(git config branch.myr14.remote)" = z &&
388 test "z$(git config branch.myr14.merge)" = z &&
389 test "z$(git config branch.myr14.rebase)" = z
390'
391
392test_expect_success 'autosetuprebase remote on an untracked local branch' '
393 git config branch.autosetuprebase remote &&
394 git config remote.local.url . &&
395 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 396 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
397 git branch --no-track myr15 mybase2 &&
398 test "z$(git config branch.myr15.remote)" = z &&
399 test "z$(git config branch.myr15.merge)" = z &&
400 test "z$(git config branch.myr15.rebase)" = z
401'
402
403test_expect_success 'autosetuprebase always on an untracked local branch' '
404 git config branch.autosetuprebase always &&
405 git config remote.local.url . &&
406 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 407 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
408 git branch --no-track myr16 mybase2 &&
409 test "z$(git config branch.myr16.remote)" = z &&
410 test "z$(git config branch.myr16.merge)" = z &&
411 test "z$(git config branch.myr16.rebase)" = z
412'
413
414test_expect_success 'autosetuprebase never on an untracked remote branch' '
415 git config branch.autosetuprebase never &&
416 git config remote.local.url . &&
417 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 418 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
419 git branch --no-track myr17 local/master &&
420 test "z$(git config branch.myr17.remote)" = z &&
421 test "z$(git config branch.myr17.merge)" = z &&
422 test "z$(git config branch.myr17.rebase)" = z
423'
424
425test_expect_success 'autosetuprebase local on an untracked remote branch' '
426 git config branch.autosetuprebase local &&
427 git config remote.local.url . &&
428 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 429 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
430 git branch --no-track myr18 local/master &&
431 test "z$(git config branch.myr18.remote)" = z &&
432 test "z$(git config branch.myr18.merge)" = z &&
433 test "z$(git config branch.myr18.rebase)" = z
434'
435
436test_expect_success 'autosetuprebase remote on an untracked remote branch' '
437 git config branch.autosetuprebase remote &&
438 git config remote.local.url . &&
439 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 440 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
441 git branch --no-track myr19 local/master &&
442 test "z$(git config branch.myr19.remote)" = z &&
443 test "z$(git config branch.myr19.merge)" = z &&
444 test "z$(git config branch.myr19.rebase)" = z
445'
446
447test_expect_success 'autosetuprebase always on an untracked remote branch' '
448 git config branch.autosetuprebase always &&
449 git config remote.local.url . &&
450 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
0cb0e143 451 (git show-ref -q refs/remotes/local/master || git fetch local) &&
c998ae9b
DS
452 git branch --no-track myr20 local/master &&
453 test "z$(git config branch.myr20.remote)" = z &&
454 test "z$(git config branch.myr20.merge)" = z &&
455 test "z$(git config branch.myr20.rebase)" = z
456'
457
458test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
459 git config branch.autosetuprebase garbage &&
460 test_must_fail git branch
461'
462
463test_expect_success 'detect misconfigured autosetuprebase (no value)' '
464 git config --unset branch.autosetuprebase &&
465 echo "[branch] autosetuprebase" >> .git/config &&
466 test_must_fail git branch &&
467 git config --unset branch.autosetuprebase
468'
469
a3b427b9 470test_done