]>
Commit | Line | Data |
---|---|---|
a3b427b9 AW |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Amos Waterland | |
4 | # | |
5 | ||
6 | test_description='git branch --foo should not create bogus branch | |
7 | ||
8 | This test runs git branch --help and checks that the argument is properly | |
9 | handled. Specifically, that a bogus branch is not created. | |
10 | ' | |
11 | . ./test-lib.sh | |
12 | ||
13 | test_expect_success \ | |
4c84f0dc | 14 | 'prepare a trivial repository' \ |
a3b427b9 | 15 | 'echo Hello > A && |
5be60078 | 16 | git update-index --add A && |
0cb0e143 | 17 | git commit -m "Initial commit." && |
9ed36cfa JS |
18 | echo World >> A && |
19 | git update-index --add A && | |
0cb0e143 | 20 | git commit -m "Second commit." && |
5be60078 | 21 | HEAD=$(git rev-parse --verify HEAD)' |
a3b427b9 | 22 | |
41ac414e JH |
23 | test_expect_success \ |
24 | 'git branch --help should not have created a bogus branch' ' | |
25 | git branch --help </dev/null >/dev/null 2>/dev/null; | |
376eb14a | 26 | test_path_is_missing .git/refs/heads/--help |
41ac414e | 27 | ' |
a3b427b9 | 28 | |
1dacfbcf NTND |
29 | test_expect_success 'branch -h in broken repository' ' |
30 | mkdir broken && | |
31 | ( | |
32 | cd broken && | |
33 | git init && | |
34 | >.git/refs/heads/master && | |
35 | test_expect_code 129 git branch -h >usage 2>&1 | |
36 | ) && | |
37 | grep "[Uu]sage" broken/usage | |
38 | ' | |
39 | ||
08db81a9 AR |
40 | test_expect_success \ |
41 | 'git branch abc should create a branch' \ | |
376eb14a | 42 | 'git branch abc && test_path_is_file .git/refs/heads/abc' |
08db81a9 AR |
43 | |
44 | test_expect_success \ | |
45 | 'git branch a/b/c should create a branch' \ | |
376eb14a | 46 | 'git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c' |
08db81a9 | 47 | |
d7fb7a37 | 48 | cat >expect <<EOF |
3749fde5 | 49 | $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master |
d7fb7a37 SP |
50 | EOF |
51 | test_expect_success \ | |
52 | 'git branch -l d/e/f should create a branch and a log' \ | |
53 | 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ | |
5be60078 | 54 | git branch -l d/e/f && |
376eb14a JK |
55 | test_path_is_file .git/refs/heads/d/e/f && |
56 | test_path_is_file .git/logs/refs/heads/d/e/f && | |
4fdf71be | 57 | test_cmp expect .git/logs/refs/heads/d/e/f' |
d7fb7a37 SP |
58 | |
59 | test_expect_success \ | |
60 | 'git branch -d d/e/f should delete a branch and a log' \ | |
5be60078 | 61 | 'git branch -d d/e/f && |
376eb14a JK |
62 | test_path_is_missing .git/refs/heads/d/e/f && |
63 | test_path_is_missing .git/logs/refs/heads/d/e/f' | |
d7fb7a37 | 64 | |
9c7b0b3f CC |
65 | test_expect_success \ |
66 | 'git branch j/k should work after branch j has been deleted' \ | |
5be60078 JH |
67 | 'git branch j && |
68 | git branch -d j && | |
69 | git branch j/k' | |
9c7b0b3f CC |
70 | |
71 | test_expect_success \ | |
72 | 'git branch l should work after branch l/m has been deleted' \ | |
5be60078 JH |
73 | 'git branch l/m && |
74 | git branch -d l/m && | |
75 | git branch l' | |
9c7b0b3f | 76 | |
db85b3a7 SN |
77 | test_expect_success \ |
78 | 'git branch -m dumps usage' \ | |
79 | 'test_expect_code 129 git branch -m 2>err && | |
80 | grep "[Uu]sage: git branch" err' | |
81 | ||
c976d415 LH |
82 | test_expect_success \ |
83 | 'git branch -m m m/m should work' \ | |
5be60078 JH |
84 | 'git branch -l m && |
85 | git branch -m m m/m && | |
376eb14a | 86 | test_path_is_file .git/logs/refs/heads/m/m' |
c976d415 LH |
87 | |
88 | test_expect_success \ | |
89 | 'git branch -m n/n n should work' \ | |
5be60078 JH |
90 | 'git branch -l n/n && |
91 | git branch -m n/n n | |
376eb14a | 92 | test_path_is_file .git/logs/refs/heads/n' |
c976d415 | 93 | |
41ac414e JH |
94 | test_expect_success 'git branch -m o/o o should fail when o/p exists' ' |
95 | git branch o/o && | |
5be60078 | 96 | git branch o/p && |
d492b31c | 97 | test_must_fail git branch -m o/o o |
41ac414e | 98 | ' |
c976d415 | 99 | |
41ac414e JH |
100 | test_expect_success 'git branch -m q r/q should fail when r exists' ' |
101 | git branch q && | |
102 | git branch r && | |
d492b31c | 103 | test_must_fail git branch -m q r/q |
41ac414e | 104 | ' |
c976d415 | 105 | |
55c4a673 CI |
106 | test_expect_success 'git branch -M foo bar should fail when bar is checked out' ' |
107 | git branch bar && | |
108 | git checkout -b foo && | |
109 | test_must_fail git branch -M bar foo | |
110 | ' | |
111 | ||
112 | test_expect_success 'git branch -M baz bam should succeed when baz is checked out' ' | |
113 | git checkout -b baz && | |
114 | git branch bam && | |
115 | git branch -M baz bam | |
116 | ' | |
117 | ||
3f59481e JN |
118 | test_expect_success 'git branch -M master should work when master is checked out' ' |
119 | git checkout master && | |
120 | git branch -M master | |
121 | ' | |
122 | ||
123 | test_expect_success 'git branch -M master master should work when master is checked out' ' | |
124 | git checkout master && | |
125 | git branch -M master master | |
126 | ' | |
127 | ||
128 | test_expect_success 'git branch -M master2 master2 should work when master is checked out' ' | |
129 | git checkout master && | |
130 | git branch master2 && | |
131 | git branch -M master2 master2 | |
132 | ' | |
133 | ||
cddd127b MG |
134 | test_expect_success 'git branch -v -d t should work' ' |
135 | git branch t && | |
376eb14a | 136 | test_path_is_file .git/refs/heads/t && |
cddd127b | 137 | git branch -v -d t && |
376eb14a | 138 | test_path_is_missing .git/refs/heads/t |
cddd127b MG |
139 | ' |
140 | ||
141 | test_expect_success 'git branch -v -m t s should work' ' | |
142 | git branch t && | |
376eb14a | 143 | test_path_is_file .git/refs/heads/t && |
cddd127b | 144 | git branch -v -m t s && |
376eb14a JK |
145 | test_path_is_missing .git/refs/heads/t && |
146 | test_path_is_file .git/refs/heads/s && | |
cddd127b MG |
147 | git branch -d s |
148 | ' | |
149 | ||
150 | test_expect_success 'git branch -m -d t s should fail' ' | |
151 | git branch t && | |
376eb14a | 152 | test_path_is_file .git/refs/heads/t && |
cddd127b MG |
153 | test_must_fail git branch -m -d t s && |
154 | git branch -d t && | |
376eb14a | 155 | test_path_is_missing .git/refs/heads/t |
cddd127b MG |
156 | ' |
157 | ||
158 | test_expect_success 'git branch --list -d t should fail' ' | |
159 | git branch t && | |
376eb14a | 160 | test_path_is_file .git/refs/heads/t && |
cddd127b MG |
161 | test_must_fail git branch --list -d t && |
162 | git branch -d t && | |
376eb14a | 163 | test_path_is_missing .git/refs/heads/t |
cddd127b MG |
164 | ' |
165 | ||
01ebb9dc GB |
166 | mv .git/config .git/config-saved |
167 | ||
08b984fb | 168 | test_expect_success 'git branch -m q q2 without config should succeed' ' |
5be60078 JH |
169 | git branch -m q q2 && |
170 | git branch -m q2 q | |
01ebb9dc GB |
171 | ' |
172 | ||
173 | mv .git/config-saved .git/config | |
174 | ||
5be60078 | 175 | git config branch.s/s.dummy Hello |
dc81c58c | 176 | |
c976d415 LH |
177 | test_expect_success \ |
178 | 'git branch -m s/s s should work when s/t is deleted' \ | |
5be60078 | 179 | 'git branch -l s/s && |
376eb14a | 180 | test_path_is_file .git/logs/refs/heads/s/s && |
5be60078 | 181 | git branch -l s/t && |
376eb14a | 182 | test_path_is_file .git/logs/refs/heads/s/t && |
5be60078 JH |
183 | git branch -d s/t && |
184 | git branch -m s/s s && | |
376eb14a | 185 | test_path_is_file .git/logs/refs/heads/s' |
c976d415 | 186 | |
dc81c58c | 187 | test_expect_success 'config information was renamed, too' \ |
5be60078 | 188 | "test $(git config branch.s.dummy) = Hello && |
d492b31c | 189 | test_must_fail git config branch.s/s/dummy" |
dc81c58c | 190 | |
fa58186c | 191 | test_expect_success 'renaming a symref is not allowed' \ |
eca35a25 MV |
192 | ' |
193 | git symbolic-ref refs/heads/master2 refs/heads/master && | |
fa58186c MV |
194 | test_must_fail git branch -m master2 master3 && |
195 | git symbolic-ref refs/heads/master2 && | |
376eb14a JK |
196 | test_path_is_file .git/refs/heads/master && |
197 | test_path_is_missing .git/refs/heads/master3 | |
eca35a25 MV |
198 | ' |
199 | ||
704a3143 | 200 | test_expect_success SYMLINKS \ |
41ac414e JH |
201 | 'git branch -m u v should fail when the reflog for u is a symlink' ' |
202 | git branch -l u && | |
16c2bfbb LH |
203 | mv .git/logs/refs/heads/u real-u && |
204 | ln -s real-u .git/logs/refs/heads/u && | |
d492b31c | 205 | test_must_fail git branch -m u v |
41ac414e | 206 | ' |
16c2bfbb | 207 | |
0746d19a | 208 | test_expect_success 'test tracking setup via --track' \ |
5be60078 JH |
209 | 'git config remote.local.url . && |
210 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 211 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
5be60078 JH |
212 | git branch --track my1 local/master && |
213 | test $(git config branch.my1.remote) = local && | |
214 | test $(git config branch.my1.merge) = refs/heads/master' | |
0746d19a PB |
215 | |
216 | test_expect_success 'test tracking setup (non-wildcard, matching)' \ | |
5be60078 JH |
217 | 'git config remote.local.url . && |
218 | git config remote.local.fetch refs/heads/master:refs/remotes/local/master && | |
0cb0e143 | 219 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
5be60078 JH |
220 | git branch --track my4 local/master && |
221 | test $(git config branch.my4.remote) = local && | |
222 | test $(git config branch.my4.merge) = refs/heads/master' | |
0746d19a PB |
223 | |
224 | test_expect_success 'test tracking setup (non-wildcard, not matching)' \ | |
5be60078 JH |
225 | 'git config remote.local.url . && |
226 | git config remote.local.fetch refs/heads/s:refs/remotes/local/s && | |
0cb0e143 | 227 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
5be60078 JH |
228 | git branch --track my5 local/master && |
229 | ! test "$(git config branch.my5.remote)" = local && | |
230 | ! test "$(git config branch.my5.merge)" = refs/heads/master' | |
0746d19a PB |
231 | |
232 | test_expect_success 'test tracking setup via config' \ | |
5be60078 JH |
233 | 'git config branch.autosetupmerge true && |
234 | git config remote.local.url . && | |
235 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 236 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
5be60078 JH |
237 | git branch my3 local/master && |
238 | test $(git config branch.my3.remote) = local && | |
239 | test $(git config branch.my3.merge) = refs/heads/master' | |
0746d19a PB |
240 | |
241 | test_expect_success 'test overriding tracking setup via --no-track' \ | |
5be60078 JH |
242 | 'git config branch.autosetupmerge true && |
243 | git config remote.local.url . && | |
244 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 245 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
5be60078 JH |
246 | git branch --no-track my2 local/master && |
247 | git config branch.autosetupmerge false && | |
248 | ! test "$(git config branch.my2.remote)" = local && | |
249 | ! test "$(git config branch.my2.merge)" = refs/heads/master' | |
0746d19a | 250 | |
6f084a56 | 251 | test_expect_success 'no tracking without .fetch entries' \ |
9ed36cfa JS |
252 | 'git config branch.autosetupmerge true && |
253 | git branch my6 s && | |
254 | git config branch.automsetupmerge false && | |
6f084a56 JS |
255 | test -z "$(git config branch.my6.remote)" && |
256 | test -z "$(git config branch.my6.merge)"' | |
9debc324 | 257 | |
11f68d90 | 258 | test_expect_success 'test tracking setup via --track but deeper' \ |
5be60078 JH |
259 | 'git config remote.local.url . && |
260 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 261 | (git show-ref -q refs/remotes/local/o/o || git fetch local) && |
5be60078 JH |
262 | git branch --track my7 local/o/o && |
263 | test "$(git config branch.my7.remote)" = local && | |
264 | test "$(git config branch.my7.merge)" = refs/heads/o/o' | |
11f68d90 | 265 | |
f1eccbab | 266 | test_expect_success 'test deleting branch deletes branch config' \ |
5be60078 | 267 | 'git branch -d my7 && |
6f084a56 JS |
268 | test -z "$(git config branch.my7.remote)" && |
269 | test -z "$(git config branch.my7.merge)"' | |
f1eccbab | 270 | |
f2c8c800 | 271 | test_expect_success 'test deleting branch without config' \ |
5be60078 | 272 | 'git branch my7 s && |
a126ed0a | 273 | sha1=$(git rev-parse my7 | cut -c 1-7) && |
f2c8c800 JH |
274 | echo "Deleted branch my7 (was $sha1)." >expect && |
275 | git branch -d my7 >actual 2>&1 && | |
276 | test_i18ncmp expect actual' | |
f1eccbab | 277 | |
9ed36cfa JS |
278 | test_expect_success 'test --track without .fetch entries' \ |
279 | 'git branch --track my8 && | |
280 | test "$(git config branch.my8.remote)" && | |
281 | test "$(git config branch.my8.merge)"' | |
282 | ||
283 | test_expect_success \ | |
284 | 'branch from non-branch HEAD w/autosetupmerge=always' \ | |
285 | 'git config branch.autosetupmerge always && | |
286 | git branch my9 HEAD^ && | |
287 | git config branch.autosetupmerge false' | |
288 | ||
289 | test_expect_success \ | |
290 | 'branch from non-branch HEAD w/--track causes failure' \ | |
03b9dfb1 | 291 | 'test_must_fail git branch --track my10 HEAD^' |
9ed36cfa | 292 | |
21b5b1e8 JH |
293 | test_expect_success \ |
294 | 'branch from tag w/--track causes failure' \ | |
295 | 'git tag foobar && | |
296 | test_must_fail git branch --track my11 foobar' | |
297 | ||
0746d19a PB |
298 | # Keep this test last, as it changes the current branch |
299 | cat >expect <<EOF | |
3749fde5 | 300 | $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master |
0746d19a PB |
301 | EOF |
302 | test_expect_success \ | |
303 | 'git checkout -b g/h/i -l should create a branch and a log' \ | |
304 | 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ | |
0cb0e143 | 305 | git checkout -b g/h/i -l master && |
376eb14a JK |
306 | test_path_is_file .git/refs/heads/g/h/i && |
307 | test_path_is_file .git/logs/refs/heads/g/h/i && | |
4fdf71be | 308 | test_cmp expect .git/logs/refs/heads/g/h/i' |
0746d19a | 309 | |
b2099957 EM |
310 | test_expect_success 'checkout -b makes reflog by default' ' |
311 | git checkout master && | |
312 | git config --unset core.logAllRefUpdates && | |
313 | git checkout -b alpha && | |
6e6842e3 | 314 | git rev-parse --verify alpha@{0} |
b2099957 EM |
315 | ' |
316 | ||
317 | test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' ' | |
318 | git checkout master && | |
319 | git config core.logAllRefUpdates false && | |
320 | git checkout -b beta && | |
6e6842e3 | 321 | test_must_fail git rev-parse --verify beta@{0} |
b2099957 EM |
322 | ' |
323 | ||
324 | test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' ' | |
325 | git checkout master && | |
326 | git checkout -lb gamma && | |
327 | git config --unset core.logAllRefUpdates && | |
6e6842e3 | 328 | git rev-parse --verify gamma@{0} |
b2099957 EM |
329 | ' |
330 | ||
1d0a694b DB |
331 | test_expect_success 'avoid ambiguous track' ' |
332 | git config branch.autosetupmerge true && | |
333 | git config remote.ambi1.url lalala && | |
334 | git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master && | |
335 | git config remote.ambi2.url lilili && | |
336 | git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master && | |
337 | git branch all1 master && | |
338 | test -z "$(git config branch.all1.merge)" | |
339 | ' | |
340 | ||
c998ae9b DS |
341 | test_expect_success 'autosetuprebase local on a tracked local branch' ' |
342 | git config remote.local.url . && | |
343 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
344 | git config branch.autosetuprebase local && | |
0cb0e143 | 345 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
346 | git branch mybase && |
347 | git branch --track myr1 mybase && | |
348 | test "$(git config branch.myr1.remote)" = . && | |
349 | test "$(git config branch.myr1.merge)" = refs/heads/mybase && | |
350 | test "$(git config branch.myr1.rebase)" = true | |
351 | ' | |
352 | ||
353 | test_expect_success 'autosetuprebase always on a tracked local branch' ' | |
354 | git config remote.local.url . && | |
355 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
356 | git config branch.autosetuprebase always && | |
0cb0e143 | 357 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
358 | git branch mybase2 && |
359 | git branch --track myr2 mybase && | |
360 | test "$(git config branch.myr2.remote)" = . && | |
361 | test "$(git config branch.myr2.merge)" = refs/heads/mybase && | |
362 | test "$(git config branch.myr2.rebase)" = true | |
363 | ' | |
364 | ||
365 | test_expect_success 'autosetuprebase remote on a tracked local branch' ' | |
366 | git config remote.local.url . && | |
367 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
368 | git config branch.autosetuprebase remote && | |
0cb0e143 | 369 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
370 | git branch mybase3 && |
371 | git branch --track myr3 mybase2 && | |
372 | test "$(git config branch.myr3.remote)" = . && | |
373 | test "$(git config branch.myr3.merge)" = refs/heads/mybase2 && | |
374 | ! test "$(git config branch.myr3.rebase)" = true | |
375 | ' | |
376 | ||
377 | test_expect_success 'autosetuprebase never on a tracked local branch' ' | |
378 | git config remote.local.url . && | |
379 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
380 | git config branch.autosetuprebase never && | |
0cb0e143 | 381 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
382 | git branch mybase4 && |
383 | git branch --track myr4 mybase2 && | |
384 | test "$(git config branch.myr4.remote)" = . && | |
385 | test "$(git config branch.myr4.merge)" = refs/heads/mybase2 && | |
386 | ! test "$(git config branch.myr4.rebase)" = true | |
387 | ' | |
388 | ||
389 | test_expect_success 'autosetuprebase local on a tracked remote branch' ' | |
390 | git config remote.local.url . && | |
391 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
392 | git config branch.autosetuprebase local && | |
0cb0e143 | 393 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
394 | git branch --track myr5 local/master && |
395 | test "$(git config branch.myr5.remote)" = local && | |
396 | test "$(git config branch.myr5.merge)" = refs/heads/master && | |
397 | ! test "$(git config branch.myr5.rebase)" = true | |
398 | ' | |
399 | ||
400 | test_expect_success 'autosetuprebase never on a tracked remote branch' ' | |
401 | git config remote.local.url . && | |
402 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
403 | git config branch.autosetuprebase never && | |
0cb0e143 | 404 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
405 | git branch --track myr6 local/master && |
406 | test "$(git config branch.myr6.remote)" = local && | |
407 | test "$(git config branch.myr6.merge)" = refs/heads/master && | |
408 | ! test "$(git config branch.myr6.rebase)" = true | |
409 | ' | |
410 | ||
411 | test_expect_success 'autosetuprebase remote on a tracked remote branch' ' | |
412 | git config remote.local.url . && | |
413 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
414 | git config branch.autosetuprebase remote && | |
0cb0e143 | 415 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
416 | git branch --track myr7 local/master && |
417 | test "$(git config branch.myr7.remote)" = local && | |
418 | test "$(git config branch.myr7.merge)" = refs/heads/master && | |
419 | test "$(git config branch.myr7.rebase)" = true | |
420 | ' | |
421 | ||
422 | test_expect_success 'autosetuprebase always on a tracked remote branch' ' | |
423 | git config remote.local.url . && | |
424 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
425 | git config branch.autosetuprebase remote && | |
0cb0e143 | 426 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
427 | git branch --track myr8 local/master && |
428 | test "$(git config branch.myr8.remote)" = local && | |
429 | test "$(git config branch.myr8.merge)" = refs/heads/master && | |
430 | test "$(git config branch.myr8.rebase)" = true | |
431 | ' | |
432 | ||
433 | test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' ' | |
434 | git config --unset branch.autosetuprebase && | |
435 | git config remote.local.url . && | |
436 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 437 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
438 | git branch --track myr9 local/master && |
439 | test "$(git config branch.myr9.remote)" = local && | |
440 | test "$(git config branch.myr9.merge)" = refs/heads/master && | |
441 | test "z$(git config branch.myr9.rebase)" = z | |
442 | ' | |
443 | ||
444 | test_expect_success 'autosetuprebase unconfigured on a tracked local branch' ' | |
445 | git config remote.local.url . && | |
446 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 447 | (git show-ref -q refs/remotes/local/o || git fetch local) && |
c998ae9b DS |
448 | git branch mybase10 && |
449 | git branch --track myr10 mybase2 && | |
450 | test "$(git config branch.myr10.remote)" = . && | |
451 | test "$(git config branch.myr10.merge)" = refs/heads/mybase2 && | |
452 | test "z$(git config branch.myr10.rebase)" = z | |
453 | ' | |
454 | ||
455 | test_expect_success 'autosetuprebase unconfigured on untracked local branch' ' | |
456 | git config remote.local.url . && | |
457 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 458 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
459 | git branch --no-track myr11 mybase2 && |
460 | test "z$(git config branch.myr11.remote)" = z && | |
461 | test "z$(git config branch.myr11.merge)" = z && | |
462 | test "z$(git config branch.myr11.rebase)" = z | |
463 | ' | |
464 | ||
465 | test_expect_success 'autosetuprebase unconfigured on untracked remote branch' ' | |
466 | git config remote.local.url . && | |
467 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 468 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
469 | git branch --no-track myr12 local/master && |
470 | test "z$(git config branch.myr12.remote)" = z && | |
471 | test "z$(git config branch.myr12.merge)" = z && | |
472 | test "z$(git config branch.myr12.rebase)" = z | |
473 | ' | |
474 | ||
475 | test_expect_success 'autosetuprebase never on an untracked local branch' ' | |
476 | git config branch.autosetuprebase never && | |
477 | git config remote.local.url . && | |
478 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 479 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
480 | git branch --no-track myr13 mybase2 && |
481 | test "z$(git config branch.myr13.remote)" = z && | |
482 | test "z$(git config branch.myr13.merge)" = z && | |
483 | test "z$(git config branch.myr13.rebase)" = z | |
484 | ' | |
485 | ||
486 | test_expect_success 'autosetuprebase local on an untracked local branch' ' | |
487 | git config branch.autosetuprebase local && | |
488 | git config remote.local.url . && | |
489 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 490 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
491 | git branch --no-track myr14 mybase2 && |
492 | test "z$(git config branch.myr14.remote)" = z && | |
493 | test "z$(git config branch.myr14.merge)" = z && | |
494 | test "z$(git config branch.myr14.rebase)" = z | |
495 | ' | |
496 | ||
497 | test_expect_success 'autosetuprebase remote on an untracked local branch' ' | |
498 | git config branch.autosetuprebase remote && | |
499 | git config remote.local.url . && | |
500 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 501 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
502 | git branch --no-track myr15 mybase2 && |
503 | test "z$(git config branch.myr15.remote)" = z && | |
504 | test "z$(git config branch.myr15.merge)" = z && | |
505 | test "z$(git config branch.myr15.rebase)" = z | |
506 | ' | |
507 | ||
508 | test_expect_success 'autosetuprebase always on an untracked local branch' ' | |
509 | git config branch.autosetuprebase always && | |
510 | git config remote.local.url . && | |
511 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 512 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
513 | git branch --no-track myr16 mybase2 && |
514 | test "z$(git config branch.myr16.remote)" = z && | |
515 | test "z$(git config branch.myr16.merge)" = z && | |
516 | test "z$(git config branch.myr16.rebase)" = z | |
517 | ' | |
518 | ||
519 | test_expect_success 'autosetuprebase never on an untracked remote branch' ' | |
520 | git config branch.autosetuprebase never && | |
521 | git config remote.local.url . && | |
522 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 523 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
524 | git branch --no-track myr17 local/master && |
525 | test "z$(git config branch.myr17.remote)" = z && | |
526 | test "z$(git config branch.myr17.merge)" = z && | |
527 | test "z$(git config branch.myr17.rebase)" = z | |
528 | ' | |
529 | ||
530 | test_expect_success 'autosetuprebase local on an untracked remote branch' ' | |
531 | git config branch.autosetuprebase local && | |
532 | git config remote.local.url . && | |
533 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 534 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
535 | git branch --no-track myr18 local/master && |
536 | test "z$(git config branch.myr18.remote)" = z && | |
537 | test "z$(git config branch.myr18.merge)" = z && | |
538 | test "z$(git config branch.myr18.rebase)" = z | |
539 | ' | |
540 | ||
541 | test_expect_success 'autosetuprebase remote on an untracked remote branch' ' | |
542 | git config branch.autosetuprebase remote && | |
543 | git config remote.local.url . && | |
544 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 545 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
546 | git branch --no-track myr19 local/master && |
547 | test "z$(git config branch.myr19.remote)" = z && | |
548 | test "z$(git config branch.myr19.merge)" = z && | |
549 | test "z$(git config branch.myr19.rebase)" = z | |
550 | ' | |
551 | ||
552 | test_expect_success 'autosetuprebase always on an untracked remote branch' ' | |
553 | git config branch.autosetuprebase always && | |
554 | git config remote.local.url . && | |
555 | git config remote.local.fetch refs/heads/*:refs/remotes/local/* && | |
0cb0e143 | 556 | (git show-ref -q refs/remotes/local/master || git fetch local) && |
c998ae9b DS |
557 | git branch --no-track myr20 local/master && |
558 | test "z$(git config branch.myr20.remote)" = z && | |
559 | test "z$(git config branch.myr20.merge)" = z && | |
560 | test "z$(git config branch.myr20.rebase)" = z | |
561 | ' | |
562 | ||
21b5b1e8 JH |
563 | test_expect_success 'autosetuprebase always on detached HEAD' ' |
564 | git config branch.autosetupmerge always && | |
565 | test_when_finished git checkout master && | |
566 | git checkout HEAD^0 && | |
567 | git branch my11 && | |
568 | test -z "$(git config branch.my11.remote)" && | |
569 | test -z "$(git config branch.my11.merge)" | |
570 | ' | |
571 | ||
c998ae9b DS |
572 | test_expect_success 'detect misconfigured autosetuprebase (bad value)' ' |
573 | git config branch.autosetuprebase garbage && | |
574 | test_must_fail git branch | |
575 | ' | |
576 | ||
577 | test_expect_success 'detect misconfigured autosetuprebase (no value)' ' | |
578 | git config --unset branch.autosetuprebase && | |
579 | echo "[branch] autosetuprebase" >> .git/config && | |
580 | test_must_fail git branch && | |
581 | git config --unset branch.autosetuprebase | |
582 | ' | |
583 | ||
99c419c9 JH |
584 | test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' ' |
585 | git checkout my9 && | |
586 | git config --unset branch.my8.merge && | |
587 | test_must_fail git branch -d my8 | |
588 | ' | |
589 | ||
590 | test_expect_success 'attempt to delete a branch merged to its base' ' | |
591 | # we are on my9 which is the initial commit; traditionally | |
592 | # we would not have allowed deleting my8 that is not merged | |
593 | # to my9, but it is set to track master that already has my8 | |
594 | git config branch.my8.merge refs/heads/master && | |
595 | git branch -d my8 | |
596 | ' | |
597 | ||
598 | test_expect_success 'attempt to delete a branch merged to its base' ' | |
599 | git checkout master && | |
600 | echo Third >>A && | |
601 | git commit -m "Third commit" A && | |
602 | git branch -t my10 my9 && | |
603 | git branch -f my10 HEAD^ && | |
604 | # we are on master which is at the third commit, and my10 | |
605 | # is behind us, so traditionally we would have allowed deleting | |
606 | # it; but my10 is set to track my9 that is further behind. | |
607 | test_must_fail git branch -d my10 | |
608 | ' | |
609 | ||
fa799376 JH |
610 | test_expect_success 'use set-upstream on the current branch' ' |
611 | git checkout master && | |
612 | git --bare init myupstream.git && | |
613 | git push myupstream.git master:refs/heads/frotz && | |
614 | git remote add origin myupstream.git && | |
615 | git fetch && | |
616 | git branch --set-upstream master origin/frotz && | |
617 | ||
618 | test "z$(git config branch.master.remote)" = "zorigin" && | |
619 | test "z$(git config branch.master.merge)" = "zrefs/heads/frotz" | |
620 | ||
621 | ' | |
622 | ||
a3b427b9 | 623 | test_done |