3 # Copyright (c) 2005 Amos Waterland
6 test_description
='git branch --foo should not create bogus branch
8 This test runs git branch --help and checks that the argument is properly
9 handled. Specifically, that a bogus branch is not created.
14 'prepare a trivial repository' \
16 git update-index --add A &&
17 git-commit -m "Initial commit." &&
19 git update-index --add A &&
20 git-commit -m "Second commit." &&
21 HEAD=$(git rev-parse --verify HEAD)'
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'
29 'git branch abc should create a branch' \
30 'git branch abc && test -f .git/refs/heads/abc'
33 'git branch a/b/c should create a branch' \
34 'git branch a/b/c && test -f .git/refs/heads/a/b/c'
37 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
40 'git branch -l d/e/f should create a branch and a log' \
41 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
42 git branch -l d/e/f &&
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'
48 'git branch -d d/e/f should delete a branch and a log' \
49 'git branch -d d/e/f &&
50 test ! -f .git/refs/heads/d/e/f &&
51 test ! -f .git/logs/refs/heads/d/e/f'
54 'git branch j/k should work after branch j has been deleted' \
60 'git branch l should work after branch l/m has been deleted' \
66 'git branch -m m m/m should work' \
68 git branch -m m m/m &&
69 test -f .git/logs/refs/heads/m/m'
72 'git branch -m n/n n should work' \
75 test -f .git/logs/refs/heads/n'
78 'git branch -m o/o o should fail when o/p exists' \
84 'git branch -m q r/q should fail when r exists' \
89 mv .git
/config .git
/config-saved
91 test_expect_success
'git branch -m q q2 without config should succeed' '
96 mv .git
/config-saved .git
/config
98 git config branch.s
/s.dummy Hello
100 test_expect_success \
101 'git branch -m s/s s should work when s/t is deleted' \
102 'git branch -l s/s &&
103 test -f .git/logs/refs/heads/s/s &&
105 test -f .git/logs/refs/heads/s/t &&
107 git branch -m s/s s &&
108 test -f .git/logs/refs/heads/s'
110 test_expect_success
'config information was renamed, too' \
111 "test $(git config branch.s.dummy) = Hello &&
112 ! git config branch.s/s/dummy"
114 test_expect_failure \
115 'git branch -m u v should fail when the reflog for u is a symlink' \
117 mv .git/logs/refs/heads/u real-u &&
118 ln -s real-u .git/logs/refs/heads/u &&
121 test_expect_success
'test tracking setup via --track' \
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'
129 test_expect_success
'test tracking setup (non-wildcard, matching)' \
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'
137 test_expect_success
'test tracking setup (non-wildcard, not matching)' \
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'
145 test_expect_success
'test tracking setup via config' \
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'
154 test_expect_success
'avoid ambiguous track' '
155 git config branch.autosetupmerge true &&
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 &&
160 git branch all1 master &&
161 test -z "$(git config branch.all1.merge)"
164 test_expect_success
'test overriding tracking setup via --no-track' \
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'
174 test_expect_success
'no tracking without .fetch entries' \
175 'git config branch.autosetupmerge true &&
177 git config branch.automsetupmerge false &&
178 test -z "$(git config branch.my6.remote)" &&
179 test -z "$(git config branch.my6.merge)"'
181 test_expect_success
'test tracking setup via --track but deeper' \
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'
189 test_expect_success
'test deleting branch deletes branch config' \
190 'git branch -d my7 &&
191 test -z "$(git config branch.my7.remote)" &&
192 test -z "$(git config branch.my7.merge)"'
194 test_expect_success
'test deleting branch without config' \
196 test "$(git branch -d my7 2>&1)" = "Deleted branch my7."'
198 test_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)"'
203 test_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'
209 test_expect_success \
210 'branch from non-branch HEAD w/--track causes failure' \
211 '!(git branch --track my10 HEAD^)'
213 # Keep this test last, as it changes the current branch
215 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
217 test_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'