Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
4 #
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.
8 #
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
18 . ./common.sh
20 test_clone_basic() {
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
26 ret=$?
27 if [ $ret -ne 0 ]; then
28 echo "got clone failed unexpectedly" >&2
29 test_done "$testroot" "1"
30 return 1
31 fi
33 # Verify that the clone operation worked fine.
34 git_fsck "$testroot" "$testroot/repo-clone"
35 ret=$?
36 if [ $ret -ne 0 ]; then
37 test_done "$testroot" "1"
38 return 1
39 fi
41 got tree -R -r "$testroot/repo-clone" > $testroot/stdout
42 cat > $testroot/stdout.expected <<EOF
43 alpha
44 beta
45 epsilon/
46 epsilon/zeta
47 gamma/
48 gamma/delta
49 EOF
50 cmp -s $testroot/stdout.expected $testroot/stdout
51 ret=$?
52 if [ $ret -ne 0 ]; then
53 diff -u $testroot/stdout.expected $testroot/stdout
54 test_done "$testroot" "$ret"
55 return 1
56 fi
58 # cloning a repository should not result in modifications
59 diff -urN ${GOTD_TEST_REPO} $testroot/repo-copy \
60 > $testroot/stdout
61 echo -n > $testroot/stdout.expected
62 cmp -s $testroot/stdout.expected $testroot/stdout
63 ret=$?
64 if [ $ret -ne 0 ]; then
65 diff -u $testroot/stdout.expected $testroot/stdout
66 test_done "$testroot" "$ret"
67 return 1
68 fi
70 test_done "$testroot" "$ret"
71 }
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 \
79 2> $testroot/stderr
80 ret=$?
81 if [ $ret -ne 0 ]; then
82 echo "git clone failed unexpectedly" >&2
83 test_done "$testroot" "1"
84 return 1
85 fi
87 # Verify that the clone operation worked fine.
88 git_fsck "$testroot" "$testroot/repo-clone"
89 ret=$?
90 if [ $ret -ne 0 ]; then
91 test_done "$testroot" "1"
92 return 1
93 fi
95 got tree -R -r "$testroot/repo-clone" > $testroot/stdout
96 cat > $testroot/stdout.expected <<EOF
97 alpha
98 beta
99 epsilon/
100 epsilon/zeta
101 gamma/
102 gamma/delta
103 EOF
104 cmp -s $testroot/stdout.expected $testroot/stdout
105 ret=$?
106 if [ $ret -ne 0 ]; then
107 diff -u $testroot/stdout.expected $testroot/stdout
108 test_done "$testroot" "$ret"
109 return 1
110 fi
112 # cloning a repository should not result in modifications
113 diff -urN ${GOTD_TEST_REPO} $testroot/repo-copy \
114 > $testroot/stdout
115 echo -n > $testroot/stdout.expected
116 cmp -s $testroot/stdout.expected $testroot/stdout
117 ret=$?
118 if [ $ret -ne 0 ]; then
119 diff -u $testroot/stdout.expected $testroot/stdout
120 test_done "$testroot" "$ret"
121 return 1
122 fi
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
134 ret=$?
135 if [ $ret -ne 0 ]; then
136 echo "got clone failed unexpectedly" >&2
137 test_done "$testroot" "1"
138 return 1
139 fi
141 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
142 ret=$?
143 if [ $ret -ne 0 ]; then
144 echo "got checkout failed unexpectedly" >&2
145 test_done "$testroot" "1"
146 return 1
147 fi
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
156 ret=$?
157 if [ $ret -eq 0 ]; then
158 echo "got send succeeded unexpectedly" >&2
159 test_done "$testroot" "1"
160 return 1
161 fi
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
168 ret=$?
169 if [ $ret -ne 0 ]; then
170 diff -u $testroot/stderr.expected $testroot/stderr
171 fi
172 test_done "$testroot" "$ret"
175 test_parseargs "$@"
176 run_test test_clone_basic
177 run_test test_clone_basic_git
178 run_test test_send_to_read_only_repo