3 9afa3de2 2023-04-04 stsp # Copyright (c) 2023 Stefan Sperling <stsp@openbsd.org>
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.
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.
17 9afa3de2 2023-04-04 stsp . ../cmdline/common.sh
18 9afa3de2 2023-04-04 stsp . ./common.sh
20 9afa3de2 2023-04-04 stsp test_create_protected_branch() {
21 9afa3de2 2023-04-04 stsp local testroot=`test_init create_protected_branch 1`
23 9afa3de2 2023-04-04 stsp got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
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
31 9afa3de2 2023-04-04 stsp got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
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
39 9afa3de2 2023-04-04 stsp (cd $testroot/wt && got branch foo) >/dev/null
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
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
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
55 9afa3de2 2023-04-04 stsp local commit_id=`git_show_branch_head $testroot/repo-clone foo`
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
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
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
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"
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
78 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
79 9afa3de2 2023-04-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
82 9afa3de2 2023-04-04 stsp test_done "$testroot" $ret
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`
88 9afa3de2 2023-04-04 stsp got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
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
96 9afa3de2 2023-04-04 stsp got tag -r $testroot/repo-clone -m "1.0" 1.0 >/dev/null
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
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
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
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
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
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
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
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
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)
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
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
158 9afa3de2 2023-04-04 stsp test_done "$testroot" 0
161 9afa3de2 2023-04-04 stsp test_delete_protected_branch() {
162 9afa3de2 2023-04-04 stsp local testroot=`test_init delete_protected_branch`
164 9afa3de2 2023-04-04 stsp got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
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
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
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
186 9afa3de2 2023-04-04 stsp test_done "$testroot" 0
189 9afa3de2 2023-04-04 stsp test_modify_protected_branch() {
190 9afa3de2 2023-04-04 stsp local testroot=`test_init modify_protected_branch`
192 9afa3de2 2023-04-04 stsp got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
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
200 9afa3de2 2023-04-04 stsp got checkout $testroot/repo-clone $testroot/wt >/dev/null
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)
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"`
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
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
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
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"
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
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
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)
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
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
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
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
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
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
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
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
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"
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
295 9afa3de2 2023-04-04 stsp if [ $ret -ne 0 ]; then
296 9afa3de2 2023-04-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
299 9afa3de2 2023-04-04 stsp test_done "$testroot" $ret
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