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." &&
18 HEAD=$(git rev-parse --verify HEAD)'
21 'git branch --help should not have created a bogus branch' '
22 git branch --help </dev/null >/dev/null 2>/dev/null;
23 ! test -f .git/refs/heads/--help
27 'git branch abc should create a branch' \
28 'git branch abc && test -f .git/refs/heads/abc'
31 'git branch a/b/c should create a branch' \
32 'git branch a/b/c && test -f .git/refs/heads/a/b/c'
35 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
38 'git branch -l d/e/f should create a branch and a log' \
39 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
40 git branch -l d/e/f &&
41 test -f .git/refs/heads/d/e/f &&
42 test -f .git/logs/refs/heads/d/e/f &&
43 diff expect .git/logs/refs/heads/d/e/f'
46 'git branch -d d/e/f should delete a branch and a log' \
47 'git branch -d d/e/f &&
48 test ! -f .git/refs/heads/d/e/f &&
49 test ! -f .git/logs/refs/heads/d/e/f'
52 'git branch j/k should work after branch j has been deleted' \
58 'git branch l should work after branch l/m has been deleted' \
64 'git branch -m m m/m should work' \
66 git branch -m m m/m &&
67 test -f .git/logs/refs/heads/m/m'
70 'git branch -m n/n n should work' \
73 test -f .git/logs/refs/heads/n'
75 test_expect_success
'git branch -m o/o o should fail when o/p exists' '
81 test_expect_success
'git branch -m q r/q should fail when r exists' '
87 mv .git
/config .git
/config-saved
89 test_expect_success
'git branch -m q q2 without config should succeed' '
94 mv .git
/config-saved .git
/config
96 git config branch.s
/s.dummy Hello
99 'git branch -m s/s s should work when s/t is deleted' \
100 'git branch -l s/s &&
101 test -f .git/logs/refs/heads/s/s &&
103 test -f .git/logs/refs/heads/s/t &&
105 git branch -m s/s s &&
106 test -f .git/logs/refs/heads/s'
108 test_expect_success
'config information was renamed, too' \
109 "test $(git config branch.s.dummy) = Hello &&
110 ! git config branch.s/s/dummy"
112 test_expect_success \
113 'git branch -m u v should fail when the reflog for u is a symlink' '
115 mv .git/logs/refs/heads/u real-u &&
116 ln -s real-u .git/logs/refs/heads/u &&
120 test_expect_success
'test tracking setup via --track' \
121 'git config remote.local.url . &&
122 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
123 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
124 git branch --track my1 local/master &&
125 test $(git config branch.my1.remote) = local &&
126 test $(git config branch.my1.merge) = refs/heads/master'
128 test_expect_success
'test tracking setup (non-wildcard, matching)' \
129 'git config remote.local.url . &&
130 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
131 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
132 git branch --track my4 local/master &&
133 test $(git config branch.my4.remote) = local &&
134 test $(git config branch.my4.merge) = refs/heads/master'
136 test_expect_success
'test tracking setup (non-wildcard, not matching)' \
137 'git config remote.local.url . &&
138 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
139 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
140 git branch --track my5 local/master &&
141 ! test "$(git config branch.my5.remote)" = local &&
142 ! test "$(git config branch.my5.merge)" = refs/heads/master'
144 test_expect_success
'test tracking setup via config' \
145 'git config branch.autosetupmerge true &&
146 git config remote.local.url . &&
147 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
148 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
149 git branch my3 local/master &&
150 test $(git config branch.my3.remote) = local &&
151 test $(git config branch.my3.merge) = refs/heads/master'
153 test_expect_success
'avoid ambiguous track' '
154 git config branch.autosetupmerge true &&
155 git config remote.ambi1.url = lalala &&
156 git config remote.ambi1.fetch = refs/heads/lalala:refs/heads/master &&
157 git config remote.ambi2.url = lilili &&
158 git config remote.ambi2.fetch = refs/heads/lilili:refs/heads/master &&
159 git branch all1 master &&
160 test -z "$(git config branch.all1.merge)"
163 test_expect_success
'test overriding tracking setup via --no-track' \
164 'git config branch.autosetupmerge true &&
165 git config remote.local.url . &&
166 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
167 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
168 git branch --no-track my2 local/master &&
169 git config branch.autosetupmerge false &&
170 ! test "$(git config branch.my2.remote)" = local &&
171 ! test "$(git config branch.my2.merge)" = refs/heads/master'
173 test_expect_success
'no tracking without .fetch entries' \
174 'git branch --track my6 s &&
175 test -z "$(git config branch.my6.remote)" &&
176 test -z "$(git config branch.my6.merge)"'
178 test_expect_success
'test tracking setup via --track but deeper' \
179 'git config remote.local.url . &&
180 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
181 (git show-ref -q refs/remotes/local/o/o || git-fetch local) &&
182 git branch --track my7 local/o/o &&
183 test "$(git config branch.my7.remote)" = local &&
184 test "$(git config branch.my7.merge)" = refs/heads/o/o'
186 test_expect_success
'test deleting branch deletes branch config' \
187 'git branch -d my7 &&
188 test -z "$(git config branch.my7.remote)" &&
189 test -z "$(git config branch.my7.merge)"'
191 test_expect_success
'test deleting branch without config' \
193 test "$(git branch -d my7 2>&1)" = "Deleted branch my7."'
195 # Keep this test last, as it changes the current branch
197 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
199 test_expect_success \
200 'git checkout -b g/h/i -l should create a branch and a log' \
201 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
202 git-checkout -b g/h/i -l master &&
203 test -f .git/refs/heads/g/h/i &&
204 test -f .git/logs/refs/heads/g/h/i &&
205 diff expect .git/logs/refs/heads/g/h/i'