Blame


1 9afa3de2 2023-04-04 stsp #!/bin/sh
2 9afa3de2 2023-04-04 stsp #
3 9afa3de2 2023-04-04 stsp # Copyright (c) 2023 Stefan Sperling <stsp@openbsd.org>
4 9afa3de2 2023-04-04 stsp #
5 9afa3de2 2023-04-04 stsp # Permission to use, copy, modify, and distribute this software for any
6 9afa3de2 2023-04-04 stsp # purpose with or without fee is hereby granted, provided that the above
7 9afa3de2 2023-04-04 stsp # copyright notice and this permission notice appear in all copies.
8 9afa3de2 2023-04-04 stsp #
9 9afa3de2 2023-04-04 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 9afa3de2 2023-04-04 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 9afa3de2 2023-04-04 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 9afa3de2 2023-04-04 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 9afa3de2 2023-04-04 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 9afa3de2 2023-04-04 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 9afa3de2 2023-04-04 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 9afa3de2 2023-04-04 stsp
17 9afa3de2 2023-04-04 stsp . ../cmdline/common.sh
18 9afa3de2 2023-04-04 stsp . ./common.sh
19 9afa3de2 2023-04-04 stsp
20 9afa3de2 2023-04-04 stsp test_create_protected_branch() {
21 9afa3de2 2023-04-04 stsp local testroot=`test_init create_protected_branch 1`
22 9afa3de2 2023-04-04 stsp
23 9afa3de2 2023-04-04 stsp got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
24 9afa3de2 2023-04-04 stsp ret=$?
25 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
26 9afa3de2 2023-04-04 stsp echo "got clone failed unexpectedly" >&2
27 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
28 9afa3de2 2023-04-04 stsp return 1
29 9afa3de2 2023-04-04 stsp fi
30 9afa3de2 2023-04-04 stsp
31 9afa3de2 2023-04-04 stsp got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
32 9afa3de2 2023-04-04 stsp ret=$?
33 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
34 9afa3de2 2023-04-04 stsp echo "got checkout failed unexpectedly" >&2
35 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
36 9afa3de2 2023-04-04 stsp return 1
37 9afa3de2 2023-04-04 stsp fi
38 9afa3de2 2023-04-04 stsp
39 9afa3de2 2023-04-04 stsp (cd $testroot/wt && got branch foo) >/dev/null
40 9afa3de2 2023-04-04 stsp ret=$?
41 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
42 9afa3de2 2023-04-04 stsp echo "got branch failed unexpectedly" >&2
43 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
44 9afa3de2 2023-04-04 stsp return 1
45 9afa3de2 2023-04-04 stsp fi
46 9afa3de2 2023-04-04 stsp
47 9afa3de2 2023-04-04 stsp echo modified alpha > $testroot/wt/alpha
48 9afa3de2 2023-04-04 stsp (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
49 9afa3de2 2023-04-04 stsp ret=$?
50 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
51 9afa3de2 2023-04-04 stsp echo "got commit failed unexpectedly" >&2
52 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
53 9afa3de2 2023-04-04 stsp return 1
54 9afa3de2 2023-04-04 stsp fi
55 9afa3de2 2023-04-04 stsp local commit_id=`git_show_branch_head $testroot/repo-clone foo`
56 9afa3de2 2023-04-04 stsp
57 9afa3de2 2023-04-04 stsp # Creating a new branch should succeed.
58 9afa3de2 2023-04-04 stsp got send -q -r $testroot/repo-clone -b foo 2> $testroot/stderr
59 9afa3de2 2023-04-04 stsp ret=$?
60 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
61 9afa3de2 2023-04-04 stsp echo "got send failed unexpectedly" >&2
62 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
63 9afa3de2 2023-04-04 stsp return 1
64 9afa3de2 2023-04-04 stsp fi
65 9afa3de2 2023-04-04 stsp
66 9afa3de2 2023-04-04 stsp # Verify that the send operation worked fine.
67 9afa3de2 2023-04-04 stsp got clone -l ${GOTD_TEST_REPO_URL} | grep foo > $testroot/stdout
68 9afa3de2 2023-04-04 stsp ret=$?
69 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
70 9afa3de2 2023-04-04 stsp echo "got clone -l failed unexpectedly" >&2
71 9afa3de2 2023-04-04 stsp test_done "$testroot" "1"
72 9afa3de2 2023-04-04 stsp return 1
73 9afa3de2 2023-04-04 stsp fi
74 9afa3de2 2023-04-04 stsp
75 9afa3de2 2023-04-04 stsp echo "refs/heads/foo: $commit_id" > $testroot/stdout.expected
76 9afa3de2 2023-04-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
77 9afa3de2 2023-04-04 stsp ret=$?
78 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
79 9afa3de2 2023-04-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
80 9afa3de2 2023-04-04 stsp fi
81 9afa3de2 2023-04-04 stsp
82 9afa3de2 2023-04-04 stsp test_done "$testroot" $ret
83 9afa3de2 2023-04-04 stsp }
84 9afa3de2 2023-04-04 stsp
85 9afa3de2 2023-04-04 stsp test_modify_protected_tag_namespace() {
86 9afa3de2 2023-04-04 stsp local testroot=`test_init modify_protected_tag_namespace`
87 9afa3de2 2023-04-04 stsp
88 9afa3de2 2023-04-04 stsp got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
89 9afa3de2 2023-04-04 stsp ret=$?
90 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
91 9afa3de2 2023-04-04 stsp echo "got clone failed unexpectedly" >&2
92 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
93 9afa3de2 2023-04-04 stsp return 1
94 9afa3de2 2023-04-04 stsp fi
95 9afa3de2 2023-04-04 stsp
96 9afa3de2 2023-04-04 stsp got tag -r $testroot/repo-clone -m "1.0" 1.0 >/dev/null
97 9afa3de2 2023-04-04 stsp ret=$?
98 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
99 9afa3de2 2023-04-04 stsp echo "got tag failed unexpectedly" >&2
100 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
101 9afa3de2 2023-04-04 stsp return 1
102 9afa3de2 2023-04-04 stsp fi
103 9afa3de2 2023-04-04 stsp
104 9afa3de2 2023-04-04 stsp # Creating a new tag should succeed.
105 9afa3de2 2023-04-04 stsp got send -q -r $testroot/repo-clone -t 1.0 2> $testroot/stderr
106 9afa3de2 2023-04-04 stsp ret=$?
107 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
108 9afa3de2 2023-04-04 stsp echo "got send failed unexpectedly" >&2
109 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
110 9afa3de2 2023-04-04 stsp return 1
111 9afa3de2 2023-04-04 stsp fi
112 9afa3de2 2023-04-04 stsp
113 9afa3de2 2023-04-04 stsp got ref -r $testroot/repo-clone -d refs/tags/1.0 > /dev/null
114 9afa3de2 2023-04-04 stsp got tag -r $testroot/repo-clone -m "another 1.0" 1.0 >/dev/null
115 9afa3de2 2023-04-04 stsp ret=$?
116 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
117 9afa3de2 2023-04-04 stsp echo "got tag failed unexpectedly" >&2
118 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
119 9afa3de2 2023-04-04 stsp return 1
120 9afa3de2 2023-04-04 stsp fi
121 9afa3de2 2023-04-04 stsp
122 9afa3de2 2023-04-04 stsp # Overwriting an existing tag should fail.
123 9afa3de2 2023-04-04 stsp got send -q -f -r $testroot/repo-clone -t 1.0 2> $testroot/stderr
124 9afa3de2 2023-04-04 stsp ret=$?
125 9afa3de2 2023-04-04 stsp if [ $ret == 0 ]; then
126 9afa3de2 2023-04-04 stsp echo "got send succeeded unexpectedly" >&2
127 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
128 9afa3de2 2023-04-04 stsp return 1
129 9afa3de2 2023-04-04 stsp fi
130 9afa3de2 2023-04-04 stsp
131 9afa3de2 2023-04-04 stsp if ! egrep -q '(gotsh|got-send-pack): refs/tags/: reference namespace is protected' \
132 9afa3de2 2023-04-04 stsp $testroot/stderr; then
133 9afa3de2 2023-04-04 stsp echo -n "error message unexpected or missing: " >&2
134 9afa3de2 2023-04-04 stsp cat $testroot/stderr >&2
135 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
136 9afa3de2 2023-04-04 stsp return 1
137 9afa3de2 2023-04-04 stsp fi
138 9afa3de2 2023-04-04 stsp
139 9afa3de2 2023-04-04 stsp # Deleting an existing tag should fail.
140 9afa3de2 2023-04-04 stsp # 'got send' cannot even do this so we use 'git push'.
141 9afa3de2 2023-04-04 stsp (cd $testroot/repo-clone && git push -q -d origin refs/tags/1.0 \
142 9afa3de2 2023-04-04 stsp 2> $testroot/stderr)
143 9afa3de2 2023-04-04 stsp ret=$?
144 9afa3de2 2023-04-04 stsp if [ $ret -eq 0 ]; then
145 9afa3de2 2023-04-04 stsp echo "git push -d succeeded unexpectedly" >&2
146 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
147 9afa3de2 2023-04-04 stsp return 1
148 9afa3de2 2023-04-04 stsp fi
149 9afa3de2 2023-04-04 stsp
150 9afa3de2 2023-04-04 stsp if ! egrep -q '(fatal: remote error|gotsh): refs/tags/: reference namespace is protected' \
151 9afa3de2 2023-04-04 stsp $testroot/stderr; then
152 9afa3de2 2023-04-04 stsp echo -n "error message unexpected or missing: " >&2
153 9afa3de2 2023-04-04 stsp cat $testroot/stderr >&2
154 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
155 9afa3de2 2023-04-04 stsp return 1
156 9afa3de2 2023-04-04 stsp fi
157 9afa3de2 2023-04-04 stsp
158 9afa3de2 2023-04-04 stsp test_done "$testroot" 0
159 9afa3de2 2023-04-04 stsp }
160 9afa3de2 2023-04-04 stsp
161 9afa3de2 2023-04-04 stsp test_delete_protected_branch() {
162 9afa3de2 2023-04-04 stsp local testroot=`test_init delete_protected_branch`
163 9afa3de2 2023-04-04 stsp
164 9afa3de2 2023-04-04 stsp got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
165 9afa3de2 2023-04-04 stsp ret=$?
166 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
167 9afa3de2 2023-04-04 stsp echo "got clone failed unexpectedly" >&2
168 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
169 9afa3de2 2023-04-04 stsp return 1
170 9afa3de2 2023-04-04 stsp fi
171 9afa3de2 2023-04-04 stsp
172 9afa3de2 2023-04-04 stsp if got send -q -r $testroot/repo-clone -d main 2> $testroot/stderr; then
173 9afa3de2 2023-04-04 stsp echo "got send succeeded unexpectedly" >&2
174 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
175 9afa3de2 2023-04-04 stsp return 1
176 9afa3de2 2023-04-04 stsp fi
177 9afa3de2 2023-04-04 stsp
178 9afa3de2 2023-04-04 stsp if ! egrep -q '(gotsh|got-send-pack): refs/heads/main: reference is protected' \
179 9afa3de2 2023-04-04 stsp $testroot/stderr; then
180 9afa3de2 2023-04-04 stsp echo -n "error message unexpected or missing: " >&2
181 9afa3de2 2023-04-04 stsp cat $testroot/stderr >&2
182 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
183 9afa3de2 2023-04-04 stsp return 1
184 9afa3de2 2023-04-04 stsp fi
185 9afa3de2 2023-04-04 stsp
186 9afa3de2 2023-04-04 stsp test_done "$testroot" 0
187 9afa3de2 2023-04-04 stsp }
188 9afa3de2 2023-04-04 stsp
189 9afa3de2 2023-04-04 stsp test_modify_protected_branch() {
190 9afa3de2 2023-04-04 stsp local testroot=`test_init modify_protected_branch`
191 9afa3de2 2023-04-04 stsp
192 9afa3de2 2023-04-04 stsp got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
193 9afa3de2 2023-04-04 stsp ret=$?
194 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
195 9afa3de2 2023-04-04 stsp echo "got clone failed unexpectedly" >&2
196 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
197 9afa3de2 2023-04-04 stsp return 1
198 9afa3de2 2023-04-04 stsp fi
199 9afa3de2 2023-04-04 stsp
200 9afa3de2 2023-04-04 stsp got checkout $testroot/repo-clone $testroot/wt >/dev/null
201 9afa3de2 2023-04-04 stsp
202 9afa3de2 2023-04-04 stsp for i in 1 2 3; do
203 9afa3de2 2023-04-04 stsp echo "more alpha" >> $testroot/wt/alpha
204 9afa3de2 2023-04-04 stsp (cd $testroot/wt && got commit -m "more" >/dev/null)
205 9afa3de2 2023-04-04 stsp done
206 9afa3de2 2023-04-04 stsp local commit_id=`git_show_head $testroot/repo-clone`
207 9afa3de2 2023-04-04 stsp local parent_commit_id=`git_show_parent_commit $testroot/repo-clone \
208 9afa3de2 2023-04-04 stsp "$commit_id"`
209 9afa3de2 2023-04-04 stsp
210 9afa3de2 2023-04-04 stsp # Modifying the branch by adding new commits on top should succeed.
211 9afa3de2 2023-04-04 stsp got send -q -r $testroot/repo-clone 2> $testroot/stderr
212 9afa3de2 2023-04-04 stsp ret=$?
213 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
214 9afa3de2 2023-04-04 stsp echo "got send failed unexpectedly" >&2
215 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
216 9afa3de2 2023-04-04 stsp return 1
217 9afa3de2 2023-04-04 stsp fi
218 9afa3de2 2023-04-04 stsp
219 9afa3de2 2023-04-04 stsp # Verify that the send operation worked fine.
220 9afa3de2 2023-04-04 stsp got clone -l ${GOTD_TEST_REPO_URL} | grep main > $testroot/stdout
221 9afa3de2 2023-04-04 stsp ret=$?
222 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
223 9afa3de2 2023-04-04 stsp echo "got clone -l failed unexpectedly" >&2
224 9afa3de2 2023-04-04 stsp test_done "$testroot" "1"
225 9afa3de2 2023-04-04 stsp return 1
226 9afa3de2 2023-04-04 stsp fi
227 9afa3de2 2023-04-04 stsp
228 9afa3de2 2023-04-04 stsp echo "HEAD: refs/heads/main" > $testroot/stdout.expected
229 9afa3de2 2023-04-04 stsp echo "refs/heads/main: $commit_id" >> $testroot/stdout.expected
230 9afa3de2 2023-04-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
231 9afa3de2 2023-04-04 stsp ret=$?
232 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
233 9afa3de2 2023-04-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
234 9afa3de2 2023-04-04 stsp test_done "$testroot" $ret
235 9afa3de2 2023-04-04 stsp return 1
236 9afa3de2 2023-04-04 stsp fi
237 9afa3de2 2023-04-04 stsp
238 9afa3de2 2023-04-04 stsp # Attempt to remove the tip commit
239 9afa3de2 2023-04-04 stsp (cd $testroot/wt && got update -c "$parent_commit_id" >/dev/null)
240 9afa3de2 2023-04-04 stsp (cd $testroot/wt && got histedit -d >/dev/null)
241 9afa3de2 2023-04-04 stsp ret=$?
242 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
243 9afa3de2 2023-04-04 stsp echo "got histedit failed unexpectedly" >&2
244 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
245 9afa3de2 2023-04-04 stsp return 1
246 9afa3de2 2023-04-04 stsp fi
247 9afa3de2 2023-04-04 stsp
248 9afa3de2 2023-04-04 stsp # The client should reject sending without -f.
249 9afa3de2 2023-04-04 stsp got send -q -r $testroot/repo-clone 2> $testroot/stderr
250 9afa3de2 2023-04-04 stsp ret=$?
251 9afa3de2 2023-04-04 stsp if [ $ret -eq 0 ]; then
252 9afa3de2 2023-04-04 stsp echo "got send succeeded unexpectedly" >&2
253 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
254 9afa3de2 2023-04-04 stsp return 1
255 9afa3de2 2023-04-04 stsp fi
256 9afa3de2 2023-04-04 stsp
257 9afa3de2 2023-04-04 stsp echo 'got: refs/heads/main: fetch and rebase required' \
258 9afa3de2 2023-04-04 stsp >> $testroot/stderr.expected
259 9afa3de2 2023-04-04 stsp if ! cmp -s $testroot/stderr.expected $testroot/stderr; then
260 9afa3de2 2023-04-04 stsp diff -u $testroot/stderr.expected $testroot/stderr
261 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
262 9afa3de2 2023-04-04 stsp return 1
263 9afa3de2 2023-04-04 stsp fi
264 9afa3de2 2023-04-04 stsp
265 9afa3de2 2023-04-04 stsp # Try again with -f.
266 9afa3de2 2023-04-04 stsp got send -q -r $testroot/repo-clone -f 2> $testroot/stderr
267 9afa3de2 2023-04-04 stsp ret=$?
268 9afa3de2 2023-04-04 stsp if [ $ret -eq 0 ]; then
269 9afa3de2 2023-04-04 stsp echo "got send succeeded unexpectedly" >&2
270 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
271 9afa3de2 2023-04-04 stsp return 1
272 9afa3de2 2023-04-04 stsp fi
273 9afa3de2 2023-04-04 stsp
274 9afa3de2 2023-04-04 stsp if ! egrep -q '(gotsh|got-send-pack): refs/heads/main: reference is protected' \
275 9afa3de2 2023-04-04 stsp $testroot/stderr; then
276 9afa3de2 2023-04-04 stsp echo -n "error message unexpected or missing: " >&2
277 9afa3de2 2023-04-04 stsp cat $testroot/stderr >&2
278 9afa3de2 2023-04-04 stsp test_done "$testroot" 1
279 9afa3de2 2023-04-04 stsp return 1
280 9afa3de2 2023-04-04 stsp fi
281 9afa3de2 2023-04-04 stsp
282 9afa3de2 2023-04-04 stsp # Verify that the send -f operation did not have any effect.
283 9afa3de2 2023-04-04 stsp got clone -l ${GOTD_TEST_REPO_URL} | grep main > $testroot/stdout
284 9afa3de2 2023-04-04 stsp ret=$?
285 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
286 9afa3de2 2023-04-04 stsp echo "got clone -l failed unexpectedly" >&2
287 9afa3de2 2023-04-04 stsp test_done "$testroot" "1"
288 9afa3de2 2023-04-04 stsp return 1
289 9afa3de2 2023-04-04 stsp fi
290 9afa3de2 2023-04-04 stsp
291 9afa3de2 2023-04-04 stsp echo "HEAD: refs/heads/main" > $testroot/stdout.expected
292 9afa3de2 2023-04-04 stsp echo "refs/heads/main: $commit_id" >> $testroot/stdout.expected
293 9afa3de2 2023-04-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
294 9afa3de2 2023-04-04 stsp ret=$?
295 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
296 9afa3de2 2023-04-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
297 9afa3de2 2023-04-04 stsp fi
298 9afa3de2 2023-04-04 stsp
299 9afa3de2 2023-04-04 stsp test_done "$testroot" $ret
300 9afa3de2 2023-04-04 stsp }
301 9afa3de2 2023-04-04 stsp
302 9afa3de2 2023-04-04 stsp test_parseargs "$@"
303 9afa3de2 2023-04-04 stsp run_test test_create_protected_branch
304 9afa3de2 2023-04-04 stsp run_test test_modify_protected_tag_namespace
305 9afa3de2 2023-04-04 stsp run_test test_delete_protected_branch
306 9afa3de2 2023-04-04 stsp run_test test_modify_protected_branch