Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2020 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 . ./common.sh
19 function test_clone_basic {
20 local testroot=`test_init clone_basic`
21 local testurl=ssh://127.0.0.1/$testroot
22 local commit_id=`git_show_head $testroot/repo`
24 got clone -q $testurl/repo $testroot/repo-clone
25 ret="$?"
26 if [ "$ret" != "0" ]; then
27 echo "got clone command failed unexpectedly" >&2
28 test_done "$testroot" "$ret"
29 return 1
30 fi
32 got log -l0 -p -r $testroot/repo > $testroot/log-repo
33 if [ "$ret" != "0" ]; then
34 echo "got log command failed unexpectedly" >&2
35 test_done "$testroot" "$ret"
36 return 1
37 fi
38 got log -l0 -p -r $testroot/repo > $testroot/log-repo-clone
39 if [ "$ret" != "0" ]; then
40 echo "got log command failed unexpectedly" >&2
41 test_done "$testroot" "$ret"
42 return 1
43 fi
44 cmp -s $testroot/log-repo $testroot/log-repo-clone
45 ret="$?"
46 if [ "$ret" != "0" ]; then
47 echo "log -p output of cloned repository differs" >&2
48 test_done "$testroot" "$ret"
49 return 1
50 fi
52 got ref -l -r $testroot/repo > $testroot/stdout
53 if [ "$ret" != "0" ]; then
54 echo "got ref command failed unexpectedly" >&2
55 test_done "$testroot" "$ret"
56 return 1
57 fi
59 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
60 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
62 cmp -s $testroot/stdout $testroot/stdout.expected
63 ret="$?"
64 if [ "$ret" != "0" ]; then
65 diff -u $testroot/stdout.expected $testroot/stdout
66 test_done "$testroot" "$ret"
67 return 1
68 fi
70 got ref -l -r $testroot/repo-clone > $testroot/stdout
71 if [ "$ret" != "0" ]; then
72 echo "got ref command failed unexpectedly" >&2
73 test_done "$testroot" "$ret"
74 return 1
75 fi
77 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
78 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
79 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
80 >> $testroot/stdout.expected
81 echo "refs/remotes/origin/master: $commit_id" \
82 >> $testroot/stdout.expected
84 cmp -s $testroot/stdout $testroot/stdout.expected
85 ret="$?"
86 if [ "$ret" != "0" ]; then
87 diff -u $testroot/stdout.expected $testroot/stdout
88 fi
89 test_done "$testroot" "$ret"
90 }
92 function test_clone_list {
93 local testroot=`test_init clone_list`
94 local testurl=ssh://127.0.0.1/$testroot
95 local commit_id=`git_show_head $testroot/repo`
97 got branch -r $testroot/repo -c $commit_id foo
98 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
99 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
101 got clone -l $testurl/repo > $testroot/stdout 2>$testroot/stderr
102 ret="$?"
103 if [ "$ret" != "0" ]; then
104 echo "got clone command failed unexpectedly" >&2
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 echo "Connecting to 127.0.0.1" > $testroot/stdout.expected
110 got ref -l -r $testroot/repo >> $testroot/stdout.expected
112 cmp -s $testroot/stdout $testroot/stdout.expected
113 ret="$?"
114 if [ "$ret" != "0" ]; then
115 diff -u $testroot/stdout.expected $testroot/stdout
116 fi
117 test_done "$testroot" "$ret"
120 function test_clone_branch {
121 local testroot=`test_init clone_branch`
122 local testurl=ssh://127.0.0.1/$testroot
123 local commit_id=`git_show_head $testroot/repo`
125 got branch -r $testroot/repo -c $commit_id foo
126 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
127 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
128 local tag_id=`got ref -r $testroot/repo -l \
129 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
131 got clone -q -b foo $testurl/repo $testroot/repo-clone
132 ret="$?"
133 if [ "$ret" != "0" ]; then
134 echo "got clone command failed unexpectedly" >&2
135 test_done "$testroot" "$ret"
136 return 1
137 fi
139 got ref -l -r $testroot/repo-clone > $testroot/stdout
141 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
142 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
143 # refs/heads/master is missing because it wasn't passed via -b
144 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
145 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
146 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
148 cmp -s $testroot/stdout $testroot/stdout.expected
149 ret="$?"
150 if [ "$ret" != "0" ]; then
151 diff -u $testroot/stdout.expected $testroot/stdout
152 fi
153 test_done "$testroot" "$ret"
156 function test_clone_all {
157 local testroot=`test_init clone_all`
158 local testurl=ssh://127.0.0.1/$testroot
159 local commit_id=`git_show_head $testroot/repo`
161 got branch -r $testroot/repo -c $commit_id foo
162 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
163 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
164 local tag_id=`got ref -r $testroot/repo -l \
165 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
167 got clone -q -a $testurl/repo $testroot/repo-clone
168 ret="$?"
169 if [ "$ret" != "0" ]; then
170 echo "got clone command failed unexpectedly" >&2
171 test_done "$testroot" "$ret"
172 return 1
173 fi
175 got ref -l -r $testroot/repo-clone > $testroot/stdout
177 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
178 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
179 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
180 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
181 >> $testroot/stdout.expected
182 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
183 echo "refs/remotes/origin/master: $commit_id" \
184 >> $testroot/stdout.expected
185 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
186 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
188 cmp -s $testroot/stdout $testroot/stdout.expected
189 ret="$?"
190 if [ "$ret" != "0" ]; then
191 diff -u $testroot/stdout.expected $testroot/stdout
192 fi
193 test_done "$testroot" "$ret"
196 function test_clone_mirror {
197 local testroot=`test_init clone_mirror`
198 local testurl=ssh://127.0.0.1/$testroot
199 local commit_id=`git_show_head $testroot/repo`
201 got branch -r $testroot/repo -c $commit_id foo
202 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
203 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
204 local tag_id=`got ref -r $testroot/repo -l \
205 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
207 got clone -q -m $testurl/repo $testroot/repo-clone
208 ret="$?"
209 if [ "$ret" != "0" ]; then
210 echo "got clone command failed unexpectedly" >&2
211 test_done "$testroot" "$ret"
212 return 1
213 fi
215 got ref -l -r $testroot/repo-clone > $testroot/stdout
217 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
218 # refs/heads/foo is missing because we're not fetching all branches
219 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
220 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
221 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
223 cmp -s $testroot/stdout $testroot/stdout.expected
224 ret="$?"
225 if [ "$ret" != "0" ]; then
226 diff -u $testroot/stdout.expected $testroot/stdout
227 fi
228 test_done "$testroot" "$ret"
231 function test_clone_mirror_all {
232 local testroot=`test_init clone_mirror_all`
233 local testurl=ssh://127.0.0.1/$testroot
234 local commit_id=`git_show_head $testroot/repo`
236 got branch -r $testroot/repo -c $commit_id foo
237 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
238 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
239 local tag_id=`got ref -r $testroot/repo -l \
240 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
242 got clone -q -m -a $testurl/repo $testroot/repo-clone
243 ret="$?"
244 if [ "$ret" != "0" ]; then
245 echo "got clone command failed unexpectedly" >&2
246 test_done "$testroot" "$ret"
247 return 1
248 fi
250 got ref -l -r $testroot/repo-clone > $testroot/stdout
252 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
253 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
254 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
255 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
256 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
258 cmp -s $testroot/stdout $testroot/stdout.expected
259 ret="$?"
260 if [ "$ret" != "0" ]; then
261 diff -u $testroot/stdout.expected $testroot/stdout
262 fi
263 test_done "$testroot" "$ret"
266 function test_clone_reference {
267 local testroot=`test_init clone_reference`
268 local testurl=ssh://127.0.0.1/$testroot
269 local commit_id=`git_show_head $testroot/repo`
271 got branch -r $testroot/repo -c $commit_id foo
272 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
273 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
274 local tag_id=`got ref -r $testroot/repo -l \
275 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
277 got clone -q -R hoo $testurl/repo $testroot/repo-clone
278 ret="$?"
279 if [ "$ret" != "0" ]; then
280 echo "got clone command failed unexpectedly" >&2
281 test_done "$testroot" "$ret"
282 return 1
283 fi
285 got ref -l -r $testroot/repo-clone > $testroot/stdout
287 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
288 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
289 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
290 >> $testroot/stdout.expected
291 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
292 >> $testroot/stdout.expected
293 echo "refs/remotes/origin/master: $commit_id" \
294 >> $testroot/stdout.expected
295 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
297 cmp -s $testroot/stdout $testroot/stdout.expected
298 ret="$?"
299 if [ "$ret" != "0" ]; then
300 diff -u $testroot/stdout.expected $testroot/stdout
301 fi
302 test_done "$testroot" "$ret"
305 function test_clone_branch_and_reference {
306 local testroot=`test_init clone_reference`
307 local testurl=ssh://127.0.0.1/$testroot
308 local commit_id=`git_show_head $testroot/repo`
310 got branch -r $testroot/repo -c $commit_id foo
311 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
312 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
313 local tag_id=`got ref -r $testroot/repo -l \
314 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
316 got clone -q -R hoo/boo/zoo -b foo $testurl/repo $testroot/repo-clone
317 ret="$?"
318 if [ "$ret" != "0" ]; then
319 echo "got clone command failed unexpectedly" >&2
320 test_done "$testroot" "$ret"
321 return 1
322 fi
324 got ref -l -r $testroot/repo-clone > $testroot/stdout
326 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
327 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
328 echo "refs/remotes/origin/foo: $commit_id" \
329 >> $testroot/stdout.expected
330 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
331 >> $testroot/stdout.expected
332 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
334 cmp -s $testroot/stdout $testroot/stdout.expected
335 ret="$?"
336 if [ "$ret" != "0" ]; then
337 diff -u $testroot/stdout.expected $testroot/stdout
338 fi
339 test_done "$testroot" "$ret"
342 function test_clone_reference_mirror {
343 local testroot=`test_init clone_reference_mirror`
344 local testurl=ssh://127.0.0.1/$testroot
345 local commit_id=`git_show_head $testroot/repo`
347 got branch -r $testroot/repo -c $commit_id foo
348 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
349 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
350 local tag_id=`got ref -r $testroot/repo -l \
351 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
353 got clone -q -R hoo -m $testurl/repo $testroot/repo-clone
354 ret="$?"
355 if [ "$ret" != "0" ]; then
356 echo "got clone command failed unexpectedly" >&2
357 test_done "$testroot" "$ret"
358 return 1
359 fi
361 got ref -l -r $testroot/repo-clone > $testroot/stdout
363 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
364 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
365 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
366 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
368 cmp -s $testroot/stdout $testroot/stdout.expected
369 ret="$?"
370 if [ "$ret" != "0" ]; then
371 diff -u $testroot/stdout.expected $testroot/stdout
372 fi
373 test_done "$testroot" "$ret"
376 run_test test_clone_basic
377 run_test test_clone_list
378 run_test test_clone_branch
379 run_test test_clone_all
380 run_test test_clone_mirror
381 run_test test_clone_mirror_all
382 run_test test_clone_reference
383 run_test test_clone_branch_and_reference
384 run_test test_clone_reference_mirror