make got-read-gotconfig clear its imsgbuf before exit in an error case
[got-portable.git] / regress / cmdline / tag.sh
blobae6a0b611d58d550c13a91db680bfa2ce6c36e1e
1 #!/bin/sh
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.
17 . ./common.sh
19 test_tag_create() {
20 local testroot=`test_init tag_create`
21 local commit_id=`git_show_head $testroot/repo`
22 local tag=1.0.0
23 local tag2=2.0.0
25 # Create a tag based on repository's HEAD reference
26 got tag -m 'test' -r $testroot/repo -c HEAD $tag > $testroot/stdout
27 ret=$?
28 if [ $ret -ne 0 ]; then
29 echo "got ref command failed unexpectedly"
30 test_done "$testroot" "$ret"
31 return 1
34 tag_id=`got ref -r $testroot/repo -l \
35 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
36 echo "Created tag $tag_id" > $testroot/stdout.expected
37 cmp -s $testroot/stdout $testroot/stdout.expected
38 ret=$?
39 if [ $ret -ne 0 ]; then
40 diff -u $testroot/stdout.expected $testroot/stdout
41 test_done "$testroot" "$ret"
42 return 1
45 # Ensure that Git recognizes the tag Got has created
46 git -C $testroot/repo checkout -q $tag
47 ret=$?
48 if [ $ret -ne 0 ]; then
49 echo "git checkout command failed unexpectedly"
50 test_done "$testroot" "$ret"
51 return 1
54 # Ensure Got recognizes the new tag
55 got checkout -c $tag $testroot/repo $testroot/wt >/dev/null
56 ret=$?
57 if [ $ret -ne 0 ]; then
58 echo "got checkout command failed unexpectedly"
59 test_done "$testroot" "$ret"
60 return 1
63 # Create a tag based on implied worktree HEAD ref
64 (cd $testroot/wt && got branch foo > /dev/null)
65 echo 'foo' >> $testroot/wt/alpha
66 (cd $testroot/wt && got commit -m foo > /dev/null)
67 local commit_id2=`git_show_branch_head $testroot/repo foo`
68 (cd $testroot/wt && got tag -m 'test' $tag2 > $testroot/stdout)
69 ret=$?
70 if [ $ret -ne 0 ]; then
71 test_done "$testroot" "$ret"
72 return 1
75 tag_id2=`got ref -r $testroot/repo -l \
76 | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
77 echo "Created tag $tag_id2" > $testroot/stdout.expected
78 cmp -s $testroot/stdout $testroot/stdout.expected
79 ret=$?
80 if [ $ret -ne 0 ]; then
81 diff -u $testroot/stdout.expected $testroot/stdout
82 test_done "$testroot" "$ret"
83 return 1
86 tagged_commit=`got cat -r $testroot/repo $tag2 | grep ^object \
87 | cut -d' ' -f2`
88 if [ "$tagged_commit" != "$commit_id2" ]; then
89 echo "wrong commit was tagged" >&2
90 test_done "$testroot" "1"
91 return 1
94 git -C $testroot/repo checkout -q $tag2
95 ret=$?
96 if [ $ret -ne 0 ]; then
97 echo "git checkout command failed unexpectedly"
98 test_done "$testroot" "$ret"
99 return 1
102 # Attempt to create a tag pointing at a non-commit
103 local tree_id=`git_show_tree $testroot/repo`
104 (cd $testroot/wt && got tag -m 'test' -c $tree_id foobar \
105 2> $testroot/stderr)
106 ret=$?
107 if [ $ret -eq 0 ]; then
108 echo "got tag command succeeded unexpectedly"
109 test_done "$testroot" "1"
110 return 1
113 echo "got: commit $tree_id: object not found" \
114 > $testroot/stderr.expected
115 cmp -s $testroot/stderr $testroot/stderr.expected
116 ret=$?
117 if [ $ret -ne 0 ]; then
118 diff -u $testroot/stderr.expected $testroot/stderr
119 test_done "$testroot" "$ret"
120 return 1
123 got ref -r $testroot/repo -l > $testroot/stdout
124 echo "HEAD: $commit_id2" > $testroot/stdout.expected
125 echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
126 cat $testroot/wt/.got/uuid | tr -d '\n' >> $testroot/stdout.expected
127 echo ": $commit_id2" >> $testroot/stdout.expected
128 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
129 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
130 echo "refs/tags/$tag: $tag_id" >> $testroot/stdout.expected
131 echo "refs/tags/$tag2: $tag_id2" >> $testroot/stdout.expected
132 cmp -s $testroot/stdout $testroot/stdout.expected
133 ret=$?
134 if [ $ret -ne 0 ]; then
135 diff -u $testroot/stdout.expected $testroot/stdout
137 test_done "$testroot" "$ret"
140 test_tag_list() {
141 local testroot=`test_init tag_list`
142 local commit_id=`git_show_head $testroot/repo`
143 local tag=1.0.0
144 local tag2=2.0.0
146 # create tag with Git
147 git -C $testroot/repo tag -a -m 'test' $tag
148 # create tag with Got
149 (cd $testroot/repo && got tag -m 'test' $tag2 > /dev/null)
151 tag_id=`got ref -r $testroot/repo -l \
152 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
153 local tagger_time=`git_show_tagger_time $testroot/repo $tag`
154 d1=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
155 tag_id2=`got ref -r $testroot/repo -l \
156 | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
157 local tagger_time2=`git_show_tagger_time $testroot/repo $tag2`
158 d2=`date -u -r $tagger_time2 +"%a %b %e %X %Y UTC"`
160 got tag -r $testroot/repo -l > $testroot/stdout
162 echo "-----------------------------------------------" \
163 > $testroot/stdout.expected
164 echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
165 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
166 echo "date: $d2" >> $testroot/stdout.expected
167 echo "object: commit $commit_id" >> $testroot/stdout.expected
168 echo " " >> $testroot/stdout.expected
169 echo " test" >> $testroot/stdout.expected
170 echo " " >> $testroot/stdout.expected
171 echo "-----------------------------------------------" \
172 >> $testroot/stdout.expected
173 echo "tag $tag $tag_id" >> $testroot/stdout.expected
174 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
175 echo "date: $d1" >> $testroot/stdout.expected
176 echo "object: commit $commit_id" >> $testroot/stdout.expected
177 echo " " >> $testroot/stdout.expected
178 echo " test" >> $testroot/stdout.expected
179 echo " " >> $testroot/stdout.expected
180 cmp -s $testroot/stdout $testroot/stdout.expected
181 ret=$?
182 if [ $ret -ne 0 ]; then
183 diff -u $testroot/stdout.expected $testroot/stdout
184 test_done "$testroot" "$ret"
185 return 1
188 got tag -r $testroot/repo -l $tag > $testroot/stdout
190 echo "-----------------------------------------------" \
191 > $testroot/stdout.expected
192 echo "tag $tag $tag_id" >> $testroot/stdout.expected
193 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
194 echo "date: $d1" >> $testroot/stdout.expected
195 echo "object: commit $commit_id" >> $testroot/stdout.expected
196 echo " " >> $testroot/stdout.expected
197 echo " test" >> $testroot/stdout.expected
198 echo " " >> $testroot/stdout.expected
199 cmp -s $testroot/stdout $testroot/stdout.expected
200 ret=$?
201 if [ $ret -ne 0 ]; then
202 diff -u $testroot/stdout.expected $testroot/stdout
203 test_done "$testroot" "$ret"
204 return 1
207 got tag -r $testroot/repo -l $tag2 > $testroot/stdout
209 echo "-----------------------------------------------" \
210 > $testroot/stdout.expected
211 echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
212 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
213 echo "date: $d2" >> $testroot/stdout.expected
214 echo "object: commit $commit_id" >> $testroot/stdout.expected
215 echo " " >> $testroot/stdout.expected
216 echo " test" >> $testroot/stdout.expected
217 echo " " >> $testroot/stdout.expected
218 cmp -s $testroot/stdout $testroot/stdout.expected
219 ret=$?
220 if [ $ret -ne 0 ]; then
221 diff -u $testroot/stdout.expected $testroot/stdout
223 test_done "$testroot" "$ret"
226 test_tag_list_oneline() {
227 local testroot=`test_init tag_list`
228 local commit_id=`git_show_head $testroot/repo`
229 local tag=1.0.0
230 local tag2=2.0.0
232 local head_ref=`got ref -r $testroot/repo -l | sed -n 's/^HEAD: //p'`
233 local tag_commit_id=`got ref -r $testroot/repo -l "$head_ref" |
234 sed -n "s:^$head_ref\: ::p"`
236 # create tag with Git
237 git -C $testroot/repo tag -a -m 'test' $tag
238 # create tag with Got
239 (cd $testroot/repo && got tag -m 'test' $tag2 > /dev/null)
241 local tagger_time=`git_show_tagger_time $testroot/repo $tag`
242 d1=`date -u -r $tagger_time +"%F"`
243 local tagger_time2=`git_show_tagger_time $testroot/repo $tag2`
244 d2=`date -u -r $tagger_time2 +"%F"`
246 got tag -r $testroot/repo -ls > $testroot/stdout
248 echo "$d2 commit:$(trim_obj_id 10 "$tag_commit_id") $tag2: test" \
249 > $testroot/stdout.expected
250 echo "$d1 commit:$(trim_obj_id 10 "$tag_commit_id") $tag: test" \
251 >> $testroot/stdout.expected
252 cmp -s $testroot/stdout $testroot/stdout.expected
253 ret=$?
254 if [ $ret -ne 0 ]; then
255 diff -u $testroot/stdout.expected $testroot/stdout
256 test_done "$testroot" "$ret"
257 return 1
260 got tag -r $testroot/repo -ls $tag > $testroot/stdout
262 echo "$d1 commit:$(trim_obj_id 10 "$tag_commit_id") $tag: test" \
263 > $testroot/stdout.expected
264 cmp -s $testroot/stdout $testroot/stdout.expected
265 ret=$?
266 if [ $ret -ne 0 ]; then
267 diff -u $testroot/stdout.expected $testroot/stdout
268 test_done "$testroot" "$ret"
269 return 1
272 got tag -r $testroot/repo -ls $tag2 > $testroot/stdout
274 echo "$d2 commit:$(trim_obj_id 10 "$tag_commit_id") $tag2: test" \
275 > $testroot/stdout.expected
276 cmp -s $testroot/stdout $testroot/stdout.expected
277 ret=$?
278 if [ $ret -ne 0 ]; then
279 diff -u $testroot/stdout.expected $testroot/stdout
281 test_done "$testroot" "$ret"
284 test_tag_list_lightweight() {
285 local testroot=`test_init tag_list_lightweight`
286 local commit_id=`git_show_head $testroot/repo`
287 local tag=1.0.0
288 local tag2=2.0.0
290 # create "lightweight" tag with Git
291 git -C $testroot/repo tag $tag
292 git -C $testroot/repo tag $tag2
294 tag_id=`got ref -r $testroot/repo -l \
295 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
296 local tagger_time=`git_show_author_time $testroot/repo $tag`
297 d1=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
298 tag_id2=`got ref -r $testroot/repo -l \
299 | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
300 local tagger_time2=`git_show_author_time $testroot/repo $tag2`
301 d2=`date -u -r $tagger_time2 +"%a %b %e %X %Y UTC"`
303 got tag -r $testroot/repo -l > $testroot/stdout
305 # test signature validation ignoring lightweight tags
306 got tag -r $testroot/repo -V > $testroot/stdout
308 echo "-----------------------------------------------" \
309 > $testroot/stdout.expected
310 echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
311 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
312 echo "date: $d2" >> $testroot/stdout.expected
313 echo "object: commit $commit_id" >> $testroot/stdout.expected
314 echo " " >> $testroot/stdout.expected
315 echo " adding the test tree" >> $testroot/stdout.expected
316 echo " " >> $testroot/stdout.expected
317 echo "-----------------------------------------------" \
318 >> $testroot/stdout.expected
319 echo "tag $tag $tag_id" >> $testroot/stdout.expected
320 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
321 echo "date: $d1" >> $testroot/stdout.expected
322 echo "object: commit $commit_id" >> $testroot/stdout.expected
323 echo " " >> $testroot/stdout.expected
324 echo " adding the test tree" >> $testroot/stdout.expected
325 echo " " >> $testroot/stdout.expected
326 cmp -s $testroot/stdout $testroot/stdout.expected
327 ret=$?
328 if [ $ret -ne 0 ]; then
329 diff -u $testroot/stdout.expected $testroot/stdout
331 test_done "$testroot" "$ret"
334 test_tag_create_ssh_signed() {
335 local testroot=`test_init tag_create`
336 local commit_id=`git_show_head $testroot/repo`
337 local tag=1.0.0
338 local tag2=2.0.0
339 local tag3=3.0.0
341 ssh-keygen -q -N '' -t ed25519 -f $testroot/id_ed25519
342 ret=$?
343 if [ $ret -ne 0 ]; then
344 echo "ssh-keygen failed unexpectedly"
345 test_done "$testroot" "$ret"
346 return 1
348 touch $testroot/allowed_signers
349 touch $testroot/revoked_signers
350 echo "allowed_signers \"$testroot/allowed_signers\"" >> \
351 $testroot/repo/.git/got.conf
352 echo "revoked_signers \"$testroot/revoked_signers\"" >> \
353 $testroot/repo/.git/got.conf
355 # Create a signed tag based on repository's HEAD reference
356 got tag -S $testroot/id_ed25519 -m 'test' -r $testroot/repo -c HEAD \
357 $tag > $testroot/stdout
358 ret=$?
359 if [ $ret -ne 0 ]; then
360 echo "got tag command failed unexpectedly"
361 test_done "$testroot" "$ret"
362 return 1
365 tag_id=`got ref -r $testroot/repo -l \
366 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
367 echo "Created tag $tag_id" > $testroot/stdout.expected
368 cmp -s $testroot/stdout $testroot/stdout.expected
369 ret=$?
370 if [ $ret -ne 0 ]; then
371 diff -u $testroot/stdout.expected $testroot/stdout
372 test_done "$testroot" "$ret"
373 return 1
376 # Ensure validation fails when the key is not allowed
377 echo "signature: Could not verify signature." > \
378 $testroot/stdout.expected
379 VERIFY_STDOUT=$(got tag -r $testroot/repo -V $tag 2> $testroot/stderr)
380 ret=$?
381 echo "$VERIFY_STDOUT" | grep '^signature: ' > $testroot/stdout
382 if [ $ret -eq 0 ]; then
383 diff -u $testroot/stdout.expected $testroot/stdout
384 test_done "$testroot" "1"
385 return 1
388 GOOD_SIG='Good "git" signature for flan_hacker@openbsd.org with ED25519 key '
390 # Validate the signature with the key allowed
391 echo -n 'flan_hacker@openbsd.org ' > $testroot/allowed_signers
392 cat $testroot/id_ed25519.pub >> $testroot/allowed_signers
393 GOT_STDOUT=$(got tag -r $testroot/repo -V $tag 2> $testroot/stderr)
394 ret=$?
395 if [ $ret -ne 0 ]; then
396 echo "got tag command failed unexpectedly"
397 diff -u $testroot/stdout.expected $testroot/stdout
398 test_done "$testroot" "$ret"
399 return 1
402 if ! echo "$GOT_STDOUT" | grep -q "^signature: $GOOD_SIG"; then
403 echo "got tag command failed to validate signature"
404 test_done "$testroot" "1"
405 return 1
408 # Ensure validation fails after revoking the key
409 ssh-keygen -y -f $testroot/id_ed25519 >> $testroot/revoked_signers
410 echo "signature: Could not verify signature." > \
411 $testroot/stdout.expected
412 VERIFY_STDOUT=$(got tag -r $testroot/repo -V $tag 2> $testroot/stderr)
413 ret=$?
414 echo "$VERIFY_STDOUT" | grep '^signature: ' > $testroot/stdout
415 if [ $ret -eq 0 ]; then
416 diff -u $testroot/stdout.expected $testroot/stdout
417 test_done "$testroot" "1"
418 return 1
421 # Later tests expect validation to work
422 echo -n > $testroot/revoked_signers
424 # Ensure that Git recognizes and verifies the tag Got has created
425 git -C $testroot/repo checkout -q $tag
426 ret=$?
427 if [ $ret -ne 0 ]; then
428 echo "git checkout command failed unexpectedly"
429 test_done "$testroot" "$ret"
430 return 1
432 git -C $testroot/repo config --local gpg.ssh.allowedSignersFile \
433 $testroot/allowed_signers
434 GIT_STDERR=$(git -C $testroot/repo tag -v $tag 2>&1 1>/dev/null)
435 if ! echo "$GIT_STDERR" | grep -q "^$GOOD_SIG"; then
436 echo "git tag command failed to validate signature"
437 test_done "$testroot" "1"
438 return 1
441 # Ensure Got recognizes the new tag
442 got checkout -c $tag $testroot/repo $testroot/wt >/dev/null
443 ret=$?
444 if [ $ret -ne 0 ]; then
445 echo "got checkout command failed unexpectedly"
446 test_done "$testroot" "$ret"
447 return 1
450 # Create another signed tag with a SHA1 commit ID
451 got tag -S $testroot/id_ed25519 -m 'test' -r $testroot/repo \
452 -c $commit_id $tag2 > $testroot/stdout
454 # Create another signed tag with key defined in got.conf(5)
455 echo "signer_id \"$testroot/id_ed25519\"" >> \
456 $testroot/repo/.git/got.conf
457 got tag -m 'test' -r $testroot/repo -c HEAD $tag3 > $testroot/stdout
458 ret=$?
459 if [ $ret -ne 0 ]; then
460 echo "got tag command failed unexpectedly"
461 test_done "$testroot" "$ret"
462 return 1
465 # got tag -V behaves like got tag -l, but with verification enabled.
466 got tag -l -r $testroot/repo > $testroot/stdout.list
467 got tag -V -r $testroot/repo > $testroot/stdout.verify
468 diff -U0 $testroot/stdout.list $testroot/stdout.verify |
469 sed -e '/^--- /d' -e '/^+++ /d' > $testroot/stdout
470 echo "@@ -5,0 +6 @@" > $testroot/stdout.expected
471 echo -n "+signature: $GOOD_SIG" >> $testroot/stdout.expected
472 ssh-keygen -l -f $testroot/id_ed25519.pub | cut -d' ' -f 2 \
473 >> $testroot/stdout.expected
474 echo "@@ -19,0 +21 @@" >> $testroot/stdout.expected
475 echo -n "+signature: $GOOD_SIG" >> $testroot/stdout.expected
476 ssh-keygen -l -f $testroot/id_ed25519.pub | cut -d' ' -f 2 \
477 >> $testroot/stdout.expected
478 echo "@@ -33,0 +36 @@" >> $testroot/stdout.expected
479 echo -n "+signature: $GOOD_SIG" >> $testroot/stdout.expected
480 ssh-keygen -l -f $testroot/id_ed25519.pub | cut -d' ' -f 2 \
481 >> $testroot/stdout.expected
482 cmp -s $testroot/stdout $testroot/stdout.expected
483 ret=$?
484 if [ $ret -ne 0 ]; then
485 diff -u $testroot/stdout.expected $testroot/stdout
487 test_done "$testroot" "$ret"
490 test_tag_create_ssh_signed_missing_key() {
491 local testroot=`test_init tag_create`
492 local commit_id=`git_show_head $testroot/repo`
493 local tag=1.0.0
495 # Fail to create a signed tag due to a missing SSH key
496 got tag -S $testroot/bogus -m 'test' -r $testroot/repo \
497 -c HEAD $tag > $testroot/stdout 2> $testroot/stderr
498 ret=$?
499 if [ $ret -eq 0 ]; then
500 echo "got tag command succeeded unexpectedly"
501 test_done "$testroot" 1
502 return 1
505 got ref -r $testroot/repo -l > $testroot/stdout
506 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
507 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
508 cmp -s $testroot/stdout $testroot/stdout.expected
509 ret=$?
510 if [ $ret -ne 0 ]; then
511 diff -u $testroot/stdout.expected $testroot/stdout
512 test_done "$testroot" "$ret"
513 return 1
515 printf "Couldn't load public key $testroot/bogus: " \
516 >> $testroot/stderr.expected
517 printf "No such file or directory\r\n" >> $testroot/stderr.expected
518 echo "got: unable to sign tag" >> $testroot/stderr.expected
519 cmp -s $testroot/stderr $testroot/stderr.expected
520 ret=$?
521 if [ $ret -ne 0 ]; then
522 diff -u $testroot/stderr.expected $testroot/stderr
524 test_done "$testroot" "$ret"
527 test_tag_commit_keywords() {
528 local testroot=$(test_init tag_commit_keywords)
529 local repo="$testroot/repo"
530 local wt="$testroot/wt"
531 local commit_id=$(git_show_head "$repo")
532 local tag=1.0.0
533 local tag2=2.0.0
535 echo "alphas" > "$repo/alpha"
536 git_commit "$repo" -m "alphas"
538 # create tag based on first gen ancestor of the repository's HEAD
539 got tag -m 'v1.0.0' -r "$repo" -c:head:- "$tag" > "$testroot/stdout"
540 ret=$?
541 if [ $ret -ne 0 ]; then
542 echo "got ref command failed unexpectedly"
543 test_done "$testroot" "$ret"
544 return 1
547 tag_id=$(got ref -r "$repo" -l \
548 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2)
549 echo "Created tag $tag_id" > "$testroot/stdout.expected"
550 cmp -s "$testroot/stdout" "$testroot/stdout.expected"
551 ret=$?
552 if [ $ret -ne 0 ]; then
553 diff -u "$testroot/stdout.expected" "$testroot/stdout"
554 test_done "$testroot" "$ret"
555 return 1
558 tag_commit=$(got cat -r "$repo" "$tag" | grep ^object | cut -d' ' -f2)
559 if [ "$tag_commit" != "$commit_id" ]; then
560 echo "wrong commit was tagged" >&2
561 test_done "$testroot" "1"
562 return 1
565 got checkout -c "$tag" "$repo" "$wt" >/dev/null
566 ret=$?
567 if [ $ret -ne 0 ]; then
568 echo "got checkout command failed unexpectedly"
569 test_done "$testroot" "$ret"
570 return 1
573 # create new tag based on the base commit's 2nd gen descendant
574 (cd "$wt" && got up > /dev/null)
575 echo 'foo' > "$wt/alpha"
576 echo 'boo' > "$wt/beta"
577 echo 'hoo' > "$wt/gamma/delta"
578 (cd "$wt" && got commit -m foo alpha > /dev/null)
579 (cd "$wt" && got commit -m boo beta > /dev/null)
580 (cd "$wt" && got commit -m hoo gamma/delta > /dev/null)
581 local head_id=$(git_show_branch_head "$repo")
582 (cd "$wt" && got up -c:base:-2 > /dev/null)
583 local base_id=$(cd "$wt" && got info | grep base | cut -d' ' -f5)
585 (cd "$wt" && got tag -m 'v2.0.0' -c:base:+2 $tag2 > "$testroot/stdout")
586 ret=$?
587 if [ $ret -ne 0 ]; then
588 test_done "$testroot" "$ret"
589 return 1
592 tag_id2=$(got ref -r "$repo" -l \
593 | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2)
594 echo "Created tag $tag_id2" > $testroot/stdout.expected
596 cmp -s $testroot/stdout $testroot/stdout.expected
597 ret=$?
598 if [ $ret -ne 0 ]; then
599 diff -u $testroot/stdout.expected $testroot/stdout
600 test_done "$testroot" "$ret"
601 return 1
604 tag2_commit=$(got cat -r "$repo" "$tag2" | grep ^object | cut -d' ' -f2)
605 if [ "$tag2_commit" != "$head_id" ]; then
606 echo "wrong commit was tagged" >&2
607 test_done "$testroot" "1"
608 return 1
611 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
612 echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
613 cat "$wt/.got/uuid" | tr -d '\n' >> $testroot/stdout.expected
614 echo ": $base_id" >> $testroot/stdout.expected
615 echo "refs/heads/master: $head_id" >> $testroot/stdout.expected
616 echo "refs/tags/$tag: $tag_id" >> $testroot/stdout.expected
617 echo "refs/tags/$tag2: $tag_id2" >> $testroot/stdout.expected
619 got ref -r "$repo" -l > $testroot/stdout
621 cmp -s $testroot/stdout $testroot/stdout.expected
622 ret=$?
623 if [ $ret -ne 0 ]; then
624 diff -u $testroot/stdout.expected $testroot/stdout
627 test_done "$testroot" "$ret"
630 test_parseargs "$@"
631 run_test test_tag_create
632 run_test test_tag_list
633 run_test test_tag_list_lightweight
634 run_test test_tag_list_oneline
635 run_test test_tag_create_ssh_signed
636 run_test test_tag_create_ssh_signed_missing_key
637 run_test test_tag_commit_keywords