]>
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 | 8 | . ./test-lib.sh |
1f537be3 | 9 | . "$TEST_DIRECTORY"/lib-rebase.sh |
a3b427b9 | 10 | |
0d158ebb RR |
11 | test_expect_success 'prepare a trivial repository' ' |
12 | echo Hello >A && | |
13 | git update-index --add A && | |
14 | git commit -m "Initial commit." && | |
15 | echo World >>A && | |
16 | git update-index --add A && | |
17 | git commit -m "Second commit." && | |
140cd845 FC |
18 | HEAD=$(git rev-parse --verify HEAD) |
19 | ' | |
0d158ebb RR |
20 | |
21 | test_expect_success 'git branch --help should not have created a bogus branch' ' | |
01e8d327 | 22 | test_might_fail git branch --man --help </dev/null >/dev/null 2>&1 && |
0d158ebb | 23 | test_path_is_missing .git/refs/heads/--help |
41ac414e | 24 | ' |
a3b427b9 | 25 | |
1dacfbcf NTND |
26 | test_expect_success 'branch -h in broken repository' ' |
27 | mkdir broken && | |
28 | ( | |
29 | cd broken && | |
30 | git init && | |
31 | >.git/refs/heads/master && | |
32 | test_expect_code 129 git branch -h >usage 2>&1 | |
33 | ) && | |
9a001381 | 34 | test_i18ngrep "[Uu]sage" broken/usage |
1dacfbcf NTND |
35 | ' |
36 | ||
0d158ebb RR |
37 | test_expect_success 'git branch abc should create a branch' ' |
38 | git branch abc && test_path_is_file .git/refs/heads/abc | |
39 | ' | |
08db81a9 | 40 | |
0d158ebb RR |
41 | test_expect_success 'git branch a/b/c should create a branch' ' |
42 | git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c | |
43 | ' | |
08db81a9 | 44 | |
e3d6539d DL |
45 | test_expect_success 'git branch mb master... should create a branch' ' |
46 | git branch mb master... && test_path_is_file .git/refs/heads/mb | |
47 | ' | |
48 | ||
0cb24fe8 JH |
49 | test_expect_success 'git branch HEAD should fail' ' |
50 | test_must_fail git branch HEAD | |
51 | ' | |
8efb8899 | 52 | |
d7fb7a37 | 53 | cat >expect <<EOF |
8125a58b | 54 | $ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master |
d7fb7a37 | 55 | EOF |
7687f19e | 56 | test_expect_success 'git branch --create-reflog d/e/f should create a branch and a log' ' |
0d158ebb | 57 | GIT_COMMITTER_DATE="2005-05-26 23:30" \ |
7687f19e | 58 | git -c core.logallrefupdates=false branch --create-reflog d/e/f && |
0d158ebb RR |
59 | test_path_is_file .git/refs/heads/d/e/f && |
60 | test_path_is_file .git/logs/refs/heads/d/e/f && | |
61 | test_cmp expect .git/logs/refs/heads/d/e/f | |
62 | ' | |
63 | ||
64 | test_expect_success 'git branch -d d/e/f should delete a branch and a log' ' | |
65 | git branch -d d/e/f && | |
66 | test_path_is_missing .git/refs/heads/d/e/f && | |
d0ab0584 | 67 | test_must_fail git reflog exists refs/heads/d/e/f |
0d158ebb RR |
68 | ' |
69 | ||
70 | test_expect_success 'git branch j/k should work after branch j has been deleted' ' | |
71 | git branch j && | |
72 | git branch -d j && | |
73 | git branch j/k | |
74 | ' | |
75 | ||
76 | test_expect_success 'git branch l should work after branch l/m has been deleted' ' | |
77 | git branch l/m && | |
78 | git branch -d l/m && | |
79 | git branch l | |
80 | ' | |
81 | ||
82 | test_expect_success 'git branch -m dumps usage' ' | |
83 | test_expect_code 128 git branch -m 2>err && | |
8054b9a6 | 84 | test_i18ngrep "branch name required" err |
0d158ebb RR |
85 | ' |
86 | ||
12fd3496 DT |
87 | test_expect_success 'git branch -m m broken_symref should work' ' |
88 | test_when_finished "git branch -D broken_symref" && | |
7687f19e | 89 | git branch --create-reflog m && |
12fd3496 DT |
90 | git symbolic-ref refs/heads/broken_symref refs/heads/i_am_broken && |
91 | git branch -m m broken_symref && | |
92 | git reflog exists refs/heads/broken_symref && | |
93 | test_must_fail git reflog exists refs/heads/i_am_broken | |
94 | ' | |
95 | ||
0d158ebb | 96 | test_expect_success 'git branch -m m m/m should work' ' |
7687f19e | 97 | git branch --create-reflog m && |
0d158ebb | 98 | git branch -m m m/m && |
d0ab0584 | 99 | git reflog exists refs/heads/m/m |
0d158ebb RR |
100 | ' |
101 | ||
102 | test_expect_success 'git branch -m n/n n should work' ' | |
7687f19e | 103 | git branch --create-reflog n/n && |
2f139044 | 104 | git branch -m n/n n && |
d0ab0584 | 105 | git reflog exists refs/heads/n |
0d158ebb | 106 | ' |
c976d415 | 107 | |
bb8efa17 SD |
108 | # The topmost entry in reflog for branch bbb is about branch creation. |
109 | # Hence, we compare bbb@{1} (instead of bbb@{0}) with aaa@{0}. | |
110 | ||
111 | test_expect_success 'git branch -m bbb should rename checked out branch' ' | |
112 | test_when_finished git branch -D bbb && | |
113 | test_when_finished git checkout master && | |
114 | git checkout -b aaa && | |
115 | git commit --allow-empty -m "a new commit" && | |
116 | git rev-parse aaa@{0} >expect && | |
117 | git branch -m bbb && | |
118 | git rev-parse bbb@{1} >actual && | |
119 | test_cmp expect actual && | |
120 | git symbolic-ref HEAD >actual && | |
121 | echo refs/heads/bbb >expect && | |
122 | test_cmp expect actual | |
123 | ' | |
124 | ||
a1c1d817 JK |
125 | test_expect_success 'renaming checked out branch works with d/f conflict' ' |
126 | test_when_finished "git branch -D foo/bar || git branch -D foo" && | |
127 | test_when_finished git checkout master && | |
128 | git checkout -b foo && | |
129 | git branch -m foo/bar && | |
130 | git symbolic-ref HEAD >actual && | |
131 | echo refs/heads/foo/bar >expect && | |
132 | test_cmp expect actual | |
133 | ' | |
134 | ||
41ac414e JH |
135 | test_expect_success 'git branch -m o/o o should fail when o/p exists' ' |
136 | git branch o/o && | |
0d158ebb | 137 | git branch o/p && |
d492b31c | 138 | test_must_fail git branch -m o/o o |
41ac414e | 139 | ' |
c976d415 | 140 | |
ff7aa81f MG |
141 | test_expect_success 'git branch -m o/q o/p should fail when o/p exists' ' |
142 | git branch o/q && | |
143 | test_must_fail git branch -m o/q o/p | |
144 | ' | |
145 | ||
146 | test_expect_success 'git branch -M o/q o/p should work when o/p exists' ' | |
147 | git branch -M o/q o/p | |
148 | ' | |
149 | ||
356e91f2 MG |
150 | test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' ' |
151 | git branch o/q && | |
152 | git branch -m -f o/q o/p | |
153 | ' | |
154 | ||
41ac414e JH |
155 | test_expect_success 'git branch -m q r/q should fail when r exists' ' |
156 | git branch q && | |
157 | git branch r && | |
d492b31c | 158 | test_must_fail git branch -m q r/q |
41ac414e | 159 | ' |
c976d415 | 160 | |
55c4a673 CI |
161 | test_expect_success 'git branch -M foo bar should fail when bar is checked out' ' |
162 | git branch bar && | |
163 | git checkout -b foo && | |
164 | test_must_fail git branch -M bar foo | |
165 | ' | |
166 | ||
167 | test_expect_success 'git branch -M baz bam should succeed when baz is checked out' ' | |
168 | git checkout -b baz && | |
169 | git branch bam && | |
70999e9c KY |
170 | git branch -M baz bam && |
171 | test $(git rev-parse --abbrev-ref HEAD) = bam | |
172 | ' | |
173 | ||
39ee4c6c | 174 | test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' ' |
893dbf5b | 175 | msg="Branch: renamed refs/heads/baz to refs/heads/bam" && |
39ee4c6c KM |
176 | grep " 0\{40\}.*$msg$" .git/logs/HEAD && |
177 | grep "^0\{40\}.*$msg$" .git/logs/HEAD | |
893dbf5b KM |
178 | ' |
179 | ||
31824d18 NTND |
180 | test_expect_success 'git branch -M should leave orphaned HEAD alone' ' |
181 | git init orphan && | |
182 | ( | |
183 | cd orphan && | |
184 | test_commit initial && | |
185 | git checkout --orphan lonely && | |
186 | grep lonely .git/HEAD && | |
187 | test_path_is_missing .git/refs/head/lonely && | |
188 | git branch -M master mistress && | |
189 | grep lonely .git/HEAD | |
190 | ) | |
191 | ' | |
192 | ||
2272d3e5 JK |
193 | test_expect_success 'resulting reflog can be shown by log -g' ' |
194 | oid=$(git rev-parse HEAD) && | |
195 | cat >expect <<-EOF && | |
196 | HEAD@{0} $oid $msg | |
2272d3e5 JK |
197 | HEAD@{2} $oid checkout: moving from foo to baz |
198 | EOF | |
d08565bf | 199 | git log -g --format="%gd %H %gs" -2 HEAD >actual && |
2272d3e5 JK |
200 | test_cmp expect actual |
201 | ' | |
202 | ||
70999e9c KY |
203 | test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' ' |
204 | git checkout master && | |
205 | git worktree add -b baz bazdir && | |
206 | git worktree add -f bazdir2 baz && | |
207 | git branch -M baz bam && | |
208 | test $(git -C bazdir rev-parse --abbrev-ref HEAD) = bam && | |
209 | test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam | |
210 | ' | |
211 | ||
212 | test_expect_success 'git branch -M baz bam should succeed within a worktree in which baz is checked out' ' | |
213 | git checkout -b baz && | |
214 | git worktree add -f bazdir3 baz && | |
215 | ( | |
216 | cd bazdir3 && | |
217 | git branch -M baz bam && | |
218 | test $(git rev-parse --abbrev-ref HEAD) = bam | |
219 | ) && | |
220 | test $(git rev-parse --abbrev-ref HEAD) = bam | |
55c4a673 CI |
221 | ' |
222 | ||
3f59481e JN |
223 | test_expect_success 'git branch -M master should work when master is checked out' ' |
224 | git checkout master && | |
225 | git branch -M master | |
226 | ' | |
227 | ||
228 | test_expect_success 'git branch -M master master should work when master is checked out' ' | |
229 | git checkout master && | |
230 | git branch -M master master | |
231 | ' | |
232 | ||
233 | test_expect_success 'git branch -M master2 master2 should work when master is checked out' ' | |
234 | git checkout master && | |
235 | git branch master2 && | |
236 | git branch -M master2 master2 | |
237 | ' | |
238 | ||
cddd127b MG |
239 | test_expect_success 'git branch -v -d t should work' ' |
240 | git branch t && | |
cbc5cf7c | 241 | git rev-parse --verify refs/heads/t && |
cddd127b | 242 | git branch -v -d t && |
cbc5cf7c | 243 | test_must_fail git rev-parse --verify refs/heads/t |
cddd127b MG |
244 | ' |
245 | ||
246 | test_expect_success 'git branch -v -m t s should work' ' | |
247 | git branch t && | |
cbc5cf7c | 248 | git rev-parse --verify refs/heads/t && |
cddd127b | 249 | git branch -v -m t s && |
cbc5cf7c DT |
250 | test_must_fail git rev-parse --verify refs/heads/t && |
251 | git rev-parse --verify refs/heads/s && | |
cddd127b MG |
252 | git branch -d s |
253 | ' | |
254 | ||
255 | test_expect_success 'git branch -m -d t s should fail' ' | |
256 | git branch t && | |
cbc5cf7c | 257 | git rev-parse refs/heads/t && |
cddd127b MG |
258 | test_must_fail git branch -m -d t s && |
259 | git branch -d t && | |
cbc5cf7c | 260 | test_must_fail git rev-parse refs/heads/t |
cddd127b MG |
261 | ' |
262 | ||
263 | test_expect_success 'git branch --list -d t should fail' ' | |
264 | git branch t && | |
cbc5cf7c | 265 | git rev-parse refs/heads/t && |
cddd127b MG |
266 | test_must_fail git branch --list -d t && |
267 | git branch -d t && | |
cbc5cf7c | 268 | test_must_fail git rev-parse refs/heads/t |
cddd127b MG |
269 | ' |
270 | ||
f3534c98 JT |
271 | test_expect_success 'deleting checked-out branch from repo that is a submodule' ' |
272 | test_when_finished "rm -rf repo1 repo2" && | |
273 | ||
274 | git init repo1 && | |
275 | git init repo1/sub && | |
276 | test_commit -C repo1/sub x && | |
277 | git -C repo1 submodule add ./sub && | |
278 | git -C repo1 commit -m "adding sub" && | |
279 | ||
280 | git clone --recurse-submodules repo1 repo2 && | |
281 | git -C repo2/sub checkout -b work && | |
282 | test_must_fail git -C repo2/sub branch -D work | |
283 | ' | |
284 | ||
285 | test_expect_success 'bare main worktree has HEAD at branch deleted by secondary worktree' ' | |
286 | test_when_finished "rm -rf nonbare base secondary" && | |
287 | ||
288 | git init nonbare && | |
289 | test_commit -C nonbare x && | |
290 | git clone --bare nonbare bare && | |
291 | git -C bare worktree add --detach ../secondary master && | |
292 | git -C secondary branch -D master | |
293 | ' | |
294 | ||
ac5bbc02 JH |
295 | test_expect_success 'git branch --list -v with --abbrev' ' |
296 | test_when_finished "git branch -D t" && | |
297 | git branch t && | |
298 | git branch -v --list t >actual.default && | |
299 | git branch -v --list --abbrev t >actual.abbrev && | |
300 | test_cmp actual.default actual.abbrev && | |
301 | ||
302 | git branch -v --list --no-abbrev t >actual.noabbrev && | |
303 | git branch -v --list --abbrev=0 t >actual.0abbrev && | |
304 | test_cmp actual.noabbrev actual.0abbrev && | |
305 | ||
306 | git branch -v --list --abbrev=36 t >actual.36abbrev && | |
307 | # how many hexdigits are used? | |
308 | read name objdefault rest <actual.abbrev && | |
309 | read name obj36 rest <actual.36abbrev && | |
310 | objfull=$(git rev-parse --verify t) && | |
311 | ||
312 | # are we really getting abbreviations? | |
313 | test "$obj36" != "$objdefault" && | |
314 | expr "$obj36" : "$objdefault" >/dev/null && | |
315 | test "$objfull" != "$obj36" && | |
316 | expr "$objfull" : "$obj36" >/dev/null | |
317 | ||
318 | ' | |
319 | ||
ebe31ef2 NTND |
320 | test_expect_success 'git branch --column' ' |
321 | COLUMNS=81 git branch --column=column >actual && | |
322 | cat >expected <<\EOF && | |
e3d6539d DL |
323 | a/b/c bam foo l * master mb o/o q |
324 | abc bar j/k m/m master2 n o/p r | |
ebe31ef2 NTND |
325 | EOF |
326 | test_cmp expected actual | |
327 | ' | |
328 | ||
329 | test_expect_success 'git branch --column with an extremely long branch name' ' | |
330 | long=this/is/a/part/of/long/branch/name && | |
331 | long=z$long/$long/$long/$long && | |
332 | test_when_finished "git branch -d $long" && | |
333 | git branch $long && | |
334 | COLUMNS=80 git branch --column=column >actual && | |
335 | cat >expected <<EOF && | |
336 | a/b/c | |
337 | abc | |
338 | bam | |
339 | bar | |
340 | foo | |
341 | j/k | |
342 | l | |
343 | m/m | |
344 | * master | |
345 | master2 | |
e3d6539d | 346 | mb |
ebe31ef2 NTND |
347 | n |
348 | o/o | |
349 | o/p | |
350 | q | |
351 | r | |
352 | $long | |
353 | EOF | |
354 | test_cmp expected actual | |
355 | ' | |
356 | ||
357 | test_expect_success 'git branch with column.*' ' | |
358 | git config column.ui column && | |
359 | git config column.branch "dense" && | |
360 | COLUMNS=80 git branch >actual && | |
361 | git config --unset column.branch && | |
362 | git config --unset column.ui && | |
363 | cat >expected <<\EOF && | |
e3d6539d DL |
364 | a/b/c bam foo l * master mb o/o q |
365 | abc bar j/k m/m master2 n o/p r | |
ebe31ef2 NTND |
366 | EOF |
367 | test_cmp expected actual | |
368 | ' | |
369 | ||
370 | test_expect_success 'git branch --column -v should fail' ' | |
371 | test_must_fail git branch --column -v | |
372 | ' | |
373 | ||
374 | test_expect_success 'git branch -v with column.ui ignored' ' | |
375 | git config column.ui column && | |
376 | COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual && | |
377 | git config --unset column.ui && | |
378 | cat >expected <<\EOF && | |
379 | a/b/c | |
380 | abc | |
381 | bam | |
382 | bar | |
383 | foo | |
384 | j/k | |
385 | l | |
386 | m/m | |
387 | * master | |
388 | master2 | |
e3d6539d | 389 | mb |
ebe31ef2 NTND |
390 | n |
391 | o/o | |
392 | o/p | |
393 | q | |
394 | r | |
395 | EOF | |
396 | test_cmp expected actual | |
397 | ' | |
398 | ||
01ebb9dc GB |
399 | mv .git/config .git/config-saved |
400 | ||
08b984fb | 401 | test_expect_success 'git branch -m q q2 without config should succeed' ' |
5be60078 JH |
402 | git branch -m q q2 && |
403 | git branch -m q2 q | |
01ebb9dc GB |
404 | ' |
405 | ||
406 | mv .git/config-saved .git/config | |
407 | ||
5be60078 | 408 | git config branch.s/s.dummy Hello |
dc81c58c | 409 | |
0d158ebb | 410 | test_expect_success 'git branch -m s/s s should work when s/t is deleted' ' |
7687f19e | 411 | git branch --create-reflog s/s && |
d0ab0584 | 412 | git reflog exists refs/heads/s/s && |
7687f19e | 413 | git branch --create-reflog s/t && |
d0ab0584 | 414 | git reflog exists refs/heads/s/t && |
0d158ebb RR |
415 | git branch -d s/t && |
416 | git branch -m s/s s && | |
d0ab0584 | 417 | git reflog exists refs/heads/s |
0d158ebb | 418 | ' |
c976d415 | 419 | |
0d158ebb RR |
420 | test_expect_success 'config information was renamed, too' ' |
421 | test $(git config branch.s.dummy) = Hello && | |
b8f354f2 | 422 | test_must_fail git config branch.s/s.dummy |
0d158ebb | 423 | ' |
dc81c58c | 424 | |
c8b2cec0 ÆAB |
425 | test_expect_success 'git branch -m correctly renames multiple config sections' ' |
426 | test_when_finished "git checkout master" && | |
427 | git checkout -b source master && | |
428 | ||
429 | # Assert that a config file with multiple config sections has | |
430 | # those sections preserved... | |
431 | cat >expect <<-\EOF && | |
432 | branch.dest.key1=value1 | |
433 | some.gar.b=age | |
434 | branch.dest.key2=value2 | |
435 | EOF | |
436 | cat >config.branch <<\EOF && | |
437 | ;; Note the lack of -\EOF above & mixed indenting here. This is | |
438 | ;; intentional, we are also testing that the formatting of copied | |
439 | ;; sections is preserved. | |
440 | ||
441 | ;; Comment for source. Tabs | |
442 | [branch "source"] | |
443 | ;; Comment for the source value | |
444 | key1 = value1 | |
445 | ;; Comment for some.gar. Spaces | |
446 | [some "gar"] | |
447 | ;; Comment for the some.gar value | |
448 | b = age | |
449 | ;; Comment for source, again. Mixed tabs/spaces. | |
450 | [branch "source"] | |
451 | ;; Comment for the source value, again | |
452 | key2 = value2 | |
453 | EOF | |
454 | cat config.branch >>.git/config && | |
455 | git branch -m source dest && | |
456 | git config -f .git/config -l | grep -F -e source -e dest -e some.gar >actual && | |
457 | test_cmp expect actual && | |
458 | ||
459 | # ...and that the comments for those sections are also | |
460 | # preserved. | |
461 | cat config.branch | sed "s/\"source\"/\"dest\"/" >expect && | |
462 | sed -n -e "/Note the lack/,\$p" .git/config >actual && | |
463 | test_cmp expect actual | |
464 | ' | |
465 | ||
52d59cc6 SD |
466 | test_expect_success 'git branch -c dumps usage' ' |
467 | test_expect_code 128 git branch -c 2>err && | |
468 | test_i18ngrep "branch name required" err | |
469 | ' | |
470 | ||
471 | test_expect_success 'git branch --copy dumps usage' ' | |
472 | test_expect_code 128 git branch --copy 2>err && | |
473 | test_i18ngrep "branch name required" err | |
474 | ' | |
475 | ||
476 | test_expect_success 'git branch -c d e should work' ' | |
7687f19e | 477 | git branch --create-reflog d && |
52d59cc6 SD |
478 | git reflog exists refs/heads/d && |
479 | git config branch.d.dummy Hello && | |
480 | git branch -c d e && | |
481 | git reflog exists refs/heads/d && | |
482 | git reflog exists refs/heads/e && | |
483 | echo Hello >expect && | |
484 | git config branch.e.dummy >actual && | |
485 | test_cmp expect actual && | |
486 | echo Hello >expect && | |
487 | git config branch.d.dummy >actual && | |
488 | test_cmp expect actual | |
489 | ' | |
490 | ||
491 | test_expect_success 'git branch --copy is a synonym for -c' ' | |
7687f19e | 492 | git branch --create-reflog copy && |
52d59cc6 SD |
493 | git reflog exists refs/heads/copy && |
494 | git config branch.copy.dummy Hello && | |
495 | git branch --copy copy copy-to && | |
496 | git reflog exists refs/heads/copy && | |
497 | git reflog exists refs/heads/copy-to && | |
498 | echo Hello >expect && | |
499 | git config branch.copy.dummy >actual && | |
500 | test_cmp expect actual && | |
501 | echo Hello >expect && | |
502 | git config branch.copy-to.dummy >actual && | |
503 | test_cmp expect actual | |
504 | ' | |
505 | ||
e5435ff1 | 506 | test_expect_success 'git branch -c ee ef should copy ee to create branch ef' ' |
52d59cc6 SD |
507 | git checkout -b ee && |
508 | git reflog exists refs/heads/ee && | |
509 | git config branch.ee.dummy Hello && | |
510 | git branch -c ee ef && | |
511 | git reflog exists refs/heads/ee && | |
512 | git reflog exists refs/heads/ef && | |
513 | test $(git config branch.ee.dummy) = Hello && | |
514 | test $(git config branch.ef.dummy) = Hello && | |
e5435ff1 | 515 | test $(git rev-parse --abbrev-ref HEAD) = ee |
52d59cc6 SD |
516 | ' |
517 | ||
518 | test_expect_success 'git branch -c f/f g/g should work' ' | |
7687f19e | 519 | git branch --create-reflog f/f && |
52d59cc6 SD |
520 | git reflog exists refs/heads/f/f && |
521 | git config branch.f/f.dummy Hello && | |
522 | git branch -c f/f g/g && | |
523 | git reflog exists refs/heads/f/f && | |
524 | git reflog exists refs/heads/g/g && | |
525 | test $(git config branch.f/f.dummy) = Hello && | |
526 | test $(git config branch.g/g.dummy) = Hello | |
527 | ' | |
528 | ||
529 | test_expect_success 'git branch -c m2 m2 should work' ' | |
7687f19e | 530 | git branch --create-reflog m2 && |
52d59cc6 SD |
531 | git reflog exists refs/heads/m2 && |
532 | git config branch.m2.dummy Hello && | |
533 | git branch -c m2 m2 && | |
534 | git reflog exists refs/heads/m2 && | |
535 | test $(git config branch.m2.dummy) = Hello | |
536 | ' | |
537 | ||
538 | test_expect_success 'git branch -c zz zz/zz should fail' ' | |
7687f19e | 539 | git branch --create-reflog zz && |
52d59cc6 SD |
540 | git reflog exists refs/heads/zz && |
541 | test_must_fail git branch -c zz zz/zz | |
542 | ' | |
543 | ||
544 | test_expect_success 'git branch -c b/b b should fail' ' | |
7687f19e | 545 | git branch --create-reflog b/b && |
52d59cc6 SD |
546 | test_must_fail git branch -c b/b b |
547 | ' | |
548 | ||
549 | test_expect_success 'git branch -C o/q o/p should work when o/p exists' ' | |
7687f19e | 550 | git branch --create-reflog o/q && |
52d59cc6 SD |
551 | git reflog exists refs/heads/o/q && |
552 | git reflog exists refs/heads/o/p && | |
553 | git branch -C o/q o/p | |
554 | ' | |
555 | ||
556 | test_expect_success 'git branch -c -f o/q o/p should work when o/p exists' ' | |
557 | git reflog exists refs/heads/o/q && | |
558 | git reflog exists refs/heads/o/p && | |
559 | git branch -c -f o/q o/p | |
560 | ' | |
561 | ||
40c17eb1 | 562 | test_expect_success 'git branch -c qq rr/qq should fail when rr exists' ' |
52d59cc6 SD |
563 | git branch qq && |
564 | git branch rr && | |
565 | test_must_fail git branch -c qq rr/qq | |
566 | ' | |
567 | ||
568 | test_expect_success 'git branch -C b1 b2 should fail when b2 is checked out' ' | |
569 | git branch b1 && | |
570 | git checkout -b b2 && | |
571 | test_must_fail git branch -C b1 b2 | |
572 | ' | |
573 | ||
574 | test_expect_success 'git branch -C c1 c2 should succeed when c1 is checked out' ' | |
575 | git checkout -b c1 && | |
576 | git branch c2 && | |
577 | git branch -C c1 c2 && | |
e5435ff1 | 578 | test $(git rev-parse --abbrev-ref HEAD) = c1 |
52d59cc6 SD |
579 | ' |
580 | ||
e5435ff1 | 581 | test_expect_success 'git branch -C c1 c2 should never touch HEAD' ' |
52d59cc6 | 582 | msg="Branch: copied refs/heads/c1 to refs/heads/c2" && |
e5435ff1 | 583 | ! grep "$msg$" .git/logs/HEAD |
52d59cc6 SD |
584 | ' |
585 | ||
586 | test_expect_success 'git branch -C master should work when master is checked out' ' | |
587 | git checkout master && | |
588 | git branch -C master | |
589 | ' | |
590 | ||
591 | test_expect_success 'git branch -C master master should work when master is checked out' ' | |
592 | git checkout master && | |
593 | git branch -C master master | |
594 | ' | |
595 | ||
596 | test_expect_success 'git branch -C master5 master5 should work when master is checked out' ' | |
597 | git checkout master && | |
598 | git branch master5 && | |
599 | git branch -C master5 master5 | |
600 | ' | |
601 | ||
602 | test_expect_success 'git branch -C ab cd should overwrite existing config for cd' ' | |
7687f19e | 603 | git branch --create-reflog cd && |
52d59cc6 SD |
604 | git reflog exists refs/heads/cd && |
605 | git config branch.cd.dummy CD && | |
7687f19e | 606 | git branch --create-reflog ab && |
52d59cc6 SD |
607 | git reflog exists refs/heads/ab && |
608 | git config branch.ab.dummy AB && | |
609 | git branch -C ab cd && | |
610 | git reflog exists refs/heads/ab && | |
611 | git reflog exists refs/heads/cd && | |
612 | test $(git config branch.ab.dummy) = AB && | |
613 | test $(git config branch.cd.dummy) = AB | |
614 | ' | |
615 | ||
616 | test_expect_success 'git branch -c correctly copies multiple config sections' ' | |
617 | FOO=1 && | |
618 | export FOO && | |
619 | test_when_finished "git checkout master" && | |
620 | git checkout -b source2 master && | |
621 | ||
622 | # Assert that a config file with multiple config sections has | |
623 | # those sections preserved... | |
624 | cat >expect <<-\EOF && | |
625 | branch.source2.key1=value1 | |
626 | branch.dest2.key1=value1 | |
627 | more.gar.b=age | |
628 | branch.source2.key2=value2 | |
629 | branch.dest2.key2=value2 | |
630 | EOF | |
631 | cat >config.branch <<\EOF && | |
632 | ;; Note the lack of -\EOF above & mixed indenting here. This is | |
633 | ;; intentional, we are also testing that the formatting of copied | |
634 | ;; sections is preserved. | |
635 | ||
636 | ;; Comment for source2. Tabs | |
637 | [branch "source2"] | |
638 | ;; Comment for the source2 value | |
639 | key1 = value1 | |
640 | ;; Comment for more.gar. Spaces | |
641 | [more "gar"] | |
642 | ;; Comment for the more.gar value | |
643 | b = age | |
644 | ;; Comment for source2, again. Mixed tabs/spaces. | |
645 | [branch "source2"] | |
646 | ;; Comment for the source2 value, again | |
647 | key2 = value2 | |
648 | EOF | |
649 | cat config.branch >>.git/config && | |
650 | git branch -c source2 dest2 && | |
651 | git config -f .git/config -l | grep -F -e source2 -e dest2 -e more.gar >actual && | |
652 | test_cmp expect actual && | |
653 | ||
654 | # ...and that the comments and formatting for those sections | |
655 | # is also preserved. | |
656 | cat >expect <<\EOF && | |
657 | ;; Comment for source2. Tabs | |
658 | [branch "source2"] | |
659 | ;; Comment for the source2 value | |
660 | key1 = value1 | |
661 | ;; Comment for more.gar. Spaces | |
662 | [branch "dest2"] | |
663 | ;; Comment for the source2 value | |
664 | key1 = value1 | |
665 | ;; Comment for more.gar. Spaces | |
666 | [more "gar"] | |
667 | ;; Comment for the more.gar value | |
668 | b = age | |
669 | ;; Comment for source2, again. Mixed tabs/spaces. | |
670 | [branch "source2"] | |
671 | ;; Comment for the source2 value, again | |
672 | key2 = value2 | |
673 | [branch "dest2"] | |
674 | ;; Comment for the source2 value, again | |
675 | key2 = value2 | |
676 | EOF | |
677 | sed -n -e "/Comment for source2/,\$p" .git/config >actual && | |
678 | test_cmp expect actual | |
679 | ' | |
680 | ||
566c7707 RS |
681 | test_expect_success 'deleting a symref' ' |
682 | git branch target && | |
683 | git symbolic-ref refs/heads/symref refs/heads/target && | |
13baa9fe | 684 | echo "Deleted branch symref (was refs/heads/target)." >expect && |
566c7707 RS |
685 | git branch -d symref >actual && |
686 | test_path_is_file .git/refs/heads/target && | |
687 | test_path_is_missing .git/refs/heads/symref && | |
688 | test_i18ncmp expect actual | |
689 | ' | |
690 | ||
0fe700e3 RS |
691 | test_expect_success 'deleting a dangling symref' ' |
692 | git symbolic-ref refs/heads/dangling-symref nowhere && | |
693 | test_path_is_file .git/refs/heads/dangling-symref && | |
13baa9fe | 694 | echo "Deleted branch dangling-symref (was nowhere)." >expect && |
0fe700e3 RS |
695 | git branch -d dangling-symref >actual && |
696 | test_path_is_missing .git/refs/heads/dangling-symref && | |
697 | test_i18ncmp expect actual | |
698 | ' | |
699 | ||
62a2d525 JN |
700 | test_expect_success 'deleting a self-referential symref' ' |
701 | git symbolic-ref refs/heads/self-reference refs/heads/self-reference && | |
702 | test_path_is_file .git/refs/heads/self-reference && | |
703 | echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect && | |
704 | git branch -d self-reference >actual && | |
705 | test_path_is_missing .git/refs/heads/self-reference && | |
706 | test_i18ncmp expect actual | |
707 | ' | |
708 | ||
0d158ebb | 709 | test_expect_success 'renaming a symref is not allowed' ' |
eca35a25 | 710 | git symbolic-ref refs/heads/master2 refs/heads/master && |
fa58186c MV |
711 | test_must_fail git branch -m master2 master3 && |
712 | git symbolic-ref refs/heads/master2 && | |
376eb14a JK |
713 | test_path_is_file .git/refs/heads/master && |
714 | test_path_is_missing .git/refs/heads/master3 | |
eca35a25 MV |
715 | ' |
716 | ||
0d158ebb | 717 | test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' ' |
7687f19e | 718 | git branch --create-reflog u && |
0d158ebb RR |
719 | mv .git/logs/refs/heads/u real-u && |
720 | ln -s real-u .git/logs/refs/heads/u && | |
721 | test_must_fail git branch -m u v | |
722 | ' | |
723 | ||
724 | test_expect_success 'test tracking setup via --track' ' | |
725 | git config remote.local.url . && | |
726 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
727 | (git show-ref -q refs/remotes/local/master || git fetch local) && | |
728 | git branch --track my1 local/master && | |
729 | test $(git config branch.my1.remote) = local && | |
730 | test $(git config branch.my1.merge) = refs/heads/master | |
731 | ' | |
732 | ||
733 | test_expect_success 'test tracking setup (non-wildcard, matching)' ' | |
734 | git config remote.local.url . && | |
735 | git config remote.local.fetch refs/heads/master:refs/remotes/local/master && | |
736 | (git show-ref -q refs/remotes/local/master || git fetch local) && | |
737 | git branch --track my4 local/master && | |
738 | test $(git config branch.my4.remote) = local && | |
739 | test $(git config branch.my4.merge) = refs/heads/master | |
740 | ' | |
741 | ||
41c21f22 | 742 | test_expect_success 'tracking setup fails on non-matching refspec' ' |
0d158ebb | 743 | git config remote.local.url . && |
81f339dc | 744 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && |
0d158ebb | 745 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
81f339dc | 746 | git config remote.local.fetch refs/heads/s:refs/remotes/local/s && |
9c9cd39a JH |
747 | test_must_fail git branch --track my5 local/master && |
748 | test_must_fail git config branch.my5.remote && | |
749 | test_must_fail git config branch.my5.merge | |
0d158ebb RR |
750 | ' |
751 | ||
752 | test_expect_success 'test tracking setup via config' ' | |
753 | git config branch.autosetupmerge true && | |
754 | git config remote.local.url . && | |
755 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
756 | (git show-ref -q refs/remotes/local/master || git fetch local) && | |
757 | git branch my3 local/master && | |
758 | test $(git config branch.my3.remote) = local && | |
759 | test $(git config branch.my3.merge) = refs/heads/master | |
760 | ' | |
761 | ||
762 | test_expect_success 'test overriding tracking setup via --no-track' ' | |
763 | git config branch.autosetupmerge true && | |
764 | git config remote.local.url . && | |
765 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
766 | (git show-ref -q refs/remotes/local/master || git fetch local) && | |
767 | git branch --no-track my2 local/master && | |
768 | git config branch.autosetupmerge false && | |
769 | ! test "$(git config branch.my2.remote)" = local && | |
770 | ! test "$(git config branch.my2.merge)" = refs/heads/master | |
771 | ' | |
772 | ||
773 | test_expect_success 'no tracking without .fetch entries' ' | |
774 | git config branch.autosetupmerge true && | |
775 | git branch my6 s && | |
002ba037 | 776 | git config branch.autosetupmerge false && |
0d158ebb RR |
777 | test -z "$(git config branch.my6.remote)" && |
778 | test -z "$(git config branch.my6.merge)" | |
779 | ' | |
780 | ||
781 | test_expect_success 'test tracking setup via --track but deeper' ' | |
782 | git config remote.local.url . && | |
783 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
784 | (git show-ref -q refs/remotes/local/o/o || git fetch local) && | |
785 | git branch --track my7 local/o/o && | |
786 | test "$(git config branch.my7.remote)" = local && | |
787 | test "$(git config branch.my7.merge)" = refs/heads/o/o | |
788 | ' | |
789 | ||
790 | test_expect_success 'test deleting branch deletes branch config' ' | |
791 | git branch -d my7 && | |
792 | test -z "$(git config branch.my7.remote)" && | |
793 | test -z "$(git config branch.my7.merge)" | |
794 | ' | |
795 | ||
796 | test_expect_success 'test deleting branch without config' ' | |
797 | git branch my7 s && | |
798 | sha1=$(git rev-parse my7 | cut -c 1-7) && | |
799 | echo "Deleted branch my7 (was $sha1)." >expect && | |
800 | git branch -d my7 >actual 2>&1 && | |
801 | test_i18ncmp expect actual | |
802 | ' | |
803 | ||
f292244c KY |
804 | test_expect_success 'deleting currently checked out branch fails' ' |
805 | git worktree add -b my7 my7 && | |
806 | test_must_fail git -C my7 branch -d my7 && | |
807 | test_must_fail git branch -d my7 | |
808 | ' | |
809 | ||
0d158ebb RR |
810 | test_expect_success 'test --track without .fetch entries' ' |
811 | git branch --track my8 && | |
812 | test "$(git config branch.my8.remote)" && | |
813 | test "$(git config branch.my8.merge)" | |
814 | ' | |
815 | ||
816 | test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' ' | |
817 | git config branch.autosetupmerge always && | |
818 | git branch my9 HEAD^ && | |
819 | git config branch.autosetupmerge false | |
820 | ' | |
821 | ||
822 | test_expect_success 'branch from non-branch HEAD w/--track causes failure' ' | |
823 | test_must_fail git branch --track my10 HEAD^ | |
824 | ' | |
825 | ||
826 | test_expect_success 'branch from tag w/--track causes failure' ' | |
827 | git tag foobar && | |
828 | test_must_fail git branch --track my11 foobar | |
829 | ' | |
830 | ||
0cb24fe8 JH |
831 | test_expect_success '--set-upstream-to fails on multiple branches' ' |
832 | test_must_fail git branch --set-upstream-to master a b c | |
833 | ' | |
834 | ||
835 | test_expect_success '--set-upstream-to fails on detached HEAD' ' | |
836 | git checkout HEAD^{} && | |
837 | test_must_fail git branch --set-upstream-to master && | |
838 | git checkout - | |
839 | ' | |
840 | ||
8a3e5ecd JK |
841 | test_expect_success '--set-upstream-to fails on a missing dst branch' ' |
842 | test_must_fail git branch --set-upstream-to master does-not-exist | |
843 | ' | |
844 | ||
845 | test_expect_success '--set-upstream-to fails on a missing src branch' ' | |
846 | test_must_fail git branch --set-upstream-to does-not-exist master | |
847 | ' | |
848 | ||
849 | test_expect_success '--set-upstream-to fails on a non-ref' ' | |
850 | test_must_fail git branch --set-upstream-to HEAD^{} | |
851 | ' | |
852 | ||
27852b2c PS |
853 | test_expect_success '--set-upstream-to fails on locked config' ' |
854 | test_when_finished "rm -f .git/config.lock" && | |
855 | >.git/config.lock && | |
856 | git branch locked && | |
857 | test_must_fail git branch --set-upstream-to locked | |
858 | ' | |
859 | ||
0d158ebb RR |
860 | test_expect_success 'use --set-upstream-to modify HEAD' ' |
861 | test_config branch.master.remote foo && | |
862 | test_config branch.master.merge foo && | |
d0423ddd | 863 | git branch my12 && |
0d158ebb RR |
864 | git branch --set-upstream-to my12 && |
865 | test "$(git config branch.master.remote)" = "." && | |
866 | test "$(git config branch.master.merge)" = "refs/heads/my12" | |
867 | ' | |
868 | ||
869 | test_expect_success 'use --set-upstream-to modify a particular branch' ' | |
d0423ddd | 870 | git branch my13 && |
0d158ebb | 871 | git branch --set-upstream-to master my13 && |
93a6b3f2 | 872 | test_when_finished "git branch --unset-upstream my13" && |
0d158ebb RR |
873 | test "$(git config branch.my13.remote)" = "." && |
874 | test "$(git config branch.my13.merge)" = "refs/heads/master" | |
875 | ' | |
876 | ||
877 | test_expect_success '--unset-upstream should fail if given a non-existent branch' ' | |
878 | test_must_fail git branch --unset-upstream i-dont-exist | |
879 | ' | |
880 | ||
b81842cb PS |
881 | test_expect_success '--unset-upstream should fail if config is locked' ' |
882 | test_when_finished "rm -f .git/config.lock" && | |
883 | git branch --set-upstream-to locked && | |
884 | >.git/config.lock && | |
885 | test_must_fail git branch --unset-upstream | |
886 | ' | |
887 | ||
0d158ebb | 888 | test_expect_success 'test --unset-upstream on HEAD' ' |
d0423ddd | 889 | git branch my14 && |
0d158ebb RR |
890 | test_config branch.master.remote foo && |
891 | test_config branch.master.merge foo && | |
892 | git branch --set-upstream-to my14 && | |
893 | git branch --unset-upstream && | |
894 | test_must_fail git config branch.master.remote && | |
895 | test_must_fail git config branch.master.merge && | |
896 | # fail for a branch without upstream set | |
897 | test_must_fail git branch --unset-upstream | |
898 | ' | |
899 | ||
0cb24fe8 JH |
900 | test_expect_success '--unset-upstream should fail on multiple branches' ' |
901 | test_must_fail git branch --unset-upstream a b c | |
902 | ' | |
903 | ||
904 | test_expect_success '--unset-upstream should fail on detached HEAD' ' | |
905 | git checkout HEAD^{} && | |
906 | test_must_fail git branch --unset-upstream && | |
907 | git checkout - | |
908 | ' | |
909 | ||
0d158ebb | 910 | test_expect_success 'test --unset-upstream on a particular branch' ' |
d0423ddd | 911 | git branch my15 && |
0d158ebb RR |
912 | git branch --set-upstream-to master my14 && |
913 | git branch --unset-upstream my14 && | |
914 | test_must_fail git config branch.my14.remote && | |
915 | test_must_fail git config branch.my14.merge | |
916 | ' | |
917 | ||
cf317877 | 918 | test_expect_success 'disabled option --set-upstream fails' ' |
52668846 | 919 | test_must_fail git branch --set-upstream origin/master |
b347d06b CMN |
920 | ' |
921 | ||
95052d1f BG |
922 | test_expect_success '--set-upstream-to notices an error to set branch as own upstream' ' |
923 | git branch --set-upstream-to refs/heads/my13 my13 2>actual && | |
924 | cat >expected <<-\EOF && | |
925 | warning: Not setting branch my13 as its own upstream. | |
926 | EOF | |
927 | test_expect_code 1 git config branch.my13.remote && | |
928 | test_expect_code 1 git config branch.my13.merge && | |
929 | test_i18ncmp expected actual | |
930 | ' | |
931 | ||
0746d19a PB |
932 | # Keep this test last, as it changes the current branch |
933 | cat >expect <<EOF | |
8125a58b | 934 | $ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master |
0746d19a | 935 | EOF |
0d158ebb RR |
936 | test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' ' |
937 | GIT_COMMITTER_DATE="2005-05-26 23:30" \ | |
938 | git checkout -b g/h/i -l master && | |
939 | test_path_is_file .git/refs/heads/g/h/i && | |
940 | test_path_is_file .git/logs/refs/heads/g/h/i && | |
941 | test_cmp expect .git/logs/refs/heads/g/h/i | |
942 | ' | |
0746d19a | 943 | |
b2099957 EM |
944 | test_expect_success 'checkout -b makes reflog by default' ' |
945 | git checkout master && | |
946 | git config --unset core.logAllRefUpdates && | |
947 | git checkout -b alpha && | |
6e6842e3 | 948 | git rev-parse --verify alpha@{0} |
b2099957 EM |
949 | ' |
950 | ||
951 | test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' ' | |
952 | git checkout master && | |
953 | git config core.logAllRefUpdates false && | |
954 | git checkout -b beta && | |
6e6842e3 | 955 | test_must_fail git rev-parse --verify beta@{0} |
b2099957 EM |
956 | ' |
957 | ||
958 | test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' ' | |
959 | git checkout master && | |
960 | git checkout -lb gamma && | |
961 | git config --unset core.logAllRefUpdates && | |
6e6842e3 | 962 | git rev-parse --verify gamma@{0} |
b2099957 EM |
963 | ' |
964 | ||
1d0a694b DB |
965 | test_expect_success 'avoid ambiguous track' ' |
966 | git config branch.autosetupmerge true && | |
967 | git config remote.ambi1.url lalala && | |
968 | git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master && | |
969 | git config remote.ambi2.url lilili && | |
970 | git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master && | |
27852b2c | 971 | test_must_fail git branch all1 master && |
1d0a694b DB |
972 | test -z "$(git config branch.all1.merge)" |
973 | ' | |
974 | ||
c998ae9b DS |
975 | test_expect_success 'autosetuprebase local on a tracked local branch' ' |
976 | git config remote.local.url . && | |
977 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
978 | git config branch.autosetuprebase local && | |
0cb0e143 | 979 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
980 | git branch mybase && |
981 | git branch --track myr1 mybase && | |
982 | test "$(git config branch.myr1.remote)" = . && | |
983 | test "$(git config branch.myr1.merge)" = refs/heads/mybase && | |
984 | test "$(git config branch.myr1.rebase)" = true | |
985 | ' | |
986 | ||
987 | test_expect_success 'autosetuprebase always on a tracked local branch' ' | |
988 | git config remote.local.url . && | |
989 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
990 | git config branch.autosetuprebase always && | |
0cb0e143 | 991 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
992 | git branch mybase2 && |
993 | git branch --track myr2 mybase && | |
994 | test "$(git config branch.myr2.remote)" = . && | |
995 | test "$(git config branch.myr2.merge)" = refs/heads/mybase && | |
996 | test "$(git config branch.myr2.rebase)" = true | |
997 | ' | |
998 | ||
999 | test_expect_success 'autosetuprebase remote on a tracked local branch' ' | |
1000 | git config remote.local.url . && | |
1001 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
1002 | git config branch.autosetuprebase remote && | |
0cb0e143 | 1003 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
1004 | git branch mybase3 && |
1005 | git branch --track myr3 mybase2 && | |
1006 | test "$(git config branch.myr3.remote)" = . && | |
1007 | test "$(git config branch.myr3.merge)" = refs/heads/mybase2 && | |
1008 | ! test "$(git config branch.myr3.rebase)" = true | |
1009 | ' | |
1010 | ||
1011 | test_expect_success 'autosetuprebase never on a tracked local branch' ' | |
1012 | git config remote.local.url . && | |
1013 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
1014 | git config branch.autosetuprebase never && | |
0cb0e143 | 1015 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
1016 | git branch mybase4 && |
1017 | git branch --track myr4 mybase2 && | |
1018 | test "$(git config branch.myr4.remote)" = . && | |
1019 | test "$(git config branch.myr4.merge)" = refs/heads/mybase2 && | |
1020 | ! test "$(git config branch.myr4.rebase)" = true | |
1021 | ' | |
1022 | ||
1023 | test_expect_success 'autosetuprebase local on a tracked remote branch' ' | |
1024 | git config remote.local.url . && | |
1025 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
1026 | git config branch.autosetuprebase local && | |
0cb0e143 | 1027 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1028 | git branch --track myr5 local/master && |
1029 | test "$(git config branch.myr5.remote)" = local && | |
1030 | test "$(git config branch.myr5.merge)" = refs/heads/master && | |
1031 | ! test "$(git config branch.myr5.rebase)" = true | |
1032 | ' | |
1033 | ||
1034 | test_expect_success 'autosetuprebase never on a tracked remote branch' ' | |
1035 | git config remote.local.url . && | |
1036 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
1037 | git config branch.autosetuprebase never && | |
0cb0e143 | 1038 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1039 | git branch --track myr6 local/master && |
1040 | test "$(git config branch.myr6.remote)" = local && | |
1041 | test "$(git config branch.myr6.merge)" = refs/heads/master && | |
1042 | ! test "$(git config branch.myr6.rebase)" = true | |
1043 | ' | |
1044 | ||
1045 | test_expect_success 'autosetuprebase remote on a tracked remote branch' ' | |
1046 | git config remote.local.url . && | |
1047 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
1048 | git config branch.autosetuprebase remote && | |
0cb0e143 | 1049 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1050 | git branch --track myr7 local/master && |
1051 | test "$(git config branch.myr7.remote)" = local && | |
1052 | test "$(git config branch.myr7.merge)" = refs/heads/master && | |
1053 | test "$(git config branch.myr7.rebase)" = true | |
1054 | ' | |
1055 | ||
1056 | test_expect_success 'autosetuprebase always on a tracked remote branch' ' | |
1057 | git config remote.local.url . && | |
1058 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
1059 | git config branch.autosetuprebase remote && | |
0cb0e143 | 1060 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1061 | git branch --track myr8 local/master && |
1062 | test "$(git config branch.myr8.remote)" = local && | |
1063 | test "$(git config branch.myr8.merge)" = refs/heads/master && | |
1064 | test "$(git config branch.myr8.rebase)" = true | |
1065 | ' | |
1066 | ||
1067 | test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' ' | |
1068 | git config --unset branch.autosetuprebase && | |
1069 | git config remote.local.url . && | |
1070 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 1071 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1072 | git branch --track myr9 local/master && |
1073 | test "$(git config branch.myr9.remote)" = local && | |
1074 | test "$(git config branch.myr9.merge)" = refs/heads/master && | |
1075 | test "z$(git config branch.myr9.rebase)" = z | |
1076 | ' | |
1077 | ||
1078 | test_expect_success 'autosetuprebase unconfigured on a tracked local branch' ' | |
1079 | git config remote.local.url . && | |
1080 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 1081 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
1082 | git branch mybase10 && |
1083 | git branch --track myr10 mybase2 && | |
1084 | test "$(git config branch.myr10.remote)" = . && | |
1085 | test "$(git config branch.myr10.merge)" = refs/heads/mybase2 && | |
1086 | test "z$(git config branch.myr10.rebase)" = z | |
1087 | ' | |
1088 | ||
1089 | test_expect_success 'autosetuprebase unconfigured on untracked local branch' ' | |
1090 | git config remote.local.url . && | |
1091 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 1092 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1093 | git branch --no-track myr11 mybase2 && |
1094 | test "z$(git config branch.myr11.remote)" = z && | |
1095 | test "z$(git config branch.myr11.merge)" = z && | |
1096 | test "z$(git config branch.myr11.rebase)" = z | |
1097 | ' | |
1098 | ||
1099 | test_expect_success 'autosetuprebase unconfigured on untracked remote branch' ' | |
1100 | git config remote.local.url . && | |
1101 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 1102 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1103 | git branch --no-track myr12 local/master && |
1104 | test "z$(git config branch.myr12.remote)" = z && | |
1105 | test "z$(git config branch.myr12.merge)" = z && | |
1106 | test "z$(git config branch.myr12.rebase)" = z | |
1107 | ' | |
1108 | ||
1109 | test_expect_success 'autosetuprebase never on an untracked local branch' ' | |
1110 | git config branch.autosetuprebase never && | |
1111 | git config remote.local.url . && | |
1112 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 1113 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1114 | git branch --no-track myr13 mybase2 && |
1115 | test "z$(git config branch.myr13.remote)" = z && | |
1116 | test "z$(git config branch.myr13.merge)" = z && | |
1117 | test "z$(git config branch.myr13.rebase)" = z | |
1118 | ' | |
1119 | ||
1120 | test_expect_success 'autosetuprebase local on an untracked local branch' ' | |
1121 | git config branch.autosetuprebase local && | |
1122 | git config remote.local.url . && | |
1123 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 1124 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1125 | git branch --no-track myr14 mybase2 && |
1126 | test "z$(git config branch.myr14.remote)" = z && | |
1127 | test "z$(git config branch.myr14.merge)" = z && | |
1128 | test "z$(git config branch.myr14.rebase)" = z | |
1129 | ' | |
1130 | ||
1131 | test_expect_success 'autosetuprebase remote on an untracked local branch' ' | |
1132 | git config branch.autosetuprebase remote && | |
1133 | git config remote.local.url . && | |
1134 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 1135 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1136 | git branch --no-track myr15 mybase2 && |
1137 | test "z$(git config branch.myr15.remote)" = z && | |
1138 | test "z$(git config branch.myr15.merge)" = z && | |
1139 | test "z$(git config branch.myr15.rebase)" = z | |
1140 | ' | |
1141 | ||
1142 | test_expect_success 'autosetuprebase always on an untracked local branch' ' | |
1143 | git config branch.autosetuprebase always && | |
1144 | git config remote.local.url . && | |
1145 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 1146 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1147 | git branch --no-track myr16 mybase2 && |
1148 | test "z$(git config branch.myr16.remote)" = z && | |
1149 | test "z$(git config branch.myr16.merge)" = z && | |
1150 | test "z$(git config branch.myr16.rebase)" = z | |
1151 | ' | |
1152 | ||
1153 | test_expect_success 'autosetuprebase never on an untracked remote branch' ' | |
1154 | git config branch.autosetuprebase never && | |
1155 | git config remote.local.url . && | |
1156 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 1157 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1158 | git branch --no-track myr17 local/master && |
1159 | test "z$(git config branch.myr17.remote)" = z && | |
1160 | test "z$(git config branch.myr17.merge)" = z && | |
1161 | test "z$(git config branch.myr17.rebase)" = z | |
1162 | ' | |
1163 | ||
1164 | test_expect_success 'autosetuprebase local on an untracked remote branch' ' | |
1165 | git config branch.autosetuprebase local && | |
1166 | git config remote.local.url . && | |
1167 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 1168 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1169 | git branch --no-track myr18 local/master && |
1170 | test "z$(git config branch.myr18.remote)" = z && | |
1171 | test "z$(git config branch.myr18.merge)" = z && | |
1172 | test "z$(git config branch.myr18.rebase)" = z | |
1173 | ' | |
1174 | ||
1175 | test_expect_success 'autosetuprebase remote on an untracked remote branch' ' | |
1176 | git config branch.autosetuprebase remote && | |
1177 | git config remote.local.url . && | |
1178 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 1179 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1180 | git branch --no-track myr19 local/master && |
1181 | test "z$(git config branch.myr19.remote)" = z && | |
1182 | test "z$(git config branch.myr19.merge)" = z && | |
1183 | test "z$(git config branch.myr19.rebase)" = z | |
1184 | ' | |
1185 | ||
1186 | test_expect_success 'autosetuprebase always on an untracked remote branch' ' | |
1187 | git config branch.autosetuprebase always && | |
1188 | git config remote.local.url . && | |
1189 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 1190 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
1191 | git branch --no-track myr20 local/master && |
1192 | test "z$(git config branch.myr20.remote)" = z && | |
1193 | test "z$(git config branch.myr20.merge)" = z && | |
1194 | test "z$(git config branch.myr20.rebase)" = z | |
1195 | ' | |
1196 | ||
21b5b1e8 JH |
1197 | test_expect_success 'autosetuprebase always on detached HEAD' ' |
1198 | git config branch.autosetupmerge always && | |
1199 | test_when_finished git checkout master && | |
1200 | git checkout HEAD^0 && | |
1201 | git branch my11 && | |
1202 | test -z "$(git config branch.my11.remote)" && | |
1203 | test -z "$(git config branch.my11.merge)" | |
1204 | ' | |
1205 | ||
c998ae9b DS |
1206 | test_expect_success 'detect misconfigured autosetuprebase (bad value)' ' |
1207 | git config branch.autosetuprebase garbage && | |
1208 | test_must_fail git branch | |
1209 | ' | |
1210 | ||
1211 | test_expect_success 'detect misconfigured autosetuprebase (no value)' ' | |
1212 | git config --unset branch.autosetuprebase && | |
0d158ebb | 1213 | echo "[branch] autosetuprebase" >>.git/config && |
c998ae9b DS |
1214 | test_must_fail git branch && |
1215 | git config --unset branch.autosetuprebase | |
1216 | ' | |
1217 | ||
99c419c9 JH |
1218 | test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' ' |
1219 | git checkout my9 && | |
1220 | git config --unset branch.my8.merge && | |
1221 | test_must_fail git branch -d my8 | |
1222 | ' | |
1223 | ||
1224 | test_expect_success 'attempt to delete a branch merged to its base' ' | |
1225 | # we are on my9 which is the initial commit; traditionally | |
1226 | # we would not have allowed deleting my8 that is not merged | |
1227 | # to my9, but it is set to track master that already has my8 | |
1228 | git config branch.my8.merge refs/heads/master && | |
1229 | git branch -d my8 | |
1230 | ' | |
1231 | ||
1232 | test_expect_success 'attempt to delete a branch merged to its base' ' | |
1233 | git checkout master && | |
1234 | echo Third >>A && | |
1235 | git commit -m "Third commit" A && | |
1236 | git branch -t my10 my9 && | |
1237 | git branch -f my10 HEAD^ && | |
1238 | # we are on master which is at the third commit, and my10 | |
1239 | # is behind us, so traditionally we would have allowed deleting | |
1240 | # it; but my10 is set to track my9 that is further behind. | |
1241 | test_must_fail git branch -d my10 | |
1242 | ' | |
1243 | ||
c2d17ba3 JH |
1244 | test_expect_success 'use --edit-description' ' |
1245 | write_script editor <<-\EOF && | |
1246 | echo "New contents" >"$1" | |
1247 | EOF | |
1248 | EDITOR=./editor git branch --edit-description && | |
1249 | write_script editor <<-\EOF && | |
1250 | git stripspace -s <"$1" >"EDITOR_OUTPUT" | |
1251 | EOF | |
1252 | EDITOR=./editor git branch --edit-description && | |
1253 | echo "New contents" >expect && | |
dcbaa0b3 | 1254 | test_cmp expect EDITOR_OUTPUT |
c2d17ba3 JH |
1255 | ' |
1256 | ||
1257 | test_expect_success 'detect typo in branch name when using --edit-description' ' | |
1258 | write_script editor <<-\EOF && | |
1259 | echo "New contents" >"$1" | |
1260 | EOF | |
512477b1 | 1261 | test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch |
c2d17ba3 JH |
1262 | ' |
1263 | ||
1264 | test_expect_success 'refuse --edit-description on unborn branch for now' ' | |
1265 | write_script editor <<-\EOF && | |
1266 | echo "New contents" >"$1" | |
1267 | EOF | |
1268 | git checkout --orphan unborn && | |
512477b1 | 1269 | test_must_fail env EDITOR=./editor git branch --edit-description |
c2d17ba3 JH |
1270 | ' |
1271 | ||
6c41e975 CMN |
1272 | test_expect_success '--merged catches invalid object names' ' |
1273 | test_must_fail git branch --merged 0000000000000000000000000000000000000000 | |
1274 | ' | |
1275 | ||
17d6c744 ÆAB |
1276 | test_expect_success '--merged is incompatible with --no-merged' ' |
1277 | test_must_fail git branch --merged HEAD --no-merged HEAD | |
1278 | ' | |
1279 | ||
1f537be3 ES |
1280 | test_expect_success '--list during rebase' ' |
1281 | test_when_finished "reset_rebase" && | |
1282 | git checkout master && | |
1283 | FAKE_LINES="1 edit 2" && | |
1284 | export FAKE_LINES && | |
1285 | set_fake_editor && | |
1286 | git rebase -i HEAD~2 && | |
1287 | git branch --list >actual && | |
1288 | test_i18ngrep "rebasing master" actual | |
1289 | ' | |
1290 | ||
1291 | test_expect_success '--list during rebase from detached HEAD' ' | |
1292 | test_when_finished "reset_rebase && git checkout master" && | |
1293 | git checkout master^0 && | |
1294 | oid=$(git rev-parse --short HEAD) && | |
1295 | FAKE_LINES="1 edit 2" && | |
1296 | export FAKE_LINES && | |
1297 | set_fake_editor && | |
1298 | git rebase -i HEAD~2 && | |
1299 | git branch --list >actual && | |
1300 | test_i18ngrep "rebasing detached HEAD $oid" actual | |
1301 | ' | |
1302 | ||
1d7358c5 | 1303 | test_expect_success 'tracking with unexpected .fetch refspec' ' |
b0f49ff1 | 1304 | rm -rf a b c d && |
62d94a3a JH |
1305 | git init a && |
1306 | ( | |
1307 | cd a && | |
1308 | test_commit a | |
1309 | ) && | |
1310 | git init b && | |
1311 | ( | |
1312 | cd b && | |
1313 | test_commit b | |
1314 | ) && | |
1315 | git init c && | |
1316 | ( | |
1317 | cd c && | |
1318 | test_commit c && | |
1319 | git remote add a ../a && | |
1320 | git remote add b ../b && | |
1321 | git fetch --all | |
1322 | ) && | |
1323 | git init d && | |
1324 | ( | |
1325 | cd d && | |
1326 | git remote add c ../c && | |
1327 | git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" && | |
1328 | git fetch c && | |
1329 | git branch --track local/a/master remotes/a/master && | |
1330 | test "$(git config branch.local/a/master.remote)" = "c" && | |
1331 | test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" && | |
1332 | git rev-parse --verify a >expect && | |
1333 | git rev-parse --verify local/a/master >actual && | |
1334 | test_cmp expect actual | |
1335 | ) | |
1336 | ' | |
1337 | ||
560ae1c1 SM |
1338 | test_expect_success 'configured committerdate sort' ' |
1339 | git init sort && | |
1340 | ( | |
1341 | cd sort && | |
1342 | git config branch.sort committerdate && | |
1343 | test_commit initial && | |
1344 | git checkout -b a && | |
1345 | test_commit a && | |
1346 | git checkout -b c && | |
1347 | test_commit c && | |
1348 | git checkout -b b && | |
1349 | test_commit b && | |
1350 | git branch >actual && | |
1351 | cat >expect <<-\EOF && | |
1352 | master | |
1353 | a | |
1354 | c | |
1355 | * b | |
1356 | EOF | |
1357 | test_cmp expect actual | |
1358 | ) | |
1359 | ' | |
1360 | ||
1361 | test_expect_success 'option override configured sort' ' | |
1362 | ( | |
1363 | cd sort && | |
1364 | git config branch.sort committerdate && | |
1365 | git branch --sort=refname >actual && | |
1366 | cat >expect <<-\EOF && | |
1367 | a | |
1368 | * b | |
1369 | c | |
1370 | master | |
1371 | EOF | |
1372 | test_cmp expect actual | |
1373 | ) | |
1374 | ' | |
1375 | ||
1376 | test_expect_success 'invalid sort parameter in configuration' ' | |
1377 | ( | |
1378 | cd sort && | |
1379 | git config branch.sort "v:notvalid" && | |
1380 | test_must_fail git branch | |
1381 | ) | |
1382 | ' | |
1383 | ||
a3b427b9 | 1384 | test_done |