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