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'
26 'git branch abc should create a branch' \
27 'git-branch abc && test -f .git/refs/heads/abc'
30 'git branch a/b/c should create a branch' \
31 'git-branch a/b/c && test -f .git/refs/heads/a/b/c'
34 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
37 'git branch -l d/e/f should create a branch and a log' \
38 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
39 git-branch -l d/e/f &&
40 test -f .git/refs/heads/d/e/f &&
41 test -f .git/logs/refs/heads/d/e/f &&
42 diff expect .git/logs/refs/heads/d/e/f'
45 'git branch -d d/e/f should delete a branch and a log' \
46 'git-branch -d d/e/f &&
47 test ! -f .git/refs/heads/d/e/f &&
48 test ! -f .git/logs/refs/heads/d/e/f'
51 'git branch j/k should work after branch j has been deleted' \
57 'git branch l should work after branch l/m has been deleted' \
63 'git branch -m m m/m should work' \
65 git-branch -m m m/m &&
66 test -f .git/logs/refs/heads/m/m'
69 'git branch -m n/n n should work' \
72 test -f .git/logs/refs/heads/n'
75 'git branch -m o/o o should fail when o/p exists' \
81 'git branch -m q r/q should fail when r exists' \
86 mv .git/config .git/config-saved
88 test_expect_success 'git branch -m q q2 without config should succeed' '
93 mv .git/config-saved .git/config
95 git-config branch.s/s.dummy Hello
98 'git branch -m s/s s should work when s/t is deleted' \
100 test -f .git/logs/refs/heads/s/s &&
102 test -f .git/logs/refs/heads/s/t &&
104 git-branch -m s/s s &&
105 test -f .git/logs/refs/heads/s'
107 test_expect_success 'config information was renamed, too' \
108 "test $(git-config branch.s.dummy) = Hello &&
109 ! git-config branch.s/s/dummy"
111 test_expect_failure \
112 'git-branch -m u v should fail when the reflog for u is a symlink' \
114 mv .git/logs/refs/heads/u real-u &&
115 ln -s real-u .git/logs/refs/heads/u &&
118 test_expect_success 'test tracking setup via --track' \
119 'git-config remote.local.url . &&
120 git-config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
121 (git-show-ref -q refs/remotes/local/master || git-fetch local) &&
122 git-branch --track my1 local/master &&
123 test $(git-config branch.my1.remote) = local &&
124 test $(git-config branch.my1.merge) = refs/heads/master'
126 test_expect_success 'test tracking setup (non-wildcard, matching)' \
127 'git-config remote.local.url . &&
128 git-config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
129 (git-show-ref -q refs/remotes/local/master || git-fetch local) &&
130 git-branch --track my4 local/master &&
131 test $(git-config branch.my4.remote) = local &&
132 test $(git-config branch.my4.merge) = refs/heads/master'
134 test_expect_success 'test tracking setup (non-wildcard, not matching)' \
135 'git-config remote.local.url . &&
136 git-config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
137 (git-show-ref -q refs/remotes/local/master || git-fetch local) &&
138 git-branch --track my5 local/master &&
139 ! test "$(git-config branch.my5.remote)" = local &&
140 ! test "$(git-config branch.my5.merge)" = refs/heads/master'
142 test_expect_success 'test tracking setup via config' \
143 'git-config branch.autosetupmerge true &&
144 git-config remote.local.url . &&
145 git-config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
146 (git-show-ref -q refs/remotes/local/master || git-fetch local) &&
147 git-branch my3 local/master &&
148 test $(git-config branch.my3.remote) = local &&
149 test $(git-config branch.my3.merge) = refs/heads/master'
151 test_expect_success 'test overriding tracking setup via --no-track' \
152 'git-config branch.autosetupmerge true &&
153 git-config remote.local.url . &&
154 git-config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
155 (git-show-ref -q refs/remotes/local/master || git-fetch local) &&
156 git-branch --no-track my2 local/master &&
157 git-config branch.autosetupmerge false &&
158 ! test "$(git-config branch.my2.remote)" = local &&
159 ! test "$(git-config branch.my2.merge)" = refs/heads/master'
161 test_expect_success 'test local tracking setup' \
162 'git branch --track my6 s &&
163 test $(git-config branch.my6.remote) = . &&
164 test $(git-config branch.my6.merge) = refs/heads/s'
166 test_expect_success 'test tracking setup via --track but deeper' \
167 'git-config remote.local.url . &&
168 git-config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
169 (git-show-ref -q refs/remotes/local/o/o || git-fetch local) &&
170 git-branch --track my7 local/o/o &&
171 test "$(git-config branch.my7.remote)" = local &&
172 test "$(git-config branch.my7.merge)" = refs/heads/o/o'
174 test_expect_success 'test deleting branch deletes branch config' \
175 'git-branch -d my7 &&
176 test "$(git-config branch.my7.remote)" = "" &&
177 test "$(git-config branch.my7.merge)" = ""'
179 test_expect_success 'test deleting branch without config' \
181 test "$(git-branch -d my7 2>&1)" = "Deleted branch my7."'
183 # Keep this test last, as it changes the current branch
185 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
187 test_expect_success \
188 'git checkout -b g/h/i -l should create a branch and a log' \
189 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
190 git-checkout -b g/h/i -l master &&
191 test -f .git/refs/heads/g/h/i &&
192 test -f .git/logs/refs/heads/g/h/i &&
193 diff expect .git/logs/refs/heads/g/h/i'