3 d1c1ae5f 2019-08-12 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 d1c1ae5f 2019-08-12 stsp # Permission to use, copy, modify, and distribute this software for any
6 d1c1ae5f 2019-08-12 stsp # purpose with or without fee is hereby granted, provided that the above
7 d1c1ae5f 2019-08-12 stsp # copyright notice and this permission notice appear in all copies.
9 d1c1ae5f 2019-08-12 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 d1c1ae5f 2019-08-12 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 d1c1ae5f 2019-08-12 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 d1c1ae5f 2019-08-12 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 d1c1ae5f 2019-08-12 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 d1c1ae5f 2019-08-12 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 d1c1ae5f 2019-08-12 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 d1c1ae5f 2019-08-12 stsp . ./common.sh
19 d1c1ae5f 2019-08-12 stsp function test_ref_create {
20 d1c1ae5f 2019-08-12 stsp local testroot=`test_init ref_create`
21 d1c1ae5f 2019-08-12 stsp local commit_id=`git_show_head $testroot/repo`
23 e31abbf2 2020-03-22 stsp # Create a ref pointing at a commit ID
24 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c $commit_id refs/heads/commitref
26 d4fc9a62 2019-10-09 stsp if [ "$ret" != "0" ]; then
27 d4fc9a62 2019-10-09 stsp echo "got ref command failed unexpectedly"
28 d4fc9a62 2019-10-09 stsp test_done "$testroot" "$ret"
32 d4fc9a62 2019-10-09 stsp # Create a ref based on repository's HEAD reference
33 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c HEAD refs/heads/newref
35 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
36 d1c1ae5f 2019-08-12 stsp echo "got ref command failed unexpectedly"
37 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
41 d1c1ae5f 2019-08-12 stsp # Ensure that Git recognizes the ref Got has created
42 d1c1ae5f 2019-08-12 stsp (cd $testroot/repo && git checkout -q newref)
44 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
45 d1c1ae5f 2019-08-12 stsp echo "git checkout command failed unexpectedly"
46 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
50 a009df92 2019-08-22 stsp # Ensure Got recognizes the new ref
51 d1c1ae5f 2019-08-12 stsp got checkout -b newref $testroot/repo $testroot/wt >/dev/null
53 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
54 d1c1ae5f 2019-08-12 stsp echo "got checkout command failed unexpectedly"
55 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
59 d1c1ae5f 2019-08-12 stsp # Create a head ref based on another specific ref
60 e31abbf2 2020-03-22 stsp (cd $testroot/wt && got ref -c refs/heads/master refs/heads/anotherref)
62 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
63 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
67 d1c1ae5f 2019-08-12 stsp (cd $testroot/repo && git checkout -q anotherref)
69 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
70 d1c1ae5f 2019-08-12 stsp echo "git checkout command failed unexpectedly"
71 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
74 d1c1ae5f 2019-08-12 stsp # Create a symbolic ref
75 e31abbf2 2020-03-22 stsp (cd $testroot/wt && got ref -s refs/heads/master refs/heads/symbolicref)
77 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
78 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
82 d1c1ae5f 2019-08-12 stsp (cd $testroot/repo && git checkout -q symbolicref)
84 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
85 d1c1ae5f 2019-08-12 stsp echo "git checkout command failed unexpectedly"
86 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
90 2d463f36 2019-08-12 stsp # Attempt to create a symbolic ref pointing at a non-reference
91 e31abbf2 2020-03-22 stsp (cd $testroot/wt && got ref -s $commit_id refs/heads/symbolicref \
92 2d463f36 2019-08-12 stsp 2> $testroot/stderr)
94 2d463f36 2019-08-12 stsp if [ "$ret" == "0" ]; then
95 2d463f36 2019-08-12 stsp echo "git ref command succeeded unexpectedly"
96 2d463f36 2019-08-12 stsp test_done "$testroot" "1"
100 2d463f36 2019-08-12 stsp echo "got: reference $commit_id not found" > $testroot/stderr.expected
101 2d463f36 2019-08-12 stsp cmp -s $testroot/stderr $testroot/stderr.expected
103 2d463f36 2019-08-12 stsp if [ "$ret" != "0" ]; then
104 2d463f36 2019-08-12 stsp diff -u $testroot/stderr.expected $testroot/stderr
105 2d463f36 2019-08-12 stsp test_done "$testroot" "$ret"
109 e31abbf2 2020-03-22 stsp # Attempt to create a reference without specifying a name
110 e31abbf2 2020-03-22 stsp (cd $testroot/wt && got ref -c $commit_id 2> $testroot/stderr)
112 e31abbf2 2020-03-22 stsp if [ "$ret" == "0" ]; then
113 e31abbf2 2020-03-22 stsp echo "git ref command succeeded unexpectedly"
114 e31abbf2 2020-03-22 stsp test_done "$testroot" "1"
118 e31abbf2 2020-03-22 stsp grep -q '^usage: got ref' $testroot/stderr
120 e31abbf2 2020-03-22 stsp if [ "$ret" != "0" ]; then
121 e31abbf2 2020-03-22 stsp echo "unexpected usage error message: " >&2
122 e31abbf2 2020-03-22 stsp cat $testroot/stderr >&2
123 e31abbf2 2020-03-22 stsp test_done "$testroot" "$ret"
127 e31abbf2 2020-03-22 stsp # Attempt to create a symbolic reference without specifying a name
128 e31abbf2 2020-03-22 stsp (cd $testroot/wt && got ref -s refs/heads/symbolicref \
129 e31abbf2 2020-03-22 stsp 2> $testroot/stderr)
131 e31abbf2 2020-03-22 stsp if [ "$ret" == "0" ]; then
132 e31abbf2 2020-03-22 stsp echo "git ref command succeeded unexpectedly"
133 e31abbf2 2020-03-22 stsp test_done "$testroot" "1"
137 e31abbf2 2020-03-22 stsp grep -q '^usage: got ref' $testroot/stderr
139 e31abbf2 2020-03-22 stsp if [ "$ret" != "0" ]; then
140 e31abbf2 2020-03-22 stsp echo "unexpected usage error message: " >&2
141 e31abbf2 2020-03-22 stsp cat $testroot/stderr >&2
142 e31abbf2 2020-03-22 stsp test_done "$testroot" "$ret"
146 7fa81f88 2020-02-21 stsp # Change HEAD
147 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -s refs/heads/newref HEAD
149 7fa81f88 2020-02-21 stsp if [ "$ret" != "0" ]; then
150 7fa81f88 2020-02-21 stsp echo "got ref command failed unexpectedly"
151 7fa81f88 2020-02-21 stsp test_done "$testroot" "$ret"
155 7fa81f88 2020-02-21 stsp # Ensure that Git recognizes the ref Got has created
156 7fa81f88 2020-02-21 stsp (cd $testroot/repo && git checkout -q HEAD)
158 7fa81f88 2020-02-21 stsp if [ "$ret" != "0" ]; then
159 7fa81f88 2020-02-21 stsp echo "git checkout command failed unexpectedly"
160 7fa81f88 2020-02-21 stsp test_done "$testroot" "$ret"
164 7fa81f88 2020-02-21 stsp # Ensure Got recognizes the new ref
165 7fa81f88 2020-02-21 stsp (cd $testroot/wt && got update -b HEAD >/dev/null)
167 7fa81f88 2020-02-21 stsp if [ "$ret" != "0" ]; then
168 7fa81f88 2020-02-21 stsp echo "got checkout command failed unexpectedly"
169 7fa81f88 2020-02-21 stsp test_done "$testroot" "$ret"
172 d1c1ae5f 2019-08-12 stsp got ref -r $testroot/repo -l > $testroot/stdout
173 7fa81f88 2020-02-21 stsp echo "HEAD: refs/heads/newref" > $testroot/stdout.expected
174 d1c1ae5f 2019-08-12 stsp echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
175 d1c1ae5f 2019-08-12 stsp cat $testroot/wt/.got/uuid | tr -d '\n' >> $testroot/stdout.expected
176 d1c1ae5f 2019-08-12 stsp echo ": $commit_id" >> $testroot/stdout.expected
177 d1c1ae5f 2019-08-12 stsp echo "refs/heads/anotherref: $commit_id" >> $testroot/stdout.expected
178 d4fc9a62 2019-10-09 stsp echo "refs/heads/commitref: $commit_id" >> $testroot/stdout.expected
179 d1c1ae5f 2019-08-12 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
180 d1c1ae5f 2019-08-12 stsp echo "refs/heads/newref: $commit_id" >> $testroot/stdout.expected
181 d1c1ae5f 2019-08-12 stsp echo "refs/heads/symbolicref: refs/heads/master" \
182 d1c1ae5f 2019-08-12 stsp >> $testroot/stdout.expected
183 d1c1ae5f 2019-08-12 stsp cmp -s $testroot/stdout $testroot/stdout.expected
185 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
186 d1c1ae5f 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
188 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
191 d1c1ae5f 2019-08-12 stsp function test_ref_delete {
192 d1c1ae5f 2019-08-12 stsp local testroot=`test_init ref_delete`
193 d1c1ae5f 2019-08-12 stsp local commit_id=`git_show_head $testroot/repo`
195 d1c1ae5f 2019-08-12 stsp for b in ref1 ref2 ref3; do
196 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c refs/heads/master refs/heads/$b
198 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
199 d1c1ae5f 2019-08-12 stsp echo "got ref command failed unexpectedly"
200 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
205 e31abbf2 2020-03-22 stsp got ref -d -r $testroot/repo refs/heads/ref2 > $testroot/stdout
207 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
208 d1c1ae5f 2019-08-12 stsp echo "got ref command failed unexpectedly"
209 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
213 d1c1ae5f 2019-08-12 stsp got ref -l -r $testroot/repo > $testroot/stdout
214 d1c1ae5f 2019-08-12 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
215 d1c1ae5f 2019-08-12 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
216 d1c1ae5f 2019-08-12 stsp echo "refs/heads/ref1: $commit_id" >> $testroot/stdout.expected
217 d1c1ae5f 2019-08-12 stsp echo "refs/heads/ref3: $commit_id" >> $testroot/stdout.expected
218 d1c1ae5f 2019-08-12 stsp cmp -s $testroot/stdout $testroot/stdout.expected
220 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
221 d1c1ae5f 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
222 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
226 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -d refs/heads/bogus_ref_name \
227 d1c1ae5f 2019-08-12 stsp > $testroot/stdout 2> $testroot/stderr
229 d1c1ae5f 2019-08-12 stsp if [ "$ret" == "0" ]; then
230 d1c1ae5f 2019-08-12 stsp echo "got ref succeeded unexpectedly"
231 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
235 d1c1ae5f 2019-08-12 stsp echo "got: reference refs/heads/bogus_ref_name not found" \
236 d1c1ae5f 2019-08-12 stsp > $testroot/stderr.expected
237 d1c1ae5f 2019-08-12 stsp cmp -s $testroot/stderr $testroot/stderr.expected
239 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
240 d1c1ae5f 2019-08-12 stsp diff -u $testroot/stderr.expected $testroot/stderr
242 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
245 b2070a3f 2020-03-22 stsp function test_ref_list {
246 b2070a3f 2020-03-22 stsp local testroot=`test_init ref_list`
247 b2070a3f 2020-03-22 stsp local commit_id=`git_show_head $testroot/repo`
249 b2070a3f 2020-03-22 stsp # Create a tag pointing at a commit ID
250 b2070a3f 2020-03-22 stsp got tag -r $testroot/repo -c $commit_id -m "1.0" "1.0" >/dev/null
252 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
253 b2070a3f 2020-03-22 stsp echo "got tag command failed unexpectedly"
254 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
257 b2070a3f 2020-03-22 stsp local tag_id=`got ref -r $testroot/repo -l \
258 b2070a3f 2020-03-22 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
260 b2070a3f 2020-03-22 stsp # Create a ref based on repository's HEAD reference
261 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -c HEAD refs/foo/zoo
263 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
264 b2070a3f 2020-03-22 stsp echo "got ref command failed unexpectedly"
265 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
269 b2070a3f 2020-03-22 stsp # Create a head ref based on another specific ref
270 b2070a3f 2020-03-22 stsp (cd $testroot/repo && got ref -c refs/heads/master refs/foo/bar/baz)
272 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
273 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
277 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l > $testroot/stdout
279 b2070a3f 2020-03-22 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
280 b2070a3f 2020-03-22 stsp echo "refs/foo/bar/baz: $commit_id" >> $testroot/stdout.expected
281 b2070a3f 2020-03-22 stsp echo "refs/foo/zoo: $commit_id" >> $testroot/stdout.expected
282 b2070a3f 2020-03-22 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
283 b2070a3f 2020-03-22 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
284 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
286 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
287 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
288 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
292 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l refs > $testroot/stdout
294 b2070a3f 2020-03-22 stsp echo "refs/foo/bar/baz: $commit_id" > $testroot/stdout.expected
295 b2070a3f 2020-03-22 stsp echo "refs/foo/zoo: $commit_id" >> $testroot/stdout.expected
296 b2070a3f 2020-03-22 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
297 b2070a3f 2020-03-22 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
298 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
300 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
301 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
302 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
306 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l refs/tags > $testroot/stdout
308 b2070a3f 2020-03-22 stsp echo "refs/tags/1.0: $tag_id" > $testroot/stdout.expected
309 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
311 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
312 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
313 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
317 b2070a3f 2020-03-22 stsp for r in refs/foo/bar/baz refs/foo/bar/baz foo/bar/baz foo/bar; do
318 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l $r > $testroot/stdout
320 b2070a3f 2020-03-22 stsp echo "refs/foo/bar/baz: $commit_id" > $testroot/stdout.expected
321 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
323 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
324 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
325 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
330 b2070a3f 2020-03-22 stsp for r in refs/foo foo; do
331 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l $r > $testroot/stdout
333 b2070a3f 2020-03-22 stsp echo "refs/foo/bar/baz: $commit_id" > $testroot/stdout.expected
334 b2070a3f 2020-03-22 stsp echo "refs/foo/zoo: $commit_id" >> $testroot/stdout.expected
335 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
337 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
338 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
339 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
344 b2070a3f 2020-03-22 stsp for r in refs//foo/bar refs//foo//bar refs////////foo//bar; do
345 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l $r > $testroot/stdout
347 b2070a3f 2020-03-22 stsp echo "refs/foo/bar/baz: $commit_id" > $testroot/stdout.expected
348 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
350 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
351 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
352 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
357 b2070a3f 2020-03-22 stsp # attempt to list non-existing references
358 b2070a3f 2020-03-22 stsp for r in refs/fo bar baz moo riffs /refs/abc refs/foo/bar/baz/moo; do
359 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l $r > $testroot/stdout
361 b2070a3f 2020-03-22 stsp echo -n > $testroot/stdout.expected
362 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
364 b2070a3f 2020-03-22 stsp if [ "$ret" != "0" ]; then
365 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
366 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
371 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
374 d1c1ae5f 2019-08-12 stsp run_test test_ref_create
375 d1c1ae5f 2019-08-12 stsp run_test test_ref_delete
376 b2070a3f 2020-03-22 stsp run_test test_ref_list