Blame


1 6ae16afd 2022-10-31 stsp #!/bin/sh
2 6ae16afd 2022-10-31 stsp #
3 6ae16afd 2022-10-31 stsp # Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
4 6ae16afd 2022-10-31 stsp #
5 6ae16afd 2022-10-31 stsp # Permission to use, copy, modify, and distribute this software for any
6 6ae16afd 2022-10-31 stsp # purpose with or without fee is hereby granted, provided that the above
7 6ae16afd 2022-10-31 stsp # copyright notice and this permission notice appear in all copies.
8 6ae16afd 2022-10-31 stsp #
9 6ae16afd 2022-10-31 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 6ae16afd 2022-10-31 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 6ae16afd 2022-10-31 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 6ae16afd 2022-10-31 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 6ae16afd 2022-10-31 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 6ae16afd 2022-10-31 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 6ae16afd 2022-10-31 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 6ae16afd 2022-10-31 stsp
17 6ae16afd 2022-10-31 stsp . ../cmdline/common.sh
18 6ae16afd 2022-10-31 stsp . ./common.sh
19 6ae16afd 2022-10-31 stsp
20 6ae16afd 2022-10-31 stsp test_clone_basic() {
21 6ae16afd 2022-10-31 stsp local testroot=`test_init clone_basic 1`
22 6ae16afd 2022-10-31 stsp
23 6ae16afd 2022-10-31 stsp cp -r ${GOTD_TEST_REPO} $testroot/repo-copy
24 6ae16afd 2022-10-31 stsp
25 6ae16afd 2022-10-31 stsp got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
26 6ae16afd 2022-10-31 stsp ret=$?
27 6ae16afd 2022-10-31 stsp if [ $ret -ne 0 ]; then
28 6ae16afd 2022-10-31 stsp echo "got clone failed unexpectedly" >&2
29 6ae16afd 2022-10-31 stsp test_done "$testroot" "1"
30 6ae16afd 2022-10-31 stsp return 1
31 6ae16afd 2022-10-31 stsp fi
32 6ae16afd 2022-10-31 stsp
33 6ae16afd 2022-10-31 stsp # Verify that the clone operation worked fine.
34 6ae16afd 2022-10-31 stsp git_fsck "$testroot" "$testroot/repo-clone"
35 6ae16afd 2022-10-31 stsp ret=$?
36 6ae16afd 2022-10-31 stsp if [ $ret -ne 0 ]; then
37 6ae16afd 2022-10-31 stsp test_done "$testroot" "1"
38 6ae16afd 2022-10-31 stsp return 1
39 6ae16afd 2022-10-31 stsp fi
40 6ae16afd 2022-10-31 stsp
41 6ae16afd 2022-10-31 stsp got tree -R -r "$testroot/repo-clone" > $testroot/stdout
42 6ae16afd 2022-10-31 stsp cat > $testroot/stdout.expected <<EOF
43 6ae16afd 2022-10-31 stsp alpha
44 6ae16afd 2022-10-31 stsp beta
45 6ae16afd 2022-10-31 stsp epsilon/
46 6ae16afd 2022-10-31 stsp epsilon/zeta
47 6ae16afd 2022-10-31 stsp gamma/
48 6ae16afd 2022-10-31 stsp gamma/delta
49 6ae16afd 2022-10-31 stsp EOF
50 6ae16afd 2022-10-31 stsp cmp -s $testroot/stdout.expected $testroot/stdout
51 6ae16afd 2022-10-31 stsp ret=$?
52 6ae16afd 2022-10-31 stsp if [ $ret -ne 0 ]; then
53 6ae16afd 2022-10-31 stsp diff -u $testroot/stdout.expected $testroot/stdout
54 6ae16afd 2022-10-31 stsp test_done "$testroot" "$ret"
55 6ae16afd 2022-10-31 stsp return 1
56 6ae16afd 2022-10-31 stsp fi
57 6ae16afd 2022-10-31 stsp
58 6ae16afd 2022-10-31 stsp # cloning a repository should not result in modifications
59 6ae16afd 2022-10-31 stsp diff -urN ${GOTD_TEST_REPO} $testroot/repo-copy \
60 6ae16afd 2022-10-31 stsp > $testroot/stdout
61 6ae16afd 2022-10-31 stsp echo -n > $testroot/stdout.expected
62 6ae16afd 2022-10-31 stsp cmp -s $testroot/stdout.expected $testroot/stdout
63 6ae16afd 2022-10-31 stsp ret=$?
64 6ae16afd 2022-10-31 stsp if [ $ret -ne 0 ]; then
65 6ae16afd 2022-10-31 stsp diff -u $testroot/stdout.expected $testroot/stdout
66 6ae16afd 2022-10-31 stsp test_done "$testroot" "$ret"
67 6ae16afd 2022-10-31 stsp return 1
68 6ae16afd 2022-10-31 stsp fi
69 6ae16afd 2022-10-31 stsp
70 6ae16afd 2022-10-31 stsp test_done "$testroot" "$ret"
71 6ae16afd 2022-10-31 stsp }
72 6ae16afd 2022-10-31 stsp
73 6e5370b0 2024-05-04 stsp test_clone_basic_git() {
74 6e5370b0 2024-05-04 stsp local testroot=`test_init clone_basic_git 1`
75 6e5370b0 2024-05-04 stsp
76 6e5370b0 2024-05-04 stsp cp -r ${GOTD_TEST_REPO} $testroot/repo-copy
77 6e5370b0 2024-05-04 stsp
78 6e5370b0 2024-05-04 stsp git clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone \
79 6e5370b0 2024-05-04 stsp 2> $testroot/stderr
80 6e5370b0 2024-05-04 stsp ret=$?
81 6e5370b0 2024-05-04 stsp if [ $ret -ne 0 ]; then
82 6e5370b0 2024-05-04 stsp echo "git clone failed unexpectedly" >&2
83 6e5370b0 2024-05-04 stsp test_done "$testroot" "1"
84 6e5370b0 2024-05-04 stsp return 1
85 6e5370b0 2024-05-04 stsp fi
86 6e5370b0 2024-05-04 stsp
87 6e5370b0 2024-05-04 stsp # Verify that the clone operation worked fine.
88 6e5370b0 2024-05-04 stsp git_fsck "$testroot" "$testroot/repo-clone"
89 6e5370b0 2024-05-04 stsp ret=$?
90 6e5370b0 2024-05-04 stsp if [ $ret -ne 0 ]; then
91 6e5370b0 2024-05-04 stsp test_done "$testroot" "1"
92 6e5370b0 2024-05-04 stsp return 1
93 6e5370b0 2024-05-04 stsp fi
94 6e5370b0 2024-05-04 stsp
95 6e5370b0 2024-05-04 stsp got tree -R -r "$testroot/repo-clone" > $testroot/stdout
96 6e5370b0 2024-05-04 stsp cat > $testroot/stdout.expected <<EOF
97 6e5370b0 2024-05-04 stsp alpha
98 6e5370b0 2024-05-04 stsp beta
99 6e5370b0 2024-05-04 stsp epsilon/
100 6e5370b0 2024-05-04 stsp epsilon/zeta
101 6e5370b0 2024-05-04 stsp gamma/
102 6e5370b0 2024-05-04 stsp gamma/delta
103 6e5370b0 2024-05-04 stsp EOF
104 6e5370b0 2024-05-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
105 6e5370b0 2024-05-04 stsp ret=$?
106 6e5370b0 2024-05-04 stsp if [ $ret -ne 0 ]; then
107 6e5370b0 2024-05-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
108 6e5370b0 2024-05-04 stsp test_done "$testroot" "$ret"
109 6e5370b0 2024-05-04 stsp return 1
110 6e5370b0 2024-05-04 stsp fi
111 6e5370b0 2024-05-04 stsp
112 6e5370b0 2024-05-04 stsp # cloning a repository should not result in modifications
113 6e5370b0 2024-05-04 stsp diff -urN ${GOTD_TEST_REPO} $testroot/repo-copy \
114 6e5370b0 2024-05-04 stsp > $testroot/stdout
115 6e5370b0 2024-05-04 stsp echo -n > $testroot/stdout.expected
116 6e5370b0 2024-05-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
117 6e5370b0 2024-05-04 stsp ret=$?
118 6e5370b0 2024-05-04 stsp if [ $ret -ne 0 ]; then
119 6e5370b0 2024-05-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
120 6e5370b0 2024-05-04 stsp test_done "$testroot" "$ret"
121 6e5370b0 2024-05-04 stsp return 1
122 6e5370b0 2024-05-04 stsp fi
123 6e5370b0 2024-05-04 stsp
124 6e5370b0 2024-05-04 stsp test_done "$testroot" "$ret"
125 6e5370b0 2024-05-04 stsp }
126 6e5370b0 2024-05-04 stsp
127 6e5370b0 2024-05-04 stsp
128 0ccf3acb 2022-11-16 stsp test_send_to_read_only_repo() {
129 0ccf3acb 2022-11-16 stsp local testroot=`test_init send_to_read_only_repo 1`
130 0ccf3acb 2022-11-16 stsp
131 0ccf3acb 2022-11-16 stsp ls -R ${GOTD_TEST_REPO} > $testroot/repo-list.before
132 0ccf3acb 2022-11-16 stsp
133 0ccf3acb 2022-11-16 stsp got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
134 0ccf3acb 2022-11-16 stsp ret=$?
135 0ccf3acb 2022-11-16 stsp if [ $ret -ne 0 ]; then
136 0ccf3acb 2022-11-16 stsp echo "got clone failed unexpectedly" >&2
137 0ccf3acb 2022-11-16 stsp test_done "$testroot" "1"
138 0ccf3acb 2022-11-16 stsp return 1
139 0ccf3acb 2022-11-16 stsp fi
140 0ccf3acb 2022-11-16 stsp
141 0ccf3acb 2022-11-16 stsp got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
142 0ccf3acb 2022-11-16 stsp ret=$?
143 0ccf3acb 2022-11-16 stsp if [ $ret -ne 0 ]; then
144 0ccf3acb 2022-11-16 stsp echo "got checkout failed unexpectedly" >&2
145 0ccf3acb 2022-11-16 stsp test_done "$testroot" "1"
146 0ccf3acb 2022-11-16 stsp return 1
147 0ccf3acb 2022-11-16 stsp fi
148 0ccf3acb 2022-11-16 stsp
149 0ccf3acb 2022-11-16 stsp mkdir $testroot/wt/psi
150 0ccf3acb 2022-11-16 stsp echo "new" > $testroot/wt/psi/new
151 0ccf3acb 2022-11-16 stsp (cd $testroot/wt && got add psi/new > /dev/null)
152 0ccf3acb 2022-11-16 stsp echo "more alpha" >> $testroot/wt/alpha
153 0ccf3acb 2022-11-16 stsp (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
154 0ccf3acb 2022-11-16 stsp
155 30eb1ad6 2022-12-09 stsp got send -q -r $testroot/repo-clone 2>$testroot/stderr.raw
156 0ccf3acb 2022-11-16 stsp ret=$?
157 0ccf3acb 2022-11-16 stsp if [ $ret -eq 0 ]; then
158 0ccf3acb 2022-11-16 stsp echo "got send succeeded unexpectedly" >&2
159 0ccf3acb 2022-11-16 stsp test_done "$testroot" "1"
160 0ccf3acb 2022-11-16 stsp return 1
161 0ccf3acb 2022-11-16 stsp fi
162 30eb1ad6 2022-12-09 stsp grep -v ^gotsh: $testroot/stderr.raw > $testroot/stderr
163 0ccf3acb 2022-11-16 stsp
164 0ccf3acb 2022-11-16 stsp echo 'got-send-pack: test-repo: Permission denied' \
165 0ccf3acb 2022-11-16 stsp > $testroot/stderr.expected
166 0ccf3acb 2022-11-16 stsp echo 'got: could not send pack file' >> $testroot/stderr.expected
167 0ccf3acb 2022-11-16 stsp cmp -s $testroot/stderr.expected $testroot/stderr
168 0ccf3acb 2022-11-16 stsp ret=$?
169 0ccf3acb 2022-11-16 stsp if [ $ret -ne 0 ]; then
170 0ccf3acb 2022-11-16 stsp diff -u $testroot/stderr.expected $testroot/stderr
171 0ccf3acb 2022-11-16 stsp fi
172 0ccf3acb 2022-11-16 stsp test_done "$testroot" "$ret"
173 0ccf3acb 2022-11-16 stsp }
174 0ccf3acb 2022-11-16 stsp
175 6ae16afd 2022-10-31 stsp test_parseargs "$@"
176 6ae16afd 2022-10-31 stsp run_test test_clone_basic
177 6e5370b0 2024-05-04 stsp run_test test_clone_basic_git
178 0ccf3acb 2022-11-16 stsp run_test test_send_to_read_only_repo