Blame


1 8e7bd50a 2019-08-22 stsp #!/bin/sh
2 8e7bd50a 2019-08-22 stsp #
3 8e7bd50a 2019-08-22 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 8e7bd50a 2019-08-22 stsp #
5 8e7bd50a 2019-08-22 stsp # Permission to use, copy, modify, and distribute this software for any
6 8e7bd50a 2019-08-22 stsp # purpose with or without fee is hereby granted, provided that the above
7 8e7bd50a 2019-08-22 stsp # copyright notice and this permission notice appear in all copies.
8 8e7bd50a 2019-08-22 stsp #
9 8e7bd50a 2019-08-22 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 8e7bd50a 2019-08-22 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 8e7bd50a 2019-08-22 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 8e7bd50a 2019-08-22 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 8e7bd50a 2019-08-22 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 8e7bd50a 2019-08-22 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 8e7bd50a 2019-08-22 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 8e7bd50a 2019-08-22 stsp
17 8e7bd50a 2019-08-22 stsp . ./common.sh
18 8e7bd50a 2019-08-22 stsp
19 f6cae3ed 2020-09-13 naddy test_tag_create() {
20 8e7bd50a 2019-08-22 stsp local testroot=`test_init tag_create`
21 8e7bd50a 2019-08-22 stsp local commit_id=`git_show_head $testroot/repo`
22 8e7bd50a 2019-08-22 stsp local tag=1.0.0
23 8e7bd50a 2019-08-22 stsp local tag2=2.0.0
24 8e7bd50a 2019-08-22 stsp
25 8e7bd50a 2019-08-22 stsp # Create a tag based on repository's HEAD reference
26 80106605 2020-02-24 stsp got tag -m 'test' -r $testroot/repo -c HEAD $tag > $testroot/stdout
27 49c543a6 2022-03-31 naddy ret=$?
28 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
29 8e7bd50a 2019-08-22 stsp echo "got ref command failed unexpectedly"
30 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
31 8e7bd50a 2019-08-22 stsp return 1
32 8e7bd50a 2019-08-22 stsp fi
33 8e7bd50a 2019-08-22 stsp
34 8e7bd50a 2019-08-22 stsp tag_id=`got ref -r $testroot/repo -l \
35 8e7bd50a 2019-08-22 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
36 8e7bd50a 2019-08-22 stsp echo "Created tag $tag_id" > $testroot/stdout.expected
37 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
38 49c543a6 2022-03-31 naddy ret=$?
39 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
40 8e7bd50a 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
41 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
42 8e7bd50a 2019-08-22 stsp return 1
43 8e7bd50a 2019-08-22 stsp fi
44 8e7bd50a 2019-08-22 stsp
45 8e7bd50a 2019-08-22 stsp # Ensure that Git recognizes the tag Got has created
46 8e7bd50a 2019-08-22 stsp (cd $testroot/repo && git checkout -q $tag)
47 49c543a6 2022-03-31 naddy ret=$?
48 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
49 8e7bd50a 2019-08-22 stsp echo "git checkout command failed unexpectedly"
50 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
51 8e7bd50a 2019-08-22 stsp return 1
52 8e7bd50a 2019-08-22 stsp fi
53 8e7bd50a 2019-08-22 stsp
54 8e7bd50a 2019-08-22 stsp # Ensure Got recognizes the new tag
55 8e7bd50a 2019-08-22 stsp got checkout -c $tag $testroot/repo $testroot/wt >/dev/null
56 49c543a6 2022-03-31 naddy ret=$?
57 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
58 8e7bd50a 2019-08-22 stsp echo "got checkout command failed unexpectedly"
59 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
60 8e7bd50a 2019-08-22 stsp return 1
61 8e7bd50a 2019-08-22 stsp fi
62 8e7bd50a 2019-08-22 stsp
63 8e7bd50a 2019-08-22 stsp # Create a tag based on implied worktree HEAD ref
64 8e7bd50a 2019-08-22 stsp (cd $testroot/wt && got tag -m 'test' $tag2 > $testroot/stdout)
65 49c543a6 2022-03-31 naddy ret=$?
66 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
67 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
68 8e7bd50a 2019-08-22 stsp return 1
69 8e7bd50a 2019-08-22 stsp fi
70 8e7bd50a 2019-08-22 stsp
71 8e7bd50a 2019-08-22 stsp tag_id2=`got ref -r $testroot/repo -l \
72 8e7bd50a 2019-08-22 stsp | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
73 8e7bd50a 2019-08-22 stsp echo "Created tag $tag_id2" > $testroot/stdout.expected
74 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
75 49c543a6 2022-03-31 naddy ret=$?
76 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
77 8e7bd50a 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
78 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
79 8e7bd50a 2019-08-22 stsp return 1
80 8e7bd50a 2019-08-22 stsp fi
81 8e7bd50a 2019-08-22 stsp
82 8e7bd50a 2019-08-22 stsp (cd $testroot/repo && git checkout -q $tag2)
83 49c543a6 2022-03-31 naddy ret=$?
84 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
85 8e7bd50a 2019-08-22 stsp echo "git checkout command failed unexpectedly"
86 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
87 a9662115 2021-08-29 naddy return 1
88 8e7bd50a 2019-08-22 stsp fi
89 8e7bd50a 2019-08-22 stsp
90 8e7bd50a 2019-08-22 stsp # Attempt to create a tag pointing at a non-commit
91 8e7bd50a 2019-08-22 stsp local tree_id=`git_show_tree $testroot/repo`
92 80106605 2020-02-24 stsp (cd $testroot/wt && got tag -m 'test' -c $tree_id foobar \
93 8e7bd50a 2019-08-22 stsp 2> $testroot/stderr)
94 49c543a6 2022-03-31 naddy ret=$?
95 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
96 8e7bd50a 2019-08-22 stsp echo "git tag command succeeded unexpectedly"
97 8e7bd50a 2019-08-22 stsp test_done "$testroot" "1"
98 8e7bd50a 2019-08-22 stsp return 1
99 8e7bd50a 2019-08-22 stsp fi
100 8e7bd50a 2019-08-22 stsp
101 138e4f47 2021-10-09 stsp echo "got: commit $tree_id: object not found" \
102 138e4f47 2021-10-09 stsp > $testroot/stderr.expected
103 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stderr $testroot/stderr.expected
104 49c543a6 2022-03-31 naddy ret=$?
105 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
106 8e7bd50a 2019-08-22 stsp diff -u $testroot/stderr.expected $testroot/stderr
107 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
108 8e7bd50a 2019-08-22 stsp return 1
109 8e7bd50a 2019-08-22 stsp fi
110 8e7bd50a 2019-08-22 stsp
111 8e7bd50a 2019-08-22 stsp got ref -r $testroot/repo -l > $testroot/stdout
112 8e7bd50a 2019-08-22 stsp echo "HEAD: $commit_id" > $testroot/stdout.expected
113 8e7bd50a 2019-08-22 stsp echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
114 8e7bd50a 2019-08-22 stsp cat $testroot/wt/.got/uuid | tr -d '\n' >> $testroot/stdout.expected
115 8e7bd50a 2019-08-22 stsp echo ": $commit_id" >> $testroot/stdout.expected
116 8e7bd50a 2019-08-22 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
117 8e7bd50a 2019-08-22 stsp echo "refs/tags/$tag: $tag_id" >> $testroot/stdout.expected
118 8e7bd50a 2019-08-22 stsp echo "refs/tags/$tag2: $tag_id2" >> $testroot/stdout.expected
119 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
120 49c543a6 2022-03-31 naddy ret=$?
121 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
122 8e7bd50a 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
123 8e7bd50a 2019-08-22 stsp fi
124 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
125 8e7bd50a 2019-08-22 stsp }
126 8e7bd50a 2019-08-22 stsp
127 f6cae3ed 2020-09-13 naddy test_tag_list() {
128 8e7bd50a 2019-08-22 stsp local testroot=`test_init tag_list`
129 8e7bd50a 2019-08-22 stsp local commit_id=`git_show_head $testroot/repo`
130 8e7bd50a 2019-08-22 stsp local tag=1.0.0
131 8e7bd50a 2019-08-22 stsp local tag2=2.0.0
132 8e7bd50a 2019-08-22 stsp
133 e8039a4a 2019-08-23 stsp # create tag with Git
134 8e7bd50a 2019-08-22 stsp (cd $testroot/repo && git tag -a -m 'test' $tag)
135 e8039a4a 2019-08-23 stsp # create tag with Got
136 e8039a4a 2019-08-23 stsp (cd $testroot/repo && got tag -m 'test' $tag2 > /dev/null)
137 8e7bd50a 2019-08-22 stsp
138 8e7bd50a 2019-08-22 stsp tag_id=`got ref -r $testroot/repo -l \
139 8e7bd50a 2019-08-22 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
140 8e7bd50a 2019-08-22 stsp local tagger_time=`git_show_tagger_time $testroot/repo $tag`
141 3a6b8760 2021-08-31 naddy d1=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
142 8e7bd50a 2019-08-22 stsp tag_id2=`got ref -r $testroot/repo -l \
143 8e7bd50a 2019-08-22 stsp | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
144 8e7bd50a 2019-08-22 stsp local tagger_time2=`git_show_tagger_time $testroot/repo $tag2`
145 3a6b8760 2021-08-31 naddy d2=`date -u -r $tagger_time2 +"%a %b %e %X %Y UTC"`
146 8e7bd50a 2019-08-22 stsp
147 8e7bd50a 2019-08-22 stsp got tag -r $testroot/repo -l > $testroot/stdout
148 8e7bd50a 2019-08-22 stsp
149 8e7bd50a 2019-08-22 stsp echo "-----------------------------------------------" \
150 8e7bd50a 2019-08-22 stsp > $testroot/stdout.expected
151 b8bad2ba 2019-08-23 stsp echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
152 8e7bd50a 2019-08-22 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
153 ac03cf6d 2020-01-17 stsp echo "date: $d2" >> $testroot/stdout.expected
154 2417344c 2019-08-23 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
155 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
156 8e7bd50a 2019-08-22 stsp echo " test" >> $testroot/stdout.expected
157 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
158 8e7bd50a 2019-08-22 stsp echo "-----------------------------------------------" \
159 8e7bd50a 2019-08-22 stsp >> $testroot/stdout.expected
160 b8bad2ba 2019-08-23 stsp echo "tag $tag $tag_id" >> $testroot/stdout.expected
161 8e7bd50a 2019-08-22 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
162 ac03cf6d 2020-01-17 stsp echo "date: $d1" >> $testroot/stdout.expected
163 2417344c 2019-08-23 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
164 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
165 8e7bd50a 2019-08-22 stsp echo " test" >> $testroot/stdout.expected
166 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
167 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
168 49c543a6 2022-03-31 naddy ret=$?
169 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
170 8e7bd50a 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
171 8c4a6db8 2022-06-29 stsp test_done "$testroot" "$ret"
172 8c4a6db8 2022-06-29 stsp return 1
173 8e7bd50a 2019-08-22 stsp fi
174 8c4a6db8 2022-06-29 stsp
175 8c4a6db8 2022-06-29 stsp got tag -r $testroot/repo -l $tag > $testroot/stdout
176 8c4a6db8 2022-06-29 stsp
177 8c4a6db8 2022-06-29 stsp echo "-----------------------------------------------" \
178 8c4a6db8 2022-06-29 stsp > $testroot/stdout.expected
179 8c4a6db8 2022-06-29 stsp echo "tag $tag $tag_id" >> $testroot/stdout.expected
180 8c4a6db8 2022-06-29 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
181 8c4a6db8 2022-06-29 stsp echo "date: $d1" >> $testroot/stdout.expected
182 8c4a6db8 2022-06-29 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
183 8c4a6db8 2022-06-29 stsp echo " " >> $testroot/stdout.expected
184 8c4a6db8 2022-06-29 stsp echo " test" >> $testroot/stdout.expected
185 8c4a6db8 2022-06-29 stsp echo " " >> $testroot/stdout.expected
186 8c4a6db8 2022-06-29 stsp cmp -s $testroot/stdout $testroot/stdout.expected
187 8c4a6db8 2022-06-29 stsp ret=$?
188 8c4a6db8 2022-06-29 stsp if [ $ret -ne 0 ]; then
189 8c4a6db8 2022-06-29 stsp diff -u $testroot/stdout.expected $testroot/stdout
190 8c4a6db8 2022-06-29 stsp test_done "$testroot" "$ret"
191 8c4a6db8 2022-06-29 stsp return 1
192 8c4a6db8 2022-06-29 stsp fi
193 8c4a6db8 2022-06-29 stsp
194 8c4a6db8 2022-06-29 stsp got tag -r $testroot/repo -l $tag2 > $testroot/stdout
195 8c4a6db8 2022-06-29 stsp
196 8c4a6db8 2022-06-29 stsp echo "-----------------------------------------------" \
197 8c4a6db8 2022-06-29 stsp > $testroot/stdout.expected
198 8c4a6db8 2022-06-29 stsp echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
199 8c4a6db8 2022-06-29 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
200 8c4a6db8 2022-06-29 stsp echo "date: $d2" >> $testroot/stdout.expected
201 8c4a6db8 2022-06-29 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
202 8c4a6db8 2022-06-29 stsp echo " " >> $testroot/stdout.expected
203 8c4a6db8 2022-06-29 stsp echo " test" >> $testroot/stdout.expected
204 8c4a6db8 2022-06-29 stsp echo " " >> $testroot/stdout.expected
205 8c4a6db8 2022-06-29 stsp cmp -s $testroot/stdout $testroot/stdout.expected
206 8c4a6db8 2022-06-29 stsp ret=$?
207 8c4a6db8 2022-06-29 stsp if [ $ret -ne 0 ]; then
208 8c4a6db8 2022-06-29 stsp diff -u $testroot/stdout.expected $testroot/stdout
209 8c4a6db8 2022-06-29 stsp fi
210 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
211 8e7bd50a 2019-08-22 stsp }
212 8e7bd50a 2019-08-22 stsp
213 f6cae3ed 2020-09-13 naddy test_tag_list_lightweight() {
214 d4efa91b 2020-01-14 stsp local testroot=`test_init tag_list_lightweight`
215 d4efa91b 2020-01-14 stsp local commit_id=`git_show_head $testroot/repo`
216 d4efa91b 2020-01-14 stsp local tag=1.0.0
217 d4efa91b 2020-01-14 stsp local tag2=2.0.0
218 d4efa91b 2020-01-14 stsp
219 d4efa91b 2020-01-14 stsp # create "lightweight" tag with Git
220 d4efa91b 2020-01-14 stsp (cd $testroot/repo && git tag $tag)
221 d4efa91b 2020-01-14 stsp (cd $testroot/repo && git tag $tag2)
222 d4efa91b 2020-01-14 stsp
223 d4efa91b 2020-01-14 stsp tag_id=`got ref -r $testroot/repo -l \
224 d4efa91b 2020-01-14 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
225 d4efa91b 2020-01-14 stsp local tagger_time=`git_show_author_time $testroot/repo $tag`
226 3a6b8760 2021-08-31 naddy d1=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
227 d4efa91b 2020-01-14 stsp tag_id2=`got ref -r $testroot/repo -l \
228 d4efa91b 2020-01-14 stsp | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
229 d4efa91b 2020-01-14 stsp local tagger_time2=`git_show_author_time $testroot/repo $tag2`
230 3a6b8760 2021-08-31 naddy d2=`date -u -r $tagger_time2 +"%a %b %e %X %Y UTC"`
231 d4efa91b 2020-01-14 stsp
232 d4efa91b 2020-01-14 stsp got tag -r $testroot/repo -l > $testroot/stdout
233 d4efa91b 2020-01-14 stsp
234 d4efa91b 2020-01-14 stsp echo "-----------------------------------------------" \
235 d4efa91b 2020-01-14 stsp > $testroot/stdout.expected
236 d4efa91b 2020-01-14 stsp echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
237 d4efa91b 2020-01-14 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
238 ac03cf6d 2020-01-17 stsp echo "date: $d2" >> $testroot/stdout.expected
239 d4efa91b 2020-01-14 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
240 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
241 d4efa91b 2020-01-14 stsp echo " adding the test tree" >> $testroot/stdout.expected
242 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
243 d4efa91b 2020-01-14 stsp echo "-----------------------------------------------" \
244 d4efa91b 2020-01-14 stsp >> $testroot/stdout.expected
245 d4efa91b 2020-01-14 stsp echo "tag $tag $tag_id" >> $testroot/stdout.expected
246 d4efa91b 2020-01-14 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
247 ac03cf6d 2020-01-17 stsp echo "date: $d1" >> $testroot/stdout.expected
248 d4efa91b 2020-01-14 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
249 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
250 d4efa91b 2020-01-14 stsp echo " adding the test tree" >> $testroot/stdout.expected
251 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
252 d4efa91b 2020-01-14 stsp cmp -s $testroot/stdout $testroot/stdout.expected
253 49c543a6 2022-03-31 naddy ret=$?
254 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
255 d4efa91b 2020-01-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
256 d4efa91b 2020-01-14 stsp fi
257 d4efa91b 2020-01-14 stsp test_done "$testroot" "$ret"
258 d4efa91b 2020-01-14 stsp }
259 4d5ee956 2022-07-02 jrick
260 4d5ee956 2022-07-02 jrick test_tag_create_ssh_signed() {
261 4d5ee956 2022-07-02 jrick local testroot=`test_init tag_create`
262 4d5ee956 2022-07-02 jrick local commit_id=`git_show_head $testroot/repo`
263 4d5ee956 2022-07-02 jrick local tag=1.0.0
264 4d5ee956 2022-07-02 jrick local tag2=2.0.0
265 4d5ee956 2022-07-02 jrick
266 4d5ee956 2022-07-02 jrick ssh-keygen -q -N '' -t ed25519 -f $testroot/id_ed25519
267 4d5ee956 2022-07-02 jrick ret=$?
268 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
269 4d5ee956 2022-07-02 jrick echo "ssh-keygen failed unexpectedly"
270 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
271 4d5ee956 2022-07-02 jrick return 1
272 4d5ee956 2022-07-02 jrick fi
273 4d5ee956 2022-07-02 jrick touch $testroot/allowed_signers
274 4d5ee956 2022-07-02 jrick echo "allowed_signers \"$testroot/allowed_signers\"" > \
275 4d5ee956 2022-07-02 jrick $testroot/repo/.git/got.conf
276 4d5ee956 2022-07-02 jrick
277 4d5ee956 2022-07-02 jrick # Create a signed tag based on repository's HEAD reference
278 4d5ee956 2022-07-02 jrick got tag -s $testroot/id_ed25519 -m 'test' -r $testroot/repo -c HEAD \
279 4d5ee956 2022-07-02 jrick $tag > $testroot/stdout
280 4d5ee956 2022-07-02 jrick ret=$?
281 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
282 4d5ee956 2022-07-02 jrick echo "got tag command failed unexpectedly"
283 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
284 4d5ee956 2022-07-02 jrick return 1
285 4d5ee956 2022-07-02 jrick fi
286 4d5ee956 2022-07-02 jrick
287 4d5ee956 2022-07-02 jrick tag_id=`got ref -r $testroot/repo -l \
288 4d5ee956 2022-07-02 jrick | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
289 4d5ee956 2022-07-02 jrick echo "Created tag $tag_id" > $testroot/stdout.expected
290 4d5ee956 2022-07-02 jrick cmp -s $testroot/stdout $testroot/stdout.expected
291 4d5ee956 2022-07-02 jrick ret=$?
292 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
293 4d5ee956 2022-07-02 jrick diff -u $testroot/stdout.expected $testroot/stdout
294 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
295 4d5ee956 2022-07-02 jrick return 1
296 4d5ee956 2022-07-02 jrick fi
297 4d5ee956 2022-07-02 jrick
298 4d5ee956 2022-07-02 jrick # Ensure validation fails when the key is not allowed
299 4d5ee956 2022-07-02 jrick echo "signature: Could not verify signature." > \
300 4d5ee956 2022-07-02 jrick $testroot/stdout.expected
301 4d5ee956 2022-07-02 jrick VERIFY_STDOUT=$(got tag -r $testroot/repo -V $tag 2> $testroot/stderr)
302 4d5ee956 2022-07-02 jrick ret=$?
303 4d5ee956 2022-07-02 jrick echo "$VERIFY_STDOUT" | grep '^signature: ' > $testroot/stdout
304 4d5ee956 2022-07-02 jrick if [ $ret -eq 0 ]; then
305 4d5ee956 2022-07-02 jrick diff -u $testroot/stdout.expected $testroot/stdout
306 4d5ee956 2022-07-02 jrick test_done "$testroot" "1"
307 4d5ee956 2022-07-02 jrick return 1
308 4d5ee956 2022-07-02 jrick fi
309 d4efa91b 2020-01-14 stsp
310 48f19407 2022-07-04 stsp GOOD_SIG='Good "git" signature for flan_hacker@openbsd.org with ED25519 key '
311 4d5ee956 2022-07-02 jrick
312 4d5ee956 2022-07-02 jrick # Validate the signature with the key allowed
313 4d5ee956 2022-07-02 jrick echo -n 'flan_hacker@openbsd.org ' > $testroot/allowed_signers
314 4d5ee956 2022-07-02 jrick cat $testroot/id_ed25519.pub >> $testroot/allowed_signers
315 4d5ee956 2022-07-02 jrick GOT_STDOUT=$(got tag -r $testroot/repo -V $tag 2> $testroot/stderr)
316 4d5ee956 2022-07-02 jrick ret=$?
317 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
318 4d5ee956 2022-07-02 jrick echo "got tag command failed unexpectedly"
319 4d5ee956 2022-07-02 jrick diff -u $testroot/stdout.expected $testroot/stdout
320 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
321 4d5ee956 2022-07-02 jrick return 1
322 4d5ee956 2022-07-02 jrick fi
323 2c0a0d66 2022-07-03 jrick
324 4d5ee956 2022-07-02 jrick if ! echo "$GOT_STDOUT" | grep -q "^signature: $GOOD_SIG"; then
325 4d5ee956 2022-07-02 jrick echo "got tag command failed to validate signature"
326 4d5ee956 2022-07-02 jrick test_done "$testroot" "1"
327 4d5ee956 2022-07-02 jrick return 1
328 4d5ee956 2022-07-02 jrick fi
329 4d5ee956 2022-07-02 jrick
330 4d5ee956 2022-07-02 jrick # Ensure that Git recognizes and verifies the tag Got has created
331 4d5ee956 2022-07-02 jrick (cd $testroot/repo && git checkout -q $tag)
332 4d5ee956 2022-07-02 jrick ret=$?
333 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
334 4d5ee956 2022-07-02 jrick echo "git checkout command failed unexpectedly"
335 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
336 4d5ee956 2022-07-02 jrick return 1
337 4d5ee956 2022-07-02 jrick fi
338 4d5ee956 2022-07-02 jrick (cd $testroot/repo && git config --local gpg.ssh.allowedSignersFile \
339 4d5ee956 2022-07-02 jrick $testroot/allowed_signers)
340 4d5ee956 2022-07-02 jrick GIT_STDERR=$(cd $testroot/repo && git tag -v $tag 2>&1 1>/dev/null)
341 4d5ee956 2022-07-02 jrick if ! echo "$GIT_STDERR" | grep -q "^$GOOD_SIG"; then
342 4d5ee956 2022-07-02 jrick echo "git tag command failed to validate signature"
343 4d5ee956 2022-07-02 jrick test_done "$testroot" "1"
344 4d5ee956 2022-07-02 jrick return 1
345 4d5ee956 2022-07-02 jrick fi
346 4d5ee956 2022-07-02 jrick
347 4d5ee956 2022-07-02 jrick # Ensure Got recognizes the new tag
348 4d5ee956 2022-07-02 jrick got checkout -c $tag $testroot/repo $testroot/wt >/dev/null
349 4d5ee956 2022-07-02 jrick ret=$?
350 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
351 4d5ee956 2022-07-02 jrick echo "got checkout command failed unexpectedly"
352 48f19407 2022-07-04 stsp test_done "$testroot" "$ret"
353 48f19407 2022-07-04 stsp return 1
354 4d5ee956 2022-07-02 jrick fi
355 48f19407 2022-07-04 stsp
356 48f19407 2022-07-04 stsp # Create another signed tag with a SHA1 commit ID
357 48f19407 2022-07-04 stsp got tag -s $testroot/id_ed25519 -m 'test' -r $testroot/repo \
358 48f19407 2022-07-04 stsp -c $commit_id $tag2 > $testroot/stdout
359 48f19407 2022-07-04 stsp
360 48f19407 2022-07-04 stsp # got tag -V behaves like got tag -l, but with verification enabled.
361 48f19407 2022-07-04 stsp got tag -l -r $testroot/repo > $testroot/stdout.list
362 48f19407 2022-07-04 stsp got tag -V -r $testroot/repo > $testroot/stdout.verify
363 48f19407 2022-07-04 stsp diff -U0 $testroot/stdout.list $testroot/stdout.verify |
364 48f19407 2022-07-04 stsp sed -e '/^--- /d' -e '/^+++ /d' > $testroot/stdout
365 48f19407 2022-07-04 stsp echo "@@ -5,0 +6 @@" > $testroot/stdout.expected
366 48f19407 2022-07-04 stsp echo -n "+signature: $GOOD_SIG" >> $testroot/stdout.expected
367 48f19407 2022-07-04 stsp ssh-keygen -l -f $testroot/id_ed25519.pub | cut -d' ' -f 2 \
368 48f19407 2022-07-04 stsp >> $testroot/stdout.expected
369 48f19407 2022-07-04 stsp echo "@@ -19,0 +21 @@" >> $testroot/stdout.expected
370 48f19407 2022-07-04 stsp echo -n "+signature: $GOOD_SIG" >> $testroot/stdout.expected
371 48f19407 2022-07-04 stsp ssh-keygen -l -f $testroot/id_ed25519.pub | cut -d' ' -f 2 \
372 48f19407 2022-07-04 stsp >> $testroot/stdout.expected
373 48f19407 2022-07-04 stsp cmp -s $testroot/stdout $testroot/stdout.expected
374 48f19407 2022-07-04 stsp ret=$?
375 48f19407 2022-07-04 stsp if [ $ret -ne 0 ]; then
376 48f19407 2022-07-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
377 48f19407 2022-07-04 stsp fi
378 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
379 4d5ee956 2022-07-02 jrick }
380 91d845ad 2022-07-03 jrick
381 91d845ad 2022-07-03 jrick test_tag_create_ssh_signed_missing_key() {
382 91d845ad 2022-07-03 jrick local testroot=`test_init tag_create`
383 91d845ad 2022-07-03 jrick local commit_id=`git_show_head $testroot/repo`
384 91d845ad 2022-07-03 jrick local tag=1.0.0
385 91d845ad 2022-07-03 jrick
386 91d845ad 2022-07-03 jrick # Fail to create a signed tag due to a missing SSH key
387 91d845ad 2022-07-03 jrick got tag -s $testroot/bogus -m 'test' -r $testroot/repo \
388 91d845ad 2022-07-03 jrick -c HEAD $tag > $testroot/stdout 2> $testroot/stderr
389 91d845ad 2022-07-03 jrick ret=$?
390 91d845ad 2022-07-03 jrick if [ $ret -eq 0 ]; then
391 91d845ad 2022-07-03 jrick echo "got tag command succeeded unexpectedly"
392 91d845ad 2022-07-03 jrick test_done "$testroot" 1
393 91d845ad 2022-07-03 jrick return 1
394 91d845ad 2022-07-03 jrick fi
395 4d5ee956 2022-07-02 jrick
396 91d845ad 2022-07-03 jrick got ref -r $testroot/repo -l > $testroot/stdout
397 91d845ad 2022-07-03 jrick echo "HEAD: refs/heads/master" > $testroot/stdout.expected
398 91d845ad 2022-07-03 jrick echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
399 91d845ad 2022-07-03 jrick cmp -s $testroot/stdout $testroot/stdout.expected
400 91d845ad 2022-07-03 jrick ret=$?
401 91d845ad 2022-07-03 jrick if [ $ret -ne 0 ]; then
402 91d845ad 2022-07-03 jrick diff -u $testroot/stdout.expected $testroot/stdout
403 91d845ad 2022-07-03 jrick test_done "$testroot" "$ret"
404 91d845ad 2022-07-03 jrick return 1
405 91d845ad 2022-07-03 jrick fi
406 91d845ad 2022-07-03 jrick printf "Couldn't load public key $testroot/bogus: " \
407 a82759bb 2022-07-03 jrick >> $testroot/stderr.expected
408 91d845ad 2022-07-03 jrick printf "No such file or directory\r\n" >> $testroot/stderr.expected
409 a82759bb 2022-07-03 jrick echo "got: unable to sign tag" >> $testroot/stderr.expected
410 91d845ad 2022-07-03 jrick cmp -s $testroot/stderr $testroot/stderr.expected
411 91d845ad 2022-07-03 jrick ret=$?
412 91d845ad 2022-07-03 jrick if [ $ret -ne 0 ]; then
413 91d845ad 2022-07-03 jrick diff -u $testroot/stderr.expected $testroot/stderr
414 91d845ad 2022-07-03 jrick fi
415 91d845ad 2022-07-03 jrick test_done "$testroot" "$ret"
416 91d845ad 2022-07-03 jrick }
417 91d845ad 2022-07-03 jrick
418 7fb414ae 2020-08-08 stsp test_parseargs "$@"
419 8e7bd50a 2019-08-22 stsp run_test test_tag_create
420 8e7bd50a 2019-08-22 stsp run_test test_tag_list
421 d4efa91b 2020-01-14 stsp run_test test_tag_list_lightweight
422 4d5ee956 2022-07-02 jrick run_test test_tag_create_ssh_signed
423 a82759bb 2022-07-03 jrick run_test test_tag_create_ssh_signed_missing_key