Blame


1 c8c71e6e 2020-03-21 stsp #!/bin/sh
2 c8c71e6e 2020-03-21 stsp #
3 c8c71e6e 2020-03-21 stsp # Copyright (c) 2020 Stefan Sperling <stsp@openbsd.org>
4 c8c71e6e 2020-03-21 stsp #
5 c8c71e6e 2020-03-21 stsp # Permission to use, copy, modify, and distribute this software for any
6 c8c71e6e 2020-03-21 stsp # purpose with or without fee is hereby granted, provided that the above
7 c8c71e6e 2020-03-21 stsp # copyright notice and this permission notice appear in all copies.
8 c8c71e6e 2020-03-21 stsp #
9 c8c71e6e 2020-03-21 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 c8c71e6e 2020-03-21 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 c8c71e6e 2020-03-21 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 c8c71e6e 2020-03-21 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 c8c71e6e 2020-03-21 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 c8c71e6e 2020-03-21 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 c8c71e6e 2020-03-21 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 c8c71e6e 2020-03-21 stsp
17 c8c71e6e 2020-03-21 stsp . ./common.sh
18 c8c71e6e 2020-03-21 stsp
19 c8c71e6e 2020-03-21 stsp function test_clone_basic {
20 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_basic`
21 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
22 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
23 c8c71e6e 2020-03-21 stsp
24 c8c71e6e 2020-03-21 stsp got clone -q $testurl/repo $testroot/repo-clone
25 c8c71e6e 2020-03-21 stsp ret="$?"
26 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
27 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
28 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
29 c8c71e6e 2020-03-21 stsp return 1
30 c8c71e6e 2020-03-21 stsp fi
31 c8c71e6e 2020-03-21 stsp
32 c8c71e6e 2020-03-21 stsp got log -l0 -p -r $testroot/repo > $testroot/log-repo
33 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
34 c8c71e6e 2020-03-21 stsp echo "got log command failed unexpectedly" >&2
35 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
36 c8c71e6e 2020-03-21 stsp return 1
37 c8c71e6e 2020-03-21 stsp fi
38 c8c71e6e 2020-03-21 stsp got log -l0 -p -r $testroot/repo > $testroot/log-repo-clone
39 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
40 c8c71e6e 2020-03-21 stsp echo "got log command failed unexpectedly" >&2
41 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
42 c8c71e6e 2020-03-21 stsp return 1
43 c8c71e6e 2020-03-21 stsp fi
44 c8c71e6e 2020-03-21 stsp cmp -s $testroot/log-repo $testroot/log-repo-clone
45 c8c71e6e 2020-03-21 stsp ret="$?"
46 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
47 c8c71e6e 2020-03-21 stsp echo "log -p output of cloned repository differs" >&2
48 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
49 c8c71e6e 2020-03-21 stsp return 1
50 c8c71e6e 2020-03-21 stsp fi
51 c8c71e6e 2020-03-21 stsp
52 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo > $testroot/stdout
53 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
54 c8c71e6e 2020-03-21 stsp echo "got ref command failed unexpectedly" >&2
55 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
56 c8c71e6e 2020-03-21 stsp return 1
57 c8c71e6e 2020-03-21 stsp fi
58 c8c71e6e 2020-03-21 stsp
59 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
60 c8c71e6e 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
61 c8c71e6e 2020-03-21 stsp
62 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
63 c8c71e6e 2020-03-21 stsp ret="$?"
64 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
65 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
66 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
67 c8c71e6e 2020-03-21 stsp return 1
68 c8c71e6e 2020-03-21 stsp fi
69 c8c71e6e 2020-03-21 stsp
70 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
71 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
72 c8c71e6e 2020-03-21 stsp echo "got ref command failed unexpectedly" >&2
73 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
74 c8c71e6e 2020-03-21 stsp return 1
75 c8c71e6e 2020-03-21 stsp fi
76 c8c71e6e 2020-03-21 stsp
77 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
78 c8c71e6e 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
79 c8c71e6e 2020-03-21 stsp echo "refs/remotes/origin/master: $commit_id" \
80 c8c71e6e 2020-03-21 stsp >> $testroot/stdout.expected
81 c8c71e6e 2020-03-21 stsp
82 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
83 c8c71e6e 2020-03-21 stsp ret="$?"
84 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
85 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
86 c8c71e6e 2020-03-21 stsp fi
87 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
88 c8c71e6e 2020-03-21 stsp }
89 c8c71e6e 2020-03-21 stsp
90 c8c71e6e 2020-03-21 stsp function test_clone_list {
91 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_list`
92 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
93 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
94 c8c71e6e 2020-03-21 stsp
95 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
96 c8c71e6e 2020-03-21 stsp got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
97 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
98 c8c71e6e 2020-03-21 stsp
99 c8c71e6e 2020-03-21 stsp got clone -l $testurl/repo > $testroot/stdout 2>$testroot/stderr
100 c8c71e6e 2020-03-21 stsp ret="$?"
101 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
102 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
103 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
104 c8c71e6e 2020-03-21 stsp return 1
105 c8c71e6e 2020-03-21 stsp fi
106 c8c71e6e 2020-03-21 stsp
107 c8c71e6e 2020-03-21 stsp echo "Connected to 127.0.0.1" > $testroot/stdout.expected
108 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo >> $testroot/stdout.expected
109 c8c71e6e 2020-03-21 stsp
110 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
111 c8c71e6e 2020-03-21 stsp ret="$?"
112 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
113 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
114 c8c71e6e 2020-03-21 stsp fi
115 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
116 c8c71e6e 2020-03-21 stsp }
117 c8c71e6e 2020-03-21 stsp
118 c8c71e6e 2020-03-21 stsp function test_clone_branch {
119 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_branch`
120 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
121 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
122 c8c71e6e 2020-03-21 stsp
123 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
124 c8c71e6e 2020-03-21 stsp got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
125 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
126 c8c71e6e 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
127 c8c71e6e 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
128 c8c71e6e 2020-03-21 stsp
129 c8c71e6e 2020-03-21 stsp got clone -q -b foo $testurl/repo $testroot/repo-clone
130 c8c71e6e 2020-03-21 stsp ret="$?"
131 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
132 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
133 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
134 c8c71e6e 2020-03-21 stsp return 1
135 c8c71e6e 2020-03-21 stsp fi
136 c8c71e6e 2020-03-21 stsp
137 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
138 c8c71e6e 2020-03-21 stsp
139 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
140 c8c71e6e 2020-03-21 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
141 c8c71e6e 2020-03-21 stsp # refs/heads/master is missing because it wasn't passed via -b
142 c8c71e6e 2020-03-21 stsp echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
143 c8c71e6e 2020-03-21 stsp # refs/hoo/boo/zoo is missing because it is outside of refs/heads
144 c8c71e6e 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
145 c8c71e6e 2020-03-21 stsp
146 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
147 c8c71e6e 2020-03-21 stsp ret="$?"
148 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
149 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
150 c8c71e6e 2020-03-21 stsp fi
151 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
152 c8c71e6e 2020-03-21 stsp }
153 c8c71e6e 2020-03-21 stsp
154 c8c71e6e 2020-03-21 stsp function test_clone_all {
155 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_all`
156 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
157 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
158 c8c71e6e 2020-03-21 stsp
159 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
160 c8c71e6e 2020-03-21 stsp got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
161 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
162 c8c71e6e 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
163 c8c71e6e 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
164 c8c71e6e 2020-03-21 stsp
165 c8c71e6e 2020-03-21 stsp got clone -q -a $testurl/repo $testroot/repo-clone
166 c8c71e6e 2020-03-21 stsp ret="$?"
167 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
168 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
169 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
170 c8c71e6e 2020-03-21 stsp return 1
171 c8c71e6e 2020-03-21 stsp fi
172 c8c71e6e 2020-03-21 stsp
173 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
174 c8c71e6e 2020-03-21 stsp
175 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
176 c8c71e6e 2020-03-21 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
177 c8c71e6e 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
178 c8c71e6e 2020-03-21 stsp echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
179 c8c71e6e 2020-03-21 stsp echo "refs/remotes/origin/master: $commit_id" \
180 c8c71e6e 2020-03-21 stsp >> $testroot/stdout.expected
181 c8c71e6e 2020-03-21 stsp # refs/hoo/boo/zoo is missing because it is outside of refs/heads
182 c8c71e6e 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
183 c8c71e6e 2020-03-21 stsp
184 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
185 c8c71e6e 2020-03-21 stsp ret="$?"
186 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
187 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
188 c8c71e6e 2020-03-21 stsp fi
189 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
190 c8c71e6e 2020-03-21 stsp }
191 c8c71e6e 2020-03-21 stsp
192 c8c71e6e 2020-03-21 stsp function test_clone_mirror {
193 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_mirror`
194 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
195 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
196 c8c71e6e 2020-03-21 stsp
197 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
198 c8c71e6e 2020-03-21 stsp got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
199 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
200 c8c71e6e 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
201 c8c71e6e 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
202 c8c71e6e 2020-03-21 stsp
203 c8c71e6e 2020-03-21 stsp got clone -q -m $testurl/repo $testroot/repo-clone
204 c8c71e6e 2020-03-21 stsp ret="$?"
205 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
206 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
207 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
208 c8c71e6e 2020-03-21 stsp return 1
209 c8c71e6e 2020-03-21 stsp fi
210 c8c71e6e 2020-03-21 stsp
211 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
212 c8c71e6e 2020-03-21 stsp
213 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
214 c8c71e6e 2020-03-21 stsp # refs/heads/foo is missing because we're not fetching all branches
215 c8c71e6e 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
216 c8c71e6e 2020-03-21 stsp # refs/hoo/boo/zoo is missing because it is outside of refs/heads
217 c8c71e6e 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
218 c8c71e6e 2020-03-21 stsp
219 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
220 c8c71e6e 2020-03-21 stsp ret="$?"
221 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
222 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
223 c8c71e6e 2020-03-21 stsp fi
224 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
225 c8c71e6e 2020-03-21 stsp }
226 c8c71e6e 2020-03-21 stsp
227 c8c71e6e 2020-03-21 stsp function test_clone_mirror_all {
228 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_mirror_all`
229 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
230 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
231 c8c71e6e 2020-03-21 stsp
232 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
233 c8c71e6e 2020-03-21 stsp got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
234 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
235 c8c71e6e 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
236 c8c71e6e 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
237 c8c71e6e 2020-03-21 stsp
238 c8c71e6e 2020-03-21 stsp got clone -q -m -a $testurl/repo $testroot/repo-clone
239 c8c71e6e 2020-03-21 stsp ret="$?"
240 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
241 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
242 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
243 c8c71e6e 2020-03-21 stsp return 1
244 c8c71e6e 2020-03-21 stsp fi
245 c8c71e6e 2020-03-21 stsp
246 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
247 c8c71e6e 2020-03-21 stsp
248 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
249 c8c71e6e 2020-03-21 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
250 c8c71e6e 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
251 c8c71e6e 2020-03-21 stsp # refs/hoo/boo/zoo is missing because it is outside of refs/heads
252 c8c71e6e 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
253 c8c71e6e 2020-03-21 stsp
254 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
255 c8c71e6e 2020-03-21 stsp ret="$?"
256 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
257 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
258 c8c71e6e 2020-03-21 stsp fi
259 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
260 c8c71e6e 2020-03-21 stsp }
261 0e4002ca 2020-03-21 stsp
262 0e4002ca 2020-03-21 stsp function test_clone_reference {
263 0e4002ca 2020-03-21 stsp local testroot=`test_init clone_reference`
264 0e4002ca 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
265 0e4002ca 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
266 c8c71e6e 2020-03-21 stsp
267 0e4002ca 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
268 0e4002ca 2020-03-21 stsp got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
269 0e4002ca 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
270 0e4002ca 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
271 0e4002ca 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
272 0e4002ca 2020-03-21 stsp
273 0e4002ca 2020-03-21 stsp got clone -q -R hoo $testurl/repo $testroot/repo-clone
274 0e4002ca 2020-03-21 stsp ret="$?"
275 0e4002ca 2020-03-21 stsp if [ "$ret" != "0" ]; then
276 0e4002ca 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
277 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
278 0e4002ca 2020-03-21 stsp return 1
279 0e4002ca 2020-03-21 stsp fi
280 0e4002ca 2020-03-21 stsp
281 0e4002ca 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
282 0e4002ca 2020-03-21 stsp
283 0e4002ca 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
284 0e4002ca 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
285 0e4002ca 2020-03-21 stsp echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
286 0e4002ca 2020-03-21 stsp >> $testroot/stdout.expected
287 0e4002ca 2020-03-21 stsp echo "refs/remotes/origin/master: $commit_id" \
288 0e4002ca 2020-03-21 stsp >> $testroot/stdout.expected
289 0e4002ca 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
290 0e4002ca 2020-03-21 stsp
291 0e4002ca 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
292 0e4002ca 2020-03-21 stsp ret="$?"
293 0e4002ca 2020-03-21 stsp if [ "$ret" != "0" ]; then
294 0e4002ca 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
295 0e4002ca 2020-03-21 stsp fi
296 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
297 0e4002ca 2020-03-21 stsp }
298 0e4002ca 2020-03-21 stsp
299 0e4002ca 2020-03-21 stsp function test_clone_branch_and_reference {
300 0e4002ca 2020-03-21 stsp local testroot=`test_init clone_reference`
301 0e4002ca 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
302 0e4002ca 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
303 0e4002ca 2020-03-21 stsp
304 0e4002ca 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
305 0e4002ca 2020-03-21 stsp got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
306 0e4002ca 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
307 0e4002ca 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
308 0e4002ca 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
309 0e4002ca 2020-03-21 stsp
310 0e4002ca 2020-03-21 stsp got clone -q -R hoo/boo/zoo -b foo $testurl/repo $testroot/repo-clone
311 0e4002ca 2020-03-21 stsp ret="$?"
312 0e4002ca 2020-03-21 stsp if [ "$ret" != "0" ]; then
313 0e4002ca 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
314 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
315 0e4002ca 2020-03-21 stsp return 1
316 0e4002ca 2020-03-21 stsp fi
317 0e4002ca 2020-03-21 stsp
318 0e4002ca 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
319 0e4002ca 2020-03-21 stsp
320 0e4002ca 2020-03-21 stsp echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
321 0e4002ca 2020-03-21 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
322 0e4002ca 2020-03-21 stsp echo "refs/remotes/origin/foo: $commit_id" \
323 0e4002ca 2020-03-21 stsp >> $testroot/stdout.expected
324 0e4002ca 2020-03-21 stsp echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
325 0e4002ca 2020-03-21 stsp >> $testroot/stdout.expected
326 0e4002ca 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
327 0e4002ca 2020-03-21 stsp
328 0e4002ca 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
329 0e4002ca 2020-03-21 stsp ret="$?"
330 0e4002ca 2020-03-21 stsp if [ "$ret" != "0" ]; then
331 0e4002ca 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
332 0e4002ca 2020-03-21 stsp fi
333 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
334 0e4002ca 2020-03-21 stsp }
335 0e4002ca 2020-03-21 stsp
336 0e4002ca 2020-03-21 stsp function test_clone_reference_mirror {
337 0e4002ca 2020-03-21 stsp local testroot=`test_init clone_reference_mirror`
338 0e4002ca 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
339 0e4002ca 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
340 0e4002ca 2020-03-21 stsp
341 0e4002ca 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
342 0e4002ca 2020-03-21 stsp got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
343 0e4002ca 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
344 0e4002ca 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
345 0e4002ca 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
346 0e4002ca 2020-03-21 stsp
347 0e4002ca 2020-03-21 stsp got clone -q -R hoo -m $testurl/repo $testroot/repo-clone
348 0e4002ca 2020-03-21 stsp ret="$?"
349 0e4002ca 2020-03-21 stsp if [ "$ret" != "0" ]; then
350 0e4002ca 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
351 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
352 0e4002ca 2020-03-21 stsp return 1
353 0e4002ca 2020-03-21 stsp fi
354 0e4002ca 2020-03-21 stsp
355 0e4002ca 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
356 0e4002ca 2020-03-21 stsp
357 0e4002ca 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
358 0e4002ca 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
359 0e4002ca 2020-03-21 stsp echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
360 0e4002ca 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
361 0e4002ca 2020-03-21 stsp
362 0e4002ca 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
363 0e4002ca 2020-03-21 stsp ret="$?"
364 0e4002ca 2020-03-21 stsp if [ "$ret" != "0" ]; then
365 0e4002ca 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
366 0e4002ca 2020-03-21 stsp fi
367 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
368 0e4002ca 2020-03-21 stsp }
369 0e4002ca 2020-03-21 stsp
370 c8c71e6e 2020-03-21 stsp run_test test_clone_basic
371 c8c71e6e 2020-03-21 stsp run_test test_clone_list
372 c8c71e6e 2020-03-21 stsp run_test test_clone_branch
373 c8c71e6e 2020-03-21 stsp run_test test_clone_all
374 c8c71e6e 2020-03-21 stsp run_test test_clone_mirror
375 c8c71e6e 2020-03-21 stsp run_test test_clone_mirror_all
376 0e4002ca 2020-03-21 stsp run_test test_clone_reference
377 0e4002ca 2020-03-21 stsp run_test test_clone_branch_and_reference
378 0e4002ca 2020-03-21 stsp run_test test_clone_reference_mirror