]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3200-branch.sh
Sane use of test_expect_failure
[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." &&
5be60078 18 HEAD=$(git rev-parse --verify HEAD)'
a3b427b9 19
41ac414e
JH
20test_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
24'
a3b427b9 25
08db81a9
AR
26test_expect_success \
27 'git branch abc should create a branch' \
5be60078 28 'git branch abc && test -f .git/refs/heads/abc'
08db81a9
AR
29
30test_expect_success \
31 'git branch a/b/c should create a branch' \
5be60078 32 'git branch a/b/c && test -f .git/refs/heads/a/b/c'
08db81a9 33
d7fb7a37 34cat >expect <<EOF
5d9e8ee7 350000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
d7fb7a37
SP
36EOF
37test_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" \
5be60078 40 git branch -l d/e/f &&
d7fb7a37
SP
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'
44
45test_expect_success \
46 'git branch -d d/e/f should delete a branch and a log' \
5be60078 47 'git branch -d d/e/f &&
d7fb7a37
SP
48 test ! -f .git/refs/heads/d/e/f &&
49 test ! -f .git/logs/refs/heads/d/e/f'
50
9c7b0b3f
CC
51test_expect_success \
52 'git branch j/k should work after branch j has been deleted' \
5be60078
JH
53 'git branch j &&
54 git branch -d j &&
55 git branch j/k'
9c7b0b3f
CC
56
57test_expect_success \
58 'git branch l should work after branch l/m has been deleted' \
5be60078
JH
59 'git branch l/m &&
60 git branch -d l/m &&
61 git branch l'
9c7b0b3f 62
c976d415
LH
63test_expect_success \
64 'git branch -m m m/m should work' \
5be60078
JH
65 'git branch -l m &&
66 git branch -m m m/m &&
c976d415
LH
67 test -f .git/logs/refs/heads/m/m'
68
69test_expect_success \
70 'git branch -m n/n n should work' \
5be60078
JH
71 'git branch -l n/n &&
72 git branch -m n/n n
c976d415
LH
73 test -f .git/logs/refs/heads/n'
74
41ac414e
JH
75test_expect_success 'git branch -m o/o o should fail when o/p exists' '
76 git branch o/o &&
5be60078 77 git branch o/p &&
41ac414e
JH
78 ! git branch -m o/o o
79'
c976d415 80
41ac414e
JH
81test_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
85'
c976d415 86
01ebb9dc
GB
87mv .git/config .git/config-saved
88
08b984fb 89test_expect_success 'git branch -m q q2 without config should succeed' '
5be60078
JH
90 git branch -m q q2 &&
91 git branch -m q2 q
01ebb9dc
GB
92'
93
94mv .git/config-saved .git/config
95
5be60078 96git config branch.s/s.dummy Hello
dc81c58c 97
c976d415
LH
98test_expect_success \
99 'git branch -m s/s s should work when s/t is deleted' \
5be60078 100 'git branch -l s/s &&
c976d415 101 test -f .git/logs/refs/heads/s/s &&
5be60078 102 git branch -l s/t &&
c976d415 103 test -f .git/logs/refs/heads/s/t &&
5be60078
JH
104 git branch -d s/t &&
105 git branch -m s/s s &&
c976d415
LH
106 test -f .git/logs/refs/heads/s'
107
dc81c58c 108test_expect_success 'config information was renamed, too' \
5be60078
JH
109 "test $(git config branch.s.dummy) = Hello &&
110 ! git config branch.s/s/dummy"
dc81c58c 111
41ac414e
JH
112test_expect_success \
113 'git branch -m u v should fail when the reflog for u is a symlink' '
114 git branch -l u &&
16c2bfbb
LH
115 mv .git/logs/refs/heads/u real-u &&
116 ln -s real-u .git/logs/refs/heads/u &&
41ac414e
JH
117 ! git branch -m u v
118'
16c2bfbb 119
0746d19a 120test_expect_success 'test tracking setup via --track' \
5be60078
JH
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'
0746d19a
PB
127
128test_expect_success 'test tracking setup (non-wildcard, matching)' \
5be60078
JH
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'
0746d19a
PB
135
136test_expect_success 'test tracking setup (non-wildcard, not matching)' \
5be60078
JH
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'
0746d19a
PB
143
144test_expect_success 'test tracking setup via config' \
5be60078
JH
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'
0746d19a 152
6f084a56 153test_expect_success 'avoid ambiguous track' '
4017761f 154 git config branch.autosetupmerge true &&
6f084a56
JS
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 &&
4017761f 159 git branch all1 master &&
6f084a56 160 test -z "$(git config branch.all1.merge)"
4017761f
JS
161'
162
0746d19a 163test_expect_success 'test overriding tracking setup via --no-track' \
5be60078
JH
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'
0746d19a 172
6f084a56 173test_expect_success 'no tracking without .fetch entries' \
9debc324 174 'git branch --track my6 s &&
6f084a56
JS
175 test -z "$(git config branch.my6.remote)" &&
176 test -z "$(git config branch.my6.merge)"'
9debc324 177
11f68d90 178test_expect_success 'test tracking setup via --track but deeper' \
5be60078
JH
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'
11f68d90 185
f1eccbab 186test_expect_success 'test deleting branch deletes branch config' \
5be60078 187 'git branch -d my7 &&
6f084a56
JS
188 test -z "$(git config branch.my7.remote)" &&
189 test -z "$(git config branch.my7.merge)"'
f1eccbab
GP
190
191test_expect_success 'test deleting branch without config' \
5be60078
JH
192 'git branch my7 s &&
193 test "$(git branch -d my7 2>&1)" = "Deleted branch my7."'
f1eccbab 194
0746d19a
PB
195# Keep this test last, as it changes the current branch
196cat >expect <<EOF
1970000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
198EOF
199test_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'
206
a3b427b9 207test_done