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 f6cae3ed 2020-09-13 naddy 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 f298ae0f 2020-03-25 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
80 f298ae0f 2020-03-25 stsp >> $testroot/stdout.expected
81 c8c71e6e 2020-03-21 stsp echo "refs/remotes/origin/master: $commit_id" \
82 c8c71e6e 2020-03-21 stsp >> $testroot/stdout.expected
83 c8c71e6e 2020-03-21 stsp
84 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
85 c8c71e6e 2020-03-21 stsp ret="$?"
86 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
87 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
88 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
89 a9c2d4c2 2020-09-24 stsp return 1
90 c8c71e6e 2020-03-21 stsp fi
91 a9c2d4c2 2020-09-24 stsp
92 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
93 a9c2d4c2 2020-09-24 stsp remote "origin" {
94 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
95 a9c2d4c2 2020-09-24 stsp protocol ssh
96 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
97 15d3c221 2021-01-05 stsp branch { "master" }
98 a9c2d4c2 2020-09-24 stsp }
99 a9c2d4c2 2020-09-24 stsp EOF
100 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
101 a9c2d4c2 2020-09-24 stsp ret="$?"
102 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
103 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
104 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
105 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
106 a9c2d4c2 2020-09-24 stsp return 1
107 a9c2d4c2 2020-09-24 stsp fi
108 a9c2d4c2 2020-09-24 stsp
109 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
110 a9c2d4c2 2020-09-24 stsp [core]
111 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
112 a9c2d4c2 2020-09-24 stsp filemode = true
113 a9c2d4c2 2020-09-24 stsp bare = true
114 a9c2d4c2 2020-09-24 stsp
115 a9c2d4c2 2020-09-24 stsp [remote "origin"]
116 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
117 a9c2d4c2 2020-09-24 stsp fetch = +refs/heads/master:refs/remotes/origin/master
118 a9c2d4c2 2020-09-24 stsp EOF
119 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
120 a9c2d4c2 2020-09-24 stsp ret="$?"
121 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
122 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
123 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
124 a9c2d4c2 2020-09-24 stsp fi
125 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
126 c8c71e6e 2020-03-21 stsp }
127 c8c71e6e 2020-03-21 stsp
128 f6cae3ed 2020-09-13 naddy test_clone_list() {
129 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_list`
130 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
131 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
132 c8c71e6e 2020-03-21 stsp
133 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
134 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
135 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
136 c8c71e6e 2020-03-21 stsp
137 c8c71e6e 2020-03-21 stsp got clone -l $testurl/repo > $testroot/stdout 2>$testroot/stderr
138 c8c71e6e 2020-03-21 stsp ret="$?"
139 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
140 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
141 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
142 c8c71e6e 2020-03-21 stsp return 1
143 c8c71e6e 2020-03-21 stsp fi
144 c8c71e6e 2020-03-21 stsp
145 d7c4e80d 2020-04-19 stsp echo "Connecting to 127.0.0.1" > $testroot/stdout.expected
146 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo >> $testroot/stdout.expected
147 c8c71e6e 2020-03-21 stsp
148 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
149 c8c71e6e 2020-03-21 stsp ret="$?"
150 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
151 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
152 c8c71e6e 2020-03-21 stsp fi
153 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
154 c8c71e6e 2020-03-21 stsp }
155 c8c71e6e 2020-03-21 stsp
156 f6cae3ed 2020-09-13 naddy test_clone_branch() {
157 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_branch`
158 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
159 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
160 c8c71e6e 2020-03-21 stsp
161 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
162 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
163 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
164 c8c71e6e 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
165 c8c71e6e 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
166 c8c71e6e 2020-03-21 stsp
167 c8c71e6e 2020-03-21 stsp got clone -q -b foo $testurl/repo $testroot/repo-clone
168 c8c71e6e 2020-03-21 stsp ret="$?"
169 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
170 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
171 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
172 c8c71e6e 2020-03-21 stsp return 1
173 c8c71e6e 2020-03-21 stsp fi
174 c8c71e6e 2020-03-21 stsp
175 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
176 c8c71e6e 2020-03-21 stsp
177 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
178 c8c71e6e 2020-03-21 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
179 c8c71e6e 2020-03-21 stsp # refs/heads/master is missing because it wasn't passed via -b
180 c8c71e6e 2020-03-21 stsp echo "refs/remotes/origin/foo: $commit_id" >> $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 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
189 a9c2d4c2 2020-09-24 stsp return 1
190 c8c71e6e 2020-03-21 stsp fi
191 a9c2d4c2 2020-09-24 stsp
192 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
193 a9c2d4c2 2020-09-24 stsp remote "origin" {
194 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
195 a9c2d4c2 2020-09-24 stsp protocol ssh
196 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
197 15d3c221 2021-01-05 stsp branch { "foo" }
198 a9c2d4c2 2020-09-24 stsp }
199 a9c2d4c2 2020-09-24 stsp EOF
200 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
201 a9c2d4c2 2020-09-24 stsp ret="$?"
202 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
203 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
204 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
205 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
206 a9c2d4c2 2020-09-24 stsp return 1
207 a9c2d4c2 2020-09-24 stsp fi
208 a9c2d4c2 2020-09-24 stsp
209 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
210 a9c2d4c2 2020-09-24 stsp [core]
211 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
212 a9c2d4c2 2020-09-24 stsp filemode = true
213 a9c2d4c2 2020-09-24 stsp bare = true
214 a9c2d4c2 2020-09-24 stsp
215 a9c2d4c2 2020-09-24 stsp [remote "origin"]
216 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
217 a9c2d4c2 2020-09-24 stsp fetch = +refs/heads/foo:refs/remotes/origin/foo
218 a9c2d4c2 2020-09-24 stsp EOF
219 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
220 a9c2d4c2 2020-09-24 stsp ret="$?"
221 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
222 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
223 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
224 a9c2d4c2 2020-09-24 stsp fi
225 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
226 c8c71e6e 2020-03-21 stsp }
227 c8c71e6e 2020-03-21 stsp
228 f6cae3ed 2020-09-13 naddy test_clone_all() {
229 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_all`
230 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
231 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
232 c8c71e6e 2020-03-21 stsp
233 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
234 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
235 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
236 c8c71e6e 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
237 c8c71e6e 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
238 c8c71e6e 2020-03-21 stsp
239 c8c71e6e 2020-03-21 stsp got clone -q -a $testurl/repo $testroot/repo-clone
240 c8c71e6e 2020-03-21 stsp ret="$?"
241 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
242 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
243 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
244 c8c71e6e 2020-03-21 stsp return 1
245 c8c71e6e 2020-03-21 stsp fi
246 c8c71e6e 2020-03-21 stsp
247 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
248 c8c71e6e 2020-03-21 stsp
249 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
250 c8c71e6e 2020-03-21 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
251 c8c71e6e 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
252 f298ae0f 2020-03-25 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
253 f298ae0f 2020-03-25 stsp >> $testroot/stdout.expected
254 c8c71e6e 2020-03-21 stsp echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
255 c8c71e6e 2020-03-21 stsp echo "refs/remotes/origin/master: $commit_id" \
256 c8c71e6e 2020-03-21 stsp >> $testroot/stdout.expected
257 c8c71e6e 2020-03-21 stsp # refs/hoo/boo/zoo is missing because it is outside of refs/heads
258 c8c71e6e 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
259 c8c71e6e 2020-03-21 stsp
260 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
261 c8c71e6e 2020-03-21 stsp ret="$?"
262 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
263 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
264 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
265 a9c2d4c2 2020-09-24 stsp return 1
266 c8c71e6e 2020-03-21 stsp fi
267 a9c2d4c2 2020-09-24 stsp
268 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
269 a9c2d4c2 2020-09-24 stsp remote "origin" {
270 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
271 a9c2d4c2 2020-09-24 stsp protocol ssh
272 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
273 15d3c221 2021-01-05 stsp branch { "master" }
274 a9c2d4c2 2020-09-24 stsp }
275 a9c2d4c2 2020-09-24 stsp EOF
276 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
277 a9c2d4c2 2020-09-24 stsp ret="$?"
278 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
279 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
280 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
281 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
282 a9c2d4c2 2020-09-24 stsp return 1
283 a9c2d4c2 2020-09-24 stsp fi
284 a9c2d4c2 2020-09-24 stsp
285 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
286 a9c2d4c2 2020-09-24 stsp [core]
287 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
288 a9c2d4c2 2020-09-24 stsp filemode = true
289 a9c2d4c2 2020-09-24 stsp bare = true
290 a9c2d4c2 2020-09-24 stsp
291 a9c2d4c2 2020-09-24 stsp [remote "origin"]
292 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
293 a9c2d4c2 2020-09-24 stsp fetch = +refs/heads/*:refs/remotes/origin/*
294 a9c2d4c2 2020-09-24 stsp EOF
295 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
296 a9c2d4c2 2020-09-24 stsp ret="$?"
297 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
298 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
299 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
300 a9c2d4c2 2020-09-24 stsp fi
301 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
302 c8c71e6e 2020-03-21 stsp }
303 c8c71e6e 2020-03-21 stsp
304 f6cae3ed 2020-09-13 naddy test_clone_mirror() {
305 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_mirror`
306 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
307 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
308 c8c71e6e 2020-03-21 stsp
309 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
310 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
311 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
312 c8c71e6e 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
313 c8c71e6e 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
314 c8c71e6e 2020-03-21 stsp
315 c8c71e6e 2020-03-21 stsp got clone -q -m $testurl/repo $testroot/repo-clone
316 c8c71e6e 2020-03-21 stsp ret="$?"
317 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
318 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
319 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
320 c8c71e6e 2020-03-21 stsp return 1
321 c8c71e6e 2020-03-21 stsp fi
322 c8c71e6e 2020-03-21 stsp
323 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
324 c8c71e6e 2020-03-21 stsp
325 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
326 c8c71e6e 2020-03-21 stsp # refs/heads/foo is missing because we're not fetching all branches
327 c8c71e6e 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
328 c8c71e6e 2020-03-21 stsp # refs/hoo/boo/zoo is missing because it is outside of refs/heads
329 c8c71e6e 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
330 c8c71e6e 2020-03-21 stsp
331 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
332 c8c71e6e 2020-03-21 stsp ret="$?"
333 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
334 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
335 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
336 a9c2d4c2 2020-09-24 stsp return 1
337 c8c71e6e 2020-03-21 stsp fi
338 a9c2d4c2 2020-09-24 stsp
339 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
340 a9c2d4c2 2020-09-24 stsp remote "origin" {
341 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
342 a9c2d4c2 2020-09-24 stsp protocol ssh
343 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
344 15d3c221 2021-01-05 stsp branch { "master" }
345 a9c2d4c2 2020-09-24 stsp mirror-references yes
346 a9c2d4c2 2020-09-24 stsp }
347 a9c2d4c2 2020-09-24 stsp EOF
348 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
349 a9c2d4c2 2020-09-24 stsp ret="$?"
350 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
351 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
352 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
353 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
354 a9c2d4c2 2020-09-24 stsp return 1
355 a9c2d4c2 2020-09-24 stsp fi
356 a9c2d4c2 2020-09-24 stsp
357 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
358 a9c2d4c2 2020-09-24 stsp [core]
359 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
360 a9c2d4c2 2020-09-24 stsp filemode = true
361 a9c2d4c2 2020-09-24 stsp bare = true
362 a9c2d4c2 2020-09-24 stsp
363 a9c2d4c2 2020-09-24 stsp [remote "origin"]
364 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
365 a9c2d4c2 2020-09-24 stsp fetch = +refs/*:refs/*
366 a9c2d4c2 2020-09-24 stsp mirror = true
367 a9c2d4c2 2020-09-24 stsp EOF
368 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
369 a9c2d4c2 2020-09-24 stsp ret="$?"
370 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
371 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
372 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
373 a9c2d4c2 2020-09-24 stsp fi
374 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
375 c8c71e6e 2020-03-21 stsp }
376 c8c71e6e 2020-03-21 stsp
377 f6cae3ed 2020-09-13 naddy test_clone_mirror_all() {
378 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_mirror_all`
379 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
380 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
381 c8c71e6e 2020-03-21 stsp
382 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
383 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
384 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
385 c8c71e6e 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
386 c8c71e6e 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
387 c8c71e6e 2020-03-21 stsp
388 c8c71e6e 2020-03-21 stsp got clone -q -m -a $testurl/repo $testroot/repo-clone
389 c8c71e6e 2020-03-21 stsp ret="$?"
390 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
391 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
392 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
393 c8c71e6e 2020-03-21 stsp return 1
394 c8c71e6e 2020-03-21 stsp fi
395 c8c71e6e 2020-03-21 stsp
396 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
397 c8c71e6e 2020-03-21 stsp
398 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
399 c8c71e6e 2020-03-21 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
400 c8c71e6e 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
401 c8c71e6e 2020-03-21 stsp # refs/hoo/boo/zoo is missing because it is outside of refs/heads
402 c8c71e6e 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
403 c8c71e6e 2020-03-21 stsp
404 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
405 c8c71e6e 2020-03-21 stsp ret="$?"
406 c8c71e6e 2020-03-21 stsp if [ "$ret" != "0" ]; then
407 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
408 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
409 a9c2d4c2 2020-09-24 stsp return 1
410 c8c71e6e 2020-03-21 stsp fi
411 a9c2d4c2 2020-09-24 stsp
412 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
413 a9c2d4c2 2020-09-24 stsp remote "origin" {
414 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
415 a9c2d4c2 2020-09-24 stsp protocol ssh
416 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
417 15d3c221 2021-01-05 stsp branch { "master" }
418 a9c2d4c2 2020-09-24 stsp mirror-references yes
419 a9c2d4c2 2020-09-24 stsp }
420 a9c2d4c2 2020-09-24 stsp EOF
421 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
422 a9c2d4c2 2020-09-24 stsp ret="$?"
423 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
424 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
425 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
426 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
427 a9c2d4c2 2020-09-24 stsp return 1
428 a9c2d4c2 2020-09-24 stsp fi
429 a9c2d4c2 2020-09-24 stsp
430 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
431 a9c2d4c2 2020-09-24 stsp [core]
432 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
433 a9c2d4c2 2020-09-24 stsp filemode = true
434 a9c2d4c2 2020-09-24 stsp bare = true
435 a9c2d4c2 2020-09-24 stsp
436 a9c2d4c2 2020-09-24 stsp [remote "origin"]
437 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
438 a9c2d4c2 2020-09-24 stsp fetch = +refs/*:refs/*
439 a9c2d4c2 2020-09-24 stsp mirror = true
440 a9c2d4c2 2020-09-24 stsp EOF
441 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
442 a9c2d4c2 2020-09-24 stsp ret="$?"
443 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
444 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
445 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
446 a9c2d4c2 2020-09-24 stsp fi
447 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
448 c8c71e6e 2020-03-21 stsp }
449 0e4002ca 2020-03-21 stsp
450 f6cae3ed 2020-09-13 naddy test_clone_reference() {
451 0e4002ca 2020-03-21 stsp local testroot=`test_init clone_reference`
452 0e4002ca 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
453 0e4002ca 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
454 c8c71e6e 2020-03-21 stsp
455 0e4002ca 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
456 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
457 0e4002ca 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
458 0e4002ca 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
459 0e4002ca 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
460 0e4002ca 2020-03-21 stsp
461 0e4002ca 2020-03-21 stsp got clone -q -R hoo $testurl/repo $testroot/repo-clone
462 0e4002ca 2020-03-21 stsp ret="$?"
463 0e4002ca 2020-03-21 stsp if [ "$ret" != "0" ]; then
464 0e4002ca 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
465 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
466 0e4002ca 2020-03-21 stsp return 1
467 0e4002ca 2020-03-21 stsp fi
468 0e4002ca 2020-03-21 stsp
469 0e4002ca 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
470 0e4002ca 2020-03-21 stsp
471 0e4002ca 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
472 0e4002ca 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
473 f298ae0f 2020-03-25 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
474 f298ae0f 2020-03-25 stsp >> $testroot/stdout.expected
475 0e4002ca 2020-03-21 stsp echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
476 0e4002ca 2020-03-21 stsp >> $testroot/stdout.expected
477 0e4002ca 2020-03-21 stsp echo "refs/remotes/origin/master: $commit_id" \
478 0e4002ca 2020-03-21 stsp >> $testroot/stdout.expected
479 0e4002ca 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
480 0e4002ca 2020-03-21 stsp
481 0e4002ca 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
482 0e4002ca 2020-03-21 stsp ret="$?"
483 0e4002ca 2020-03-21 stsp if [ "$ret" != "0" ]; then
484 0e4002ca 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
485 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
486 a9c2d4c2 2020-09-24 stsp return 1
487 0e4002ca 2020-03-21 stsp fi
488 a9c2d4c2 2020-09-24 stsp
489 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
490 a9c2d4c2 2020-09-24 stsp remote "origin" {
491 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
492 a9c2d4c2 2020-09-24 stsp protocol ssh
493 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
494 15d3c221 2021-01-05 stsp branch { "master" }
495 a9c2d4c2 2020-09-24 stsp }
496 a9c2d4c2 2020-09-24 stsp EOF
497 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
498 a9c2d4c2 2020-09-24 stsp ret="$?"
499 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
500 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
501 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
502 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
503 a9c2d4c2 2020-09-24 stsp return 1
504 a9c2d4c2 2020-09-24 stsp fi
505 a9c2d4c2 2020-09-24 stsp
506 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
507 a9c2d4c2 2020-09-24 stsp [core]
508 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
509 a9c2d4c2 2020-09-24 stsp filemode = true
510 a9c2d4c2 2020-09-24 stsp bare = true
511 a9c2d4c2 2020-09-24 stsp
512 a9c2d4c2 2020-09-24 stsp [remote "origin"]
513 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
514 a9c2d4c2 2020-09-24 stsp fetch = +refs/heads/master:refs/remotes/origin/master
515 a9c2d4c2 2020-09-24 stsp EOF
516 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
517 a9c2d4c2 2020-09-24 stsp ret="$?"
518 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
519 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
520 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
521 a9c2d4c2 2020-09-24 stsp fi
522 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
523 0e4002ca 2020-03-21 stsp }
524 0e4002ca 2020-03-21 stsp
525 f6cae3ed 2020-09-13 naddy test_clone_branch_and_reference() {
526 0e4002ca 2020-03-21 stsp local testroot=`test_init clone_reference`
527 0e4002ca 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
528 0e4002ca 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
529 0e4002ca 2020-03-21 stsp
530 0e4002ca 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
531 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
532 0e4002ca 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
533 0e4002ca 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
534 0e4002ca 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
535 0e4002ca 2020-03-21 stsp
536 0e4002ca 2020-03-21 stsp got clone -q -R hoo/boo/zoo -b foo $testurl/repo $testroot/repo-clone
537 0e4002ca 2020-03-21 stsp ret="$?"
538 0e4002ca 2020-03-21 stsp if [ "$ret" != "0" ]; then
539 0e4002ca 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
540 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
541 0e4002ca 2020-03-21 stsp return 1
542 0e4002ca 2020-03-21 stsp fi
543 0e4002ca 2020-03-21 stsp
544 0e4002ca 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
545 0e4002ca 2020-03-21 stsp
546 0e4002ca 2020-03-21 stsp echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
547 0e4002ca 2020-03-21 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
548 0e4002ca 2020-03-21 stsp echo "refs/remotes/origin/foo: $commit_id" \
549 0e4002ca 2020-03-21 stsp >> $testroot/stdout.expected
550 0e4002ca 2020-03-21 stsp echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
551 0e4002ca 2020-03-21 stsp >> $testroot/stdout.expected
552 0e4002ca 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
553 0e4002ca 2020-03-21 stsp
554 0e4002ca 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
555 0e4002ca 2020-03-21 stsp ret="$?"
556 0e4002ca 2020-03-21 stsp if [ "$ret" != "0" ]; then
557 0e4002ca 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
558 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
559 a9c2d4c2 2020-09-24 stsp return 1
560 0e4002ca 2020-03-21 stsp fi
561 a9c2d4c2 2020-09-24 stsp
562 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
563 a9c2d4c2 2020-09-24 stsp remote "origin" {
564 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
565 a9c2d4c2 2020-09-24 stsp protocol ssh
566 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
567 15d3c221 2021-01-05 stsp branch { "foo" }
568 a9c2d4c2 2020-09-24 stsp }
569 a9c2d4c2 2020-09-24 stsp EOF
570 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
571 a9c2d4c2 2020-09-24 stsp ret="$?"
572 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
573 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
574 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
575 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
576 a9c2d4c2 2020-09-24 stsp return 1
577 a9c2d4c2 2020-09-24 stsp fi
578 a9c2d4c2 2020-09-24 stsp
579 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
580 a9c2d4c2 2020-09-24 stsp [core]
581 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
582 a9c2d4c2 2020-09-24 stsp filemode = true
583 a9c2d4c2 2020-09-24 stsp bare = true
584 a9c2d4c2 2020-09-24 stsp
585 a9c2d4c2 2020-09-24 stsp [remote "origin"]
586 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
587 a9c2d4c2 2020-09-24 stsp fetch = +refs/heads/foo:refs/remotes/origin/foo
588 a9c2d4c2 2020-09-24 stsp EOF
589 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
590 a9c2d4c2 2020-09-24 stsp ret="$?"
591 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
592 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
593 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
594 a9c2d4c2 2020-09-24 stsp fi
595 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
596 0e4002ca 2020-03-21 stsp }
597 0e4002ca 2020-03-21 stsp
598 f6cae3ed 2020-09-13 naddy test_clone_reference_mirror() {
599 0e4002ca 2020-03-21 stsp local testroot=`test_init clone_reference_mirror`
600 0e4002ca 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
601 0e4002ca 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
602 0e4002ca 2020-03-21 stsp
603 0e4002ca 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
604 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
605 0e4002ca 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
606 0e4002ca 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
607 0e4002ca 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
608 0e4002ca 2020-03-21 stsp
609 0e4002ca 2020-03-21 stsp got clone -q -R hoo -m $testurl/repo $testroot/repo-clone
610 0e4002ca 2020-03-21 stsp ret="$?"
611 0e4002ca 2020-03-21 stsp if [ "$ret" != "0" ]; then
612 0e4002ca 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
613 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
614 0e4002ca 2020-03-21 stsp return 1
615 0e4002ca 2020-03-21 stsp fi
616 0e4002ca 2020-03-21 stsp
617 0e4002ca 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
618 0e4002ca 2020-03-21 stsp
619 0e4002ca 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
620 0e4002ca 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
621 0e4002ca 2020-03-21 stsp echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
622 0e4002ca 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
623 0e4002ca 2020-03-21 stsp
624 0e4002ca 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
625 0e4002ca 2020-03-21 stsp ret="$?"
626 0e4002ca 2020-03-21 stsp if [ "$ret" != "0" ]; then
627 0e4002ca 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
628 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
629 a9c2d4c2 2020-09-24 stsp return 1
630 0e4002ca 2020-03-21 stsp fi
631 a9c2d4c2 2020-09-24 stsp
632 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
633 a9c2d4c2 2020-09-24 stsp remote "origin" {
634 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
635 a9c2d4c2 2020-09-24 stsp protocol ssh
636 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
637 15d3c221 2021-01-05 stsp branch { "master" }
638 a9c2d4c2 2020-09-24 stsp mirror-references yes
639 a9c2d4c2 2020-09-24 stsp }
640 a9c2d4c2 2020-09-24 stsp EOF
641 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
642 a9c2d4c2 2020-09-24 stsp ret="$?"
643 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
644 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
645 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
646 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
647 a9c2d4c2 2020-09-24 stsp return 1
648 a9c2d4c2 2020-09-24 stsp fi
649 a9c2d4c2 2020-09-24 stsp
650 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
651 a9c2d4c2 2020-09-24 stsp [core]
652 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
653 a9c2d4c2 2020-09-24 stsp filemode = true
654 a9c2d4c2 2020-09-24 stsp bare = true
655 a9c2d4c2 2020-09-24 stsp
656 a9c2d4c2 2020-09-24 stsp [remote "origin"]
657 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
658 a9c2d4c2 2020-09-24 stsp fetch = +refs/*:refs/*
659 a9c2d4c2 2020-09-24 stsp mirror = true
660 a9c2d4c2 2020-09-24 stsp EOF
661 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
662 a9c2d4c2 2020-09-24 stsp ret="$?"
663 a9c2d4c2 2020-09-24 stsp if [ "$ret" != "0" ]; then
664 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
665 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
666 a9c2d4c2 2020-09-24 stsp fi
667 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
668 0e4002ca 2020-03-21 stsp }
669 0e4002ca 2020-03-21 stsp
670 7fb414ae 2020-08-08 stsp test_parseargs "$@"
671 c8c71e6e 2020-03-21 stsp run_test test_clone_basic
672 c8c71e6e 2020-03-21 stsp run_test test_clone_list
673 c8c71e6e 2020-03-21 stsp run_test test_clone_branch
674 c8c71e6e 2020-03-21 stsp run_test test_clone_all
675 c8c71e6e 2020-03-21 stsp run_test test_clone_mirror
676 c8c71e6e 2020-03-21 stsp run_test test_clone_mirror_all
677 0e4002ca 2020-03-21 stsp run_test test_clone_reference
678 0e4002ca 2020-03-21 stsp run_test test_clone_branch_and_reference
679 0e4002ca 2020-03-21 stsp run_test test_clone_reference_mirror