3 6d7eb4f7 2023-04-04 thomas # Copyright (c) 2023 Stefan Sperling <stsp@openbsd.org>
5 6d7eb4f7 2023-04-04 thomas # Permission to use, copy, modify, and distribute this software for any
6 6d7eb4f7 2023-04-04 thomas # purpose with or without fee is hereby granted, provided that the above
7 6d7eb4f7 2023-04-04 thomas # copyright notice and this permission notice appear in all copies.
9 6d7eb4f7 2023-04-04 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 6d7eb4f7 2023-04-04 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 6d7eb4f7 2023-04-04 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 6d7eb4f7 2023-04-04 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 6d7eb4f7 2023-04-04 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 6d7eb4f7 2023-04-04 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 6d7eb4f7 2023-04-04 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 6d7eb4f7 2023-04-04 thomas . ../cmdline/common.sh
18 6d7eb4f7 2023-04-04 thomas . ./common.sh
20 6d7eb4f7 2023-04-04 thomas test_create_protected_branch() {
21 6d7eb4f7 2023-04-04 thomas local testroot=`test_init create_protected_branch 1`
23 6d7eb4f7 2023-04-04 thomas got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
25 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
26 6d7eb4f7 2023-04-04 thomas echo "got clone failed unexpectedly" >&2
27 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
31 6d7eb4f7 2023-04-04 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
33 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
34 6d7eb4f7 2023-04-04 thomas echo "got checkout failed unexpectedly" >&2
35 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
39 6d7eb4f7 2023-04-04 thomas (cd $testroot/wt && got branch foo) >/dev/null
41 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
42 6d7eb4f7 2023-04-04 thomas echo "got branch failed unexpectedly" >&2
43 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
47 6d7eb4f7 2023-04-04 thomas echo modified alpha > $testroot/wt/alpha
48 6d7eb4f7 2023-04-04 thomas (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
50 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
51 6d7eb4f7 2023-04-04 thomas echo "got commit failed unexpectedly" >&2
52 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
55 6d7eb4f7 2023-04-04 thomas local commit_id=`git_show_branch_head $testroot/repo-clone foo`
57 6d7eb4f7 2023-04-04 thomas # Creating a new branch should succeed.
58 6d7eb4f7 2023-04-04 thomas got send -q -r $testroot/repo-clone -b foo 2> $testroot/stderr
60 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
61 6d7eb4f7 2023-04-04 thomas echo "got send failed unexpectedly" >&2
62 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
66 6d7eb4f7 2023-04-04 thomas # Verify that the send operation worked fine.
67 6d7eb4f7 2023-04-04 thomas got clone -l ${GOTD_TEST_REPO_URL} | grep foo > $testroot/stdout
69 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
70 6d7eb4f7 2023-04-04 thomas echo "got clone -l failed unexpectedly" >&2
71 6d7eb4f7 2023-04-04 thomas test_done "$testroot" "1"
75 6d7eb4f7 2023-04-04 thomas echo "refs/heads/foo: $commit_id" > $testroot/stdout.expected
76 6d7eb4f7 2023-04-04 thomas cmp -s $testroot/stdout.expected $testroot/stdout
78 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
79 6d7eb4f7 2023-04-04 thomas diff -u $testroot/stdout.expected $testroot/stdout
82 6d7eb4f7 2023-04-04 thomas test_done "$testroot" $ret
85 6d7eb4f7 2023-04-04 thomas test_modify_protected_tag_namespace() {
86 6d7eb4f7 2023-04-04 thomas local testroot=`test_init modify_protected_tag_namespace`
88 6d7eb4f7 2023-04-04 thomas got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
90 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
91 6d7eb4f7 2023-04-04 thomas echo "got clone failed unexpectedly" >&2
92 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
96 6d7eb4f7 2023-04-04 thomas got tag -r $testroot/repo-clone -m "1.0" 1.0 >/dev/null
98 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
99 6d7eb4f7 2023-04-04 thomas echo "got tag failed unexpectedly" >&2
100 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
104 6d7eb4f7 2023-04-04 thomas # Creating a new tag should succeed.
105 6d7eb4f7 2023-04-04 thomas got send -q -r $testroot/repo-clone -t 1.0 2> $testroot/stderr
107 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
108 6d7eb4f7 2023-04-04 thomas echo "got send failed unexpectedly" >&2
109 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
113 6d7eb4f7 2023-04-04 thomas got ref -r $testroot/repo-clone -d refs/tags/1.0 > /dev/null
114 6d7eb4f7 2023-04-04 thomas got tag -r $testroot/repo-clone -m "another 1.0" 1.0 >/dev/null
116 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
117 6d7eb4f7 2023-04-04 thomas echo "got tag failed unexpectedly" >&2
118 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
122 6d7eb4f7 2023-04-04 thomas # Overwriting an existing tag should fail.
123 6d7eb4f7 2023-04-04 thomas got send -q -f -r $testroot/repo-clone -t 1.0 2> $testroot/stderr
125 6d7eb4f7 2023-04-04 thomas if [ $ret == 0 ]; then
126 6d7eb4f7 2023-04-04 thomas echo "got send succeeded unexpectedly" >&2
127 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
131 6d7eb4f7 2023-04-04 thomas if ! egrep -q '(gotsh|got-send-pack): refs/tags/: reference namespace is protected' \
132 6d7eb4f7 2023-04-04 thomas $testroot/stderr; then
133 6d7eb4f7 2023-04-04 thomas echo -n "error message unexpected or missing: " >&2
134 6d7eb4f7 2023-04-04 thomas cat $testroot/stderr >&2
135 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
139 6d7eb4f7 2023-04-04 thomas # Deleting an existing tag should fail.
140 6d7eb4f7 2023-04-04 thomas # 'got send' cannot even do this so we use 'git push'.
141 6d7eb4f7 2023-04-04 thomas (cd $testroot/repo-clone && git push -q -d origin refs/tags/1.0 \
142 6d7eb4f7 2023-04-04 thomas 2> $testroot/stderr)
144 6d7eb4f7 2023-04-04 thomas if [ $ret -eq 0 ]; then
145 6d7eb4f7 2023-04-04 thomas echo "git push -d succeeded unexpectedly" >&2
146 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
150 6d7eb4f7 2023-04-04 thomas if ! egrep -q '(fatal: remote error|gotsh): refs/tags/: reference namespace is protected' \
151 6d7eb4f7 2023-04-04 thomas $testroot/stderr; then
152 6d7eb4f7 2023-04-04 thomas echo -n "error message unexpected or missing: " >&2
153 6d7eb4f7 2023-04-04 thomas cat $testroot/stderr >&2
154 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
158 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 0
161 6d7eb4f7 2023-04-04 thomas test_delete_protected_branch() {
162 6d7eb4f7 2023-04-04 thomas local testroot=`test_init delete_protected_branch`
164 6d7eb4f7 2023-04-04 thomas got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
166 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
167 6d7eb4f7 2023-04-04 thomas echo "got clone failed unexpectedly" >&2
168 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
172 6d7eb4f7 2023-04-04 thomas if got send -q -r $testroot/repo-clone -d main 2> $testroot/stderr; then
173 6d7eb4f7 2023-04-04 thomas echo "got send succeeded unexpectedly" >&2
174 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
178 6d7eb4f7 2023-04-04 thomas if ! egrep -q '(gotsh|got-send-pack): refs/heads/main: reference is protected' \
179 6d7eb4f7 2023-04-04 thomas $testroot/stderr; then
180 6d7eb4f7 2023-04-04 thomas echo -n "error message unexpected or missing: " >&2
181 6d7eb4f7 2023-04-04 thomas cat $testroot/stderr >&2
182 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
186 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 0
189 6d7eb4f7 2023-04-04 thomas test_modify_protected_branch() {
190 6d7eb4f7 2023-04-04 thomas local testroot=`test_init modify_protected_branch`
192 6d7eb4f7 2023-04-04 thomas got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
194 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
195 6d7eb4f7 2023-04-04 thomas echo "got clone failed unexpectedly" >&2
196 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
200 6d7eb4f7 2023-04-04 thomas got checkout $testroot/repo-clone $testroot/wt >/dev/null
202 6d7eb4f7 2023-04-04 thomas for i in 1 2 3; do
203 6d7eb4f7 2023-04-04 thomas echo "more alpha" >> $testroot/wt/alpha
204 6d7eb4f7 2023-04-04 thomas (cd $testroot/wt && got commit -m "more" >/dev/null)
206 6d7eb4f7 2023-04-04 thomas local commit_id=`git_show_head $testroot/repo-clone`
207 6d7eb4f7 2023-04-04 thomas local parent_commit_id=`git_show_parent_commit $testroot/repo-clone \
208 6d7eb4f7 2023-04-04 thomas "$commit_id"`
210 6d7eb4f7 2023-04-04 thomas # Modifying the branch by adding new commits on top should succeed.
211 6d7eb4f7 2023-04-04 thomas got send -q -r $testroot/repo-clone 2> $testroot/stderr
213 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
214 6d7eb4f7 2023-04-04 thomas echo "got send failed unexpectedly" >&2
215 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
219 6d7eb4f7 2023-04-04 thomas # Verify that the send operation worked fine.
220 6d7eb4f7 2023-04-04 thomas got clone -l ${GOTD_TEST_REPO_URL} | grep main > $testroot/stdout
222 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
223 6d7eb4f7 2023-04-04 thomas echo "got clone -l failed unexpectedly" >&2
224 6d7eb4f7 2023-04-04 thomas test_done "$testroot" "1"
228 6d7eb4f7 2023-04-04 thomas echo "HEAD: refs/heads/main" > $testroot/stdout.expected
229 6d7eb4f7 2023-04-04 thomas echo "refs/heads/main: $commit_id" >> $testroot/stdout.expected
230 6d7eb4f7 2023-04-04 thomas cmp -s $testroot/stdout.expected $testroot/stdout
232 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
233 6d7eb4f7 2023-04-04 thomas diff -u $testroot/stdout.expected $testroot/stdout
234 6d7eb4f7 2023-04-04 thomas test_done "$testroot" $ret
238 6d7eb4f7 2023-04-04 thomas # Attempt to remove the tip commit
239 6d7eb4f7 2023-04-04 thomas (cd $testroot/wt && got update -c "$parent_commit_id" >/dev/null)
240 6d7eb4f7 2023-04-04 thomas (cd $testroot/wt && got histedit -d >/dev/null)
242 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
243 6d7eb4f7 2023-04-04 thomas echo "got histedit failed unexpectedly" >&2
244 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
248 6d7eb4f7 2023-04-04 thomas # The client should reject sending without -f.
249 6d7eb4f7 2023-04-04 thomas got send -q -r $testroot/repo-clone 2> $testroot/stderr
251 6d7eb4f7 2023-04-04 thomas if [ $ret -eq 0 ]; then
252 6d7eb4f7 2023-04-04 thomas echo "got send succeeded unexpectedly" >&2
253 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
257 6d7eb4f7 2023-04-04 thomas echo 'got: refs/heads/main: fetch and rebase required' \
258 6d7eb4f7 2023-04-04 thomas >> $testroot/stderr.expected
259 6d7eb4f7 2023-04-04 thomas if ! cmp -s $testroot/stderr.expected $testroot/stderr; then
260 6d7eb4f7 2023-04-04 thomas diff -u $testroot/stderr.expected $testroot/stderr
261 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
265 6d7eb4f7 2023-04-04 thomas # Try again with -f.
266 6d7eb4f7 2023-04-04 thomas got send -q -r $testroot/repo-clone -f 2> $testroot/stderr
268 6d7eb4f7 2023-04-04 thomas if [ $ret -eq 0 ]; then
269 6d7eb4f7 2023-04-04 thomas echo "got send succeeded unexpectedly" >&2
270 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
274 6d7eb4f7 2023-04-04 thomas if ! egrep -q '(gotsh|got-send-pack): refs/heads/main: reference is protected' \
275 6d7eb4f7 2023-04-04 thomas $testroot/stderr; then
276 6d7eb4f7 2023-04-04 thomas echo -n "error message unexpected or missing: " >&2
277 6d7eb4f7 2023-04-04 thomas cat $testroot/stderr >&2
278 6d7eb4f7 2023-04-04 thomas test_done "$testroot" 1
282 6d7eb4f7 2023-04-04 thomas # Verify that the send -f operation did not have any effect.
283 6d7eb4f7 2023-04-04 thomas got clone -l ${GOTD_TEST_REPO_URL} | grep main > $testroot/stdout
285 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
286 6d7eb4f7 2023-04-04 thomas echo "got clone -l failed unexpectedly" >&2
287 6d7eb4f7 2023-04-04 thomas test_done "$testroot" "1"
291 6d7eb4f7 2023-04-04 thomas echo "HEAD: refs/heads/main" > $testroot/stdout.expected
292 6d7eb4f7 2023-04-04 thomas echo "refs/heads/main: $commit_id" >> $testroot/stdout.expected
293 6d7eb4f7 2023-04-04 thomas cmp -s $testroot/stdout.expected $testroot/stdout
295 6d7eb4f7 2023-04-04 thomas if [ $ret -ne 0 ]; then
296 6d7eb4f7 2023-04-04 thomas diff -u $testroot/stdout.expected $testroot/stdout
299 6d7eb4f7 2023-04-04 thomas test_done "$testroot" $ret
302 6d7eb4f7 2023-04-04 thomas test_parseargs "$@"
303 6d7eb4f7 2023-04-04 thomas run_test test_create_protected_branch
304 6d7eb4f7 2023-04-04 thomas run_test test_modify_protected_tag_namespace
305 6d7eb4f7 2023-04-04 thomas run_test test_delete_protected_branch
306 6d7eb4f7 2023-04-04 thomas run_test test_modify_protected_branch