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