]>
Commit | Line | Data |
---|---|---|
a3b427b9 AW |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Amos Waterland | |
4 | # | |
5 | ||
c2d17ba3 | 6 | test_description='git branch assorted tests' |
a3b427b9 | 7 | |
a3b427b9 AW |
8 | . ./test-lib.sh |
9 | ||
0d158ebb RR |
10 | test_expect_success 'prepare a trivial repository' ' |
11 | echo Hello >A && | |
12 | git update-index --add A && | |
13 | git commit -m "Initial commit." && | |
14 | echo World >>A && | |
15 | git update-index --add A && | |
16 | git commit -m "Second commit." && | |
140cd845 FC |
17 | HEAD=$(git rev-parse --verify HEAD) |
18 | ' | |
0d158ebb RR |
19 | |
20 | test_expect_success 'git branch --help should not have created a bogus branch' ' | |
01e8d327 | 21 | test_might_fail git branch --man --help </dev/null >/dev/null 2>&1 && |
0d158ebb | 22 | test_path_is_missing .git/refs/heads/--help |
41ac414e | 23 | ' |
a3b427b9 | 24 | |
1dacfbcf NTND |
25 | test_expect_success 'branch -h in broken repository' ' |
26 | mkdir broken && | |
27 | ( | |
28 | cd broken && | |
29 | git init && | |
30 | >.git/refs/heads/master && | |
31 | test_expect_code 129 git branch -h >usage 2>&1 | |
32 | ) && | |
9a001381 | 33 | test_i18ngrep "[Uu]sage" broken/usage |
1dacfbcf NTND |
34 | ' |
35 | ||
0d158ebb RR |
36 | test_expect_success 'git branch abc should create a branch' ' |
37 | git branch abc && test_path_is_file .git/refs/heads/abc | |
38 | ' | |
08db81a9 | 39 | |
0d158ebb RR |
40 | test_expect_success 'git branch a/b/c should create a branch' ' |
41 | git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c | |
42 | ' | |
08db81a9 | 43 | |
0cb24fe8 JH |
44 | test_expect_success 'git branch HEAD should fail' ' |
45 | test_must_fail git branch HEAD | |
46 | ' | |
8efb8899 | 47 | |
d7fb7a37 | 48 | cat >expect <<EOF |
3749fde5 | 49 | $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master |
d7fb7a37 | 50 | EOF |
0d158ebb RR |
51 | test_expect_success 'git branch -l d/e/f should create a branch and a log' ' |
52 | GIT_COMMITTER_DATE="2005-05-26 23:30" \ | |
53 | git branch -l d/e/f && | |
54 | test_path_is_file .git/refs/heads/d/e/f && | |
55 | test_path_is_file .git/logs/refs/heads/d/e/f && | |
56 | test_cmp expect .git/logs/refs/heads/d/e/f | |
57 | ' | |
58 | ||
59 | test_expect_success 'git branch -d d/e/f should delete a branch and a log' ' | |
60 | git branch -d d/e/f && | |
61 | test_path_is_missing .git/refs/heads/d/e/f && | |
d0ab0584 | 62 | test_must_fail git reflog exists refs/heads/d/e/f |
0d158ebb RR |
63 | ' |
64 | ||
65 | test_expect_success 'git branch j/k should work after branch j has been deleted' ' | |
66 | git branch j && | |
67 | git branch -d j && | |
68 | git branch j/k | |
69 | ' | |
70 | ||
71 | test_expect_success 'git branch l should work after branch l/m has been deleted' ' | |
72 | git branch l/m && | |
73 | git branch -d l/m && | |
74 | git branch l | |
75 | ' | |
76 | ||
77 | test_expect_success 'git branch -m dumps usage' ' | |
78 | test_expect_code 128 git branch -m 2>err && | |
8054b9a6 | 79 | test_i18ngrep "branch name required" err |
0d158ebb RR |
80 | ' |
81 | ||
82 | test_expect_success 'git branch -m m m/m should work' ' | |
83 | git branch -l m && | |
84 | git branch -m m m/m && | |
d0ab0584 | 85 | git reflog exists refs/heads/m/m |
0d158ebb RR |
86 | ' |
87 | ||
88 | test_expect_success 'git branch -m n/n n should work' ' | |
89 | git branch -l n/n && | |
2f139044 | 90 | git branch -m n/n n && |
d0ab0584 | 91 | git reflog exists refs/heads/n |
0d158ebb | 92 | ' |
c976d415 | 93 | |
41ac414e JH |
94 | test_expect_success 'git branch -m o/o o should fail when o/p exists' ' |
95 | git branch o/o && | |
0d158ebb | 96 | git branch o/p && |
d492b31c | 97 | test_must_fail git branch -m o/o o |
41ac414e | 98 | ' |
c976d415 | 99 | |
ff7aa81f MG |
100 | test_expect_success 'git branch -m o/q o/p should fail when o/p exists' ' |
101 | git branch o/q && | |
102 | test_must_fail git branch -m o/q o/p | |
103 | ' | |
104 | ||
105 | test_expect_success 'git branch -M o/q o/p should work when o/p exists' ' | |
106 | git branch -M o/q o/p | |
107 | ' | |
108 | ||
356e91f2 MG |
109 | test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' ' |
110 | git branch o/q && | |
111 | git branch -m -f o/q o/p | |
112 | ' | |
113 | ||
41ac414e JH |
114 | test_expect_success 'git branch -m q r/q should fail when r exists' ' |
115 | git branch q && | |
116 | git branch r && | |
d492b31c | 117 | test_must_fail git branch -m q r/q |
41ac414e | 118 | ' |
c976d415 | 119 | |
55c4a673 CI |
120 | test_expect_success 'git branch -M foo bar should fail when bar is checked out' ' |
121 | git branch bar && | |
122 | git checkout -b foo && | |
123 | test_must_fail git branch -M bar foo | |
124 | ' | |
125 | ||
126 | test_expect_success 'git branch -M baz bam should succeed when baz is checked out' ' | |
127 | git checkout -b baz && | |
128 | git branch bam && | |
129 | git branch -M baz bam | |
130 | ' | |
131 | ||
3f59481e JN |
132 | test_expect_success 'git branch -M master should work when master is checked out' ' |
133 | git checkout master && | |
134 | git branch -M master | |
135 | ' | |
136 | ||
137 | test_expect_success 'git branch -M master master should work when master is checked out' ' | |
138 | git checkout master && | |
139 | git branch -M master master | |
140 | ' | |
141 | ||
142 | test_expect_success 'git branch -M master2 master2 should work when master is checked out' ' | |
143 | git checkout master && | |
144 | git branch master2 && | |
145 | git branch -M master2 master2 | |
146 | ' | |
147 | ||
cddd127b MG |
148 | test_expect_success 'git branch -v -d t should work' ' |
149 | git branch t && | |
376eb14a | 150 | test_path_is_file .git/refs/heads/t && |
cddd127b | 151 | git branch -v -d t && |
376eb14a | 152 | test_path_is_missing .git/refs/heads/t |
cddd127b MG |
153 | ' |
154 | ||
155 | test_expect_success 'git branch -v -m t s should work' ' | |
156 | git branch t && | |
376eb14a | 157 | test_path_is_file .git/refs/heads/t && |
cddd127b | 158 | git branch -v -m t s && |
376eb14a JK |
159 | test_path_is_missing .git/refs/heads/t && |
160 | test_path_is_file .git/refs/heads/s && | |
cddd127b MG |
161 | git branch -d s |
162 | ' | |
163 | ||
164 | test_expect_success 'git branch -m -d t s should fail' ' | |
165 | git branch t && | |
376eb14a | 166 | test_path_is_file .git/refs/heads/t && |
cddd127b MG |
167 | test_must_fail git branch -m -d t s && |
168 | git branch -d t && | |
376eb14a | 169 | test_path_is_missing .git/refs/heads/t |
cddd127b MG |
170 | ' |
171 | ||
172 | test_expect_success 'git branch --list -d t should fail' ' | |
173 | git branch t && | |
376eb14a | 174 | test_path_is_file .git/refs/heads/t && |
cddd127b MG |
175 | test_must_fail git branch --list -d t && |
176 | git branch -d t && | |
376eb14a | 177 | test_path_is_missing .git/refs/heads/t |
cddd127b MG |
178 | ' |
179 | ||
ebe31ef2 NTND |
180 | test_expect_success 'git branch --column' ' |
181 | COLUMNS=81 git branch --column=column >actual && | |
182 | cat >expected <<\EOF && | |
183 | a/b/c bam foo l * master n o/p r | |
184 | abc bar j/k m/m master2 o/o q | |
185 | EOF | |
186 | test_cmp expected actual | |
187 | ' | |
188 | ||
189 | test_expect_success 'git branch --column with an extremely long branch name' ' | |
190 | long=this/is/a/part/of/long/branch/name && | |
191 | long=z$long/$long/$long/$long && | |
192 | test_when_finished "git branch -d $long" && | |
193 | git branch $long && | |
194 | COLUMNS=80 git branch --column=column >actual && | |
195 | cat >expected <<EOF && | |
196 | a/b/c | |
197 | abc | |
198 | bam | |
199 | bar | |
200 | foo | |
201 | j/k | |
202 | l | |
203 | m/m | |
204 | * master | |
205 | master2 | |
206 | n | |
207 | o/o | |
208 | o/p | |
209 | q | |
210 | r | |
211 | $long | |
212 | EOF | |
213 | test_cmp expected actual | |
214 | ' | |
215 | ||
216 | test_expect_success 'git branch with column.*' ' | |
217 | git config column.ui column && | |
218 | git config column.branch "dense" && | |
219 | COLUMNS=80 git branch >actual && | |
220 | git config --unset column.branch && | |
221 | git config --unset column.ui && | |
222 | cat >expected <<\EOF && | |
223 | a/b/c bam foo l * master n o/p r | |
224 | abc bar j/k m/m master2 o/o q | |
225 | EOF | |
226 | test_cmp expected actual | |
227 | ' | |
228 | ||
229 | test_expect_success 'git branch --column -v should fail' ' | |
230 | test_must_fail git branch --column -v | |
231 | ' | |
232 | ||
233 | test_expect_success 'git branch -v with column.ui ignored' ' | |
234 | git config column.ui column && | |
235 | COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual && | |
236 | git config --unset column.ui && | |
237 | cat >expected <<\EOF && | |
238 | a/b/c | |
239 | abc | |
240 | bam | |
241 | bar | |
242 | foo | |
243 | j/k | |
244 | l | |
245 | m/m | |
246 | * master | |
247 | master2 | |
248 | n | |
249 | o/o | |
250 | o/p | |
251 | q | |
252 | r | |
253 | EOF | |
254 | test_cmp expected actual | |
255 | ' | |
256 | ||
01ebb9dc GB |
257 | mv .git/config .git/config-saved |
258 | ||
08b984fb | 259 | test_expect_success 'git branch -m q q2 without config should succeed' ' |
5be60078 JH |
260 | git branch -m q q2 && |
261 | git branch -m q2 q | |
01ebb9dc GB |
262 | ' |
263 | ||
264 | mv .git/config-saved .git/config | |
265 | ||
5be60078 | 266 | git config branch.s/s.dummy Hello |
dc81c58c | 267 | |
0d158ebb RR |
268 | test_expect_success 'git branch -m s/s s should work when s/t is deleted' ' |
269 | git branch -l s/s && | |
d0ab0584 | 270 | git reflog exists refs/heads/s/s && |
0d158ebb | 271 | git branch -l s/t && |
d0ab0584 | 272 | git reflog exists refs/heads/s/t && |
0d158ebb RR |
273 | git branch -d s/t && |
274 | git branch -m s/s s && | |
d0ab0584 | 275 | git reflog exists refs/heads/s |
0d158ebb | 276 | ' |
c976d415 | 277 | |
0d158ebb RR |
278 | test_expect_success 'config information was renamed, too' ' |
279 | test $(git config branch.s.dummy) = Hello && | |
280 | test_must_fail git config branch.s/s/dummy | |
281 | ' | |
dc81c58c | 282 | |
566c7707 RS |
283 | test_expect_success 'deleting a symref' ' |
284 | git branch target && | |
285 | git symbolic-ref refs/heads/symref refs/heads/target && | |
13baa9fe | 286 | echo "Deleted branch symref (was refs/heads/target)." >expect && |
566c7707 RS |
287 | git branch -d symref >actual && |
288 | test_path_is_file .git/refs/heads/target && | |
289 | test_path_is_missing .git/refs/heads/symref && | |
290 | test_i18ncmp expect actual | |
291 | ' | |
292 | ||
0fe700e3 RS |
293 | test_expect_success 'deleting a dangling symref' ' |
294 | git symbolic-ref refs/heads/dangling-symref nowhere && | |
295 | test_path_is_file .git/refs/heads/dangling-symref && | |
13baa9fe | 296 | echo "Deleted branch dangling-symref (was nowhere)." >expect && |
0fe700e3 RS |
297 | git branch -d dangling-symref >actual && |
298 | test_path_is_missing .git/refs/heads/dangling-symref && | |
299 | test_i18ncmp expect actual | |
300 | ' | |
301 | ||
62a2d525 JN |
302 | test_expect_success 'deleting a self-referential symref' ' |
303 | git symbolic-ref refs/heads/self-reference refs/heads/self-reference && | |
304 | test_path_is_file .git/refs/heads/self-reference && | |
305 | echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect && | |
306 | git branch -d self-reference >actual && | |
307 | test_path_is_missing .git/refs/heads/self-reference && | |
308 | test_i18ncmp expect actual | |
309 | ' | |
310 | ||
0d158ebb | 311 | test_expect_success 'renaming a symref is not allowed' ' |
eca35a25 | 312 | git symbolic-ref refs/heads/master2 refs/heads/master && |
fa58186c MV |
313 | test_must_fail git branch -m master2 master3 && |
314 | git symbolic-ref refs/heads/master2 && | |
376eb14a JK |
315 | test_path_is_file .git/refs/heads/master && |
316 | test_path_is_missing .git/refs/heads/master3 | |
eca35a25 MV |
317 | ' |
318 | ||
0d158ebb RR |
319 | test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' ' |
320 | git branch -l u && | |
321 | mv .git/logs/refs/heads/u real-u && | |
322 | ln -s real-u .git/logs/refs/heads/u && | |
323 | test_must_fail git branch -m u v | |
324 | ' | |
325 | ||
326 | test_expect_success 'test tracking setup via --track' ' | |
327 | git config remote.local.url . && | |
328 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
329 | (git show-ref -q refs/remotes/local/master || git fetch local) && | |
330 | git branch --track my1 local/master && | |
331 | test $(git config branch.my1.remote) = local && | |
332 | test $(git config branch.my1.merge) = refs/heads/master | |
333 | ' | |
334 | ||
335 | test_expect_success 'test tracking setup (non-wildcard, matching)' ' | |
336 | git config remote.local.url . && | |
337 | git config remote.local.fetch refs/heads/master:refs/remotes/local/master && | |
338 | (git show-ref -q refs/remotes/local/master || git fetch local) && | |
339 | git branch --track my4 local/master && | |
340 | test $(git config branch.my4.remote) = local && | |
341 | test $(git config branch.my4.merge) = refs/heads/master | |
342 | ' | |
343 | ||
41c21f22 | 344 | test_expect_success 'tracking setup fails on non-matching refspec' ' |
0d158ebb | 345 | git config remote.local.url . && |
81f339dc | 346 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && |
0d158ebb | 347 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
81f339dc | 348 | git config remote.local.fetch refs/heads/s:refs/remotes/local/s && |
9c9cd39a JH |
349 | test_must_fail git branch --track my5 local/master && |
350 | test_must_fail git config branch.my5.remote && | |
351 | test_must_fail git config branch.my5.merge | |
0d158ebb RR |
352 | ' |
353 | ||
354 | test_expect_success 'test tracking setup via config' ' | |
355 | git config branch.autosetupmerge true && | |
356 | git config remote.local.url . && | |
357 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
358 | (git show-ref -q refs/remotes/local/master || git fetch local) && | |
359 | git branch my3 local/master && | |
360 | test $(git config branch.my3.remote) = local && | |
361 | test $(git config branch.my3.merge) = refs/heads/master | |
362 | ' | |
363 | ||
364 | test_expect_success 'test overriding tracking setup via --no-track' ' | |
365 | git config branch.autosetupmerge true && | |
366 | git config remote.local.url . && | |
367 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
368 | (git show-ref -q refs/remotes/local/master || git fetch local) && | |
369 | git branch --no-track my2 local/master && | |
370 | git config branch.autosetupmerge false && | |
371 | ! test "$(git config branch.my2.remote)" = local && | |
372 | ! test "$(git config branch.my2.merge)" = refs/heads/master | |
373 | ' | |
374 | ||
375 | test_expect_success 'no tracking without .fetch entries' ' | |
376 | git config branch.autosetupmerge true && | |
377 | git branch my6 s && | |
002ba037 | 378 | git config branch.autosetupmerge false && |
0d158ebb RR |
379 | test -z "$(git config branch.my6.remote)" && |
380 | test -z "$(git config branch.my6.merge)" | |
381 | ' | |
382 | ||
383 | test_expect_success 'test tracking setup via --track but deeper' ' | |
384 | git config remote.local.url . && | |
385 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
386 | (git show-ref -q refs/remotes/local/o/o || git fetch local) && | |
387 | git branch --track my7 local/o/o && | |
388 | test "$(git config branch.my7.remote)" = local && | |
389 | test "$(git config branch.my7.merge)" = refs/heads/o/o | |
390 | ' | |
391 | ||
392 | test_expect_success 'test deleting branch deletes branch config' ' | |
393 | git branch -d my7 && | |
394 | test -z "$(git config branch.my7.remote)" && | |
395 | test -z "$(git config branch.my7.merge)" | |
396 | ' | |
397 | ||
398 | test_expect_success 'test deleting branch without config' ' | |
399 | git branch my7 s && | |
400 | sha1=$(git rev-parse my7 | cut -c 1-7) && | |
401 | echo "Deleted branch my7 (was $sha1)." >expect && | |
402 | git branch -d my7 >actual 2>&1 && | |
403 | test_i18ncmp expect actual | |
404 | ' | |
405 | ||
406 | test_expect_success 'test --track without .fetch entries' ' | |
407 | git branch --track my8 && | |
408 | test "$(git config branch.my8.remote)" && | |
409 | test "$(git config branch.my8.merge)" | |
410 | ' | |
411 | ||
412 | test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' ' | |
413 | git config branch.autosetupmerge always && | |
414 | git branch my9 HEAD^ && | |
415 | git config branch.autosetupmerge false | |
416 | ' | |
417 | ||
418 | test_expect_success 'branch from non-branch HEAD w/--track causes failure' ' | |
419 | test_must_fail git branch --track my10 HEAD^ | |
420 | ' | |
421 | ||
422 | test_expect_success 'branch from tag w/--track causes failure' ' | |
423 | git tag foobar && | |
424 | test_must_fail git branch --track my11 foobar | |
425 | ' | |
426 | ||
0cb24fe8 JH |
427 | test_expect_success '--set-upstream-to fails on multiple branches' ' |
428 | test_must_fail git branch --set-upstream-to master a b c | |
429 | ' | |
430 | ||
431 | test_expect_success '--set-upstream-to fails on detached HEAD' ' | |
432 | git checkout HEAD^{} && | |
433 | test_must_fail git branch --set-upstream-to master && | |
434 | git checkout - | |
435 | ' | |
436 | ||
8a3e5ecd JK |
437 | test_expect_success '--set-upstream-to fails on a missing dst branch' ' |
438 | test_must_fail git branch --set-upstream-to master does-not-exist | |
439 | ' | |
440 | ||
441 | test_expect_success '--set-upstream-to fails on a missing src branch' ' | |
442 | test_must_fail git branch --set-upstream-to does-not-exist master | |
443 | ' | |
444 | ||
445 | test_expect_success '--set-upstream-to fails on a non-ref' ' | |
446 | test_must_fail git branch --set-upstream-to HEAD^{} | |
447 | ' | |
448 | ||
0d158ebb RR |
449 | test_expect_success 'use --set-upstream-to modify HEAD' ' |
450 | test_config branch.master.remote foo && | |
451 | test_config branch.master.merge foo && | |
d0423ddd | 452 | git branch my12 && |
0d158ebb RR |
453 | git branch --set-upstream-to my12 && |
454 | test "$(git config branch.master.remote)" = "." && | |
455 | test "$(git config branch.master.merge)" = "refs/heads/my12" | |
456 | ' | |
457 | ||
458 | test_expect_success 'use --set-upstream-to modify a particular branch' ' | |
d0423ddd | 459 | git branch my13 && |
0d158ebb RR |
460 | git branch --set-upstream-to master my13 && |
461 | test "$(git config branch.my13.remote)" = "." && | |
462 | test "$(git config branch.my13.merge)" = "refs/heads/master" | |
463 | ' | |
464 | ||
465 | test_expect_success '--unset-upstream should fail if given a non-existent branch' ' | |
466 | test_must_fail git branch --unset-upstream i-dont-exist | |
467 | ' | |
468 | ||
469 | test_expect_success 'test --unset-upstream on HEAD' ' | |
d0423ddd | 470 | git branch my14 && |
0d158ebb RR |
471 | test_config branch.master.remote foo && |
472 | test_config branch.master.merge foo && | |
473 | git branch --set-upstream-to my14 && | |
474 | git branch --unset-upstream && | |
475 | test_must_fail git config branch.master.remote && | |
476 | test_must_fail git config branch.master.merge && | |
477 | # fail for a branch without upstream set | |
478 | test_must_fail git branch --unset-upstream | |
479 | ' | |
480 | ||
0cb24fe8 JH |
481 | test_expect_success '--unset-upstream should fail on multiple branches' ' |
482 | test_must_fail git branch --unset-upstream a b c | |
483 | ' | |
484 | ||
485 | test_expect_success '--unset-upstream should fail on detached HEAD' ' | |
486 | git checkout HEAD^{} && | |
487 | test_must_fail git branch --unset-upstream && | |
488 | git checkout - | |
489 | ' | |
490 | ||
0d158ebb | 491 | test_expect_success 'test --unset-upstream on a particular branch' ' |
d0423ddd | 492 | git branch my15 && |
0d158ebb RR |
493 | git branch --set-upstream-to master my14 && |
494 | git branch --unset-upstream my14 && | |
495 | test_must_fail git config branch.my14.remote && | |
496 | test_must_fail git config branch.my14.merge | |
497 | ' | |
498 | ||
499 | test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' ' | |
500 | git update-ref refs/remotes/origin/master HEAD && | |
501 | git branch --set-upstream origin/master 2>actual && | |
502 | test_when_finished git update-ref -d refs/remotes/origin/master && | |
503 | test_when_finished git branch -d origin/master && | |
504 | cat >expected <<EOF && | |
b347d06b CMN |
505 | The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to |
506 | ||
507 | If you wanted to make '"'master'"' track '"'origin/master'"', do this: | |
508 | ||
509 | git branch -d origin/master | |
510 | git branch --set-upstream-to origin/master | |
511 | EOF | |
0d158ebb | 512 | test_cmp expected actual |
b347d06b CMN |
513 | ' |
514 | ||
0d158ebb RR |
515 | test_expect_success '--set-upstream with two args only shows the deprecation message' ' |
516 | git branch --set-upstream master my13 2>actual && | |
517 | test_when_finished git branch --unset-upstream master && | |
518 | cat >expected <<EOF && | |
b347d06b CMN |
519 | The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to |
520 | EOF | |
0d158ebb | 521 | test_cmp expected actual |
b347d06b CMN |
522 | ' |
523 | ||
0d158ebb RR |
524 | test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' ' |
525 | git branch --set-upstream my13 2>actual && | |
526 | test_when_finished git branch --unset-upstream my13 && | |
527 | cat >expected <<EOF && | |
b347d06b CMN |
528 | The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to |
529 | EOF | |
0d158ebb | 530 | test_cmp expected actual |
b347d06b CMN |
531 | ' |
532 | ||
95052d1f BG |
533 | test_expect_success '--set-upstream-to notices an error to set branch as own upstream' ' |
534 | git branch --set-upstream-to refs/heads/my13 my13 2>actual && | |
535 | cat >expected <<-\EOF && | |
536 | warning: Not setting branch my13 as its own upstream. | |
537 | EOF | |
538 | test_expect_code 1 git config branch.my13.remote && | |
539 | test_expect_code 1 git config branch.my13.merge && | |
540 | test_i18ncmp expected actual | |
541 | ' | |
542 | ||
0746d19a PB |
543 | # Keep this test last, as it changes the current branch |
544 | cat >expect <<EOF | |
3749fde5 | 545 | $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master |
0746d19a | 546 | EOF |
0d158ebb RR |
547 | test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' ' |
548 | GIT_COMMITTER_DATE="2005-05-26 23:30" \ | |
549 | git checkout -b g/h/i -l master && | |
550 | test_path_is_file .git/refs/heads/g/h/i && | |
551 | test_path_is_file .git/logs/refs/heads/g/h/i && | |
552 | test_cmp expect .git/logs/refs/heads/g/h/i | |
553 | ' | |
0746d19a | 554 | |
b2099957 EM |
555 | test_expect_success 'checkout -b makes reflog by default' ' |
556 | git checkout master && | |
557 | git config --unset core.logAllRefUpdates && | |
558 | git checkout -b alpha && | |
6e6842e3 | 559 | git rev-parse --verify alpha@{0} |
b2099957 EM |
560 | ' |
561 | ||
562 | test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' ' | |
563 | git checkout master && | |
564 | git config core.logAllRefUpdates false && | |
565 | git checkout -b beta && | |
6e6842e3 | 566 | test_must_fail git rev-parse --verify beta@{0} |
b2099957 EM |
567 | ' |
568 | ||
569 | test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' ' | |
570 | git checkout master && | |
571 | git checkout -lb gamma && | |
572 | git config --unset core.logAllRefUpdates && | |
6e6842e3 | 573 | git rev-parse --verify gamma@{0} |
b2099957 EM |
574 | ' |
575 | ||
1d0a694b DB |
576 | test_expect_success 'avoid ambiguous track' ' |
577 | git config branch.autosetupmerge true && | |
578 | git config remote.ambi1.url lalala && | |
579 | git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master && | |
580 | git config remote.ambi2.url lilili && | |
581 | git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master && | |
582 | git branch all1 master && | |
583 | test -z "$(git config branch.all1.merge)" | |
584 | ' | |
585 | ||
c998ae9b DS |
586 | test_expect_success 'autosetuprebase local on a tracked local branch' ' |
587 | git config remote.local.url . && | |
588 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
589 | git config branch.autosetuprebase local && | |
0cb0e143 | 590 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
591 | git branch mybase && |
592 | git branch --track myr1 mybase && | |
593 | test "$(git config branch.myr1.remote)" = . && | |
594 | test "$(git config branch.myr1.merge)" = refs/heads/mybase && | |
595 | test "$(git config branch.myr1.rebase)" = true | |
596 | ' | |
597 | ||
598 | test_expect_success 'autosetuprebase always on a tracked local branch' ' | |
599 | git config remote.local.url . && | |
600 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
601 | git config branch.autosetuprebase always && | |
0cb0e143 | 602 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
603 | git branch mybase2 && |
604 | git branch --track myr2 mybase && | |
605 | test "$(git config branch.myr2.remote)" = . && | |
606 | test "$(git config branch.myr2.merge)" = refs/heads/mybase && | |
607 | test "$(git config branch.myr2.rebase)" = true | |
608 | ' | |
609 | ||
610 | test_expect_success 'autosetuprebase remote on a tracked local branch' ' | |
611 | git config remote.local.url . && | |
612 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
613 | git config branch.autosetuprebase remote && | |
0cb0e143 | 614 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
615 | git branch mybase3 && |
616 | git branch --track myr3 mybase2 && | |
617 | test "$(git config branch.myr3.remote)" = . && | |
618 | test "$(git config branch.myr3.merge)" = refs/heads/mybase2 && | |
619 | ! test "$(git config branch.myr3.rebase)" = true | |
620 | ' | |
621 | ||
622 | test_expect_success 'autosetuprebase never on a tracked local branch' ' | |
623 | git config remote.local.url . && | |
624 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
625 | git config branch.autosetuprebase never && | |
0cb0e143 | 626 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
627 | git branch mybase4 && |
628 | git branch --track myr4 mybase2 && | |
629 | test "$(git config branch.myr4.remote)" = . && | |
630 | test "$(git config branch.myr4.merge)" = refs/heads/mybase2 && | |
631 | ! test "$(git config branch.myr4.rebase)" = true | |
632 | ' | |
633 | ||
634 | test_expect_success 'autosetuprebase local on a tracked remote branch' ' | |
635 | git config remote.local.url . && | |
636 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
637 | git config branch.autosetuprebase local && | |
0cb0e143 | 638 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
639 | git branch --track myr5 local/master && |
640 | test "$(git config branch.myr5.remote)" = local && | |
641 | test "$(git config branch.myr5.merge)" = refs/heads/master && | |
642 | ! test "$(git config branch.myr5.rebase)" = true | |
643 | ' | |
644 | ||
645 | test_expect_success 'autosetuprebase never on a tracked remote branch' ' | |
646 | git config remote.local.url . && | |
647 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
648 | git config branch.autosetuprebase never && | |
0cb0e143 | 649 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
650 | git branch --track myr6 local/master && |
651 | test "$(git config branch.myr6.remote)" = local && | |
652 | test "$(git config branch.myr6.merge)" = refs/heads/master && | |
653 | ! test "$(git config branch.myr6.rebase)" = true | |
654 | ' | |
655 | ||
656 | test_expect_success 'autosetuprebase remote on a tracked remote branch' ' | |
657 | git config remote.local.url . && | |
658 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
659 | git config branch.autosetuprebase remote && | |
0cb0e143 | 660 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
661 | git branch --track myr7 local/master && |
662 | test "$(git config branch.myr7.remote)" = local && | |
663 | test "$(git config branch.myr7.merge)" = refs/heads/master && | |
664 | test "$(git config branch.myr7.rebase)" = true | |
665 | ' | |
666 | ||
667 | test_expect_success 'autosetuprebase always on a tracked remote branch' ' | |
668 | git config remote.local.url . && | |
669 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
670 | git config branch.autosetuprebase remote && | |
0cb0e143 | 671 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
672 | git branch --track myr8 local/master && |
673 | test "$(git config branch.myr8.remote)" = local && | |
674 | test "$(git config branch.myr8.merge)" = refs/heads/master && | |
675 | test "$(git config branch.myr8.rebase)" = true | |
676 | ' | |
677 | ||
678 | test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' ' | |
679 | git config --unset branch.autosetuprebase && | |
680 | git config remote.local.url . && | |
681 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 682 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
683 | git branch --track myr9 local/master && |
684 | test "$(git config branch.myr9.remote)" = local && | |
685 | test "$(git config branch.myr9.merge)" = refs/heads/master && | |
686 | test "z$(git config branch.myr9.rebase)" = z | |
687 | ' | |
688 | ||
689 | test_expect_success 'autosetuprebase unconfigured on a tracked local branch' ' | |
690 | git config remote.local.url . && | |
691 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 692 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
693 | git branch mybase10 && |
694 | git branch --track myr10 mybase2 && | |
695 | test "$(git config branch.myr10.remote)" = . && | |
696 | test "$(git config branch.myr10.merge)" = refs/heads/mybase2 && | |
697 | test "z$(git config branch.myr10.rebase)" = z | |
698 | ' | |
699 | ||
700 | test_expect_success 'autosetuprebase unconfigured on untracked local branch' ' | |
701 | git config remote.local.url . && | |
702 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 703 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
704 | git branch --no-track myr11 mybase2 && |
705 | test "z$(git config branch.myr11.remote)" = z && | |
706 | test "z$(git config branch.myr11.merge)" = z && | |
707 | test "z$(git config branch.myr11.rebase)" = z | |
708 | ' | |
709 | ||
710 | test_expect_success 'autosetuprebase unconfigured on untracked remote branch' ' | |
711 | git config remote.local.url . && | |
712 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 713 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
714 | git branch --no-track myr12 local/master && |
715 | test "z$(git config branch.myr12.remote)" = z && | |
716 | test "z$(git config branch.myr12.merge)" = z && | |
717 | test "z$(git config branch.myr12.rebase)" = z | |
718 | ' | |
719 | ||
720 | test_expect_success 'autosetuprebase never on an untracked local branch' ' | |
721 | git config branch.autosetuprebase never && | |
722 | git config remote.local.url . && | |
723 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 724 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
725 | git branch --no-track myr13 mybase2 && |
726 | test "z$(git config branch.myr13.remote)" = z && | |
727 | test "z$(git config branch.myr13.merge)" = z && | |
728 | test "z$(git config branch.myr13.rebase)" = z | |
729 | ' | |
730 | ||
731 | test_expect_success 'autosetuprebase local on an untracked local branch' ' | |
732 | git config branch.autosetuprebase local && | |
733 | git config remote.local.url . && | |
734 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 735 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
736 | git branch --no-track myr14 mybase2 && |
737 | test "z$(git config branch.myr14.remote)" = z && | |
738 | test "z$(git config branch.myr14.merge)" = z && | |
739 | test "z$(git config branch.myr14.rebase)" = z | |
740 | ' | |
741 | ||
742 | test_expect_success 'autosetuprebase remote on an untracked local branch' ' | |
743 | git config branch.autosetuprebase remote && | |
744 | git config remote.local.url . && | |
745 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 746 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
747 | git branch --no-track myr15 mybase2 && |
748 | test "z$(git config branch.myr15.remote)" = z && | |
749 | test "z$(git config branch.myr15.merge)" = z && | |
750 | test "z$(git config branch.myr15.rebase)" = z | |
751 | ' | |
752 | ||
753 | test_expect_success 'autosetuprebase always on an untracked local branch' ' | |
754 | git config branch.autosetuprebase always && | |
755 | git config remote.local.url . && | |
756 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 757 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
758 | git branch --no-track myr16 mybase2 && |
759 | test "z$(git config branch.myr16.remote)" = z && | |
760 | test "z$(git config branch.myr16.merge)" = z && | |
761 | test "z$(git config branch.myr16.rebase)" = z | |
762 | ' | |
763 | ||
764 | test_expect_success 'autosetuprebase never on an untracked remote branch' ' | |
765 | git config branch.autosetuprebase never && | |
766 | git config remote.local.url . && | |
767 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 768 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
769 | git branch --no-track myr17 local/master && |
770 | test "z$(git config branch.myr17.remote)" = z && | |
771 | test "z$(git config branch.myr17.merge)" = z && | |
772 | test "z$(git config branch.myr17.rebase)" = z | |
773 | ' | |
774 | ||
775 | test_expect_success 'autosetuprebase local on an untracked remote branch' ' | |
776 | git config branch.autosetuprebase local && | |
777 | git config remote.local.url . && | |
778 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 779 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
780 | git branch --no-track myr18 local/master && |
781 | test "z$(git config branch.myr18.remote)" = z && | |
782 | test "z$(git config branch.myr18.merge)" = z && | |
783 | test "z$(git config branch.myr18.rebase)" = z | |
784 | ' | |
785 | ||
786 | test_expect_success 'autosetuprebase remote on an untracked remote branch' ' | |
787 | git config branch.autosetuprebase remote && | |
788 | git config remote.local.url . && | |
789 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 790 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
791 | git branch --no-track myr19 local/master && |
792 | test "z$(git config branch.myr19.remote)" = z && | |
793 | test "z$(git config branch.myr19.merge)" = z && | |
794 | test "z$(git config branch.myr19.rebase)" = z | |
795 | ' | |
796 | ||
797 | test_expect_success 'autosetuprebase always on an untracked remote branch' ' | |
798 | git config branch.autosetuprebase always && | |
799 | git config remote.local.url . && | |
800 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 801 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
802 | git branch --no-track myr20 local/master && |
803 | test "z$(git config branch.myr20.remote)" = z && | |
804 | test "z$(git config branch.myr20.merge)" = z && | |
805 | test "z$(git config branch.myr20.rebase)" = z | |
806 | ' | |
807 | ||
21b5b1e8 JH |
808 | test_expect_success 'autosetuprebase always on detached HEAD' ' |
809 | git config branch.autosetupmerge always && | |
810 | test_when_finished git checkout master && | |
811 | git checkout HEAD^0 && | |
812 | git branch my11 && | |
813 | test -z "$(git config branch.my11.remote)" && | |
814 | test -z "$(git config branch.my11.merge)" | |
815 | ' | |
816 | ||
c998ae9b DS |
817 | test_expect_success 'detect misconfigured autosetuprebase (bad value)' ' |
818 | git config branch.autosetuprebase garbage && | |
819 | test_must_fail git branch | |
820 | ' | |
821 | ||
822 | test_expect_success 'detect misconfigured autosetuprebase (no value)' ' | |
823 | git config --unset branch.autosetuprebase && | |
0d158ebb | 824 | echo "[branch] autosetuprebase" >>.git/config && |
c998ae9b DS |
825 | test_must_fail git branch && |
826 | git config --unset branch.autosetuprebase | |
827 | ' | |
828 | ||
99c419c9 JH |
829 | test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' ' |
830 | git checkout my9 && | |
831 | git config --unset branch.my8.merge && | |
832 | test_must_fail git branch -d my8 | |
833 | ' | |
834 | ||
835 | test_expect_success 'attempt to delete a branch merged to its base' ' | |
836 | # we are on my9 which is the initial commit; traditionally | |
837 | # we would not have allowed deleting my8 that is not merged | |
838 | # to my9, but it is set to track master that already has my8 | |
839 | git config branch.my8.merge refs/heads/master && | |
840 | git branch -d my8 | |
841 | ' | |
842 | ||
843 | test_expect_success 'attempt to delete a branch merged to its base' ' | |
844 | git checkout master && | |
845 | echo Third >>A && | |
846 | git commit -m "Third commit" A && | |
847 | git branch -t my10 my9 && | |
848 | git branch -f my10 HEAD^ && | |
849 | # we are on master which is at the third commit, and my10 | |
850 | # is behind us, so traditionally we would have allowed deleting | |
851 | # it; but my10 is set to track my9 that is further behind. | |
852 | test_must_fail git branch -d my10 | |
853 | ' | |
854 | ||
fa799376 JH |
855 | test_expect_success 'use set-upstream on the current branch' ' |
856 | git checkout master && | |
857 | git --bare init myupstream.git && | |
858 | git push myupstream.git master:refs/heads/frotz && | |
859 | git remote add origin myupstream.git && | |
860 | git fetch && | |
861 | git branch --set-upstream master origin/frotz && | |
862 | ||
863 | test "z$(git config branch.master.remote)" = "zorigin" && | |
864 | test "z$(git config branch.master.merge)" = "zrefs/heads/frotz" | |
865 | ||
866 | ' | |
867 | ||
c2d17ba3 JH |
868 | test_expect_success 'use --edit-description' ' |
869 | write_script editor <<-\EOF && | |
870 | echo "New contents" >"$1" | |
871 | EOF | |
872 | EDITOR=./editor git branch --edit-description && | |
873 | write_script editor <<-\EOF && | |
874 | git stripspace -s <"$1" >"EDITOR_OUTPUT" | |
875 | EOF | |
876 | EDITOR=./editor git branch --edit-description && | |
877 | echo "New contents" >expect && | |
878 | test_cmp EDITOR_OUTPUT expect | |
879 | ' | |
880 | ||
881 | test_expect_success 'detect typo in branch name when using --edit-description' ' | |
882 | write_script editor <<-\EOF && | |
883 | echo "New contents" >"$1" | |
884 | EOF | |
512477b1 | 885 | test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch |
c2d17ba3 JH |
886 | ' |
887 | ||
888 | test_expect_success 'refuse --edit-description on unborn branch for now' ' | |
889 | write_script editor <<-\EOF && | |
890 | echo "New contents" >"$1" | |
891 | EOF | |
892 | git checkout --orphan unborn && | |
512477b1 | 893 | test_must_fail env EDITOR=./editor git branch --edit-description |
c2d17ba3 JH |
894 | ' |
895 | ||
6c41e975 CMN |
896 | test_expect_success '--merged catches invalid object names' ' |
897 | test_must_fail git branch --merged 0000000000000000000000000000000000000000 | |
898 | ' | |
899 | ||
1d7358c5 | 900 | test_expect_success 'tracking with unexpected .fetch refspec' ' |
b0f49ff1 | 901 | rm -rf a b c d && |
62d94a3a JH |
902 | git init a && |
903 | ( | |
904 | cd a && | |
905 | test_commit a | |
906 | ) && | |
907 | git init b && | |
908 | ( | |
909 | cd b && | |
910 | test_commit b | |
911 | ) && | |
912 | git init c && | |
913 | ( | |
914 | cd c && | |
915 | test_commit c && | |
916 | git remote add a ../a && | |
917 | git remote add b ../b && | |
918 | git fetch --all | |
919 | ) && | |
920 | git init d && | |
921 | ( | |
922 | cd d && | |
923 | git remote add c ../c && | |
924 | git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" && | |
925 | git fetch c && | |
926 | git branch --track local/a/master remotes/a/master && | |
927 | test "$(git config branch.local/a/master.remote)" = "c" && | |
928 | test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" && | |
929 | git rev-parse --verify a >expect && | |
930 | git rev-parse --verify local/a/master >actual && | |
931 | test_cmp expect actual | |
932 | ) | |
933 | ' | |
934 | ||
a3b427b9 | 935 | test_done |