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 d68f2c0e 2022-07-05 jrick local tag3=3.0.0
266 4d5ee956 2022-07-02 jrick
267 4d5ee956 2022-07-02 jrick ssh-keygen -q -N '' -t ed25519 -f $testroot/id_ed25519
268 4d5ee956 2022-07-02 jrick ret=$?
269 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
270 4d5ee956 2022-07-02 jrick echo "ssh-keygen failed unexpectedly"
271 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
272 4d5ee956 2022-07-02 jrick return 1
273 4d5ee956 2022-07-02 jrick fi
274 4d5ee956 2022-07-02 jrick touch $testroot/allowed_signers
275 2eeb8068 2022-07-04 jrick touch $testroot/revoked_signers
276 2eeb8068 2022-07-04 jrick echo "allowed_signers \"$testroot/allowed_signers\"" >> \
277 2eeb8068 2022-07-04 jrick $testroot/repo/.git/got.conf
278 2eeb8068 2022-07-04 jrick echo "revoked_signers \"$testroot/revoked_signers\"" >> \
279 4d5ee956 2022-07-02 jrick $testroot/repo/.git/got.conf
280 4d5ee956 2022-07-02 jrick
281 4d5ee956 2022-07-02 jrick # Create a signed tag based on repository's HEAD reference
282 4d5ee956 2022-07-02 jrick got tag -s $testroot/id_ed25519 -m 'test' -r $testroot/repo -c HEAD \
283 4d5ee956 2022-07-02 jrick $tag > $testroot/stdout
284 4d5ee956 2022-07-02 jrick ret=$?
285 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
286 4d5ee956 2022-07-02 jrick echo "got tag command failed unexpectedly"
287 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
288 4d5ee956 2022-07-02 jrick return 1
289 4d5ee956 2022-07-02 jrick fi
290 4d5ee956 2022-07-02 jrick
291 4d5ee956 2022-07-02 jrick tag_id=`got ref -r $testroot/repo -l \
292 4d5ee956 2022-07-02 jrick | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
293 4d5ee956 2022-07-02 jrick echo "Created tag $tag_id" > $testroot/stdout.expected
294 4d5ee956 2022-07-02 jrick cmp -s $testroot/stdout $testroot/stdout.expected
295 4d5ee956 2022-07-02 jrick ret=$?
296 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
297 4d5ee956 2022-07-02 jrick diff -u $testroot/stdout.expected $testroot/stdout
298 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
299 4d5ee956 2022-07-02 jrick return 1
300 4d5ee956 2022-07-02 jrick fi
301 4d5ee956 2022-07-02 jrick
302 4d5ee956 2022-07-02 jrick # Ensure validation fails when the key is not allowed
303 4d5ee956 2022-07-02 jrick echo "signature: Could not verify signature." > \
304 4d5ee956 2022-07-02 jrick $testroot/stdout.expected
305 4d5ee956 2022-07-02 jrick VERIFY_STDOUT=$(got tag -r $testroot/repo -V $tag 2> $testroot/stderr)
306 4d5ee956 2022-07-02 jrick ret=$?
307 4d5ee956 2022-07-02 jrick echo "$VERIFY_STDOUT" | grep '^signature: ' > $testroot/stdout
308 4d5ee956 2022-07-02 jrick if [ $ret -eq 0 ]; then
309 4d5ee956 2022-07-02 jrick diff -u $testroot/stdout.expected $testroot/stdout
310 4d5ee956 2022-07-02 jrick test_done "$testroot" "1"
311 4d5ee956 2022-07-02 jrick return 1
312 4d5ee956 2022-07-02 jrick fi
313 d4efa91b 2020-01-14 stsp
314 48f19407 2022-07-04 stsp GOOD_SIG='Good "git" signature for flan_hacker@openbsd.org with ED25519 key '
315 4d5ee956 2022-07-02 jrick
316 4d5ee956 2022-07-02 jrick # Validate the signature with the key allowed
317 4d5ee956 2022-07-02 jrick echo -n 'flan_hacker@openbsd.org ' > $testroot/allowed_signers
318 4d5ee956 2022-07-02 jrick cat $testroot/id_ed25519.pub >> $testroot/allowed_signers
319 4d5ee956 2022-07-02 jrick GOT_STDOUT=$(got tag -r $testroot/repo -V $tag 2> $testroot/stderr)
320 4d5ee956 2022-07-02 jrick ret=$?
321 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
322 4d5ee956 2022-07-02 jrick echo "got tag command failed unexpectedly"
323 4d5ee956 2022-07-02 jrick diff -u $testroot/stdout.expected $testroot/stdout
324 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
325 4d5ee956 2022-07-02 jrick return 1
326 4d5ee956 2022-07-02 jrick fi
327 2c0a0d66 2022-07-03 jrick
328 4d5ee956 2022-07-02 jrick if ! echo "$GOT_STDOUT" | grep -q "^signature: $GOOD_SIG"; then
329 4d5ee956 2022-07-02 jrick echo "got tag command failed to validate signature"
330 4d5ee956 2022-07-02 jrick test_done "$testroot" "1"
331 4d5ee956 2022-07-02 jrick return 1
332 4d5ee956 2022-07-02 jrick fi
333 4d5ee956 2022-07-02 jrick
334 2eeb8068 2022-07-04 jrick # Ensure validation fails after revoking the key
335 2eeb8068 2022-07-04 jrick ssh-keygen -y -f $testroot/id_ed25519 >> $testroot/revoked_signers
336 2eeb8068 2022-07-04 jrick echo "signature: Could not verify signature." > \
337 2eeb8068 2022-07-04 jrick $testroot/stdout.expected
338 2eeb8068 2022-07-04 jrick VERIFY_STDOUT=$(got tag -r $testroot/repo -V $tag 2> $testroot/stderr)
339 2eeb8068 2022-07-04 jrick ret=$?
340 2eeb8068 2022-07-04 jrick echo "$VERIFY_STDOUT" | grep '^signature: ' > $testroot/stdout
341 2eeb8068 2022-07-04 jrick if [ $ret -eq 0 ]; then
342 2eeb8068 2022-07-04 jrick diff -u $testroot/stdout.expected $testroot/stdout
343 2eeb8068 2022-07-04 jrick test_done "$testroot" "1"
344 2eeb8068 2022-07-04 jrick return 1
345 2eeb8068 2022-07-04 jrick fi
346 2eeb8068 2022-07-04 jrick
347 2eeb8068 2022-07-04 jrick # Later tests expect validation to work
348 2eeb8068 2022-07-04 jrick echo -n > $testroot/revoked_signers
349 2eeb8068 2022-07-04 jrick
350 4d5ee956 2022-07-02 jrick # Ensure that Git recognizes and verifies the tag Got has created
351 4d5ee956 2022-07-02 jrick (cd $testroot/repo && git checkout -q $tag)
352 4d5ee956 2022-07-02 jrick ret=$?
353 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
354 4d5ee956 2022-07-02 jrick echo "git checkout command failed unexpectedly"
355 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
356 4d5ee956 2022-07-02 jrick return 1
357 4d5ee956 2022-07-02 jrick fi
358 4d5ee956 2022-07-02 jrick (cd $testroot/repo && git config --local gpg.ssh.allowedSignersFile \
359 4d5ee956 2022-07-02 jrick $testroot/allowed_signers)
360 4d5ee956 2022-07-02 jrick GIT_STDERR=$(cd $testroot/repo && git tag -v $tag 2>&1 1>/dev/null)
361 4d5ee956 2022-07-02 jrick if ! echo "$GIT_STDERR" | grep -q "^$GOOD_SIG"; then
362 4d5ee956 2022-07-02 jrick echo "git tag command failed to validate signature"
363 4d5ee956 2022-07-02 jrick test_done "$testroot" "1"
364 4d5ee956 2022-07-02 jrick return 1
365 4d5ee956 2022-07-02 jrick fi
366 4d5ee956 2022-07-02 jrick
367 4d5ee956 2022-07-02 jrick # Ensure Got recognizes the new tag
368 4d5ee956 2022-07-02 jrick got checkout -c $tag $testroot/repo $testroot/wt >/dev/null
369 4d5ee956 2022-07-02 jrick ret=$?
370 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
371 4d5ee956 2022-07-02 jrick echo "got checkout command failed unexpectedly"
372 48f19407 2022-07-04 stsp test_done "$testroot" "$ret"
373 48f19407 2022-07-04 stsp return 1
374 4d5ee956 2022-07-02 jrick fi
375 48f19407 2022-07-04 stsp
376 48f19407 2022-07-04 stsp # Create another signed tag with a SHA1 commit ID
377 48f19407 2022-07-04 stsp got tag -s $testroot/id_ed25519 -m 'test' -r $testroot/repo \
378 48f19407 2022-07-04 stsp -c $commit_id $tag2 > $testroot/stdout
379 d68f2c0e 2022-07-05 jrick
380 d68f2c0e 2022-07-05 jrick # Create another signed tag with key defined in got.conf(5)
381 d68f2c0e 2022-07-05 jrick echo "signer_id \"$testroot/id_ed25519\"" >> \
382 d68f2c0e 2022-07-05 jrick $testroot/repo/.git/got.conf
383 d68f2c0e 2022-07-05 jrick got tag -m 'test' -r $testroot/repo -c HEAD $tag3 > $testroot/stdout
384 d68f2c0e 2022-07-05 jrick ret=$?
385 d68f2c0e 2022-07-05 jrick if [ $ret -ne 0 ]; then
386 d68f2c0e 2022-07-05 jrick echo "got tag command failed unexpectedly"
387 d68f2c0e 2022-07-05 jrick test_done "$testroot" "$ret"
388 d68f2c0e 2022-07-05 jrick return 1
389 d68f2c0e 2022-07-05 jrick fi
390 48f19407 2022-07-04 stsp
391 48f19407 2022-07-04 stsp # got tag -V behaves like got tag -l, but with verification enabled.
392 48f19407 2022-07-04 stsp got tag -l -r $testroot/repo > $testroot/stdout.list
393 48f19407 2022-07-04 stsp got tag -V -r $testroot/repo > $testroot/stdout.verify
394 48f19407 2022-07-04 stsp diff -U0 $testroot/stdout.list $testroot/stdout.verify |
395 48f19407 2022-07-04 stsp sed -e '/^--- /d' -e '/^+++ /d' > $testroot/stdout
396 48f19407 2022-07-04 stsp echo "@@ -5,0 +6 @@" > $testroot/stdout.expected
397 48f19407 2022-07-04 stsp echo -n "+signature: $GOOD_SIG" >> $testroot/stdout.expected
398 48f19407 2022-07-04 stsp ssh-keygen -l -f $testroot/id_ed25519.pub | cut -d' ' -f 2 \
399 48f19407 2022-07-04 stsp >> $testroot/stdout.expected
400 48f19407 2022-07-04 stsp echo "@@ -19,0 +21 @@" >> $testroot/stdout.expected
401 48f19407 2022-07-04 stsp echo -n "+signature: $GOOD_SIG" >> $testroot/stdout.expected
402 48f19407 2022-07-04 stsp ssh-keygen -l -f $testroot/id_ed25519.pub | cut -d' ' -f 2 \
403 48f19407 2022-07-04 stsp >> $testroot/stdout.expected
404 d68f2c0e 2022-07-05 jrick echo "@@ -33,0 +36 @@" >> $testroot/stdout.expected
405 d68f2c0e 2022-07-05 jrick echo -n "+signature: $GOOD_SIG" >> $testroot/stdout.expected
406 d68f2c0e 2022-07-05 jrick ssh-keygen -l -f $testroot/id_ed25519.pub | cut -d' ' -f 2 \
407 d68f2c0e 2022-07-05 jrick >> $testroot/stdout.expected
408 48f19407 2022-07-04 stsp cmp -s $testroot/stdout $testroot/stdout.expected
409 48f19407 2022-07-04 stsp ret=$?
410 48f19407 2022-07-04 stsp if [ $ret -ne 0 ]; then
411 48f19407 2022-07-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
412 48f19407 2022-07-04 stsp fi
413 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
414 4d5ee956 2022-07-02 jrick }
415 91d845ad 2022-07-03 jrick
416 91d845ad 2022-07-03 jrick test_tag_create_ssh_signed_missing_key() {
417 91d845ad 2022-07-03 jrick local testroot=`test_init tag_create`
418 91d845ad 2022-07-03 jrick local commit_id=`git_show_head $testroot/repo`
419 91d845ad 2022-07-03 jrick local tag=1.0.0
420 91d845ad 2022-07-03 jrick
421 91d845ad 2022-07-03 jrick # Fail to create a signed tag due to a missing SSH key
422 91d845ad 2022-07-03 jrick got tag -s $testroot/bogus -m 'test' -r $testroot/repo \
423 91d845ad 2022-07-03 jrick -c HEAD $tag > $testroot/stdout 2> $testroot/stderr
424 91d845ad 2022-07-03 jrick ret=$?
425 91d845ad 2022-07-03 jrick if [ $ret -eq 0 ]; then
426 91d845ad 2022-07-03 jrick echo "got tag command succeeded unexpectedly"
427 91d845ad 2022-07-03 jrick test_done "$testroot" 1
428 91d845ad 2022-07-03 jrick return 1
429 91d845ad 2022-07-03 jrick fi
430 4d5ee956 2022-07-02 jrick
431 91d845ad 2022-07-03 jrick got ref -r $testroot/repo -l > $testroot/stdout
432 91d845ad 2022-07-03 jrick echo "HEAD: refs/heads/master" > $testroot/stdout.expected
433 91d845ad 2022-07-03 jrick echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
434 91d845ad 2022-07-03 jrick cmp -s $testroot/stdout $testroot/stdout.expected
435 91d845ad 2022-07-03 jrick ret=$?
436 91d845ad 2022-07-03 jrick if [ $ret -ne 0 ]; then
437 91d845ad 2022-07-03 jrick diff -u $testroot/stdout.expected $testroot/stdout
438 91d845ad 2022-07-03 jrick test_done "$testroot" "$ret"
439 91d845ad 2022-07-03 jrick return 1
440 91d845ad 2022-07-03 jrick fi
441 91d845ad 2022-07-03 jrick printf "Couldn't load public key $testroot/bogus: " \
442 a82759bb 2022-07-03 jrick >> $testroot/stderr.expected
443 91d845ad 2022-07-03 jrick printf "No such file or directory\r\n" >> $testroot/stderr.expected
444 a82759bb 2022-07-03 jrick echo "got: unable to sign tag" >> $testroot/stderr.expected
445 91d845ad 2022-07-03 jrick cmp -s $testroot/stderr $testroot/stderr.expected
446 91d845ad 2022-07-03 jrick ret=$?
447 91d845ad 2022-07-03 jrick if [ $ret -ne 0 ]; then
448 91d845ad 2022-07-03 jrick diff -u $testroot/stderr.expected $testroot/stderr
449 91d845ad 2022-07-03 jrick fi
450 91d845ad 2022-07-03 jrick test_done "$testroot" "$ret"
451 91d845ad 2022-07-03 jrick }
452 91d845ad 2022-07-03 jrick
453 7fb414ae 2020-08-08 stsp test_parseargs "$@"
454 8e7bd50a 2019-08-22 stsp run_test test_tag_create
455 8e7bd50a 2019-08-22 stsp run_test test_tag_list
456 d4efa91b 2020-01-14 stsp run_test test_tag_list_lightweight
457 4d5ee956 2022-07-02 jrick run_test test_tag_create_ssh_signed
458 a82759bb 2022-07-03 jrick run_test test_tag_create_ssh_signed_missing_key