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