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 clone_basic 1`
23 cp -r ${GOTD_TEST_REPO} $testroot/repo-copy
25 got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
27 if [ $ret -ne 0 ]; then
28 echo "got clone failed unexpectedly" >&2
29 test_done "$testroot" "1"
33 # Verify that the clone operation worked fine.
34 git_fsck "$testroot" "$testroot/repo-clone"
36 if [ $ret -ne 0 ]; then
37 test_done "$testroot" "1"
41 got tree -R -r "$testroot/repo-clone" > $testroot/stdout
42 cat > $testroot/stdout.expected <<EOF
50 cmp -s $testroot/stdout.expected $testroot/stdout
52 if [ $ret -ne 0 ]; then
53 diff -u $testroot/stdout.expected $testroot/stdout
54 test_done "$testroot" "$ret"
58 # cloning a repository should not result in modifications
59 diff -urN ${GOTD_TEST_REPO} $testroot/repo-copy \
61 echo -n > $testroot/stdout.expected
62 cmp -s $testroot/stdout.expected $testroot/stdout
64 if [ $ret -ne 0 ]; then
65 diff -u $testroot/stdout.expected $testroot/stdout
66 test_done "$testroot" "$ret"
70 test_done "$testroot" "$ret"
73 test_clone_basic_git() {
74 local testroot=`test_init clone_basic_git 1`
76 cp -r ${GOTD_TEST_REPO} $testroot/repo-copy
78 git clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone \
81 if [ $ret -ne 0 ]; then
82 echo "git clone failed unexpectedly" >&2
83 test_done "$testroot" "1"
87 # Verify that the clone operation worked fine.
88 git_fsck "$testroot" "$testroot/repo-clone"
90 if [ $ret -ne 0 ]; then
91 test_done "$testroot" "1"
95 got tree -R -r "$testroot/repo-clone" > $testroot/stdout
96 cat > $testroot/stdout.expected <<EOF
104 cmp -s $testroot/stdout.expected $testroot/stdout
106 if [ $ret -ne 0 ]; then
107 diff -u $testroot/stdout.expected $testroot/stdout
108 test_done "$testroot" "$ret"
112 # cloning a repository should not result in modifications
113 diff -urN ${GOTD_TEST_REPO} $testroot/repo-copy \
115 echo -n > $testroot/stdout.expected
116 cmp -s $testroot/stdout.expected $testroot/stdout
118 if [ $ret -ne 0 ]; then
119 diff -u $testroot/stdout.expected $testroot/stdout
120 test_done "$testroot" "$ret"
124 test_done "$testroot" "$ret"
128 test_send_to_read_only_repo() {
129 local testroot=`test_init send_to_read_only_repo 1`
131 ls -R ${GOTD_TEST_REPO} > $testroot/repo-list.before
133 got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
135 if [ $ret -ne 0 ]; then
136 echo "got clone failed unexpectedly" >&2
137 test_done "$testroot" "1"
141 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
143 if [ $ret -ne 0 ]; then
144 echo "got checkout failed unexpectedly" >&2
145 test_done "$testroot" "1"
149 mkdir $testroot/wt/psi
150 echo "new" > $testroot/wt/psi/new
151 (cd $testroot/wt && got add psi/new > /dev/null)
152 echo "more alpha" >> $testroot/wt/alpha
153 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
155 got send -q -r $testroot/repo-clone 2>$testroot/stderr.raw
157 if [ $ret -eq 0 ]; then
158 echo "got send succeeded unexpectedly" >&2
159 test_done "$testroot" "1"
162 grep -v ^gotsh: $testroot/stderr.raw > $testroot/stderr
164 echo 'got-send-pack: test-repo: Permission denied' \
165 > $testroot/stderr.expected
166 echo 'got: could not send pack file' >> $testroot/stderr.expected
167 cmp -s $testroot/stderr.expected $testroot/stderr
169 if [ $ret -ne 0 ]; then
170 diff -u $testroot/stderr.expected $testroot/stderr
172 test_done "$testroot" "$ret"
176 run_test test_clone_basic
177 run_test test_clone_basic_git
178 run_test test_send_to_read_only_repo