3 # Copyright (c) 2022 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
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
31 if [ $ret -ne 0 ]; then
32 diff -u $testroot/ref-list.expected
$testroot/ref-list.before
33 test_done
"$testroot" "$ret"
37 got checkout
-q $testroot/repo
$testroot/wt
>/dev
/null
39 if [ $ret -ne 0 ]; then
40 echo "got checkout failed unexpectedly" >&2
41 test_done
"$testroot" 1
45 # send contents of $testroot/repo to ${GOTD_TEST_REPO}
46 cat >> $testroot/wt
/.got
/got.conf
<<EOF
48 server ${GOTD_DEVUSER}@127.0.0.1
49 repository "test-repo"
53 (cd $testroot/wt
&& got send
-q -a gotd
)
55 if [ $ret -ne 0 ]; then
56 echo "got send failed unexpectedly" >&2
57 test_done
"$testroot" 1
61 # Server should have created a new reference.
62 got ref
-l -r ${GOTD_TEST_REPO} > $testroot/ref-list.after
63 cat > $testroot/ref-list.expected
<<EOF
65 refs/heads/master: $commit_id
67 cmp -s $testroot/ref-list.expected
$testroot/ref-list.after
69 if [ $ret -ne 0 ]; then
70 diff -u $testroot/ref-list.expected
$testroot/ref-list.after
71 test_done
"$testroot" "$ret"
75 # Verify that the result can be cloned again.
76 # XXX need -b master at present because gotd does not rewrite HEAD
77 got clone
-q -b master
${GOTD_TEST_REPO_URL} $testroot/repo-clone2
79 if [ $ret -ne 0 ]; then
80 echo "got clone failed unexpectedly" >&2
81 test_done
"$testroot" 1
85 got tree
-R -r $testroot/repo-clone2
> $testroot/stdout
86 cat > $testroot/stdout.expected
<<EOF
94 cmp -s $testroot/stdout.expected
$testroot/stdout
96 if [ $ret -ne 0 ]; then
97 diff -u $testroot/stdout.expected
$testroot/stdout
98 test_done
"$testroot" "$ret"
102 # sending to a repository should result in a new pack file
103 (cd ${GOTD_TEST_REPO} && find .
> $testroot/repo-list.after
)
104 diff -u $testroot/repo-list.before
$testroot/repo-list.after \
105 > $testroot/repo-list.
diff
106 grep '^+[^+]' < $testroot/repo-list.
diff > $testroot/repo-list.newlines
107 nplus
=`awk '/^\+[^+]/{c++} END{print c}' $testroot/repo-list.diff`
108 if [ "$nplus" != "4" ]; then
109 echo "$nplus new files created:" >&2
110 cat $testroot/repo-list.
diff
111 test_done
"$testroot" 1
114 egrep -q '\+\./objects/pack/pack-[a-f0-9]{40}\.pack' $testroot/repo-list.newlines
116 if [ $ret -ne 0 ]; then
117 echo "new pack file not found in ${GOTD_TEST_REPO}"
118 cat $testroot/repo-list.newlines
119 test_done
"$testroot" "$ret"
122 egrep -q '\+\./objects/pack/pack-[a-f0-9]{40}\.idx' $testroot/repo-list.newlines
124 if [ $ret -ne 0 ]; then
125 echo "new pack index not found in ${GOTD_TEST_REPO}"
126 test_done
"$testroot" "$ret"
129 fgrep
-q '+./refs/heads' $testroot/repo-list.newlines
131 if [ $ret -ne 0 ]; then
132 echo "new refs/heads directory not found"
133 test_done
"$testroot" "$ret"
136 if [ ! -d ${GOTD_TEST_REPO}/refs
/heads
]; then
137 echo "new refs/heads is not a directory"
138 test_done
"$testroot" 1
141 fgrep
-q '+./refs/heads/master' $testroot/repo-list.newlines
143 if [ $ret -ne 0 ]; then
144 echo "new refs/heads/master not found"
145 test_done
"$testroot" "$ret"
149 test_done
"$testroot" "$ret"
153 run_test test_send_empty