Blame


1 a07c01e0 2022-11-08 thomas #!/bin/sh
2 a07c01e0 2022-11-08 thomas #
3 a07c01e0 2022-11-08 thomas # Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
4 a07c01e0 2022-11-08 thomas #
5 a07c01e0 2022-11-08 thomas # Permission to use, copy, modify, and distribute this software for any
6 a07c01e0 2022-11-08 thomas # purpose with or without fee is hereby granted, provided that the above
7 a07c01e0 2022-11-08 thomas # copyright notice and this permission notice appear in all copies.
8 a07c01e0 2022-11-08 thomas #
9 a07c01e0 2022-11-08 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 a07c01e0 2022-11-08 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 a07c01e0 2022-11-08 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 a07c01e0 2022-11-08 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 a07c01e0 2022-11-08 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 a07c01e0 2022-11-08 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 a07c01e0 2022-11-08 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 a07c01e0 2022-11-08 thomas
17 a07c01e0 2022-11-08 thomas . ../cmdline/common.sh
18 a07c01e0 2022-11-08 thomas . ./common.sh
19 a07c01e0 2022-11-08 thomas
20 a07c01e0 2022-11-08 thomas test_send_empty() {
21 a07c01e0 2022-11-08 thomas local testroot=`test_init send_empty`
22 a07c01e0 2022-11-08 thomas local commit_id=`git_show_head $testroot/repo`
23 a07c01e0 2022-11-08 thomas
24 a07c01e0 2022-11-08 thomas (cd ${GOTD_TEST_REPO} && find . > $testroot/repo-list.before)
25 a07c01e0 2022-11-08 thomas
26 a07c01e0 2022-11-08 thomas # The gotd-controlled test repository starts out empty.
27 a07c01e0 2022-11-08 thomas got ref -l -r ${GOTD_TEST_REPO} > $testroot/ref-list.before
28 a07c01e0 2022-11-08 thomas echo "HEAD: refs/heads/main" > $testroot/ref-list.expected
29 a07c01e0 2022-11-08 thomas cmp -s $testroot/ref-list.expected $testroot/ref-list.before
30 a07c01e0 2022-11-08 thomas ret=$?
31 a07c01e0 2022-11-08 thomas if [ $ret -ne 0 ]; then
32 a07c01e0 2022-11-08 thomas diff -u $testroot/ref-list.expected $testroot/ref-list.before
33 a07c01e0 2022-11-08 thomas test_done "$testroot" "$ret"
34 a07c01e0 2022-11-08 thomas return 1
35 a07c01e0 2022-11-08 thomas fi
36 a07c01e0 2022-11-08 thomas
37 a07c01e0 2022-11-08 thomas got checkout -q $testroot/repo $testroot/wt >/dev/null
38 a07c01e0 2022-11-08 thomas ret=$?
39 a07c01e0 2022-11-08 thomas if [ $ret -ne 0 ]; then
40 a07c01e0 2022-11-08 thomas echo "got checkout failed unexpectedly" >&2
41 86ebaa2c 2022-11-08 thomas test_done "$testroot" 1
42 a07c01e0 2022-11-08 thomas return 1
43 a07c01e0 2022-11-08 thomas fi
44 a07c01e0 2022-11-08 thomas
45 a07c01e0 2022-11-08 thomas # send contents of $testroot/repo to ${GOTD_TEST_REPO}
46 a07c01e0 2022-11-08 thomas cat >> $testroot/wt/.got/got.conf <<EOF
47 a07c01e0 2022-11-08 thomas remote "gotd" {
48 a07c01e0 2022-11-08 thomas server ${GOTD_DEVUSER}@127.0.0.1
49 a07c01e0 2022-11-08 thomas repository "test-repo"
50 a07c01e0 2022-11-08 thomas protocol ssh
51 a07c01e0 2022-11-08 thomas }
52 a07c01e0 2022-11-08 thomas EOF
53 a07c01e0 2022-11-08 thomas (cd $testroot/wt && got send -q -a gotd)
54 a07c01e0 2022-11-08 thomas ret=$?
55 a07c01e0 2022-11-08 thomas if [ $ret -ne 0 ]; then
56 a07c01e0 2022-11-08 thomas echo "got send failed unexpectedly" >&2
57 86ebaa2c 2022-11-08 thomas test_done "$testroot" 1
58 a07c01e0 2022-11-08 thomas return 1
59 a07c01e0 2022-11-08 thomas fi
60 a07c01e0 2022-11-08 thomas
61 a07c01e0 2022-11-08 thomas # Server should have created a new reference.
62 a07c01e0 2022-11-08 thomas got ref -l -r ${GOTD_TEST_REPO} > $testroot/ref-list.after
63 a07c01e0 2022-11-08 thomas cat > $testroot/ref-list.expected <<EOF
64 a07c01e0 2022-11-08 thomas HEAD: refs/heads/main
65 a07c01e0 2022-11-08 thomas refs/heads/master: $commit_id
66 a07c01e0 2022-11-08 thomas EOF
67 a07c01e0 2022-11-08 thomas cmp -s $testroot/ref-list.expected $testroot/ref-list.after
68 a07c01e0 2022-11-08 thomas ret=$?
69 a07c01e0 2022-11-08 thomas if [ $ret -ne 0 ]; then
70 a07c01e0 2022-11-08 thomas diff -u $testroot/ref-list.expected $testroot/ref-list.after
71 a07c01e0 2022-11-08 thomas test_done "$testroot" "$ret"
72 a07c01e0 2022-11-08 thomas return 1
73 a07c01e0 2022-11-08 thomas fi
74 a07c01e0 2022-11-08 thomas
75 a07c01e0 2022-11-08 thomas # Verify that the result can be cloned again.
76 a07c01e0 2022-11-08 thomas # XXX need -b master at present because gotd does not rewrite HEAD
77 a07c01e0 2022-11-08 thomas got clone -q -b master ${GOTD_TEST_REPO_URL} $testroot/repo-clone2
78 a07c01e0 2022-11-08 thomas ret=$?
79 a07c01e0 2022-11-08 thomas if [ $ret -ne 0 ]; then
80 a07c01e0 2022-11-08 thomas echo "got clone failed unexpectedly" >&2
81 86ebaa2c 2022-11-08 thomas test_done "$testroot" 1
82 a07c01e0 2022-11-08 thomas return 1
83 a07c01e0 2022-11-08 thomas fi
84 a07c01e0 2022-11-08 thomas
85 a07c01e0 2022-11-08 thomas got tree -R -r $testroot/repo-clone2 > $testroot/stdout
86 a07c01e0 2022-11-08 thomas cat > $testroot/stdout.expected <<EOF
87 a07c01e0 2022-11-08 thomas alpha
88 a07c01e0 2022-11-08 thomas beta
89 a07c01e0 2022-11-08 thomas epsilon/
90 a07c01e0 2022-11-08 thomas epsilon/zeta
91 a07c01e0 2022-11-08 thomas gamma/
92 a07c01e0 2022-11-08 thomas gamma/delta
93 a07c01e0 2022-11-08 thomas EOF
94 a07c01e0 2022-11-08 thomas cmp -s $testroot/stdout.expected $testroot/stdout
95 a07c01e0 2022-11-08 thomas ret=$?
96 a07c01e0 2022-11-08 thomas if [ $ret -ne 0 ]; then
97 a07c01e0 2022-11-08 thomas diff -u $testroot/stdout.expected $testroot/stdout
98 a07c01e0 2022-11-08 thomas test_done "$testroot" "$ret"
99 a07c01e0 2022-11-08 thomas return 1
100 a07c01e0 2022-11-08 thomas fi
101 a07c01e0 2022-11-08 thomas
102 a07c01e0 2022-11-08 thomas # sending to a repository should result in a new pack file
103 a07c01e0 2022-11-08 thomas (cd ${GOTD_TEST_REPO} && find . > $testroot/repo-list.after)
104 a07c01e0 2022-11-08 thomas diff -u $testroot/repo-list.before $testroot/repo-list.after \
105 a07c01e0 2022-11-08 thomas > $testroot/repo-list.diff
106 a07c01e0 2022-11-08 thomas grep '^+[^+]' < $testroot/repo-list.diff > $testroot/repo-list.newlines
107 86ebaa2c 2022-11-08 thomas nplus=`awk '/^\+[^+]/{c++} END{print c}' $testroot/repo-list.diff`
108 a07c01e0 2022-11-08 thomas if [ "$nplus" != "4" ]; then
109 86ebaa2c 2022-11-08 thomas echo "$nplus new files created:" >&2
110 a07c01e0 2022-11-08 thomas cat $testroot/repo-list.diff
111 86ebaa2c 2022-11-08 thomas test_done "$testroot" 1
112 a07c01e0 2022-11-08 thomas return 1
113 a07c01e0 2022-11-08 thomas fi
114 86ebaa2c 2022-11-08 thomas egrep -q '\+\./objects/pack/pack-[a-f0-9]{40}\.pack' $testroot/repo-list.newlines
115 a07c01e0 2022-11-08 thomas ret=$?
116 a07c01e0 2022-11-08 thomas if [ $ret -ne 0 ]; then
117 a07c01e0 2022-11-08 thomas echo "new pack file not found in ${GOTD_TEST_REPO}"
118 a07c01e0 2022-11-08 thomas cat $testroot/repo-list.newlines
119 a07c01e0 2022-11-08 thomas test_done "$testroot" "$ret"
120 a07c01e0 2022-11-08 thomas return 1
121 a07c01e0 2022-11-08 thomas fi
122 86ebaa2c 2022-11-08 thomas egrep -q '\+\./objects/pack/pack-[a-f0-9]{40}\.idx' $testroot/repo-list.newlines
123 a07c01e0 2022-11-08 thomas ret=$?
124 a07c01e0 2022-11-08 thomas if [ $ret -ne 0 ]; then
125 a07c01e0 2022-11-08 thomas echo "new pack index not found in ${GOTD_TEST_REPO}"
126 a07c01e0 2022-11-08 thomas test_done "$testroot" "$ret"
127 a07c01e0 2022-11-08 thomas return 1
128 a07c01e0 2022-11-08 thomas fi
129 86ebaa2c 2022-11-08 thomas fgrep -q '+./refs/heads' $testroot/repo-list.newlines
130 a07c01e0 2022-11-08 thomas ret=$?
131 a07c01e0 2022-11-08 thomas if [ $ret -ne 0 ]; then
132 a07c01e0 2022-11-08 thomas echo "new refs/heads directory not found"
133 a07c01e0 2022-11-08 thomas test_done "$testroot" "$ret"
134 a07c01e0 2022-11-08 thomas return 1
135 a07c01e0 2022-11-08 thomas fi
136 86ebaa2c 2022-11-08 thomas if [ ! -d ${GOTD_TEST_REPO}/refs/heads ]; then
137 a07c01e0 2022-11-08 thomas echo "new refs/heads is not a directory"
138 86ebaa2c 2022-11-08 thomas test_done "$testroot" 1
139 a07c01e0 2022-11-08 thomas return 1
140 a07c01e0 2022-11-08 thomas fi
141 86ebaa2c 2022-11-08 thomas fgrep -q '+./refs/heads/master' $testroot/repo-list.newlines
142 a07c01e0 2022-11-08 thomas ret=$?
143 a07c01e0 2022-11-08 thomas if [ $ret -ne 0 ]; then
144 a07c01e0 2022-11-08 thomas echo "new refs/heads/master not found"
145 a07c01e0 2022-11-08 thomas test_done "$testroot" "$ret"
146 a07c01e0 2022-11-08 thomas return 1
147 a07c01e0 2022-11-08 thomas fi
148 a07c01e0 2022-11-08 thomas
149 a07c01e0 2022-11-08 thomas test_done "$testroot" "$ret"
150 a07c01e0 2022-11-08 thomas }
151 a07c01e0 2022-11-08 thomas
152 a07c01e0 2022-11-08 thomas test_parseargs "$@"
153 a07c01e0 2022-11-08 thomas run_test test_send_empty