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