Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2024 Stefan Sperling <stsp@openbsd.org>
4 #
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.
8 #
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
18 . ./common.sh
20 test_send_empty_readonly() {
21 local testroot=`test_init send_empty`
22 local commit_id=`git_show_head $testroot/repo`
24 (cd ${GOTD_TEST_REPO} && find . > $testroot/repo-list.before)
26 # The gotd-controlled test repository starts out empty.
27 got ref -l -r ${GOTD_TEST_REPO} > $testroot/ref-list.before
28 echo "HEAD: refs/heads/main" > $testroot/ref-list.expected
29 cmp -s $testroot/ref-list.expected $testroot/ref-list.before
30 ret=$?
31 if [ $ret -ne 0 ]; then
32 diff -u $testroot/ref-list.expected $testroot/ref-list.before
33 test_done "$testroot" "$ret"
34 return 1
35 fi
37 got checkout -q $testroot/repo $testroot/wt >/dev/null
38 ret=$?
39 if [ $ret -ne 0 ]; then
40 echo "got checkout failed unexpectedly" >&2
41 test_done "$testroot" 1
42 return 1
43 fi
45 # send contents of $testroot/repo to ${GOTD_TEST_REPO}
46 cat >> $testroot/wt/.got/got.conf <<EOF
47 remote "gotd" {
48 server ${GOTD_DEVUSER}@127.0.0.1
49 repository "test-repo"
50 protocol ssh
51 }
52 EOF
53 (cd $testroot/wt && got send -q -a gotd 2> $testroot/stderr)
54 ret=$?
55 if [ $ret -eq 0 ]; then
56 echo "got send succeeded unexpectedly" >&2
57 test_done "$testroot" 1
58 return 1
59 fi
61 echo "got-send-pack: test-repo: Permission denied" \
62 > $testroot/stderr.expected
63 grep '^got-send-pack:' $testroot/stderr > $testroot/stderr.filtered
64 cmp -s $testroot/stderr.expected $testroot/stderr.filtered
65 ret=$?
66 if [ $ret -ne 0 ]; then
67 diff -u $testroot/stderr.expected $testroot/stderr.filtered
68 test_done "$testroot" "$ret"
69 return 1
70 fi
72 # Server should not have created a new reference.
73 got ref -l -r ${GOTD_TEST_REPO} > $testroot/ref-list.after
74 echo "HEAD: refs/heads/main" > $testroot/ref-list.expected
75 cmp -s $testroot/ref-list.expected $testroot/ref-list.after
76 ret=$?
77 if [ $ret -ne 0 ]; then
78 diff -u $testroot/ref-list.expected $testroot/ref-list.after
79 test_done "$testroot" "$ret"
80 return 1
81 fi
83 test_done "$testroot" "$ret"
84 }
86 test_parseargs "$@"
87 run_test test_send_empty_readonly