git-multimail: update to release 1.2.0
[git.git] / t / t1430-bad-ref-name.sh
blob16d0b8bd1a5b6b6a2701fea1c4f35858cec9528b
1 #!/bin/sh
3 test_description='Test handling of ref names that check-ref-format rejects'
4 . ./test-lib.sh
6 test_expect_success setup '
7 test_commit one &&
8 test_commit two
11 test_expect_success 'fast-import: fail on invalid branch name ".badbranchname"' '
12 test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
13 cat >input <<-INPUT_END &&
14 commit .badbranchname
15 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
16 data <<COMMIT
17 corrupt
18 COMMIT
20 from refs/heads/master
22 INPUT_END
23 test_must_fail git fast-import <input
26 test_expect_success 'fast-import: fail on invalid branch name "bad[branch]name"' '
27 test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
28 cat >input <<-INPUT_END &&
29 commit bad[branch]name
30 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
31 data <<COMMIT
32 corrupt
33 COMMIT
35 from refs/heads/master
37 INPUT_END
38 test_must_fail git fast-import <input
41 test_expect_success 'git branch shows badly named ref' '
42 cp .git/refs/heads/master .git/refs/heads/broken...ref &&
43 test_when_finished "rm -f .git/refs/heads/broken...ref" &&
44 git branch >output &&
45 grep -e "broken\.\.\.ref" output
48 test_expect_success 'branch -d can delete badly named ref' '
49 cp .git/refs/heads/master .git/refs/heads/broken...ref &&
50 test_when_finished "rm -f .git/refs/heads/broken...ref" &&
51 git branch -d broken...ref &&
52 git branch >output &&
53 ! grep -e "broken\.\.\.ref" output
56 test_expect_success 'branch -D can delete badly named ref' '
57 cp .git/refs/heads/master .git/refs/heads/broken...ref &&
58 test_when_finished "rm -f .git/refs/heads/broken...ref" &&
59 git branch -D broken...ref &&
60 git branch >output &&
61 ! grep -e "broken\.\.\.ref" output
64 test_expect_success 'branch -D cannot delete non-ref in .git dir' '
65 echo precious >.git/my-private-file &&
66 echo precious >expect &&
67 test_must_fail git branch -D ../../my-private-file &&
68 test_cmp expect .git/my-private-file
71 test_expect_success 'branch -D cannot delete ref in .git dir' '
72 git rev-parse HEAD >.git/my-private-file &&
73 git rev-parse HEAD >expect &&
74 git branch foo/legit &&
75 test_must_fail git branch -D foo////./././../../../my-private-file &&
76 test_cmp expect .git/my-private-file
79 test_expect_success 'branch -D cannot delete absolute path' '
80 git branch -f extra &&
81 test_must_fail git branch -D "$(pwd)/.git/refs/heads/extra" &&
82 test_cmp_rev HEAD extra
85 test_expect_success 'git branch cannot create a badly named ref' '
86 test_when_finished "rm -f .git/refs/heads/broken...ref" &&
87 test_must_fail git branch broken...ref &&
88 git branch >output &&
89 ! grep -e "broken\.\.\.ref" output
92 test_expect_success 'branch -m cannot rename to a bad ref name' '
93 test_when_finished "rm -f .git/refs/heads/broken...ref" &&
94 test_might_fail git branch -D goodref &&
95 git branch goodref &&
96 test_must_fail git branch -m goodref broken...ref &&
97 test_cmp_rev master goodref &&
98 git branch >output &&
99 ! grep -e "broken\.\.\.ref" output
102 test_expect_failure 'branch -m can rename from a bad ref name' '
103 cp .git/refs/heads/master .git/refs/heads/broken...ref &&
104 test_when_finished "rm -f .git/refs/heads/broken...ref" &&
105 git branch -m broken...ref renamed &&
106 test_cmp_rev master renamed &&
107 git branch >output &&
108 ! grep -e "broken\.\.\.ref" output
111 test_expect_success 'push cannot create a badly named ref' '
112 test_when_finished "rm -f .git/refs/heads/broken...ref" &&
113 test_must_fail git push "file://$(pwd)" HEAD:refs/heads/broken...ref &&
114 git branch >output &&
115 ! grep -e "broken\.\.\.ref" output
118 test_expect_failure 'push --mirror can delete badly named ref' '
119 top=$(pwd) &&
120 git init src &&
121 git init dest &&
124 cd src &&
125 test_commit one
126 ) &&
128 cd dest &&
129 test_commit two &&
130 git checkout --detach &&
131 cp .git/refs/heads/master .git/refs/heads/broken...ref
132 ) &&
133 git -C src push --mirror "file://$top/dest" &&
134 git -C dest branch >output &&
135 ! grep -e "broken\.\.\.ref" output
138 test_expect_success 'rev-parse skips symref pointing to broken name' '
139 test_when_finished "rm -f .git/refs/heads/broken...ref" &&
140 git branch shadow one &&
141 cp .git/refs/heads/master .git/refs/heads/broken...ref &&
142 git symbolic-ref refs/tags/shadow refs/heads/broken...ref &&
144 git rev-parse --verify one >expect &&
145 git rev-parse --verify shadow >actual 2>err &&
146 test_cmp expect actual &&
147 test_i18ngrep "ignoring.*refs/tags/shadow" err
150 test_expect_success 'update-ref --no-deref -d can delete reference to broken name' '
151 git symbolic-ref refs/heads/badname refs/heads/broken...ref &&
152 test_when_finished "rm -f .git/refs/heads/badname" &&
153 test_path_is_file .git/refs/heads/badname &&
154 git update-ref --no-deref -d refs/heads/badname &&
155 test_path_is_missing .git/refs/heads/badname
158 test_expect_success 'update-ref -d can delete broken name' '
159 cp .git/refs/heads/master .git/refs/heads/broken...ref &&
160 test_when_finished "rm -f .git/refs/heads/broken...ref" &&
161 git update-ref -d refs/heads/broken...ref &&
162 git branch >output &&
163 ! grep -e "broken\.\.\.ref" output
166 test_expect_success 'update-ref -d cannot delete non-ref in .git dir' '
167 echo precious >.git/my-private-file &&
168 echo precious >expect &&
169 test_must_fail git update-ref -d my-private-file &&
170 test_cmp expect .git/my-private-file
173 test_expect_success 'update-ref -d cannot delete absolute path' '
174 git branch -f extra &&
175 test_must_fail git update-ref -d "$(pwd)/.git/refs/heads/extra" &&
176 test_cmp_rev HEAD extra
179 test_expect_success 'update-ref --stdin fails create with bad ref name' '
180 echo "create ~a refs/heads/master" >stdin &&
181 test_must_fail git update-ref --stdin <stdin 2>err &&
182 grep "fatal: invalid ref format: ~a" err
185 test_expect_success 'update-ref --stdin fails update with bad ref name' '
186 echo "update ~a refs/heads/master" >stdin &&
187 test_must_fail git update-ref --stdin <stdin 2>err &&
188 grep "fatal: invalid ref format: ~a" err
191 test_expect_success 'update-ref --stdin fails delete with bad ref name' '
192 echo "delete ~a refs/heads/master" >stdin &&
193 test_must_fail git update-ref --stdin <stdin 2>err &&
194 grep "fatal: invalid ref format: ~a" err
197 test_expect_success 'update-ref --stdin -z fails create with bad ref name' '
198 printf "%s\0" "create ~a " refs/heads/master >stdin &&
199 test_must_fail git update-ref -z --stdin <stdin 2>err &&
200 grep "fatal: invalid ref format: ~a " err
203 test_expect_success 'update-ref --stdin -z fails update with bad ref name' '
204 printf "%s\0" "update ~a" refs/heads/master "" >stdin &&
205 test_must_fail git update-ref -z --stdin <stdin 2>err &&
206 grep "fatal: invalid ref format: ~a" err
209 test_expect_success 'update-ref --stdin -z fails delete with bad ref name' '
210 printf "%s\0" "delete ~a" refs/heads/master >stdin &&
211 test_must_fail git update-ref -z --stdin <stdin 2>err &&
212 grep "fatal: invalid ref format: ~a" err
215 test_done