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 f6cae3ed 2020-09-13 naddy 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 49c543a6 2022-03-31 naddy if [ $ret -ne 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 49c543a6 2022-03-31 naddy if [ $ret -ne 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 f73bf5bd 2023-10-01 naddy git -C $testroot/repo checkout -q newref
44 49c543a6 2022-03-31 naddy if [ $ret -ne 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 49c543a6 2022-03-31 naddy if [ $ret -ne 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 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
63 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
67 f73bf5bd 2023-10-01 naddy git -C $testroot/repo checkout -q anotherref
69 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
70 d1c1ae5f 2019-08-12 stsp echo "git checkout command failed unexpectedly"
71 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
75 d1c1ae5f 2019-08-12 stsp # Create a symbolic ref
76 e31abbf2 2020-03-22 stsp (cd $testroot/wt && got ref -s refs/heads/master refs/heads/symbolicref)
78 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
79 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
83 f73bf5bd 2023-10-01 naddy git -C $testroot/repo checkout -q symbolicref
85 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
86 d1c1ae5f 2019-08-12 stsp echo "git checkout command failed unexpectedly"
87 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
91 2d463f36 2019-08-12 stsp # Attempt to create a symbolic ref pointing at a non-reference
92 e31abbf2 2020-03-22 stsp (cd $testroot/wt && got ref -s $commit_id refs/heads/symbolicref \
93 2d463f36 2019-08-12 stsp 2> $testroot/stderr)
95 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
96 81a19701 2022-03-10 naddy echo "got ref command succeeded unexpectedly"
97 2d463f36 2019-08-12 stsp test_done "$testroot" "1"
101 2d463f36 2019-08-12 stsp echo "got: reference $commit_id not found" > $testroot/stderr.expected
102 2d463f36 2019-08-12 stsp cmp -s $testroot/stderr $testroot/stderr.expected
104 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
105 2d463f36 2019-08-12 stsp diff -u $testroot/stderr.expected $testroot/stderr
106 2d463f36 2019-08-12 stsp test_done "$testroot" "$ret"
110 e31abbf2 2020-03-22 stsp # Attempt to create a reference without specifying a name
111 e31abbf2 2020-03-22 stsp (cd $testroot/wt && got ref -c $commit_id 2> $testroot/stderr)
113 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
114 81a19701 2022-03-10 naddy echo "got ref command succeeded unexpectedly"
115 e31abbf2 2020-03-22 stsp test_done "$testroot" "1"
119 e31abbf2 2020-03-22 stsp grep -q '^usage: got ref' $testroot/stderr
121 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
122 e31abbf2 2020-03-22 stsp echo "unexpected usage error message: " >&2
123 e31abbf2 2020-03-22 stsp cat $testroot/stderr >&2
124 e31abbf2 2020-03-22 stsp test_done "$testroot" "$ret"
128 e31abbf2 2020-03-22 stsp # Attempt to create a symbolic reference without specifying a name
129 e31abbf2 2020-03-22 stsp (cd $testroot/wt && got ref -s refs/heads/symbolicref \
130 e31abbf2 2020-03-22 stsp 2> $testroot/stderr)
132 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
133 81a19701 2022-03-10 naddy echo "got ref command succeeded unexpectedly"
134 e31abbf2 2020-03-22 stsp test_done "$testroot" "1"
138 e31abbf2 2020-03-22 stsp grep -q '^usage: got ref' $testroot/stderr
140 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
141 e31abbf2 2020-03-22 stsp echo "unexpected usage error message: " >&2
142 e31abbf2 2020-03-22 stsp cat $testroot/stderr >&2
143 e31abbf2 2020-03-22 stsp test_done "$testroot" "$ret"
147 7fa81f88 2020-02-21 stsp # Change HEAD
148 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -s refs/heads/newref HEAD
150 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
151 7fa81f88 2020-02-21 stsp echo "got ref command failed unexpectedly"
152 7fa81f88 2020-02-21 stsp test_done "$testroot" "$ret"
156 7fa81f88 2020-02-21 stsp # Ensure that Git recognizes the ref Got has created
157 f73bf5bd 2023-10-01 naddy git -C $testroot/repo checkout -q HEAD
159 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
160 7fa81f88 2020-02-21 stsp echo "git checkout command failed unexpectedly"
161 7fa81f88 2020-02-21 stsp test_done "$testroot" "$ret"
165 7fa81f88 2020-02-21 stsp # Ensure Got recognizes the new ref
166 7fa81f88 2020-02-21 stsp (cd $testroot/wt && got update -b HEAD >/dev/null)
168 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
169 81a19701 2022-03-10 naddy echo "got update command failed unexpectedly"
170 7fa81f88 2020-02-21 stsp test_done "$testroot" "$ret"
173 d1c1ae5f 2019-08-12 stsp got ref -r $testroot/repo -l > $testroot/stdout
174 7fa81f88 2020-02-21 stsp echo "HEAD: refs/heads/newref" > $testroot/stdout.expected
175 d1c1ae5f 2019-08-12 stsp echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
176 d1c1ae5f 2019-08-12 stsp cat $testroot/wt/.got/uuid | tr -d '\n' >> $testroot/stdout.expected
177 d1c1ae5f 2019-08-12 stsp echo ": $commit_id" >> $testroot/stdout.expected
178 d1c1ae5f 2019-08-12 stsp echo "refs/heads/anotherref: $commit_id" >> $testroot/stdout.expected
179 d4fc9a62 2019-10-09 stsp echo "refs/heads/commitref: $commit_id" >> $testroot/stdout.expected
180 d1c1ae5f 2019-08-12 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
181 d1c1ae5f 2019-08-12 stsp echo "refs/heads/newref: $commit_id" >> $testroot/stdout.expected
182 d1c1ae5f 2019-08-12 stsp echo "refs/heads/symbolicref: refs/heads/master" \
183 d1c1ae5f 2019-08-12 stsp >> $testroot/stdout.expected
184 d1c1ae5f 2019-08-12 stsp cmp -s $testroot/stdout $testroot/stdout.expected
186 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
187 d1c1ae5f 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
189 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
192 f6cae3ed 2020-09-13 naddy test_ref_delete() {
193 d1c1ae5f 2019-08-12 stsp local testroot=`test_init ref_delete`
194 d1c1ae5f 2019-08-12 stsp local commit_id=`git_show_head $testroot/repo`
196 d1c1ae5f 2019-08-12 stsp for b in ref1 ref2 ref3; do
197 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c refs/heads/master refs/heads/$b
199 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
200 d1c1ae5f 2019-08-12 stsp echo "got ref command failed unexpectedly"
201 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
206 e31abbf2 2020-03-22 stsp got ref -d -r $testroot/repo refs/heads/ref2 > $testroot/stdout
208 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
209 d1c1ae5f 2019-08-12 stsp echo "got ref command failed unexpectedly"
210 993f033b 2021-07-16 stsp test_done "$testroot" "$ret"
213 993f033b 2021-07-16 stsp echo "Deleted refs/heads/ref2: $commit_id" > $testroot/stdout.expected
214 993f033b 2021-07-16 stsp cmp -s $testroot/stdout $testroot/stdout.expected
216 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
217 993f033b 2021-07-16 stsp diff -u $testroot/stdout.expected $testroot/stdout
218 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
222 d1c1ae5f 2019-08-12 stsp got ref -l -r $testroot/repo > $testroot/stdout
223 d1c1ae5f 2019-08-12 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
224 d1c1ae5f 2019-08-12 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
225 d1c1ae5f 2019-08-12 stsp echo "refs/heads/ref1: $commit_id" >> $testroot/stdout.expected
226 d1c1ae5f 2019-08-12 stsp echo "refs/heads/ref3: $commit_id" >> $testroot/stdout.expected
227 d1c1ae5f 2019-08-12 stsp cmp -s $testroot/stdout $testroot/stdout.expected
229 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
230 d1c1ae5f 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
231 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
235 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -d refs/heads/bogus_ref_name \
236 d1c1ae5f 2019-08-12 stsp > $testroot/stdout 2> $testroot/stderr
238 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
239 d1c1ae5f 2019-08-12 stsp echo "got ref succeeded unexpectedly"
240 a19f439c 2022-06-03 op test_done "$testroot" "1"
244 d1c1ae5f 2019-08-12 stsp echo "got: reference refs/heads/bogus_ref_name not found" \
245 d1c1ae5f 2019-08-12 stsp > $testroot/stderr.expected
246 d1c1ae5f 2019-08-12 stsp cmp -s $testroot/stderr $testroot/stderr.expected
248 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
249 d1c1ae5f 2019-08-12 stsp diff -u $testroot/stderr.expected $testroot/stderr
250 2a104ff6 2020-09-21 stsp test_done "$testroot" "$ret"
254 f73bf5bd 2023-10-01 naddy git -C $testroot/repo pack-refs --all
256 2a104ff6 2020-09-21 stsp echo "modified alpha" > $testroot/repo/alpha
257 2a104ff6 2020-09-21 stsp git_commit $testroot/repo -m "modified alpha"
258 2a104ff6 2020-09-21 stsp local commit_id2=`git_show_head $testroot/repo`
260 2a104ff6 2020-09-21 stsp # ref 'master' now exists in both packed and loose forms
262 2a104ff6 2020-09-21 stsp got ref -l -r $testroot/repo > $testroot/stdout
263 2a104ff6 2020-09-21 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
264 2a104ff6 2020-09-21 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
265 2a104ff6 2020-09-21 stsp echo "refs/heads/ref1: $commit_id" >> $testroot/stdout.expected
266 2a104ff6 2020-09-21 stsp echo "refs/heads/ref3: $commit_id" >> $testroot/stdout.expected
267 2a104ff6 2020-09-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
269 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
270 2a104ff6 2020-09-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
271 2a104ff6 2020-09-21 stsp test_done "$testroot" "$ret"
275 993f033b 2021-07-16 stsp got ref -r $testroot/repo -d master >/dev/null
277 2a104ff6 2020-09-21 stsp got ref -l -r $testroot/repo > $testroot/stdout
278 48cae60d 2020-09-22 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
279 48cae60d 2020-09-22 stsp echo "refs/heads/ref1: $commit_id" >> $testroot/stdout.expected
280 2a104ff6 2020-09-21 stsp echo "refs/heads/ref3: $commit_id" >> $testroot/stdout.expected
281 2a104ff6 2020-09-21 stsp cmp -s $testroot/stdout $testroot/stdout.expected
283 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
284 2a104ff6 2020-09-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
286 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
289 f6cae3ed 2020-09-13 naddy test_ref_list() {
290 b2070a3f 2020-03-22 stsp local testroot=`test_init ref_list`
291 b2070a3f 2020-03-22 stsp local commit_id=`git_show_head $testroot/repo`
293 b2070a3f 2020-03-22 stsp # Create a tag pointing at a commit ID
294 b2070a3f 2020-03-22 stsp got tag -r $testroot/repo -c $commit_id -m "1.0" "1.0" >/dev/null
296 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
297 b2070a3f 2020-03-22 stsp echo "got tag command failed unexpectedly"
298 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
301 b2070a3f 2020-03-22 stsp local tag_id=`got ref -r $testroot/repo -l \
302 b2070a3f 2020-03-22 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
304 b2070a3f 2020-03-22 stsp # Create a ref based on repository's HEAD reference
305 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -c HEAD refs/foo/zoo
307 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
308 b2070a3f 2020-03-22 stsp echo "got ref command failed unexpectedly"
309 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
313 b2070a3f 2020-03-22 stsp # Create a head ref based on another specific ref
314 b2070a3f 2020-03-22 stsp (cd $testroot/repo && got ref -c refs/heads/master refs/foo/bar/baz)
316 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
317 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
321 75236079 2020-03-25 stsp # Create a HEAD ref in the namespace of a remote repository
322 75236079 2020-03-25 stsp (cd $testroot/repo && got ref -s refs/heads/master \
323 75236079 2020-03-25 stsp refs/remotes/origin/HEAD)
325 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
326 75236079 2020-03-25 stsp test_done "$testroot" "$ret"
330 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l > $testroot/stdout
332 b2070a3f 2020-03-22 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
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 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
336 75236079 2020-03-25 stsp echo "refs/remotes/origin/HEAD: refs/heads/master" \
337 75236079 2020-03-25 stsp >> $testroot/stdout.expected
338 b2070a3f 2020-03-22 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
339 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
341 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
342 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
343 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
347 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l refs > $testroot/stdout
349 b2070a3f 2020-03-22 stsp echo "refs/foo/bar/baz: $commit_id" > $testroot/stdout.expected
350 b2070a3f 2020-03-22 stsp echo "refs/foo/zoo: $commit_id" >> $testroot/stdout.expected
351 b2070a3f 2020-03-22 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
352 75236079 2020-03-25 stsp echo "refs/remotes/origin/HEAD: refs/heads/master" \
353 75236079 2020-03-25 stsp >> $testroot/stdout.expected
354 b2070a3f 2020-03-22 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
355 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
357 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
358 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
359 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
363 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l refs/tags > $testroot/stdout
365 b2070a3f 2020-03-22 stsp echo "refs/tags/1.0: $tag_id" > $testroot/stdout.expected
366 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
368 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
369 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
370 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
374 b2070a3f 2020-03-22 stsp for r in refs/foo/bar/baz refs/foo/bar/baz foo/bar/baz foo/bar; do
375 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l $r > $testroot/stdout
377 b2070a3f 2020-03-22 stsp echo "refs/foo/bar/baz: $commit_id" > $testroot/stdout.expected
378 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
380 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
381 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
382 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
387 b2070a3f 2020-03-22 stsp for r in refs/foo foo; do
388 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l $r > $testroot/stdout
390 b2070a3f 2020-03-22 stsp echo "refs/foo/bar/baz: $commit_id" > $testroot/stdout.expected
391 b2070a3f 2020-03-22 stsp echo "refs/foo/zoo: $commit_id" >> $testroot/stdout.expected
392 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
394 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
395 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
396 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
401 57c18198 2021-05-24 stsp for r in /refs/abc refs//foo/bar refs//foo//bar refs////////foo//bar; do
402 57c18198 2021-05-24 stsp got ref -r $testroot/repo -l $r > $testroot/stdout \
403 57c18198 2021-05-24 stsp 2> $testroot/stderr
405 57c18198 2021-05-24 stsp echo -n > $testroot/stdout.expected
406 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
408 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
409 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
410 57c18198 2021-05-24 stsp test_done "$testroot" "$ret"
414 57c18198 2021-05-24 stsp echo "got: $r: bad reference name" > $testroot/stderr.expected
415 57c18198 2021-05-24 stsp cmp -s $testroot/stderr $testroot/stderr.expected
417 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
418 57c18198 2021-05-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
419 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
424 b2070a3f 2020-03-22 stsp # attempt to list non-existing references
425 57c18198 2021-05-24 stsp for r in refs/fo bar baz moo riffs refs/abc refs/foo/bar/baz/moo; do
426 b2070a3f 2020-03-22 stsp got ref -r $testroot/repo -l $r > $testroot/stdout
428 b2070a3f 2020-03-22 stsp echo -n > $testroot/stdout.expected
429 b2070a3f 2020-03-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
431 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
432 b2070a3f 2020-03-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
433 b2070a3f 2020-03-22 stsp test_done "$testroot" "$ret"
438 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
441 0f8a0e25 2024-03-19 stsp test_ref_list_packed_refs() {
442 0f8a0e25 2024-03-19 stsp local testroot=`test_init ref_list_packed_refs`
443 0f8a0e25 2024-03-19 stsp local commit_id=`git_show_head $testroot/repo`
444 0f8a0e25 2024-03-19 stsp local tag=1.0.0
445 0f8a0e25 2024-03-19 stsp local tag2=2.0.0
447 0f8a0e25 2024-03-19 stsp # create tag with Git
448 0f8a0e25 2024-03-19 stsp git -C $testroot/repo tag -a -m 'test' $tag
449 0f8a0e25 2024-03-19 stsp # create tag with Got
450 0f8a0e25 2024-03-19 stsp (cd $testroot/repo && got tag -m 'test' $tag2 > /dev/null)
452 0f8a0e25 2024-03-19 stsp tag_id=`got ref -r $testroot/repo -l \
453 0f8a0e25 2024-03-19 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
454 0f8a0e25 2024-03-19 stsp local tagger_time=`git_show_tagger_time $testroot/repo $tag`
455 0f8a0e25 2024-03-19 stsp d1=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
456 0f8a0e25 2024-03-19 stsp tag_id2=`got ref -r $testroot/repo -l \
457 0f8a0e25 2024-03-19 stsp | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
458 0f8a0e25 2024-03-19 stsp local tagger_time2=`git_show_tagger_time $testroot/repo $tag2`
459 0f8a0e25 2024-03-19 stsp d2=`date -u -r $tagger_time2 +"%a %b %e %X %Y UTC"`
461 0f8a0e25 2024-03-19 stsp for i in 1 2; do
462 0f8a0e25 2024-03-19 stsp if [ $i -eq 2 ]; then
463 0f8a0e25 2024-03-19 stsp # Move all refs into the packed-refs file
464 0f8a0e25 2024-03-19 stsp git -C $testroot/repo pack-refs --all
467 0f8a0e25 2024-03-19 stsp got ref -r $testroot/repo -l > $testroot/stdout
469 0f8a0e25 2024-03-19 stsp cat > $testroot/stdout.expected <<EOF
470 0f8a0e25 2024-03-19 stsp HEAD: refs/heads/master
471 0f8a0e25 2024-03-19 stsp refs/heads/master: $commit_id
472 0f8a0e25 2024-03-19 stsp refs/tags/1.0.0: $tag_id
473 0f8a0e25 2024-03-19 stsp refs/tags/2.0.0: $tag_id2
475 0f8a0e25 2024-03-19 stsp cmp -s $testroot/stdout $testroot/stdout.expected
477 0f8a0e25 2024-03-19 stsp if [ $ret -ne 0 ]; then
478 0f8a0e25 2024-03-19 stsp diff -u $testroot/stdout.expected $testroot/stdout
479 0f8a0e25 2024-03-19 stsp test_done "$testroot" "$ret"
483 0f8a0e25 2024-03-19 stsp got ref -r $testroot/repo -l tags/$tag > $testroot/stdout
485 0f8a0e25 2024-03-19 stsp cat > $testroot/stdout.expected <<EOF
486 0f8a0e25 2024-03-19 stsp refs/tags/1.0.0: $tag_id
488 0f8a0e25 2024-03-19 stsp cmp -s $testroot/stdout $testroot/stdout.expected
490 0f8a0e25 2024-03-19 stsp if [ $ret -ne 0 ]; then
491 0f8a0e25 2024-03-19 stsp diff -u $testroot/stdout.expected $testroot/stdout
492 0f8a0e25 2024-03-19 stsp test_done "$testroot" "$ret"
496 0f8a0e25 2024-03-19 stsp got ref -r $testroot/repo -l $tag2 > $testroot/stdout
498 0f8a0e25 2024-03-19 stsp cat > $testroot/stdout.expected <<EOF
499 0f8a0e25 2024-03-19 stsp refs/tags/2.0.0: $tag_id2
501 0f8a0e25 2024-03-19 stsp cmp -s $testroot/stdout $testroot/stdout.expected
503 0f8a0e25 2024-03-19 stsp if [ $ret -ne 0 ]; then
504 0f8a0e25 2024-03-19 stsp diff -u $testroot/stdout.expected $testroot/stdout
505 0f8a0e25 2024-03-19 stsp test_done "$testroot" "$ret"
509 0f8a0e25 2024-03-19 stsp got ref -r $testroot/repo -l tags > $testroot/stdout
510 0f8a0e25 2024-03-19 stsp cat > $testroot/stdout.expected <<EOF
511 0f8a0e25 2024-03-19 stsp refs/tags/1.0.0: $tag_id
512 0f8a0e25 2024-03-19 stsp refs/tags/2.0.0: $tag_id2
514 0f8a0e25 2024-03-19 stsp cmp -s $testroot/stdout $testroot/stdout.expected
516 0f8a0e25 2024-03-19 stsp if [ $ret -ne 0 ]; then
517 0f8a0e25 2024-03-19 stsp diff -u $testroot/stdout.expected $testroot/stdout
518 0f8a0e25 2024-03-19 stsp test_done "$testroot" "$ret"
523 0f8a0e25 2024-03-19 stsp test_done "$testroot" "0"
526 4390d6c1 2023-07-18 mark test_ref_commit_keywords() {
527 4390d6c1 2023-07-18 mark local testroot=$(test_init ref_commit_keywords)
528 4390d6c1 2023-07-18 mark local repo="$testroot/repo"
529 4390d6c1 2023-07-18 mark local wt="$testroot/wt"
531 4390d6c1 2023-07-18 mark got checkout "$repo" "$wt" > /dev/null
533 4390d6c1 2023-07-18 mark if [ $ret -ne 0 ]; then
534 4390d6c1 2023-07-18 mark echo "checkout failed unexpectedly" >&2
535 4390d6c1 2023-07-18 mark test_done "$testroot" "$ret"
539 4390d6c1 2023-07-18 mark for i in $(seq 8); do
540 4390d6c1 2023-07-18 mark echo "alpha change $i" > "$wt/alpha"
542 4390d6c1 2023-07-18 mark (cd "$wt" && got ci -m "commit number $i" > /dev/null)
544 4390d6c1 2023-07-18 mark if [ $ret -ne 0 ]; then
545 4390d6c1 2023-07-18 mark echo "commit failed unexpectedly" >&2
546 4390d6c1 2023-07-18 mark test_done "$testroot" "$ret"
550 79c49d84 2023-07-24 mark set -- "$@" "$(git_show_head $repo)"
553 4390d6c1 2023-07-18 mark (cd "$wt" && got ref -c:head:-4 refs/heads/head-4)
555 4390d6c1 2023-07-18 mark if [ $ret -ne 0 ]; then
556 4390d6c1 2023-07-18 mark echo "got ref command failed unexpectedly"
557 4390d6c1 2023-07-18 mark test_done "$testroot" "$ret"
561 4390d6c1 2023-07-18 mark (cd "$wt" && got up -c head-4 > /dev/null)
563 4390d6c1 2023-07-18 mark if [ $ret -ne 0 ]; then
564 4390d6c1 2023-07-18 mark echo "got checkout command failed unexpectedly"
565 4390d6c1 2023-07-18 mark test_done "$testroot" "$ret"
569 4390d6c1 2023-07-18 mark (cd "$wt" && got ref -c:base:+2 refs/heads/base+2)
571 4390d6c1 2023-07-18 mark if [ $ret -ne 0 ]; then
572 4390d6c1 2023-07-18 mark echo "got ref command failed unexpectedly"
573 4390d6c1 2023-07-18 mark test_done "$testroot" "$ret"
577 4390d6c1 2023-07-18 mark (cd "$wt" && got ref -cmaster:- refs/heads/master-)
579 4390d6c1 2023-07-18 mark if [ $ret -ne 0 ]; then
580 4390d6c1 2023-07-18 mark echo "got ref command failed unexpectedly"
581 4390d6c1 2023-07-18 mark test_done "$testroot" "$ret"
585 4390d6c1 2023-07-18 mark echo "HEAD: refs/heads/master" > $testroot/stdout.expected
586 4390d6c1 2023-07-18 mark echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
587 4390d6c1 2023-07-18 mark cat "$wt/.got/uuid" | tr -d '\n' >> $testroot/stdout.expected
588 79c49d84 2023-07-24 mark echo ": $(pop_idx 4 $@)" >> $testroot/stdout.expected
589 79c49d84 2023-07-24 mark echo "refs/heads/base+2: $(pop_idx 6 $@)" >> $testroot/stdout.expected
590 79c49d84 2023-07-24 mark echo "refs/heads/head-4: $(pop_idx 4 $@)" >> $testroot/stdout.expected
591 79c49d84 2023-07-24 mark echo "refs/heads/master: $(pop_idx 8 $@)" >> $testroot/stdout.expected
592 79c49d84 2023-07-24 mark echo "refs/heads/master-: $(pop_idx 7 $@)" >> $testroot/stdout.expected
594 4390d6c1 2023-07-18 mark got ref -r "$repo" -l > $testroot/stdout
595 4390d6c1 2023-07-18 mark cmp -s $testroot/stdout $testroot/stdout.expected
597 4390d6c1 2023-07-18 mark if [ $ret -ne 0 ]; then
598 4390d6c1 2023-07-18 mark diff -u $testroot/stdout.expected $testroot/stdout
600 4390d6c1 2023-07-18 mark test_done "$testroot" "$ret"
603 7fb414ae 2020-08-08 stsp test_parseargs "$@"
604 d1c1ae5f 2019-08-12 stsp run_test test_ref_create
605 d1c1ae5f 2019-08-12 stsp run_test test_ref_delete
606 b2070a3f 2020-03-22 stsp run_test test_ref_list
607 0f8a0e25 2024-03-19 stsp run_test test_ref_list_packed_refs
608 4390d6c1 2023-07-18 mark run_test test_ref_commit_keywords