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