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.
19 function test_tag_create {
20 local testroot=`test_init tag_create`
21 local commit_id=`git_show_head $testroot/repo`
25 # Create a tag based on repository's HEAD reference
26 got tag -m 'test' -r $testroot/repo $tag HEAD > $testroot/stdout
28 if [ "$ret" != "0" ]; then
29 echo "got ref command failed unexpectedly"
30 test_done "$testroot" "$ret"
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
39 if [ "$ret" != "0" ]; then
40 diff -u $testroot/stdout.expected $testroot/stdout
41 test_done "$testroot" "$ret"
45 # Ensure that Git recognizes the tag Got has created
46 (cd $testroot/repo && git checkout -q $tag)
48 if [ "$ret" != "0" ]; then
49 echo "git checkout command failed unexpectedly"
50 test_done "$testroot" "$ret"
54 # Ensure Got recognizes the new tag
55 got checkout -c $tag $testroot/repo $testroot/wt >/dev/null
57 if [ "$ret" != "0" ]; then
58 echo "got checkout command failed unexpectedly"
59 test_done "$testroot" "$ret"
63 # Create a tag based on implied worktree HEAD ref
64 (cd $testroot/wt && got tag -m 'test' $tag2 > $testroot/stdout)
66 if [ "$ret" != "0" ]; then
67 test_done "$testroot" "$ret"
71 tag_id2=`got ref -r $testroot/repo -l \
72 | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
73 echo "Created tag $tag_id2" > $testroot/stdout.expected
74 cmp -s $testroot/stdout $testroot/stdout.expected
76 if [ "$ret" != "0" ]; then
77 diff -u $testroot/stdout.expected $testroot/stdout
78 test_done "$testroot" "$ret"
82 (cd $testroot/repo && git checkout -q $tag2)
84 if [ "$ret" != "0" ]; then
85 echo "git checkout command failed unexpectedly"
86 test_done "$testroot" "$ret"
89 # Attempt to create a tag pointing at a non-commit
90 local tree_id=`git_show_tree $testroot/repo`
91 (cd $testroot/wt && got tag -m 'test' foobar $tree_id \
94 if [ "$ret" == "0" ]; then
95 echo "git tag command succeeded unexpectedly"
96 test_done "$testroot" "1"
100 echo "got: object not found" > $testroot/stderr.expected
101 cmp -s $testroot/stderr $testroot/stderr.expected
103 if [ "$ret" != "0" ]; then
104 diff -u $testroot/stderr.expected $testroot/stderr
105 test_done "$testroot" "$ret"
109 got ref -r $testroot/repo -l > $testroot/stdout
110 echo "HEAD: $commit_id" > $testroot/stdout.expected
111 echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
112 cat $testroot/wt/.got/uuid | tr -d '\n' >> $testroot/stdout.expected
113 echo ": $commit_id" >> $testroot/stdout.expected
114 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
115 echo "refs/tags/$tag: $tag_id" >> $testroot/stdout.expected
116 echo "refs/tags/$tag2: $tag_id2" >> $testroot/stdout.expected
117 cmp -s $testroot/stdout $testroot/stdout.expected
119 if [ "$ret" != "0" ]; then
120 diff -u $testroot/stdout.expected $testroot/stdout
122 test_done "$testroot" "$ret"
125 function test_tag_list {
126 local testroot=`test_init tag_list`
127 local commit_id=`git_show_head $testroot/repo`
131 (cd $testroot/repo && git tag -a -m 'test' $tag)
132 (cd $testroot/repo && git tag -a -m 'test' $tag2)
134 tag_id=`got ref -r $testroot/repo -l \
135 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
136 local tagger_time=`git_show_tagger_time $testroot/repo $tag`
137 d1=`env TZ=UTC date -r $tagger_time +"%a %b %d %X %Y UTC"`
138 tag_id2=`got ref -r $testroot/repo -l \
139 | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
140 local tagger_time2=`git_show_tagger_time $testroot/repo $tag2`
141 d2=`env TZ=UTC date -r $tagger_time2 +"%a %b %d %X %Y UTC"`
143 got tag -r $testroot/repo -l > $testroot/stdout
145 echo "-----------------------------------------------" \
146 > $testroot/stdout.expected
147 echo "tag $tag $tag_id" >> $testroot/stdout.expected
148 echo "commit $commit_id" >> $testroot/stdout.expected
149 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
150 echo "date: $d1" >> $testroot/stdout.expected
151 echo " " >> $testroot/stdout.expected
152 echo " test" >> $testroot/stdout.expected
153 echo " " >> $testroot/stdout.expected
154 echo "-----------------------------------------------" \
155 >> $testroot/stdout.expected
156 echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
157 echo "commit $commit_id" >> $testroot/stdout.expected
158 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
159 echo "date: $d2" >> $testroot/stdout.expected
160 echo " " >> $testroot/stdout.expected
161 echo " test" >> $testroot/stdout.expected
162 echo " " >> $testroot/stdout.expected
163 cmp -s $testroot/stdout $testroot/stdout.expected
165 if [ "$ret" != "0" ]; then
166 diff -u $testroot/stdout.expected $testroot/stdout
168 test_done "$testroot" "$ret"
171 run_test test_tag_create
172 run_test test_tag_list