Blame


1 bbca3812 2024-04-12 stsp #!/bin/sh
2 bbca3812 2024-04-12 stsp #
3 bbca3812 2024-04-12 stsp # Copyright (c) 2024 Stefan Sperling <stsp@openbsd.org>
4 bbca3812 2024-04-12 stsp #
5 bbca3812 2024-04-12 stsp # Permission to use, copy, modify, and distribute this software for any
6 bbca3812 2024-04-12 stsp # purpose with or without fee is hereby granted, provided that the above
7 bbca3812 2024-04-12 stsp # copyright notice and this permission notice appear in all copies.
8 bbca3812 2024-04-12 stsp #
9 bbca3812 2024-04-12 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 bbca3812 2024-04-12 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 bbca3812 2024-04-12 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 bbca3812 2024-04-12 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 bbca3812 2024-04-12 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 bbca3812 2024-04-12 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 bbca3812 2024-04-12 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 bbca3812 2024-04-12 stsp
17 bbca3812 2024-04-12 stsp . ../cmdline/common.sh
18 bbca3812 2024-04-12 stsp . ./common.sh
19 bbca3812 2024-04-12 stsp
20 bbca3812 2024-04-12 stsp test_send_empty_readonly() {
21 bbca3812 2024-04-12 stsp local testroot=`test_init send_empty`
22 bbca3812 2024-04-12 stsp local commit_id=`git_show_head $testroot/repo`
23 bbca3812 2024-04-12 stsp
24 bbca3812 2024-04-12 stsp (cd ${GOTD_TEST_REPO} && find . > $testroot/repo-list.before)
25 bbca3812 2024-04-12 stsp
26 bbca3812 2024-04-12 stsp # The gotd-controlled test repository starts out empty.
27 bbca3812 2024-04-12 stsp got ref -l -r ${GOTD_TEST_REPO} > $testroot/ref-list.before
28 bbca3812 2024-04-12 stsp echo "HEAD: refs/heads/main" > $testroot/ref-list.expected
29 bbca3812 2024-04-12 stsp cmp -s $testroot/ref-list.expected $testroot/ref-list.before
30 bbca3812 2024-04-12 stsp ret=$?
31 bbca3812 2024-04-12 stsp if [ $ret -ne 0 ]; then
32 bbca3812 2024-04-12 stsp diff -u $testroot/ref-list.expected $testroot/ref-list.before
33 bbca3812 2024-04-12 stsp test_done "$testroot" "$ret"
34 bbca3812 2024-04-12 stsp return 1
35 bbca3812 2024-04-12 stsp fi
36 bbca3812 2024-04-12 stsp
37 bbca3812 2024-04-12 stsp got checkout -q $testroot/repo $testroot/wt >/dev/null
38 bbca3812 2024-04-12 stsp ret=$?
39 bbca3812 2024-04-12 stsp if [ $ret -ne 0 ]; then
40 bbca3812 2024-04-12 stsp echo "got checkout failed unexpectedly" >&2
41 bbca3812 2024-04-12 stsp test_done "$testroot" 1
42 bbca3812 2024-04-12 stsp return 1
43 bbca3812 2024-04-12 stsp fi
44 bbca3812 2024-04-12 stsp
45 bbca3812 2024-04-12 stsp # send contents of $testroot/repo to ${GOTD_TEST_REPO}
46 bbca3812 2024-04-12 stsp cat >> $testroot/wt/.got/got.conf <<EOF
47 bbca3812 2024-04-12 stsp remote "gotd" {
48 bbca3812 2024-04-12 stsp server ${GOTD_DEVUSER}@127.0.0.1
49 bbca3812 2024-04-12 stsp repository "test-repo"
50 bbca3812 2024-04-12 stsp protocol ssh
51 bbca3812 2024-04-12 stsp }
52 bbca3812 2024-04-12 stsp EOF
53 bbca3812 2024-04-12 stsp (cd $testroot/wt && got send -q -a gotd 2> $testroot/stderr)
54 bbca3812 2024-04-12 stsp ret=$?
55 bbca3812 2024-04-12 stsp if [ $ret -eq 0 ]; then
56 bbca3812 2024-04-12 stsp echo "got send succeeded unexpectedly" >&2
57 bbca3812 2024-04-12 stsp test_done "$testroot" 1
58 bbca3812 2024-04-12 stsp return 1
59 bbca3812 2024-04-12 stsp fi
60 bbca3812 2024-04-12 stsp
61 bbca3812 2024-04-12 stsp echo "got-send-pack: test-repo: Permission denied" \
62 bbca3812 2024-04-12 stsp > $testroot/stderr.expected
63 bbca3812 2024-04-12 stsp grep '^got-send-pack:' $testroot/stderr > $testroot/stderr.filtered
64 bbca3812 2024-04-12 stsp cmp -s $testroot/stderr.expected $testroot/stderr.filtered
65 bbca3812 2024-04-12 stsp ret=$?
66 bbca3812 2024-04-12 stsp if [ $ret -ne 0 ]; then
67 bbca3812 2024-04-12 stsp diff -u $testroot/stderr.expected $testroot/stderr.filtered
68 bbca3812 2024-04-12 stsp test_done "$testroot" "$ret"
69 bbca3812 2024-04-12 stsp return 1
70 bbca3812 2024-04-12 stsp fi
71 bbca3812 2024-04-12 stsp
72 bbca3812 2024-04-12 stsp # Server should not have created a new reference.
73 bbca3812 2024-04-12 stsp got ref -l -r ${GOTD_TEST_REPO} > $testroot/ref-list.after
74 bbca3812 2024-04-12 stsp echo "HEAD: refs/heads/main" > $testroot/ref-list.expected
75 bbca3812 2024-04-12 stsp cmp -s $testroot/ref-list.expected $testroot/ref-list.after
76 bbca3812 2024-04-12 stsp ret=$?
77 bbca3812 2024-04-12 stsp if [ $ret -ne 0 ]; then
78 bbca3812 2024-04-12 stsp diff -u $testroot/ref-list.expected $testroot/ref-list.after
79 bbca3812 2024-04-12 stsp test_done "$testroot" "$ret"
80 bbca3812 2024-04-12 stsp return 1
81 bbca3812 2024-04-12 stsp fi
82 bbca3812 2024-04-12 stsp
83 bbca3812 2024-04-12 stsp test_done "$testroot" "$ret"
84 bbca3812 2024-04-12 stsp }
85 bbca3812 2024-04-12 stsp
86 bbca3812 2024-04-12 stsp test_parseargs "$@"
87 bbca3812 2024-04-12 stsp run_test test_send_empty_readonly