Merge branch 'master' of git://repo.or.cz/alt-git
[git/dscho.git] / t / t3200-branch.sh
blob92350c6ade75eed145004b4210598e7aa01a8d4e
1 #!/bin/sh
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.
11 . ./test-lib.sh
13 test_expect_success \
14 'prepare a trivial repository' \
15 'echo Hello > A &&
16 git update-index --add A &&
17 git-commit -m "Initial commit." &&
18 HEAD=$(git rev-parse --verify HEAD)'
20 test_expect_success \
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 test_expect_success \
27 'git branch abc should create a branch' \
28 'git branch abc && test -f .git/refs/heads/abc'
30 test_expect_success \
31 'git branch a/b/c should create a branch' \
32 'git branch a/b/c && test -f .git/refs/heads/a/b/c'
34 cat >expect <<EOF
35 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
36 EOF
37 test_expect_success \
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'
45 test_expect_success \
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'
51 test_expect_success \
52 'git branch j/k should work after branch j has been deleted' \
53 'git branch j &&
54 git branch -d j &&
55 git branch j/k'
57 test_expect_success \
58 'git branch l should work after branch l/m has been deleted' \
59 'git branch l/m &&
60 git branch -d l/m &&
61 git branch l'
63 test_expect_success \
64 'git branch -m m m/m should work' \
65 'git branch -l m &&
66 git branch -m m m/m &&
67 test -f .git/logs/refs/heads/m/m'
69 test_expect_success \
70 'git branch -m n/n n should work' \
71 'git branch -l n/n &&
72 git branch -m n/n n
73 test -f .git/logs/refs/heads/n'
75 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
76 git branch o/o &&
77 git branch o/p &&
78 ! git branch -m o/o o
81 test_expect_success 'git branch -m q r/q should fail when r exists' '
82 git branch q &&
83 git branch r &&
84 ! git branch -m q r/q
87 mv .git/config .git/config-saved
89 test_expect_success 'git branch -m q q2 without config should succeed' '
90 git branch -m q q2 &&
91 git branch -m q2 q
94 mv .git/config-saved .git/config
96 git config branch.s/s.dummy Hello
98 test_expect_success \
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 &&
102 git branch -l s/t &&
103 test -f .git/logs/refs/heads/s/t &&
104 git branch -d 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 "$no_symlinks" || {
113 test_expect_success \
114 'git branch -m u v should fail when the reflog for u is a symlink' '
115 git branch -l u &&
116 mv .git/logs/refs/heads/u real-u &&
117 ln -s real-u .git/logs/refs/heads/u &&
118 ! git branch -m u v
122 test_expect_success 'test tracking setup via --track' \
123 'git config remote.local.url . &&
124 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
125 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
126 git branch --track my1 local/master &&
127 test $(git config branch.my1.remote) = local &&
128 test $(git config branch.my1.merge) = refs/heads/master'
130 test_expect_success 'test tracking setup (non-wildcard, matching)' \
131 'git config remote.local.url . &&
132 git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
133 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
134 git branch --track my4 local/master &&
135 test $(git config branch.my4.remote) = local &&
136 test $(git config branch.my4.merge) = refs/heads/master'
138 test_expect_success 'test tracking setup (non-wildcard, not matching)' \
139 'git config remote.local.url . &&
140 git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
141 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
142 git branch --track my5 local/master &&
143 ! test "$(git config branch.my5.remote)" = local &&
144 ! test "$(git config branch.my5.merge)" = refs/heads/master'
146 test_expect_success 'test tracking setup via config' \
147 'git config branch.autosetupmerge true &&
148 git config remote.local.url . &&
149 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
150 (git show-ref -q refs/remotes/local/master || git-fetch local) &&
151 git branch my3 local/master &&
152 test $(git config branch.my3.remote) = local &&
153 test $(git config branch.my3.merge) = refs/heads/master'
155 test_expect_success 'avoid ambiguous track' '
156 git config branch.autosetupmerge true &&
157 git config remote.ambi1.url = lalala &&
158 git config remote.ambi1.fetch = refs/heads/lalala:refs/heads/master &&
159 git config remote.ambi2.url = lilili &&
160 git config remote.ambi2.fetch = refs/heads/lilili:refs/heads/master &&
161 git branch all1 master &&
162 test -z "$(git config branch.all1.merge)"
165 test_expect_success 'test overriding tracking setup via --no-track' \
166 'git config branch.autosetupmerge true &&
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/master || git-fetch local) &&
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'
175 test_expect_success 'no tracking without .fetch entries' \
176 'git branch --track my6 s &&
177 test -z "$(git config branch.my6.remote)" &&
178 test -z "$(git config branch.my6.merge)"'
180 test_expect_success 'test tracking setup via --track but deeper' \
181 'git config remote.local.url . &&
182 git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
183 (git show-ref -q refs/remotes/local/o/o || git-fetch local) &&
184 git branch --track my7 local/o/o &&
185 test "$(git config branch.my7.remote)" = local &&
186 test "$(git config branch.my7.merge)" = refs/heads/o/o'
188 test_expect_success 'test deleting branch deletes branch config' \
189 'git branch -d my7 &&
190 test -z "$(git config branch.my7.remote)" &&
191 test -z "$(git config branch.my7.merge)"'
193 test_expect_success 'test deleting branch without config' \
194 'git branch my7 s &&
195 test "$(git branch -d my7 2>&1)" = "Deleted branch my7."'
197 # Keep this test last, as it changes the current branch
198 cat >expect <<EOF
199 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
201 test_expect_success \
202 'git checkout -b g/h/i -l should create a branch and a log' \
203 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
204 git-checkout -b g/h/i -l master &&
205 test -f .git/refs/heads/g/h/i &&
206 test -f .git/logs/refs/heads/g/h/i &&
207 diff expect .git/logs/refs/heads/g/h/i'
209 test_done