3 a07c01e0 2022-11-08 thomas # Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
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.
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.
17 a07c01e0 2022-11-08 thomas . ../cmdline/common.sh
18 a07c01e0 2022-11-08 thomas . ./common.sh
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`
24 a07c01e0 2022-11-08 thomas (cd ${GOTD_TEST_REPO} && find . > $testroot/repo-list.before)
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
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"
37 a07c01e0 2022-11-08 thomas got checkout -q $testroot/repo $testroot/wt >/dev/null
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
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
53 a07c01e0 2022-11-08 thomas (cd $testroot/wt && got send -q -a gotd)
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
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
67 a07c01e0 2022-11-08 thomas cmp -s $testroot/ref-list.expected $testroot/ref-list.after
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"
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
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
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
90 a07c01e0 2022-11-08 thomas epsilon/zeta
92 a07c01e0 2022-11-08 thomas gamma/delta
94 a07c01e0 2022-11-08 thomas cmp -s $testroot/stdout.expected $testroot/stdout
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"
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
114 86ebaa2c 2022-11-08 thomas egrep -q '\+\./objects/pack/pack-[a-f0-9]{40}\.pack' $testroot/repo-list.newlines
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"
122 86ebaa2c 2022-11-08 thomas egrep -q '\+\./objects/pack/pack-[a-f0-9]{40}\.idx' $testroot/repo-list.newlines
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"
129 86ebaa2c 2022-11-08 thomas fgrep -q '+./refs/heads' $testroot/repo-list.newlines
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"
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
141 86ebaa2c 2022-11-08 thomas fgrep -q '+./refs/heads/master' $testroot/repo-list.newlines
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"
149 a07c01e0 2022-11-08 thomas test_done "$testroot" "$ret"
152 a07c01e0 2022-11-08 thomas test_parseargs "$@"
153 a07c01e0 2022-11-08 thomas run_test test_send_empty