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