3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 local testroot
=`test_init ref_create`
21 local commit_id
=`git_show_head $testroot/repo`
23 # Create a ref pointing at a commit ID
24 got ref
-r $testroot/repo
-c $commit_id refs
/heads
/commitref
26 if [ "$ret" != "0" ]; then
27 echo "got ref command failed unexpectedly"
28 test_done
"$testroot" "$ret"
32 # Create a ref based on repository's HEAD reference
33 got ref
-r $testroot/repo
-c HEAD refs
/heads
/newref
35 if [ "$ret" != "0" ]; then
36 echo "got ref command failed unexpectedly"
37 test_done
"$testroot" "$ret"
41 # Ensure that Git recognizes the ref Got has created
42 (cd $testroot/repo
&& git checkout
-q newref
)
44 if [ "$ret" != "0" ]; then
45 echo "git checkout command failed unexpectedly"
46 test_done
"$testroot" "$ret"
50 # Ensure Got recognizes the new ref
51 got checkout
-b newref
$testroot/repo
$testroot/wt
>/dev
/null
53 if [ "$ret" != "0" ]; then
54 echo "got checkout command failed unexpectedly"
55 test_done
"$testroot" "$ret"
59 # Create a head ref based on another specific ref
60 (cd $testroot/wt
&& got ref
-c refs
/heads
/master refs
/heads
/anotherref
)
62 if [ "$ret" != "0" ]; then
63 test_done
"$testroot" "$ret"
67 (cd $testroot/repo
&& git checkout
-q anotherref
)
69 if [ "$ret" != "0" ]; then
70 echo "git checkout command failed unexpectedly"
71 test_done
"$testroot" "$ret"
75 # Create a symbolic ref
76 (cd $testroot/wt
&& got ref
-s refs
/heads
/master refs
/heads
/symbolicref
)
78 if [ "$ret" != "0" ]; then
79 test_done
"$testroot" "$ret"
83 (cd $testroot/repo
&& git checkout
-q symbolicref
)
85 if [ "$ret" != "0" ]; then
86 echo "git checkout command failed unexpectedly"
87 test_done
"$testroot" "$ret"
91 # Attempt to create a symbolic ref pointing at a non-reference
92 (cd $testroot/wt
&& got ref
-s $commit_id refs
/heads
/symbolicref \
95 if [ "$ret" = "0" ]; then
96 echo "git ref command succeeded unexpectedly"
97 test_done
"$testroot" "1"
101 echo "got: reference $commit_id not found" > $testroot/stderr.expected
102 cmp -s $testroot/stderr
$testroot/stderr.expected
104 if [ "$ret" != "0" ]; then
105 diff -u $testroot/stderr.expected
$testroot/stderr
106 test_done
"$testroot" "$ret"
110 # Attempt to create a reference without specifying a name
111 (cd $testroot/wt
&& got ref
-c $commit_id 2> $testroot/stderr
)
113 if [ "$ret" = "0" ]; then
114 echo "git ref command succeeded unexpectedly"
115 test_done
"$testroot" "1"
119 grep -q '^usage: got ref' $testroot/stderr
121 if [ "$ret" != "0" ]; then
122 echo "unexpected usage error message: " >&2
123 cat $testroot/stderr
>&2
124 test_done
"$testroot" "$ret"
128 # Attempt to create a symbolic reference without specifying a name
129 (cd $testroot/wt
&& got ref
-s refs
/heads
/symbolicref \
132 if [ "$ret" = "0" ]; then
133 echo "git ref command succeeded unexpectedly"
134 test_done
"$testroot" "1"
138 grep -q '^usage: got ref' $testroot/stderr
140 if [ "$ret" != "0" ]; then
141 echo "unexpected usage error message: " >&2
142 cat $testroot/stderr
>&2
143 test_done
"$testroot" "$ret"
148 got ref
-r $testroot/repo
-s refs
/heads
/newref HEAD
150 if [ "$ret" != "0" ]; then
151 echo "got ref command failed unexpectedly"
152 test_done
"$testroot" "$ret"
156 # Ensure that Git recognizes the ref Got has created
157 (cd $testroot/repo
&& git checkout
-q HEAD
)
159 if [ "$ret" != "0" ]; then
160 echo "git checkout command failed unexpectedly"
161 test_done
"$testroot" "$ret"
165 # Ensure Got recognizes the new ref
166 (cd $testroot/wt
&& got update
-b HEAD
>/dev
/null
)
168 if [ "$ret" != "0" ]; then
169 echo "got checkout command failed unexpectedly"
170 test_done
"$testroot" "$ret"
173 got ref
-r $testroot/repo
-l > $testroot/stdout
174 echo "HEAD: refs/heads/newref" > $testroot/stdout.expected
175 echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
176 cat $testroot/wt
/.got
/uuid |
tr -d '\n' >> $testroot/stdout.expected
177 echo ": $commit_id" >> $testroot/stdout.expected
178 echo "refs/heads/anotherref: $commit_id" >> $testroot/stdout.expected
179 echo "refs/heads/commitref: $commit_id" >> $testroot/stdout.expected
180 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
181 echo "refs/heads/newref: $commit_id" >> $testroot/stdout.expected
182 echo "refs/heads/symbolicref: refs/heads/master" \
183 >> $testroot/stdout.expected
184 cmp -s $testroot/stdout
$testroot/stdout.expected
186 if [ "$ret" != "0" ]; then
187 diff -u $testroot/stdout.expected
$testroot/stdout
189 test_done
"$testroot" "$ret"
193 local testroot
=`test_init ref_delete`
194 local commit_id
=`git_show_head $testroot/repo`
196 for b
in ref1 ref2 ref3
; do
197 got ref
-r $testroot/repo
-c refs
/heads
/master refs
/heads
/$b
199 if [ "$ret" != "0" ]; then
200 echo "got ref command failed unexpectedly"
201 test_done
"$testroot" "$ret"
206 got ref
-d -r $testroot/repo refs
/heads
/ref2
> $testroot/stdout
208 if [ "$ret" != "0" ]; then
209 echo "got ref command failed unexpectedly"
210 test_done
"$testroot" "$ret"
213 echo "Deleted refs/heads/ref2: $commit_id" > $testroot/stdout.expected
214 cmp -s $testroot/stdout
$testroot/stdout.expected
216 if [ "$ret" != "0" ]; then
217 diff -u $testroot/stdout.expected
$testroot/stdout
218 test_done
"$testroot" "$ret"
222 got ref
-l -r $testroot/repo
> $testroot/stdout
223 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
224 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
225 echo "refs/heads/ref1: $commit_id" >> $testroot/stdout.expected
226 echo "refs/heads/ref3: $commit_id" >> $testroot/stdout.expected
227 cmp -s $testroot/stdout
$testroot/stdout.expected
229 if [ "$ret" != "0" ]; then
230 diff -u $testroot/stdout.expected
$testroot/stdout
231 test_done
"$testroot" "$ret"
235 got ref
-r $testroot/repo
-d refs
/heads
/bogus_ref_name \
236 > $testroot/stdout
2> $testroot/stderr
238 if [ "$ret" = "0" ]; then
239 echo "got ref succeeded unexpectedly"
240 test_done
"$testroot" "$ret"
244 echo "got: reference refs/heads/bogus_ref_name not found" \
245 > $testroot/stderr.expected
246 cmp -s $testroot/stderr
$testroot/stderr.expected
248 if [ "$ret" != "0" ]; then
249 diff -u $testroot/stderr.expected
$testroot/stderr
250 test_done
"$testroot" "$ret"
254 (cd $testroot/repo
&& git pack-refs
--all)
256 echo "modified alpha" > $testroot/repo
/alpha
257 git_commit
$testroot/repo
-m "modified alpha"
258 local commit_id2
=`git_show_head $testroot/repo`
260 # ref 'master' now exists in both packed and loose forms
262 got ref
-l -r $testroot/repo
> $testroot/stdout
263 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
264 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
265 echo "refs/heads/ref1: $commit_id" >> $testroot/stdout.expected
266 echo "refs/heads/ref3: $commit_id" >> $testroot/stdout.expected
267 cmp -s $testroot/stdout
$testroot/stdout.expected
269 if [ "$ret" != "0" ]; then
270 diff -u $testroot/stdout.expected
$testroot/stdout
271 test_done
"$testroot" "$ret"
275 got ref
-r $testroot/repo
-d master
>/dev
/null
277 got ref
-l -r $testroot/repo
> $testroot/stdout
278 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
279 echo "refs/heads/ref1: $commit_id" >> $testroot/stdout.expected
280 echo "refs/heads/ref3: $commit_id" >> $testroot/stdout.expected
281 cmp -s $testroot/stdout
$testroot/stdout.expected
283 if [ "$ret" != "0" ]; then
284 diff -u $testroot/stdout.expected
$testroot/stdout
286 test_done
"$testroot" "$ret"
290 local testroot
=`test_init ref_list`
291 local commit_id
=`git_show_head $testroot/repo`
293 # Create a tag pointing at a commit ID
294 got tag
-r $testroot/repo
-c $commit_id -m "1.0" "1.0" >/dev
/null
296 if [ "$ret" != "0" ]; then
297 echo "got tag command failed unexpectedly"
298 test_done
"$testroot" "$ret"
301 local tag_id
=`got ref -r $testroot/repo -l \
302 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
304 # Create a ref based on repository's HEAD reference
305 got ref
-r $testroot/repo
-c HEAD refs
/foo
/zoo
307 if [ "$ret" != "0" ]; then
308 echo "got ref command failed unexpectedly"
309 test_done
"$testroot" "$ret"
313 # Create a head ref based on another specific ref
314 (cd $testroot/repo
&& got ref
-c refs
/heads
/master refs
/foo
/bar
/baz
)
316 if [ "$ret" != "0" ]; then
317 test_done
"$testroot" "$ret"
321 # Create a HEAD ref in the namespace of a remote repository
322 (cd $testroot/repo
&& got ref
-s refs
/heads
/master \
323 refs
/remotes
/origin
/HEAD
)
325 if [ "$ret" != "0" ]; then
326 test_done
"$testroot" "$ret"
330 got ref
-r $testroot/repo
-l > $testroot/stdout
332 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
333 echo "refs/foo/bar/baz: $commit_id" >> $testroot/stdout.expected
334 echo "refs/foo/zoo: $commit_id" >> $testroot/stdout.expected
335 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
336 echo "refs/remotes/origin/HEAD: refs/heads/master" \
337 >> $testroot/stdout.expected
338 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
339 cmp -s $testroot/stdout
$testroot/stdout.expected
341 if [ "$ret" != "0" ]; then
342 diff -u $testroot/stdout.expected
$testroot/stdout
343 test_done
"$testroot" "$ret"
347 got ref
-r $testroot/repo
-l refs
> $testroot/stdout
349 echo "refs/foo/bar/baz: $commit_id" > $testroot/stdout.expected
350 echo "refs/foo/zoo: $commit_id" >> $testroot/stdout.expected
351 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
352 echo "refs/remotes/origin/HEAD: refs/heads/master" \
353 >> $testroot/stdout.expected
354 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
355 cmp -s $testroot/stdout
$testroot/stdout.expected
357 if [ "$ret" != "0" ]; then
358 diff -u $testroot/stdout.expected
$testroot/stdout
359 test_done
"$testroot" "$ret"
363 got ref
-r $testroot/repo
-l refs
/tags
> $testroot/stdout
365 echo "refs/tags/1.0: $tag_id" > $testroot/stdout.expected
366 cmp -s $testroot/stdout
$testroot/stdout.expected
368 if [ "$ret" != "0" ]; then
369 diff -u $testroot/stdout.expected
$testroot/stdout
370 test_done
"$testroot" "$ret"
374 for r
in refs
/foo
/bar
/baz refs
/foo
/bar
/baz foo
/bar
/baz foo
/bar
; do
375 got ref
-r $testroot/repo
-l $r > $testroot/stdout
377 echo "refs/foo/bar/baz: $commit_id" > $testroot/stdout.expected
378 cmp -s $testroot/stdout
$testroot/stdout.expected
380 if [ "$ret" != "0" ]; then
381 diff -u $testroot/stdout.expected
$testroot/stdout
382 test_done
"$testroot" "$ret"
387 for r
in refs
/foo foo
; do
388 got ref
-r $testroot/repo
-l $r > $testroot/stdout
390 echo "refs/foo/bar/baz: $commit_id" > $testroot/stdout.expected
391 echo "refs/foo/zoo: $commit_id" >> $testroot/stdout.expected
392 cmp -s $testroot/stdout
$testroot/stdout.expected
394 if [ "$ret" != "0" ]; then
395 diff -u $testroot/stdout.expected
$testroot/stdout
396 test_done
"$testroot" "$ret"
401 for r
in /refs
/abc refs
//foo
/bar refs
//foo
//bar refs
////////foo
//bar
; do
402 got ref
-r $testroot/repo
-l $r > $testroot/stdout \
405 echo -n > $testroot/stdout.expected
406 cmp -s $testroot/stdout
$testroot/stdout.expected
408 if [ "$ret" != "0" ]; then
409 diff -u $testroot/stdout.expected
$testroot/stdout
410 test_done
"$testroot" "$ret"
414 echo "got: $r: bad reference name" > $testroot/stderr.expected
415 cmp -s $testroot/stderr
$testroot/stderr.expected
417 if [ "$ret" != "0" ]; then
418 diff -u $testroot/stderr.expected
$testroot/stderr
419 test_done
"$testroot" "$ret"
424 # attempt to list non-existing references
425 for r
in refs
/fo bar baz moo riffs refs
/abc refs
/foo
/bar
/baz
/moo
; do
426 got ref
-r $testroot/repo
-l $r > $testroot/stdout
428 echo -n > $testroot/stdout.expected
429 cmp -s $testroot/stdout
$testroot/stdout.expected
431 if [ "$ret" != "0" ]; then
432 diff -u $testroot/stdout.expected
$testroot/stdout
433 test_done
"$testroot" "$ret"
438 test_done
"$testroot" "$ret"
442 run_test test_ref_create
443 run_test test_ref_delete
444 run_test test_ref_list