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 49c543a6 2022-03-31 naddy ret=$?
26 49c543a6 2022-03-31 naddy if [ $ret -ne 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 84246752 2022-06-03 op ret=$?
34 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
35 c8c71e6e 2020-03-21 stsp echo "got log command failed unexpectedly" >&2
36 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
37 c8c71e6e 2020-03-21 stsp return 1
38 c8c71e6e 2020-03-21 stsp fi
39 8c9ae19c 2023-03-10 op got log -l0 -p -r $testroot/repo-clone | \
40 8c9ae19c 2023-03-10 op sed 's@master, origin/master@master@g' \
41 8c9ae19c 2023-03-10 op > $testroot/log-repo-clone
42 8c9ae19c 2023-03-10 op
43 c8c71e6e 2020-03-21 stsp cmp -s $testroot/log-repo $testroot/log-repo-clone
44 49c543a6 2022-03-31 naddy ret=$?
45 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
46 c8c71e6e 2020-03-21 stsp echo "log -p output of cloned repository differs" >&2
47 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
48 c8c71e6e 2020-03-21 stsp return 1
49 c8c71e6e 2020-03-21 stsp fi
50 c8c71e6e 2020-03-21 stsp
51 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo > $testroot/stdout
52 84246752 2022-06-03 op ret=$?
53 49c543a6 2022-03-31 naddy if [ $ret -ne 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 49c543a6 2022-03-31 naddy ret=$?
64 49c543a6 2022-03-31 naddy if [ $ret -ne 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 84246752 2022-06-03 op ret=$?
72 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
73 c8c71e6e 2020-03-21 stsp echo "got ref command failed unexpectedly" >&2
74 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
75 c8c71e6e 2020-03-21 stsp return 1
76 c8c71e6e 2020-03-21 stsp fi
77 c8c71e6e 2020-03-21 stsp
78 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
79 c8c71e6e 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
80 f298ae0f 2020-03-25 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
81 f298ae0f 2020-03-25 stsp >> $testroot/stdout.expected
82 c8c71e6e 2020-03-21 stsp echo "refs/remotes/origin/master: $commit_id" \
83 c8c71e6e 2020-03-21 stsp >> $testroot/stdout.expected
84 c8c71e6e 2020-03-21 stsp
85 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
86 49c543a6 2022-03-31 naddy ret=$?
87 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
88 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
89 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
90 a9c2d4c2 2020-09-24 stsp return 1
91 c8c71e6e 2020-03-21 stsp fi
92 a9c2d4c2 2020-09-24 stsp
93 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
94 a9c2d4c2 2020-09-24 stsp remote "origin" {
95 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
96 a9c2d4c2 2020-09-24 stsp protocol ssh
97 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
98 15d3c221 2021-01-05 stsp branch { "master" }
99 a9c2d4c2 2020-09-24 stsp }
100 a9c2d4c2 2020-09-24 stsp EOF
101 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
102 49c543a6 2022-03-31 naddy ret=$?
103 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
104 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
105 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
106 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
107 a9c2d4c2 2020-09-24 stsp return 1
108 a9c2d4c2 2020-09-24 stsp fi
109 a9c2d4c2 2020-09-24 stsp
110 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
111 a9c2d4c2 2020-09-24 stsp [core]
112 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
113 a9c2d4c2 2020-09-24 stsp filemode = true
114 a9c2d4c2 2020-09-24 stsp bare = true
115 a9c2d4c2 2020-09-24 stsp
116 a9c2d4c2 2020-09-24 stsp [remote "origin"]
117 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
118 56d0a753 2021-01-20 stsp fetch = refs/heads/master:refs/remotes/origin/master
119 56d0a753 2021-01-20 stsp fetch = refs/tags/*:refs/tags/*
120 a9c2d4c2 2020-09-24 stsp EOF
121 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
122 49c543a6 2022-03-31 naddy ret=$?
123 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
124 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
125 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
126 a9c2d4c2 2020-09-24 stsp fi
127 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
128 c8c71e6e 2020-03-21 stsp }
129 c8c71e6e 2020-03-21 stsp
130 f6cae3ed 2020-09-13 naddy test_clone_list() {
131 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_list`
132 0deb9607 2022-11-18 op local testurl=ssh://127.0.0.1$testroot
133 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
134 c8c71e6e 2020-03-21 stsp
135 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
136 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
137 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
138 c8c71e6e 2020-03-21 stsp
139 c8c71e6e 2020-03-21 stsp got clone -l $testurl/repo > $testroot/stdout 2>$testroot/stderr
140 49c543a6 2022-03-31 naddy ret=$?
141 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
142 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
143 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
144 c8c71e6e 2020-03-21 stsp return 1
145 c8c71e6e 2020-03-21 stsp fi
146 c8c71e6e 2020-03-21 stsp
147 0deb9607 2022-11-18 op echo "Connecting to $testurl/repo" > $testroot/stdout.expected
148 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo >> $testroot/stdout.expected
149 c8c71e6e 2020-03-21 stsp
150 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
151 49c543a6 2022-03-31 naddy ret=$?
152 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
153 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
154 c8c71e6e 2020-03-21 stsp fi
155 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
156 c8c71e6e 2020-03-21 stsp }
157 c8c71e6e 2020-03-21 stsp
158 f6cae3ed 2020-09-13 naddy test_clone_branch() {
159 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_branch`
160 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
161 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
162 c8c71e6e 2020-03-21 stsp
163 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
164 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
165 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
166 c8c71e6e 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
167 c8c71e6e 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
168 c8c71e6e 2020-03-21 stsp
169 c8c71e6e 2020-03-21 stsp got clone -q -b foo $testurl/repo $testroot/repo-clone
170 49c543a6 2022-03-31 naddy ret=$?
171 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
172 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
173 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
174 c8c71e6e 2020-03-21 stsp return 1
175 c8c71e6e 2020-03-21 stsp fi
176 c8c71e6e 2020-03-21 stsp
177 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
178 c8c71e6e 2020-03-21 stsp
179 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
180 c8c71e6e 2020-03-21 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
181 c8c71e6e 2020-03-21 stsp # refs/heads/master is missing because it wasn't passed via -b
182 c8c71e6e 2020-03-21 stsp echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
183 c8c71e6e 2020-03-21 stsp # refs/hoo/boo/zoo is missing because it is outside of refs/heads
184 c8c71e6e 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
185 c8c71e6e 2020-03-21 stsp
186 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
187 49c543a6 2022-03-31 naddy ret=$?
188 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
189 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
190 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
191 a9c2d4c2 2020-09-24 stsp return 1
192 c8c71e6e 2020-03-21 stsp fi
193 a9c2d4c2 2020-09-24 stsp
194 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
195 a9c2d4c2 2020-09-24 stsp remote "origin" {
196 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
197 a9c2d4c2 2020-09-24 stsp protocol ssh
198 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
199 15d3c221 2021-01-05 stsp branch { "foo" }
200 a9c2d4c2 2020-09-24 stsp }
201 a9c2d4c2 2020-09-24 stsp EOF
202 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
203 49c543a6 2022-03-31 naddy ret=$?
204 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
205 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
206 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
207 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
208 a9c2d4c2 2020-09-24 stsp return 1
209 a9c2d4c2 2020-09-24 stsp fi
210 a9c2d4c2 2020-09-24 stsp
211 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
212 a9c2d4c2 2020-09-24 stsp [core]
213 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
214 a9c2d4c2 2020-09-24 stsp filemode = true
215 a9c2d4c2 2020-09-24 stsp bare = true
216 a9c2d4c2 2020-09-24 stsp
217 a9c2d4c2 2020-09-24 stsp [remote "origin"]
218 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
219 56d0a753 2021-01-20 stsp fetch = refs/heads/foo:refs/remotes/origin/foo
220 56d0a753 2021-01-20 stsp fetch = refs/tags/*:refs/tags/*
221 a9c2d4c2 2020-09-24 stsp EOF
222 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
223 49c543a6 2022-03-31 naddy ret=$?
224 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
225 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
226 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
227 a9c2d4c2 2020-09-24 stsp fi
228 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
229 c8c71e6e 2020-03-21 stsp }
230 c8c71e6e 2020-03-21 stsp
231 f6cae3ed 2020-09-13 naddy test_clone_all() {
232 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_all`
233 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
234 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
235 c8c71e6e 2020-03-21 stsp
236 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
237 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
238 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
239 c8c71e6e 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
240 c8c71e6e 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
241 c8c71e6e 2020-03-21 stsp
242 c8c71e6e 2020-03-21 stsp got clone -q -a $testurl/repo $testroot/repo-clone
243 49c543a6 2022-03-31 naddy ret=$?
244 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
245 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
246 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
247 c8c71e6e 2020-03-21 stsp return 1
248 c8c71e6e 2020-03-21 stsp fi
249 c8c71e6e 2020-03-21 stsp
250 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
251 c8c71e6e 2020-03-21 stsp
252 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
253 c8c71e6e 2020-03-21 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
254 c8c71e6e 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
255 f298ae0f 2020-03-25 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
256 f298ae0f 2020-03-25 stsp >> $testroot/stdout.expected
257 c8c71e6e 2020-03-21 stsp echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
258 c8c71e6e 2020-03-21 stsp echo "refs/remotes/origin/master: $commit_id" \
259 c8c71e6e 2020-03-21 stsp >> $testroot/stdout.expected
260 c8c71e6e 2020-03-21 stsp # refs/hoo/boo/zoo is missing because it is outside of refs/heads
261 c8c71e6e 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
262 c8c71e6e 2020-03-21 stsp
263 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
264 49c543a6 2022-03-31 naddy ret=$?
265 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
266 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
267 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
268 a9c2d4c2 2020-09-24 stsp return 1
269 c8c71e6e 2020-03-21 stsp fi
270 a9c2d4c2 2020-09-24 stsp
271 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
272 a9c2d4c2 2020-09-24 stsp remote "origin" {
273 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
274 a9c2d4c2 2020-09-24 stsp protocol ssh
275 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
276 f1bf60d1 2022-07-03 stsp fetch_all_branches yes
277 a9c2d4c2 2020-09-24 stsp }
278 a9c2d4c2 2020-09-24 stsp EOF
279 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
280 49c543a6 2022-03-31 naddy ret=$?
281 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
282 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
283 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
284 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
285 a9c2d4c2 2020-09-24 stsp return 1
286 a9c2d4c2 2020-09-24 stsp fi
287 a9c2d4c2 2020-09-24 stsp
288 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
289 a9c2d4c2 2020-09-24 stsp [core]
290 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
291 a9c2d4c2 2020-09-24 stsp filemode = true
292 a9c2d4c2 2020-09-24 stsp bare = true
293 a9c2d4c2 2020-09-24 stsp
294 a9c2d4c2 2020-09-24 stsp [remote "origin"]
295 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
296 56d0a753 2021-01-20 stsp fetch = refs/heads/*:refs/remotes/origin/*
297 56d0a753 2021-01-20 stsp fetch = refs/tags/*:refs/tags/*
298 a9c2d4c2 2020-09-24 stsp EOF
299 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
300 49c543a6 2022-03-31 naddy ret=$?
301 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
302 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
303 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
304 a9c2d4c2 2020-09-24 stsp fi
305 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
306 c8c71e6e 2020-03-21 stsp }
307 c8c71e6e 2020-03-21 stsp
308 f6cae3ed 2020-09-13 naddy test_clone_mirror() {
309 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_mirror`
310 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
311 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
312 c8c71e6e 2020-03-21 stsp
313 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
314 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
315 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
316 c8c71e6e 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
317 c8c71e6e 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
318 c8c71e6e 2020-03-21 stsp
319 c8c71e6e 2020-03-21 stsp got clone -q -m $testurl/repo $testroot/repo-clone
320 49c543a6 2022-03-31 naddy ret=$?
321 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
322 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
323 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
324 c8c71e6e 2020-03-21 stsp return 1
325 c8c71e6e 2020-03-21 stsp fi
326 c8c71e6e 2020-03-21 stsp
327 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
328 c8c71e6e 2020-03-21 stsp
329 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
330 c8c71e6e 2020-03-21 stsp # refs/heads/foo is missing because we're not fetching all branches
331 c8c71e6e 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
332 c8c71e6e 2020-03-21 stsp # refs/hoo/boo/zoo is missing because it is outside of refs/heads
333 c8c71e6e 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
334 c8c71e6e 2020-03-21 stsp
335 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
336 49c543a6 2022-03-31 naddy ret=$?
337 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
338 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
339 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
340 a9c2d4c2 2020-09-24 stsp return 1
341 c8c71e6e 2020-03-21 stsp fi
342 a9c2d4c2 2020-09-24 stsp
343 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
344 a9c2d4c2 2020-09-24 stsp remote "origin" {
345 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
346 a9c2d4c2 2020-09-24 stsp protocol ssh
347 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
348 15d3c221 2021-01-05 stsp branch { "master" }
349 26e6f38e 2022-07-03 stsp mirror_references yes
350 a9c2d4c2 2020-09-24 stsp }
351 a9c2d4c2 2020-09-24 stsp EOF
352 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
353 49c543a6 2022-03-31 naddy ret=$?
354 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
355 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
356 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
357 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
358 a9c2d4c2 2020-09-24 stsp return 1
359 a9c2d4c2 2020-09-24 stsp fi
360 a9c2d4c2 2020-09-24 stsp
361 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
362 a9c2d4c2 2020-09-24 stsp [core]
363 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
364 a9c2d4c2 2020-09-24 stsp filemode = true
365 a9c2d4c2 2020-09-24 stsp bare = true
366 a9c2d4c2 2020-09-24 stsp
367 a9c2d4c2 2020-09-24 stsp [remote "origin"]
368 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
369 56d0a753 2021-01-20 stsp fetch = refs/heads/master:refs/heads/master
370 56d0a753 2021-01-20 stsp fetch = refs/tags/*:refs/tags/*
371 a9c2d4c2 2020-09-24 stsp EOF
372 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
373 49c543a6 2022-03-31 naddy ret=$?
374 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
375 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
376 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
377 a9c2d4c2 2020-09-24 stsp fi
378 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
379 c8c71e6e 2020-03-21 stsp }
380 c8c71e6e 2020-03-21 stsp
381 f6cae3ed 2020-09-13 naddy test_clone_mirror_all() {
382 c8c71e6e 2020-03-21 stsp local testroot=`test_init clone_mirror_all`
383 c8c71e6e 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
384 c8c71e6e 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
385 c8c71e6e 2020-03-21 stsp
386 c8c71e6e 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
387 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
388 c8c71e6e 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
389 c8c71e6e 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
390 c8c71e6e 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
391 c8c71e6e 2020-03-21 stsp
392 c8c71e6e 2020-03-21 stsp got clone -q -m -a $testurl/repo $testroot/repo-clone
393 49c543a6 2022-03-31 naddy ret=$?
394 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
395 c8c71e6e 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
396 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
397 c8c71e6e 2020-03-21 stsp return 1
398 c8c71e6e 2020-03-21 stsp fi
399 c8c71e6e 2020-03-21 stsp
400 c8c71e6e 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
401 c8c71e6e 2020-03-21 stsp
402 c8c71e6e 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
403 c8c71e6e 2020-03-21 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
404 c8c71e6e 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
405 c8c71e6e 2020-03-21 stsp # refs/hoo/boo/zoo is missing because it is outside of refs/heads
406 c8c71e6e 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
407 c8c71e6e 2020-03-21 stsp
408 c8c71e6e 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
409 49c543a6 2022-03-31 naddy ret=$?
410 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
411 c8c71e6e 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
412 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
413 a9c2d4c2 2020-09-24 stsp return 1
414 c8c71e6e 2020-03-21 stsp fi
415 a9c2d4c2 2020-09-24 stsp
416 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
417 a9c2d4c2 2020-09-24 stsp remote "origin" {
418 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
419 a9c2d4c2 2020-09-24 stsp protocol ssh
420 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
421 26e6f38e 2022-07-03 stsp mirror_references yes
422 f1bf60d1 2022-07-03 stsp fetch_all_branches yes
423 a9c2d4c2 2020-09-24 stsp }
424 a9c2d4c2 2020-09-24 stsp EOF
425 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
426 49c543a6 2022-03-31 naddy ret=$?
427 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
428 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
429 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
430 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
431 a9c2d4c2 2020-09-24 stsp return 1
432 a9c2d4c2 2020-09-24 stsp fi
433 a9c2d4c2 2020-09-24 stsp
434 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
435 a9c2d4c2 2020-09-24 stsp [core]
436 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
437 a9c2d4c2 2020-09-24 stsp filemode = true
438 a9c2d4c2 2020-09-24 stsp bare = true
439 a9c2d4c2 2020-09-24 stsp
440 a9c2d4c2 2020-09-24 stsp [remote "origin"]
441 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
442 56d0a753 2021-01-20 stsp fetch = refs/heads/*:refs/heads/*
443 56d0a753 2021-01-20 stsp fetch = refs/tags/*:refs/tags/*
444 a9c2d4c2 2020-09-24 stsp EOF
445 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
446 49c543a6 2022-03-31 naddy ret=$?
447 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
448 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
449 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
450 a9c2d4c2 2020-09-24 stsp fi
451 c8c71e6e 2020-03-21 stsp test_done "$testroot" "$ret"
452 c8c71e6e 2020-03-21 stsp }
453 0e4002ca 2020-03-21 stsp
454 f6cae3ed 2020-09-13 naddy test_clone_reference() {
455 0e4002ca 2020-03-21 stsp local testroot=`test_init clone_reference`
456 0e4002ca 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
457 0e4002ca 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
458 c8c71e6e 2020-03-21 stsp
459 0e4002ca 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
460 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
461 0e4002ca 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
462 0e4002ca 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
463 0e4002ca 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
464 0e4002ca 2020-03-21 stsp
465 0e4002ca 2020-03-21 stsp got clone -q -R hoo $testurl/repo $testroot/repo-clone
466 49c543a6 2022-03-31 naddy ret=$?
467 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
468 0e4002ca 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
469 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
470 0e4002ca 2020-03-21 stsp return 1
471 0e4002ca 2020-03-21 stsp fi
472 0e4002ca 2020-03-21 stsp
473 0e4002ca 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
474 0e4002ca 2020-03-21 stsp
475 0e4002ca 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
476 0e4002ca 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
477 f298ae0f 2020-03-25 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
478 f298ae0f 2020-03-25 stsp >> $testroot/stdout.expected
479 0e4002ca 2020-03-21 stsp echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
480 0e4002ca 2020-03-21 stsp >> $testroot/stdout.expected
481 0e4002ca 2020-03-21 stsp echo "refs/remotes/origin/master: $commit_id" \
482 0e4002ca 2020-03-21 stsp >> $testroot/stdout.expected
483 0e4002ca 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
484 0e4002ca 2020-03-21 stsp
485 0e4002ca 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
486 49c543a6 2022-03-31 naddy ret=$?
487 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
488 0e4002ca 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
489 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
490 a9c2d4c2 2020-09-24 stsp return 1
491 0e4002ca 2020-03-21 stsp fi
492 a9c2d4c2 2020-09-24 stsp
493 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
494 a9c2d4c2 2020-09-24 stsp remote "origin" {
495 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
496 a9c2d4c2 2020-09-24 stsp protocol ssh
497 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
498 15d3c221 2021-01-05 stsp branch { "master" }
499 99495ddb 2021-01-10 stsp reference { "hoo" }
500 a9c2d4c2 2020-09-24 stsp }
501 a9c2d4c2 2020-09-24 stsp EOF
502 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
503 49c543a6 2022-03-31 naddy ret=$?
504 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
505 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
506 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
507 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
508 a9c2d4c2 2020-09-24 stsp return 1
509 a9c2d4c2 2020-09-24 stsp fi
510 a9c2d4c2 2020-09-24 stsp
511 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
512 a9c2d4c2 2020-09-24 stsp [core]
513 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
514 a9c2d4c2 2020-09-24 stsp filemode = true
515 a9c2d4c2 2020-09-24 stsp bare = true
516 a9c2d4c2 2020-09-24 stsp
517 a9c2d4c2 2020-09-24 stsp [remote "origin"]
518 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
519 56d0a753 2021-01-20 stsp fetch = refs/heads/master:refs/remotes/origin/master
520 56d0a753 2021-01-20 stsp fetch = refs/hoo:refs/remotes/origin/hoo
521 56d0a753 2021-01-20 stsp fetch = refs/tags/*:refs/tags/*
522 a9c2d4c2 2020-09-24 stsp EOF
523 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
524 49c543a6 2022-03-31 naddy ret=$?
525 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
526 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
527 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
528 a9c2d4c2 2020-09-24 stsp fi
529 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
530 0e4002ca 2020-03-21 stsp }
531 0e4002ca 2020-03-21 stsp
532 f6cae3ed 2020-09-13 naddy test_clone_branch_and_reference() {
533 0e4002ca 2020-03-21 stsp local testroot=`test_init clone_reference`
534 0e4002ca 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
535 0e4002ca 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
536 0e4002ca 2020-03-21 stsp
537 0e4002ca 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
538 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
539 0e4002ca 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
540 0e4002ca 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
541 0e4002ca 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
542 0e4002ca 2020-03-21 stsp
543 0e4002ca 2020-03-21 stsp got clone -q -R hoo/boo/zoo -b foo $testurl/repo $testroot/repo-clone
544 49c543a6 2022-03-31 naddy ret=$?
545 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
546 0e4002ca 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
547 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
548 0e4002ca 2020-03-21 stsp return 1
549 0e4002ca 2020-03-21 stsp fi
550 0e4002ca 2020-03-21 stsp
551 0e4002ca 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
552 0e4002ca 2020-03-21 stsp
553 0e4002ca 2020-03-21 stsp echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
554 0e4002ca 2020-03-21 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
555 0e4002ca 2020-03-21 stsp echo "refs/remotes/origin/foo: $commit_id" \
556 0e4002ca 2020-03-21 stsp >> $testroot/stdout.expected
557 0e4002ca 2020-03-21 stsp echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
558 0e4002ca 2020-03-21 stsp >> $testroot/stdout.expected
559 0e4002ca 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
560 0e4002ca 2020-03-21 stsp
561 0e4002ca 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
562 49c543a6 2022-03-31 naddy ret=$?
563 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
564 0e4002ca 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
565 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
566 a9c2d4c2 2020-09-24 stsp return 1
567 0e4002ca 2020-03-21 stsp fi
568 a9c2d4c2 2020-09-24 stsp
569 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
570 a9c2d4c2 2020-09-24 stsp remote "origin" {
571 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
572 a9c2d4c2 2020-09-24 stsp protocol ssh
573 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
574 15d3c221 2021-01-05 stsp branch { "foo" }
575 99495ddb 2021-01-10 stsp reference { "hoo/boo/zoo" }
576 a9c2d4c2 2020-09-24 stsp }
577 a9c2d4c2 2020-09-24 stsp EOF
578 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
579 49c543a6 2022-03-31 naddy ret=$?
580 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
581 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
582 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
583 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
584 a9c2d4c2 2020-09-24 stsp return 1
585 a9c2d4c2 2020-09-24 stsp fi
586 a9c2d4c2 2020-09-24 stsp
587 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
588 a9c2d4c2 2020-09-24 stsp [core]
589 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
590 a9c2d4c2 2020-09-24 stsp filemode = true
591 a9c2d4c2 2020-09-24 stsp bare = true
592 a9c2d4c2 2020-09-24 stsp
593 a9c2d4c2 2020-09-24 stsp [remote "origin"]
594 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
595 56d0a753 2021-01-20 stsp fetch = refs/heads/foo:refs/remotes/origin/foo
596 56d0a753 2021-01-20 stsp fetch = refs/hoo/boo/zoo:refs/remotes/origin/hoo/boo/zoo
597 56d0a753 2021-01-20 stsp fetch = refs/tags/*:refs/tags/*
598 a9c2d4c2 2020-09-24 stsp EOF
599 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
600 49c543a6 2022-03-31 naddy ret=$?
601 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
602 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
603 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
604 a9c2d4c2 2020-09-24 stsp fi
605 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
606 0e4002ca 2020-03-21 stsp }
607 0e4002ca 2020-03-21 stsp
608 f6cae3ed 2020-09-13 naddy test_clone_reference_mirror() {
609 0e4002ca 2020-03-21 stsp local testroot=`test_init clone_reference_mirror`
610 0e4002ca 2020-03-21 stsp local testurl=ssh://127.0.0.1/$testroot
611 0e4002ca 2020-03-21 stsp local commit_id=`git_show_head $testroot/repo`
612 0e4002ca 2020-03-21 stsp
613 0e4002ca 2020-03-21 stsp got branch -r $testroot/repo -c $commit_id foo
614 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
615 0e4002ca 2020-03-21 stsp got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
616 0e4002ca 2020-03-21 stsp local tag_id=`got ref -r $testroot/repo -l \
617 0e4002ca 2020-03-21 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
618 0e4002ca 2020-03-21 stsp
619 0e4002ca 2020-03-21 stsp got clone -q -R hoo -m $testurl/repo $testroot/repo-clone
620 49c543a6 2022-03-31 naddy ret=$?
621 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
622 0e4002ca 2020-03-21 stsp echo "got clone command failed unexpectedly" >&2
623 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
624 0e4002ca 2020-03-21 stsp return 1
625 0e4002ca 2020-03-21 stsp fi
626 0e4002ca 2020-03-21 stsp
627 0e4002ca 2020-03-21 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
628 0e4002ca 2020-03-21 stsp
629 0e4002ca 2020-03-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
630 0e4002ca 2020-03-21 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
631 0e4002ca 2020-03-21 stsp echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
632 0e4002ca 2020-03-21 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
633 0e4002ca 2020-03-21 stsp
634 0e4002ca 2020-03-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
635 49c543a6 2022-03-31 naddy ret=$?
636 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
637 0e4002ca 2020-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
638 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
639 a9c2d4c2 2020-09-24 stsp return 1
640 0e4002ca 2020-03-21 stsp fi
641 a9c2d4c2 2020-09-24 stsp
642 a9c2d4c2 2020-09-24 stsp cat > $testroot/got.conf.expected <<EOF
643 a9c2d4c2 2020-09-24 stsp remote "origin" {
644 a9c2d4c2 2020-09-24 stsp server 127.0.0.1
645 a9c2d4c2 2020-09-24 stsp protocol ssh
646 a9c2d4c2 2020-09-24 stsp repository "$testroot/repo"
647 15d3c221 2021-01-05 stsp branch { "master" }
648 99495ddb 2021-01-10 stsp reference { "hoo" }
649 26e6f38e 2022-07-03 stsp mirror_references yes
650 a9c2d4c2 2020-09-24 stsp }
651 a9c2d4c2 2020-09-24 stsp EOF
652 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
653 49c543a6 2022-03-31 naddy ret=$?
654 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
655 a9c2d4c2 2020-09-24 stsp diff -u $testroot/got.conf.expected \
656 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/got.conf
657 a9c2d4c2 2020-09-24 stsp test_done "$testroot" "$ret"
658 a9c2d4c2 2020-09-24 stsp return 1
659 a9c2d4c2 2020-09-24 stsp fi
660 a9c2d4c2 2020-09-24 stsp
661 a9c2d4c2 2020-09-24 stsp cat > $testroot/config.expected <<EOF
662 a9c2d4c2 2020-09-24 stsp [core]
663 a9c2d4c2 2020-09-24 stsp repositoryformatversion = 0
664 a9c2d4c2 2020-09-24 stsp filemode = true
665 a9c2d4c2 2020-09-24 stsp bare = true
666 a9c2d4c2 2020-09-24 stsp
667 a9c2d4c2 2020-09-24 stsp [remote "origin"]
668 a9c2d4c2 2020-09-24 stsp url = ssh://127.0.0.1$testroot/repo
669 56d0a753 2021-01-20 stsp fetch = refs/heads/master:refs/heads/master
670 56d0a753 2021-01-20 stsp fetch = refs/hoo:refs/hoo
671 56d0a753 2021-01-20 stsp fetch = refs/tags/*:refs/tags/*
672 132af4a5 2021-01-05 stsp EOF
673 132af4a5 2021-01-05 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
674 49c543a6 2022-03-31 naddy ret=$?
675 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
676 132af4a5 2021-01-05 stsp diff -u $testroot/config.expected \
677 132af4a5 2021-01-05 stsp $testroot/repo-clone/config
678 132af4a5 2021-01-05 stsp fi
679 132af4a5 2021-01-05 stsp test_done "$testroot" "$ret"
680 132af4a5 2021-01-05 stsp }
681 132af4a5 2021-01-05 stsp
682 132af4a5 2021-01-05 stsp test_clone_multiple_branches() {
683 132af4a5 2021-01-05 stsp local testroot=`test_init clone_multiple_branches`
684 132af4a5 2021-01-05 stsp local testurl=ssh://127.0.0.1/$testroot
685 132af4a5 2021-01-05 stsp local commit_id=`git_show_head $testroot/repo`
686 132af4a5 2021-01-05 stsp
687 132af4a5 2021-01-05 stsp got branch -r $testroot/repo -c $commit_id foo
688 132af4a5 2021-01-05 stsp got branch -r $testroot/repo -c $commit_id bar
689 132af4a5 2021-01-05 stsp
690 132af4a5 2021-01-05 stsp got clone -q -b foo -b bar $testurl/repo $testroot/repo-clone
691 49c543a6 2022-03-31 naddy ret=$?
692 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
693 132af4a5 2021-01-05 stsp echo "got clone command failed unexpectedly" >&2
694 132af4a5 2021-01-05 stsp test_done "$testroot" "$ret"
695 132af4a5 2021-01-05 stsp return 1
696 132af4a5 2021-01-05 stsp fi
697 132af4a5 2021-01-05 stsp
698 132af4a5 2021-01-05 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
699 132af4a5 2021-01-05 stsp
700 132af4a5 2021-01-05 stsp echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
701 132af4a5 2021-01-05 stsp echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
702 132af4a5 2021-01-05 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
703 132af4a5 2021-01-05 stsp echo "refs/remotes/origin/bar: $commit_id" \
704 132af4a5 2021-01-05 stsp >> $testroot/stdout.expected
705 132af4a5 2021-01-05 stsp echo "refs/remotes/origin/foo: $commit_id" \
706 132af4a5 2021-01-05 stsp >> $testroot/stdout.expected
707 132af4a5 2021-01-05 stsp
708 132af4a5 2021-01-05 stsp cmp -s $testroot/stdout $testroot/stdout.expected
709 49c543a6 2022-03-31 naddy ret=$?
710 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
711 132af4a5 2021-01-05 stsp diff -u $testroot/stdout.expected $testroot/stdout
712 132af4a5 2021-01-05 stsp test_done "$testroot" "$ret"
713 132af4a5 2021-01-05 stsp return 1
714 132af4a5 2021-01-05 stsp fi
715 132af4a5 2021-01-05 stsp
716 132af4a5 2021-01-05 stsp cat > $testroot/got.conf.expected <<EOF
717 132af4a5 2021-01-05 stsp remote "origin" {
718 132af4a5 2021-01-05 stsp server 127.0.0.1
719 132af4a5 2021-01-05 stsp protocol ssh
720 132af4a5 2021-01-05 stsp repository "$testroot/repo"
721 132af4a5 2021-01-05 stsp branch { "foo" "bar" }
722 132af4a5 2021-01-05 stsp }
723 a9c2d4c2 2020-09-24 stsp EOF
724 132af4a5 2021-01-05 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
725 49c543a6 2022-03-31 naddy ret=$?
726 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
727 132af4a5 2021-01-05 stsp diff -u $testroot/got.conf.expected \
728 132af4a5 2021-01-05 stsp $testroot/repo-clone/got.conf
729 132af4a5 2021-01-05 stsp test_done "$testroot" "$ret"
730 132af4a5 2021-01-05 stsp return 1
731 132af4a5 2021-01-05 stsp fi
732 132af4a5 2021-01-05 stsp
733 132af4a5 2021-01-05 stsp cat > $testroot/config.expected <<EOF
734 132af4a5 2021-01-05 stsp [core]
735 132af4a5 2021-01-05 stsp repositoryformatversion = 0
736 132af4a5 2021-01-05 stsp filemode = true
737 132af4a5 2021-01-05 stsp bare = true
738 132af4a5 2021-01-05 stsp
739 132af4a5 2021-01-05 stsp [remote "origin"]
740 132af4a5 2021-01-05 stsp url = ssh://127.0.0.1$testroot/repo
741 56d0a753 2021-01-20 stsp fetch = refs/heads/foo:refs/remotes/origin/foo
742 56d0a753 2021-01-20 stsp fetch = refs/heads/bar:refs/remotes/origin/bar
743 c9f1ac46 2022-11-08 stsp fetch = refs/tags/*:refs/tags/*
744 c9f1ac46 2022-11-08 stsp EOF
745 c9f1ac46 2022-11-08 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
746 c9f1ac46 2022-11-08 stsp ret=$?
747 c9f1ac46 2022-11-08 stsp if [ $ret -ne 0 ]; then
748 c9f1ac46 2022-11-08 stsp diff -u $testroot/config.expected \
749 c9f1ac46 2022-11-08 stsp $testroot/repo-clone/config
750 c9f1ac46 2022-11-08 stsp fi
751 c9f1ac46 2022-11-08 stsp test_done "$testroot" "$ret"
752 c9f1ac46 2022-11-08 stsp }
753 c9f1ac46 2022-11-08 stsp
754 c9f1ac46 2022-11-08 stsp test_clone_dangling_headref() {
755 c9f1ac46 2022-11-08 stsp local testroot=`test_init clone_dangling_headref`
756 c9f1ac46 2022-11-08 stsp local testurl=ssh://127.0.0.1/$testroot
757 c9f1ac46 2022-11-08 stsp local commit_id=`git_show_head $testroot/repo`
758 c9f1ac46 2022-11-08 stsp
759 c9f1ac46 2022-11-08 stsp got branch -r $testroot/repo -d master > /dev/null
760 c9f1ac46 2022-11-08 stsp got branch -r $testroot/repo -c $commit_id foo
761 c9f1ac46 2022-11-08 stsp
762 c9f1ac46 2022-11-08 stsp got ref -l -r $testroot/repo > $testroot/stdout
763 c9f1ac46 2022-11-08 stsp
764 c9f1ac46 2022-11-08 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
765 c9f1ac46 2022-11-08 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
766 c9f1ac46 2022-11-08 stsp # refs/heads/master is missing because it was deleted above
767 c9f1ac46 2022-11-08 stsp
768 c9f1ac46 2022-11-08 stsp cmp -s $testroot/stdout $testroot/stdout.expected
769 c9f1ac46 2022-11-08 stsp ret=$?
770 c9f1ac46 2022-11-08 stsp if [ $ret -ne 0 ]; then
771 c9f1ac46 2022-11-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
772 c9f1ac46 2022-11-08 stsp test_done "$testroot" "$ret"
773 c9f1ac46 2022-11-08 stsp return 1
774 c9f1ac46 2022-11-08 stsp fi
775 c9f1ac46 2022-11-08 stsp
776 c9f1ac46 2022-11-08 stsp got clone -q -b foo $testurl/repo $testroot/repo-clone
777 c9f1ac46 2022-11-08 stsp ret=$?
778 c9f1ac46 2022-11-08 stsp if [ $ret -ne 0 ]; then
779 c9f1ac46 2022-11-08 stsp echo "got clone command failed unexpectedly" >&2
780 c9f1ac46 2022-11-08 stsp test_done "$testroot" "$ret"
781 c9f1ac46 2022-11-08 stsp return 1
782 c9f1ac46 2022-11-08 stsp fi
783 c9f1ac46 2022-11-08 stsp
784 c9f1ac46 2022-11-08 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
785 c9f1ac46 2022-11-08 stsp
786 c9f1ac46 2022-11-08 stsp echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
787 c9f1ac46 2022-11-08 stsp echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
788 c9f1ac46 2022-11-08 stsp echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
789 c9f1ac46 2022-11-08 stsp
790 c9f1ac46 2022-11-08 stsp cmp -s $testroot/stdout $testroot/stdout.expected
791 c9f1ac46 2022-11-08 stsp ret=$?
792 c9f1ac46 2022-11-08 stsp if [ $ret -ne 0 ]; then
793 c9f1ac46 2022-11-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
794 c9f1ac46 2022-11-08 stsp test_done "$testroot" "$ret"
795 c9f1ac46 2022-11-08 stsp return 1
796 c9f1ac46 2022-11-08 stsp fi
797 c9f1ac46 2022-11-08 stsp
798 c9f1ac46 2022-11-08 stsp cat > $testroot/got.conf.expected <<EOF
799 c9f1ac46 2022-11-08 stsp remote "origin" {
800 c9f1ac46 2022-11-08 stsp server 127.0.0.1
801 c9f1ac46 2022-11-08 stsp protocol ssh
802 c9f1ac46 2022-11-08 stsp repository "$testroot/repo"
803 c9f1ac46 2022-11-08 stsp branch { "foo" }
804 c9f1ac46 2022-11-08 stsp }
805 c9f1ac46 2022-11-08 stsp EOF
806 c9f1ac46 2022-11-08 stsp cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
807 c9f1ac46 2022-11-08 stsp ret=$?
808 c9f1ac46 2022-11-08 stsp if [ $ret -ne 0 ]; then
809 c9f1ac46 2022-11-08 stsp diff -u $testroot/got.conf.expected \
810 c9f1ac46 2022-11-08 stsp $testroot/repo-clone/got.conf
811 c9f1ac46 2022-11-08 stsp test_done "$testroot" "$ret"
812 c9f1ac46 2022-11-08 stsp return 1
813 c9f1ac46 2022-11-08 stsp fi
814 c9f1ac46 2022-11-08 stsp
815 c9f1ac46 2022-11-08 stsp cat > $testroot/config.expected <<EOF
816 c9f1ac46 2022-11-08 stsp [core]
817 c9f1ac46 2022-11-08 stsp repositoryformatversion = 0
818 c9f1ac46 2022-11-08 stsp filemode = true
819 c9f1ac46 2022-11-08 stsp bare = true
820 c9f1ac46 2022-11-08 stsp
821 c9f1ac46 2022-11-08 stsp [remote "origin"]
822 c9f1ac46 2022-11-08 stsp url = ssh://127.0.0.1$testroot/repo
823 c9f1ac46 2022-11-08 stsp fetch = refs/heads/foo:refs/remotes/origin/foo
824 56d0a753 2021-01-20 stsp fetch = refs/tags/*:refs/tags/*
825 132af4a5 2021-01-05 stsp EOF
826 a9c2d4c2 2020-09-24 stsp cmp -s $testroot/repo-clone/config $testroot/config.expected
827 49c543a6 2022-03-31 naddy ret=$?
828 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
829 a9c2d4c2 2020-09-24 stsp diff -u $testroot/config.expected \
830 a9c2d4c2 2020-09-24 stsp $testroot/repo-clone/config
831 a9c2d4c2 2020-09-24 stsp fi
832 0e4002ca 2020-03-21 stsp test_done "$testroot" "$ret"
833 0e4002ca 2020-03-21 stsp }
834 0e4002ca 2020-03-21 stsp
835 7fb414ae 2020-08-08 stsp test_parseargs "$@"
836 c8c71e6e 2020-03-21 stsp run_test test_clone_basic
837 c8c71e6e 2020-03-21 stsp run_test test_clone_list
838 c8c71e6e 2020-03-21 stsp run_test test_clone_branch
839 c8c71e6e 2020-03-21 stsp run_test test_clone_all
840 c8c71e6e 2020-03-21 stsp run_test test_clone_mirror
841 c8c71e6e 2020-03-21 stsp run_test test_clone_mirror_all
842 0e4002ca 2020-03-21 stsp run_test test_clone_reference
843 0e4002ca 2020-03-21 stsp run_test test_clone_branch_and_reference
844 0e4002ca 2020-03-21 stsp run_test test_clone_reference_mirror
845 132af4a5 2021-01-05 stsp run_test test_clone_multiple_branches
846 c9f1ac46 2022-11-08 stsp run_test test_clone_dangling_headref