]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3200-branch.sh
branch: optionally setup branch.*.merge from upstream local branches
[thirdparty/git.git] / t / t3200-branch.sh
CommitLineData
a3b427b9
AW
1#!/bin/sh
2#
3# Copyright (c) 2005 Amos Waterland
4#
5
6test_description='git branch --foo should not create bogus branch
7
8This test runs git branch --help and checks that the argument is properly
9handled. Specifically, that a bogus branch is not created.
10'
11. ./test-lib.sh
12
13test_expect_success \
4c84f0dc 14 'prepare a trivial repository' \
a3b427b9 15 'echo Hello > A &&
5be60078 16 git update-index --add A &&
d7fb7a37 17 git-commit -m "Initial commit." &&
9ed36cfa
JS
18 echo World >> A &&
19 git update-index --add A &&
20 git-commit -m "Second commit." &&
5be60078 21 HEAD=$(git rev-parse --verify HEAD)'
a3b427b9 22
a3b427b9
AW
23test_expect_failure \
24 'git branch --help should not have created a bogus branch' \
5be60078 25 'git branch --help </dev/null >/dev/null 2>/dev/null || :
5d9e8ee7 26 test -f .git/refs/heads/--help'
a3b427b9 27
08db81a9
AR
28test_expect_success \
29 'git branch abc should create a branch' \
5be60078 30 'git branch abc && test -f .git/refs/heads/abc'
08db81a9
AR
31
32test_expect_success \
33 'git branch a/b/c should create a branch' \
5be60078 34 'git branch a/b/c && test -f .git/refs/heads/a/b/c'
08db81a9 35
d7fb7a37 36cat >expect <<EOF
5d9e8ee7 370000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
d7fb7a37
SP
38EOF
39test_expect_success \
40 'git branch -l d/e/f should create a branch and a log' \
41 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
5be60078 42 git branch -l d/e/f &&
d7fb7a37
SP
43 test -f .git/refs/heads/d/e/f &&
44 test -f .git/logs/refs/heads/d/e/f &&
45 diff expect .git/logs/refs/heads/d/e/f'
46
47test_expect_success \
48 'git branch -d d/e/f should delete a branch and a log' \
5be60078 49 'git branch -d d/e/f &&
d7fb7a37
SP
50 test ! -f .git/refs/heads/d/e/f &&
51 test ! -f .git/logs/refs/heads/d/e/f'
52
9c7b0b3f
CC
53test_expect_success \
54 'git branch j/k should work after branch j has been deleted' \
5be60078
JH
55 'git branch j &&
56 git branch -d j &&
57 git branch j/k'
9c7b0b3f
CC
58
59test_expect_success \
60 'git branch l should work after branch l/m has been deleted' \
5be60078
JH
61 'git branch l/m &&
62 git branch -d l/m &&
63 git branch l'
9c7b0b3f 64
c976d415
LH
65test_expect_success \
66 'git branch -m m m/m should work' \
5be60078
JH
67 'git branch -l m &&
68 git branch -m m m/m &&
c976d415
LH
69 test -f .git/logs/refs/heads/m/m'
70
71test_expect_success \
72 'git branch -m n/n n should work' \
5be60078
JH
73 'git branch -l n/n &&
74 git branch -m n/n n
c976d415
LH
75 test -f .git/logs/refs/heads/n'
76
77test_expect_failure \
78 'git branch -m o/o o should fail when o/p exists' \
5be60078
JH
79 'git branch o/o &&
80 git branch o/p &&
81 git branch -m o/o o'
c976d415
LH
82
83test_expect_failure \
84 'git branch -m q r/q should fail when r exists' \
5be60078
JH
85 'git branch q &&
86 git branch r &&
87 git branch -m q r/q'
c976d415 88
01ebb9dc
GB
89mv .git/config .git/config-saved
90
08b984fb 91test_expect_success 'git branch -m q q2 without config should succeed' '
5be60078
JH
92 git branch -m q q2 &&
93 git branch -m q2 q
01ebb9dc
GB
94'
95
96mv .git/config-saved .git/config
97
5be60078 98git config branch.s/s.dummy Hello
dc81c58c 99
c976d415
LH
100test_expect_success \
101 'git branch -m s/s s should work when s/t is deleted' \
5be60078 102 'git branch -l s/s &&
c976d415 103 test -f .git/logs/refs/heads/s/s &&
5be60078 104 git branch -l s/t &&
c976d415 105 test -f .git/logs/refs/heads/s/t &&
5be60078
JH
106 git branch -d s/t &&
107 git branch -m s/s s &&
c976d415
LH
108 test -f .git/logs/refs/heads/s'
109
dc81c58c 110test_expect_success 'config information was renamed, too' \
5be60078
JH
111 "test $(git config branch.s.dummy) = Hello &&
112 ! git config branch.s/s/dummy"
dc81c58c 113
16c2bfbb 114test_expect_failure \
5be60078
JH
115 'git branch -m u v should fail when the reflog for u is a symlink' \
116 'git branch -l u &&
16c2bfbb
LH
117 mv .git/logs/refs/heads/u real-u &&
118 ln -s real-u .git/logs/refs/heads/u &&
5be60078 119 git branch -m u v'
16c2bfbb 120
0746d19a 121test_expect_success 'test tracking setup via --track' \
5be60078
JH
122 'git config remote.local.url . &&
123 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
124 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
125 git branch --track my1 local/master &&
126 test $(git config branch.my1.remote) = local &&
127 test $(git config branch.my1.merge) = refs/heads/master'
0746d19a
PB
128
129test_expect_success 'test tracking setup (non-wildcard, matching)' \
5be60078
JH
130 'git config remote.local.url . &&
131 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
132 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
133 git branch --track my4 local/master &&
134 test $(git config branch.my4.remote) = local &&
135 test $(git config branch.my4.merge) = refs/heads/master'
0746d19a
PB
136
137test_expect_success 'test tracking setup (non-wildcard, not matching)' \
5be60078
JH
138 'git config remote.local.url . &&
139 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
140 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
141 git branch --track my5 local/master &&
142 ! test "$(git config branch.my5.remote)" = local &&
143 ! test "$(git config branch.my5.merge)" = refs/heads/master'
0746d19a
PB
144
145test_expect_success 'test tracking setup via config' \
5be60078
JH
146 'git config branch.autosetupmerge true &&
147 git config remote.local.url . &&
148 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
149 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
150 git branch my3 local/master &&
151 test $(git config branch.my3.remote) = local &&
152 test $(git config branch.my3.merge) = refs/heads/master'
0746d19a 153
6f084a56 154test_expect_success 'avoid ambiguous track' '
4017761f 155 git config branch.autosetupmerge true &&
6f084a56
JS
156 git config remote.ambi1.url = lalala &&
157 git config remote.ambi1.fetch = refs/heads/lalala:refs/heads/master &&
158 git config remote.ambi2.url = lilili &&
159 git config remote.ambi2.fetch = refs/heads/lilili:refs/heads/master &&
4017761f 160 git branch all1 master &&
6f084a56 161 test -z "$(git config branch.all1.merge)"
4017761f
JS
162'
163
0746d19a 164test_expect_success 'test overriding tracking setup via --no-track' \
5be60078
JH
165 'git config branch.autosetupmerge true &&
166 git config remote.local.url . &&
167 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
168 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
169 git branch --no-track my2 local/master &&
170 git config branch.autosetupmerge false &&
171 ! test "$(git config branch.my2.remote)" = local &&
172 ! test "$(git config branch.my2.merge)" = refs/heads/master'
0746d19a 173
6f084a56 174test_expect_success 'no tracking without .fetch entries' \
9ed36cfa
JS
175 'git config branch.autosetupmerge true &&
176 git branch my6 s &&
177 git config branch.automsetupmerge false &&
6f084a56
JS
178 test -z "$(git config branch.my6.remote)" &&
179 test -z "$(git config branch.my6.merge)"'
9debc324 180
11f68d90 181test_expect_success 'test tracking setup via --track but deeper' \
5be60078
JH
182 'git config remote.local.url . &&
183 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
184 (git show-ref -q refs/remotes/local/o/o || git-fetch local) &&
185 git branch --track my7 local/o/o &&
186 test "$(git config branch.my7.remote)" = local &&
187 test "$(git config branch.my7.merge)" = refs/heads/o/o'
11f68d90 188
f1eccbab 189test_expect_success 'test deleting branch deletes branch config' \
5be60078 190 'git branch -d my7 &&
6f084a56
JS
191 test -z "$(git config branch.my7.remote)" &&
192 test -z "$(git config branch.my7.merge)"'
f1eccbab
GP
193
194test_expect_success 'test deleting branch without config' \
5be60078
JH
195 'git branch my7 s &&
196 test "$(git branch -d my7 2>&1)" = "Deleted branch my7."'
f1eccbab 197
9ed36cfa
JS
198test_expect_success 'test --track without .fetch entries' \
199 'git branch --track my8 &&
200 test "$(git config branch.my8.remote)" &&
201 test "$(git config branch.my8.merge)"'
202
203test_expect_success \
204 'branch from non-branch HEAD w/autosetupmerge=always' \
205 'git config branch.autosetupmerge always &&
206 git branch my9 HEAD^ &&
207 git config branch.autosetupmerge false'
208
209test_expect_success \
210 'branch from non-branch HEAD w/--track causes failure' \
211 '!(git branch --track my10 HEAD^)'
212
0746d19a
PB
213# Keep this test last, as it changes the current branch
214cat >expect <<EOF
2150000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
216EOF
217test_expect_success \
218 'git checkout -b g/h/i -l should create a branch and a log' \
219 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
220 git-checkout -b g/h/i -l master &&
221 test -f .git/refs/heads/g/h/i &&
222 test -f .git/logs/refs/heads/g/h/i &&
223 diff expect .git/logs/refs/heads/g/h/i'
224
a3b427b9 225test_done