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.
14 'prepare a trivial repository' \
16 git update-index --add A &&
17 git-commit -m "Initial commit." &&
19 git update-index --add A &&
20 git-commit -m "Second commit." &&
21 HEAD=$(git rev-parse --verify HEAD)'
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
30 'git branch abc should create a branch' \
31 'git branch abc && test -f .git/refs/heads/abc'
34 'git branch a/b/c should create a branch' \
35 'git branch a/b/c && test -f .git/refs/heads/a/b/c'
38 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
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'
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'
55 'git branch j/k should work after branch j has been deleted' \
61 'git branch l should work after branch l/m has been deleted' \
67 'git branch -m m m/m should work' \
69 git branch -m m m/m &&
70 test -f .git/logs/refs/heads/m/m'
73 'git branch -m n/n n should work' \
76 test -f .git/logs/refs/heads/n'
78 test_expect_success
'git branch -m o/o o should fail when o/p exists' '
84 test_expect_success
'git branch -m q r/q should fail when r exists' '
90 mv .git
/config .git
/config-saved
92 test_expect_success
'git branch -m q q2 without config should succeed' '
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 &&
106 test -f .git/logs/refs/heads/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 ! git config branch.s/s/dummy"
115 test "$no_symlinks" ||
{
116 test_expect_success \
117 'git branch -m u v should fail when the reflog for u is a symlink' '
119 mv .git/logs/refs/heads/u real-u &&
120 ln -s real-u .git/logs/refs/heads/u &&
125 test_expect_success
'test tracking setup via --track' \
126 'git config remote.local.url . &&
127 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
128 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
129 git branch --track my1 local/master &&
130 test $(git config branch.my1.remote) = local &&
131 test $(git config branch.my1.merge) = refs/heads/master'
133 test_expect_success
'test tracking setup (non-wildcard, matching)' \
134 'git config remote.local.url . &&
135 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
136 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
137 git branch --track my4 local/master &&
138 test $(git config branch.my4.remote) = local &&
139 test $(git config branch.my4.merge) = refs/heads/master'
141 test_expect_success
'test tracking setup (non-wildcard, not matching)' \
142 'git config remote.local.url . &&
143 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
144 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
145 git branch --track my5 local/master &&
146 ! test "$(git config branch.my5.remote)" = local &&
147 ! test "$(git config branch.my5.merge)" = refs/heads/master'
149 test_expect_success
'test tracking setup via config' \
150 'git config branch.autosetupmerge true &&
151 git config remote.local.url . &&
152 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
153 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
154 git branch my3 local/master &&
155 test $(git config branch.my3.remote) = local &&
156 test $(git config branch.my3.merge) = refs/heads/master'
158 test_expect_success
'test overriding tracking setup via --no-track' \
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 --no-track my2 local/master &&
164 git config branch.autosetupmerge false &&
165 ! test "$(git config branch.my2.remote)" = local &&
166 ! test "$(git config branch.my2.merge)" = refs/heads/master'
168 test_expect_success
'no tracking without .fetch entries' \
169 'git config branch.autosetupmerge true &&
171 git config branch.automsetupmerge false &&
172 test -z "$(git config branch.my6.remote)" &&
173 test -z "$(git config branch.my6.merge)"'
175 test_expect_success
'test tracking setup via --track but deeper' \
176 'git config remote.local.url . &&
177 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
178 (git show-ref -q refs/remotes/local/o/o || git-fetch local) &&
179 git branch --track my7 local/o/o &&
180 test "$(git config branch.my7.remote)" = local &&
181 test "$(git config branch.my7.merge)" = refs/heads/o/o'
183 test_expect_success
'test deleting branch deletes branch config' \
184 'git branch -d my7 &&
185 test -z "$(git config branch.my7.remote)" &&
186 test -z "$(git config branch.my7.merge)"'
188 test_expect_success
'test deleting branch without config' \
190 test "$(git branch -d my7 2>&1)" = "Deleted branch my7."'
192 test_expect_success
'test --track without .fetch entries' \
193 'git branch --track my8 &&
194 test "$(git config branch.my8.remote)" &&
195 test "$(git config branch.my8.merge)"'
197 test_expect_success \
198 'branch from non-branch HEAD w/autosetupmerge=always' \
199 'git config branch.autosetupmerge always &&
200 git branch my9 HEAD^ &&
201 git config branch.autosetupmerge false'
203 test_expect_success \
204 'branch from non-branch HEAD w/--track causes failure' \
205 '!(git branch --track my10 HEAD^)'
207 # Keep this test last, as it changes the current branch
209 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
211 test_expect_success \
212 'git checkout -b g/h/i -l should create a branch and a log' \
213 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
214 git-checkout -b g/h/i -l master &&
215 test -f .git/refs/heads/g/h/i &&
216 test -f .git/logs/refs/heads/g/h/i &&
217 diff expect .git/logs/refs/heads/g/h/i'
219 test_expect_success
'avoid ambiguous track' '
220 git config branch.autosetupmerge true &&
221 git config remote.ambi1.url lalala &&
222 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
223 git config remote.ambi2.url lilili &&
224 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
225 git branch all1 master &&
226 test -z "$(git config branch.all1.merge)"
229 test_expect_success
'autosetuprebase local on a tracked local branch' '
230 git config remote.local.url . &&
231 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
232 git config branch.autosetuprebase local &&
233 (git show-ref -q refs/remotes/local/o || git-fetch local) &&
235 git branch --track myr1 mybase &&
236 test "$(git config branch.myr1.remote)" = . &&
237 test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
238 test "$(git config branch.myr1.rebase)" = true
241 test_expect_success
'autosetuprebase always on a tracked local branch' '
242 git config remote.local.url . &&
243 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
244 git config branch.autosetuprebase always &&
245 (git show-ref -q refs/remotes/local/o || git-fetch local) &&
246 git branch mybase2 &&
247 git branch --track myr2 mybase &&
248 test "$(git config branch.myr2.remote)" = . &&
249 test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
250 test "$(git config branch.myr2.rebase)" = true
253 test_expect_success
'autosetuprebase remote on a tracked local branch' '
254 git config remote.local.url . &&
255 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
256 git config branch.autosetuprebase remote &&
257 (git show-ref -q refs/remotes/local/o || git-fetch local) &&
258 git branch mybase3 &&
259 git branch --track myr3 mybase2 &&
260 test "$(git config branch.myr3.remote)" = . &&
261 test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
262 ! test "$(git config branch.myr3.rebase)" = true
265 test_expect_success
'autosetuprebase never on a tracked local branch' '
266 git config remote.local.url . &&
267 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
268 git config branch.autosetuprebase never &&
269 (git show-ref -q refs/remotes/local/o || git-fetch local) &&
270 git branch mybase4 &&
271 git branch --track myr4 mybase2 &&
272 test "$(git config branch.myr4.remote)" = . &&
273 test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
274 ! test "$(git config branch.myr4.rebase)" = true
277 test_expect_success
'autosetuprebase local on a tracked remote branch' '
278 git config remote.local.url . &&
279 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
280 git config branch.autosetuprebase local &&
281 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
282 git branch --track myr5 local/master &&
283 test "$(git config branch.myr5.remote)" = local &&
284 test "$(git config branch.myr5.merge)" = refs/heads/master &&
285 ! test "$(git config branch.myr5.rebase)" = true
288 test_expect_success
'autosetuprebase never on a tracked remote branch' '
289 git config remote.local.url . &&
290 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
291 git config branch.autosetuprebase never &&
292 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
293 git branch --track myr6 local/master &&
294 test "$(git config branch.myr6.remote)" = local &&
295 test "$(git config branch.myr6.merge)" = refs/heads/master &&
296 ! test "$(git config branch.myr6.rebase)" = true
299 test_expect_success
'autosetuprebase remote on a tracked remote branch' '
300 git config remote.local.url . &&
301 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
302 git config branch.autosetuprebase remote &&
303 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
304 git branch --track myr7 local/master &&
305 test "$(git config branch.myr7.remote)" = local &&
306 test "$(git config branch.myr7.merge)" = refs/heads/master &&
307 test "$(git config branch.myr7.rebase)" = true
310 test_expect_success
'autosetuprebase always on a tracked remote branch' '
311 git config remote.local.url . &&
312 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
313 git config branch.autosetuprebase remote &&
314 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
315 git branch --track myr8 local/master &&
316 test "$(git config branch.myr8.remote)" = local &&
317 test "$(git config branch.myr8.merge)" = refs/heads/master &&
318 test "$(git config branch.myr8.rebase)" = true
321 test_expect_success
'autosetuprebase unconfigured on a tracked remote branch' '
322 git config --unset branch.autosetuprebase &&
323 git config remote.local.url . &&
324 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
325 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
326 git branch --track myr9 local/master &&
327 test "$(git config branch.myr9.remote)" = local &&
328 test "$(git config branch.myr9.merge)" = refs/heads/master &&
329 test "z$(git config branch.myr9.rebase)" = z
332 test_expect_success
'autosetuprebase unconfigured on a tracked local branch' '
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/o || git-fetch local) &&
336 git branch mybase10 &&
337 git branch --track myr10 mybase2 &&
338 test "$(git config branch.myr10.remote)" = . &&
339 test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
340 test "z$(git config branch.myr10.rebase)" = z
343 test_expect_success
'autosetuprebase unconfigured on untracked local branch' '
344 git config remote.local.url . &&
345 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
346 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
347 git branch --no-track myr11 mybase2 &&
348 test "z$(git config branch.myr11.remote)" = z &&
349 test "z$(git config branch.myr11.merge)" = z &&
350 test "z$(git config branch.myr11.rebase)" = z
353 test_expect_success
'autosetuprebase unconfigured on untracked remote 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 myr12 local/master &&
358 test "z$(git config branch.myr12.remote)" = z &&
359 test "z$(git config branch.myr12.merge)" = z &&
360 test "z$(git config branch.myr12.rebase)" = z
363 test_expect_success
'autosetuprebase never on an untracked local branch' '
364 git config branch.autosetuprebase never &&
365 git config remote.local.url . &&
366 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
367 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
368 git branch --no-track myr13 mybase2 &&
369 test "z$(git config branch.myr13.remote)" = z &&
370 test "z$(git config branch.myr13.merge)" = z &&
371 test "z$(git config branch.myr13.rebase)" = z
374 test_expect_success
'autosetuprebase local on an untracked local branch' '
375 git config branch.autosetuprebase local &&
376 git config remote.local.url . &&
377 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
378 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
379 git branch --no-track myr14 mybase2 &&
380 test "z$(git config branch.myr14.remote)" = z &&
381 test "z$(git config branch.myr14.merge)" = z &&
382 test "z$(git config branch.myr14.rebase)" = z
385 test_expect_success
'autosetuprebase remote on an untracked local branch' '
386 git config branch.autosetuprebase remote &&
387 git config remote.local.url . &&
388 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
389 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
390 git branch --no-track myr15 mybase2 &&
391 test "z$(git config branch.myr15.remote)" = z &&
392 test "z$(git config branch.myr15.merge)" = z &&
393 test "z$(git config branch.myr15.rebase)" = z
396 test_expect_success
'autosetuprebase always on an untracked local branch' '
397 git config branch.autosetuprebase always &&
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 myr16 mybase2 &&
402 test "z$(git config branch.myr16.remote)" = z &&
403 test "z$(git config branch.myr16.merge)" = z &&
404 test "z$(git config branch.myr16.rebase)" = z
407 test_expect_success
'autosetuprebase never on an untracked remote 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 myr17 local/master &&
413 test "z$(git config branch.myr17.remote)" = z &&
414 test "z$(git config branch.myr17.merge)" = z &&
415 test "z$(git config branch.myr17.rebase)" = z
418 test_expect_success
'autosetuprebase local on an untracked remote 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 myr18 local/master &&
424 test "z$(git config branch.myr18.remote)" = z &&
425 test "z$(git config branch.myr18.merge)" = z &&
426 test "z$(git config branch.myr18.rebase)" = z
429 test_expect_success
'autosetuprebase remote on an untracked remote 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 myr19 local/master &&
435 test "z$(git config branch.myr19.remote)" = z &&
436 test "z$(git config branch.myr19.merge)" = z &&
437 test "z$(git config branch.myr19.rebase)" = z
440 test_expect_success
'autosetuprebase always on an untracked remote 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 myr20 local/master &&
446 test "z$(git config branch.myr20.remote)" = z &&
447 test "z$(git config branch.myr20.merge)" = z &&
448 test "z$(git config branch.myr20.rebase)" = z
451 test_expect_success
'detect misconfigured autosetuprebase (bad value)' '
452 git config branch.autosetuprebase garbage &&
453 test_must_fail git branch
456 test_expect_success
'detect misconfigured autosetuprebase (no value)' '
457 git config --unset branch.autosetuprebase &&
458 echo "[branch] autosetuprebase" >> .git/config &&
459 test_must_fail git branch &&
460 git config --unset branch.autosetuprebase