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 1bdf356c 2022-08-04 stsp (cd $testroot/wt && got branch foo > /dev/null)
65 1bdf356c 2022-08-04 stsp echo 'foo' >> $testroot/wt/alpha
66 1bdf356c 2022-08-04 stsp (cd $testroot/wt && got commit -m foo > /dev/null)
67 1bdf356c 2022-08-04 stsp local commit_id2=`git_show_branch_head $testroot/repo foo`
68 8e7bd50a 2019-08-22 stsp (cd $testroot/wt && got tag -m 'test' $tag2 > $testroot/stdout)
69 49c543a6 2022-03-31 naddy ret=$?
70 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
71 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
72 8e7bd50a 2019-08-22 stsp return 1
73 8e7bd50a 2019-08-22 stsp fi
74 8e7bd50a 2019-08-22 stsp
75 8e7bd50a 2019-08-22 stsp tag_id2=`got ref -r $testroot/repo -l \
76 8e7bd50a 2019-08-22 stsp | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
77 8e7bd50a 2019-08-22 stsp echo "Created tag $tag_id2" > $testroot/stdout.expected
78 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
79 49c543a6 2022-03-31 naddy ret=$?
80 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
81 8e7bd50a 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
82 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
83 8e7bd50a 2019-08-22 stsp return 1
84 8e7bd50a 2019-08-22 stsp fi
85 8e7bd50a 2019-08-22 stsp
86 1bdf356c 2022-08-04 stsp tagged_commit=`got cat -r $testroot/repo $tag2 | grep ^object \
87 1bdf356c 2022-08-04 stsp | cut -d' ' -f2`
88 1bdf356c 2022-08-04 stsp if [ "$tagged_commit" != "$commit_id2" ]; then
89 1bdf356c 2022-08-04 stsp echo "wrong commit was tagged" >&2
90 1bdf356c 2022-08-04 stsp test_done "$testroot" "1"
91 1bdf356c 2022-08-04 stsp return 1
92 1bdf356c 2022-08-04 stsp fi
93 1bdf356c 2022-08-04 stsp
94 8e7bd50a 2019-08-22 stsp (cd $testroot/repo && git checkout -q $tag2)
95 49c543a6 2022-03-31 naddy ret=$?
96 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
97 8e7bd50a 2019-08-22 stsp echo "git checkout command failed unexpectedly"
98 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
99 a9662115 2021-08-29 naddy return 1
100 8e7bd50a 2019-08-22 stsp fi
101 8e7bd50a 2019-08-22 stsp
102 8e7bd50a 2019-08-22 stsp # Attempt to create a tag pointing at a non-commit
103 8e7bd50a 2019-08-22 stsp local tree_id=`git_show_tree $testroot/repo`
104 80106605 2020-02-24 stsp (cd $testroot/wt && got tag -m 'test' -c $tree_id foobar \
105 8e7bd50a 2019-08-22 stsp 2> $testroot/stderr)
106 49c543a6 2022-03-31 naddy ret=$?
107 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
108 1bdf356c 2022-08-04 stsp echo "got tag command succeeded unexpectedly"
109 8e7bd50a 2019-08-22 stsp test_done "$testroot" "1"
110 8e7bd50a 2019-08-22 stsp return 1
111 8e7bd50a 2019-08-22 stsp fi
112 8e7bd50a 2019-08-22 stsp
113 138e4f47 2021-10-09 stsp echo "got: commit $tree_id: object not found" \
114 138e4f47 2021-10-09 stsp > $testroot/stderr.expected
115 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stderr $testroot/stderr.expected
116 49c543a6 2022-03-31 naddy ret=$?
117 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
118 8e7bd50a 2019-08-22 stsp diff -u $testroot/stderr.expected $testroot/stderr
119 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
120 8e7bd50a 2019-08-22 stsp return 1
121 8e7bd50a 2019-08-22 stsp fi
122 8e7bd50a 2019-08-22 stsp
123 8e7bd50a 2019-08-22 stsp got ref -r $testroot/repo -l > $testroot/stdout
124 1bdf356c 2022-08-04 stsp echo "HEAD: $commit_id2" > $testroot/stdout.expected
125 8e7bd50a 2019-08-22 stsp echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
126 8e7bd50a 2019-08-22 stsp cat $testroot/wt/.got/uuid | tr -d '\n' >> $testroot/stdout.expected
127 1bdf356c 2022-08-04 stsp echo ": $commit_id2" >> $testroot/stdout.expected
128 1bdf356c 2022-08-04 stsp echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
129 8e7bd50a 2019-08-22 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
130 8e7bd50a 2019-08-22 stsp echo "refs/tags/$tag: $tag_id" >> $testroot/stdout.expected
131 8e7bd50a 2019-08-22 stsp echo "refs/tags/$tag2: $tag_id2" >> $testroot/stdout.expected
132 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
133 49c543a6 2022-03-31 naddy ret=$?
134 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
135 8e7bd50a 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
136 8e7bd50a 2019-08-22 stsp fi
137 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
138 8e7bd50a 2019-08-22 stsp }
139 8e7bd50a 2019-08-22 stsp
140 f6cae3ed 2020-09-13 naddy test_tag_list() {
141 8e7bd50a 2019-08-22 stsp local testroot=`test_init tag_list`
142 8e7bd50a 2019-08-22 stsp local commit_id=`git_show_head $testroot/repo`
143 8e7bd50a 2019-08-22 stsp local tag=1.0.0
144 8e7bd50a 2019-08-22 stsp local tag2=2.0.0
145 8e7bd50a 2019-08-22 stsp
146 e8039a4a 2019-08-23 stsp # create tag with Git
147 8e7bd50a 2019-08-22 stsp (cd $testroot/repo && git tag -a -m 'test' $tag)
148 e8039a4a 2019-08-23 stsp # create tag with Got
149 e8039a4a 2019-08-23 stsp (cd $testroot/repo && got tag -m 'test' $tag2 > /dev/null)
150 8e7bd50a 2019-08-22 stsp
151 8e7bd50a 2019-08-22 stsp tag_id=`got ref -r $testroot/repo -l \
152 8e7bd50a 2019-08-22 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
153 8e7bd50a 2019-08-22 stsp local tagger_time=`git_show_tagger_time $testroot/repo $tag`
154 3a6b8760 2021-08-31 naddy d1=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
155 8e7bd50a 2019-08-22 stsp tag_id2=`got ref -r $testroot/repo -l \
156 8e7bd50a 2019-08-22 stsp | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
157 8e7bd50a 2019-08-22 stsp local tagger_time2=`git_show_tagger_time $testroot/repo $tag2`
158 3a6b8760 2021-08-31 naddy d2=`date -u -r $tagger_time2 +"%a %b %e %X %Y UTC"`
159 8e7bd50a 2019-08-22 stsp
160 8e7bd50a 2019-08-22 stsp got tag -r $testroot/repo -l > $testroot/stdout
161 8e7bd50a 2019-08-22 stsp
162 8e7bd50a 2019-08-22 stsp echo "-----------------------------------------------" \
163 8e7bd50a 2019-08-22 stsp > $testroot/stdout.expected
164 b8bad2ba 2019-08-23 stsp echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
165 8e7bd50a 2019-08-22 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
166 ac03cf6d 2020-01-17 stsp echo "date: $d2" >> $testroot/stdout.expected
167 2417344c 2019-08-23 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
168 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
169 8e7bd50a 2019-08-22 stsp echo " test" >> $testroot/stdout.expected
170 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
171 8e7bd50a 2019-08-22 stsp echo "-----------------------------------------------" \
172 8e7bd50a 2019-08-22 stsp >> $testroot/stdout.expected
173 b8bad2ba 2019-08-23 stsp echo "tag $tag $tag_id" >> $testroot/stdout.expected
174 8e7bd50a 2019-08-22 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
175 ac03cf6d 2020-01-17 stsp echo "date: $d1" >> $testroot/stdout.expected
176 2417344c 2019-08-23 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
177 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
178 8e7bd50a 2019-08-22 stsp echo " test" >> $testroot/stdout.expected
179 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
180 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
181 49c543a6 2022-03-31 naddy ret=$?
182 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
183 8e7bd50a 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
184 8c4a6db8 2022-06-29 stsp test_done "$testroot" "$ret"
185 8c4a6db8 2022-06-29 stsp return 1
186 8e7bd50a 2019-08-22 stsp fi
187 8c4a6db8 2022-06-29 stsp
188 8c4a6db8 2022-06-29 stsp got tag -r $testroot/repo -l $tag > $testroot/stdout
189 8c4a6db8 2022-06-29 stsp
190 8c4a6db8 2022-06-29 stsp echo "-----------------------------------------------" \
191 8c4a6db8 2022-06-29 stsp > $testroot/stdout.expected
192 8c4a6db8 2022-06-29 stsp echo "tag $tag $tag_id" >> $testroot/stdout.expected
193 8c4a6db8 2022-06-29 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
194 8c4a6db8 2022-06-29 stsp echo "date: $d1" >> $testroot/stdout.expected
195 8c4a6db8 2022-06-29 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
196 8c4a6db8 2022-06-29 stsp echo " " >> $testroot/stdout.expected
197 8c4a6db8 2022-06-29 stsp echo " test" >> $testroot/stdout.expected
198 8c4a6db8 2022-06-29 stsp echo " " >> $testroot/stdout.expected
199 8c4a6db8 2022-06-29 stsp cmp -s $testroot/stdout $testroot/stdout.expected
200 8c4a6db8 2022-06-29 stsp ret=$?
201 8c4a6db8 2022-06-29 stsp if [ $ret -ne 0 ]; then
202 8c4a6db8 2022-06-29 stsp diff -u $testroot/stdout.expected $testroot/stdout
203 8c4a6db8 2022-06-29 stsp test_done "$testroot" "$ret"
204 8c4a6db8 2022-06-29 stsp return 1
205 8c4a6db8 2022-06-29 stsp fi
206 8c4a6db8 2022-06-29 stsp
207 8c4a6db8 2022-06-29 stsp got tag -r $testroot/repo -l $tag2 > $testroot/stdout
208 8c4a6db8 2022-06-29 stsp
209 8c4a6db8 2022-06-29 stsp echo "-----------------------------------------------" \
210 8c4a6db8 2022-06-29 stsp > $testroot/stdout.expected
211 8c4a6db8 2022-06-29 stsp echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
212 8c4a6db8 2022-06-29 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
213 8c4a6db8 2022-06-29 stsp echo "date: $d2" >> $testroot/stdout.expected
214 8c4a6db8 2022-06-29 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
215 8c4a6db8 2022-06-29 stsp echo " " >> $testroot/stdout.expected
216 8c4a6db8 2022-06-29 stsp echo " test" >> $testroot/stdout.expected
217 8c4a6db8 2022-06-29 stsp echo " " >> $testroot/stdout.expected
218 8c4a6db8 2022-06-29 stsp cmp -s $testroot/stdout $testroot/stdout.expected
219 8c4a6db8 2022-06-29 stsp ret=$?
220 8c4a6db8 2022-06-29 stsp if [ $ret -ne 0 ]; then
221 8c4a6db8 2022-06-29 stsp diff -u $testroot/stdout.expected $testroot/stdout
222 8c4a6db8 2022-06-29 stsp fi
223 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
224 8e7bd50a 2019-08-22 stsp }
225 8e7bd50a 2019-08-22 stsp
226 f6cae3ed 2020-09-13 naddy test_tag_list_lightweight() {
227 d4efa91b 2020-01-14 stsp local testroot=`test_init tag_list_lightweight`
228 d4efa91b 2020-01-14 stsp local commit_id=`git_show_head $testroot/repo`
229 d4efa91b 2020-01-14 stsp local tag=1.0.0
230 d4efa91b 2020-01-14 stsp local tag2=2.0.0
231 d4efa91b 2020-01-14 stsp
232 d4efa91b 2020-01-14 stsp # create "lightweight" tag with Git
233 d4efa91b 2020-01-14 stsp (cd $testroot/repo && git tag $tag)
234 d4efa91b 2020-01-14 stsp (cd $testroot/repo && git tag $tag2)
235 d4efa91b 2020-01-14 stsp
236 d4efa91b 2020-01-14 stsp tag_id=`got ref -r $testroot/repo -l \
237 d4efa91b 2020-01-14 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
238 d4efa91b 2020-01-14 stsp local tagger_time=`git_show_author_time $testroot/repo $tag`
239 3a6b8760 2021-08-31 naddy d1=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
240 d4efa91b 2020-01-14 stsp tag_id2=`got ref -r $testroot/repo -l \
241 d4efa91b 2020-01-14 stsp | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
242 d4efa91b 2020-01-14 stsp local tagger_time2=`git_show_author_time $testroot/repo $tag2`
243 3a6b8760 2021-08-31 naddy d2=`date -u -r $tagger_time2 +"%a %b %e %X %Y UTC"`
244 d4efa91b 2020-01-14 stsp
245 d4efa91b 2020-01-14 stsp got tag -r $testroot/repo -l > $testroot/stdout
246 d4efa91b 2020-01-14 stsp
247 8d4a8ca1 2022-09-02 jrick # test signature validation ignoring lightweight tags
248 8d4a8ca1 2022-09-02 jrick got tag -r $testroot/repo -V > $testroot/stdout
249 8d4a8ca1 2022-09-02 jrick
250 d4efa91b 2020-01-14 stsp echo "-----------------------------------------------" \
251 d4efa91b 2020-01-14 stsp > $testroot/stdout.expected
252 d4efa91b 2020-01-14 stsp echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
253 d4efa91b 2020-01-14 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
254 ac03cf6d 2020-01-17 stsp echo "date: $d2" >> $testroot/stdout.expected
255 d4efa91b 2020-01-14 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
256 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
257 d4efa91b 2020-01-14 stsp echo " adding the test tree" >> $testroot/stdout.expected
258 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
259 d4efa91b 2020-01-14 stsp echo "-----------------------------------------------" \
260 d4efa91b 2020-01-14 stsp >> $testroot/stdout.expected
261 d4efa91b 2020-01-14 stsp echo "tag $tag $tag_id" >> $testroot/stdout.expected
262 d4efa91b 2020-01-14 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
263 ac03cf6d 2020-01-17 stsp echo "date: $d1" >> $testroot/stdout.expected
264 d4efa91b 2020-01-14 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
265 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
266 d4efa91b 2020-01-14 stsp echo " adding the test tree" >> $testroot/stdout.expected
267 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
268 d4efa91b 2020-01-14 stsp cmp -s $testroot/stdout $testroot/stdout.expected
269 49c543a6 2022-03-31 naddy ret=$?
270 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
271 d4efa91b 2020-01-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
272 d4efa91b 2020-01-14 stsp fi
273 d4efa91b 2020-01-14 stsp test_done "$testroot" "$ret"
274 d4efa91b 2020-01-14 stsp }
275 4d5ee956 2022-07-02 jrick
276 4d5ee956 2022-07-02 jrick test_tag_create_ssh_signed() {
277 4d5ee956 2022-07-02 jrick local testroot=`test_init tag_create`
278 4d5ee956 2022-07-02 jrick local commit_id=`git_show_head $testroot/repo`
279 4d5ee956 2022-07-02 jrick local tag=1.0.0
280 4d5ee956 2022-07-02 jrick local tag2=2.0.0
281 d68f2c0e 2022-07-05 jrick local tag3=3.0.0
282 4d5ee956 2022-07-02 jrick
283 4d5ee956 2022-07-02 jrick ssh-keygen -q -N '' -t ed25519 -f $testroot/id_ed25519
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 "ssh-keygen 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 touch $testroot/allowed_signers
291 2eeb8068 2022-07-04 jrick touch $testroot/revoked_signers
292 2eeb8068 2022-07-04 jrick echo "allowed_signers \"$testroot/allowed_signers\"" >> \
293 2eeb8068 2022-07-04 jrick $testroot/repo/.git/got.conf
294 2eeb8068 2022-07-04 jrick echo "revoked_signers \"$testroot/revoked_signers\"" >> \
295 4d5ee956 2022-07-02 jrick $testroot/repo/.git/got.conf
296 4d5ee956 2022-07-02 jrick
297 4d5ee956 2022-07-02 jrick # Create a signed tag based on repository's HEAD reference
298 4d5ee956 2022-07-02 jrick got tag -s $testroot/id_ed25519 -m 'test' -r $testroot/repo -c HEAD \
299 4d5ee956 2022-07-02 jrick $tag > $testroot/stdout
300 4d5ee956 2022-07-02 jrick ret=$?
301 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
302 4d5ee956 2022-07-02 jrick echo "got tag command failed unexpectedly"
303 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
304 4d5ee956 2022-07-02 jrick return 1
305 4d5ee956 2022-07-02 jrick fi
306 4d5ee956 2022-07-02 jrick
307 4d5ee956 2022-07-02 jrick tag_id=`got ref -r $testroot/repo -l \
308 4d5ee956 2022-07-02 jrick | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
309 4d5ee956 2022-07-02 jrick echo "Created tag $tag_id" > $testroot/stdout.expected
310 4d5ee956 2022-07-02 jrick cmp -s $testroot/stdout $testroot/stdout.expected
311 4d5ee956 2022-07-02 jrick ret=$?
312 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
313 4d5ee956 2022-07-02 jrick diff -u $testroot/stdout.expected $testroot/stdout
314 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
315 4d5ee956 2022-07-02 jrick return 1
316 4d5ee956 2022-07-02 jrick fi
317 4d5ee956 2022-07-02 jrick
318 4d5ee956 2022-07-02 jrick # Ensure validation fails when the key is not allowed
319 4d5ee956 2022-07-02 jrick echo "signature: Could not verify signature." > \
320 4d5ee956 2022-07-02 jrick $testroot/stdout.expected
321 4d5ee956 2022-07-02 jrick VERIFY_STDOUT=$(got tag -r $testroot/repo -V $tag 2> $testroot/stderr)
322 4d5ee956 2022-07-02 jrick ret=$?
323 4d5ee956 2022-07-02 jrick echo "$VERIFY_STDOUT" | grep '^signature: ' > $testroot/stdout
324 4d5ee956 2022-07-02 jrick if [ $ret -eq 0 ]; then
325 4d5ee956 2022-07-02 jrick diff -u $testroot/stdout.expected $testroot/stdout
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 d4efa91b 2020-01-14 stsp
330 48f19407 2022-07-04 stsp GOOD_SIG='Good "git" signature for flan_hacker@openbsd.org with ED25519 key '
331 4d5ee956 2022-07-02 jrick
332 4d5ee956 2022-07-02 jrick # Validate the signature with the key allowed
333 4d5ee956 2022-07-02 jrick echo -n 'flan_hacker@openbsd.org ' > $testroot/allowed_signers
334 4d5ee956 2022-07-02 jrick cat $testroot/id_ed25519.pub >> $testroot/allowed_signers
335 4d5ee956 2022-07-02 jrick GOT_STDOUT=$(got tag -r $testroot/repo -V $tag 2> $testroot/stderr)
336 4d5ee956 2022-07-02 jrick ret=$?
337 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
338 4d5ee956 2022-07-02 jrick echo "got tag command failed unexpectedly"
339 4d5ee956 2022-07-02 jrick diff -u $testroot/stdout.expected $testroot/stdout
340 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
341 4d5ee956 2022-07-02 jrick return 1
342 4d5ee956 2022-07-02 jrick fi
343 2c0a0d66 2022-07-03 jrick
344 4d5ee956 2022-07-02 jrick if ! echo "$GOT_STDOUT" | grep -q "^signature: $GOOD_SIG"; then
345 4d5ee956 2022-07-02 jrick echo "got tag command failed to validate signature"
346 4d5ee956 2022-07-02 jrick test_done "$testroot" "1"
347 4d5ee956 2022-07-02 jrick return 1
348 4d5ee956 2022-07-02 jrick fi
349 4d5ee956 2022-07-02 jrick
350 2eeb8068 2022-07-04 jrick # Ensure validation fails after revoking the key
351 2eeb8068 2022-07-04 jrick ssh-keygen -y -f $testroot/id_ed25519 >> $testroot/revoked_signers
352 2eeb8068 2022-07-04 jrick echo "signature: Could not verify signature." > \
353 2eeb8068 2022-07-04 jrick $testroot/stdout.expected
354 2eeb8068 2022-07-04 jrick VERIFY_STDOUT=$(got tag -r $testroot/repo -V $tag 2> $testroot/stderr)
355 2eeb8068 2022-07-04 jrick ret=$?
356 2eeb8068 2022-07-04 jrick echo "$VERIFY_STDOUT" | grep '^signature: ' > $testroot/stdout
357 2eeb8068 2022-07-04 jrick if [ $ret -eq 0 ]; then
358 2eeb8068 2022-07-04 jrick diff -u $testroot/stdout.expected $testroot/stdout
359 2eeb8068 2022-07-04 jrick test_done "$testroot" "1"
360 2eeb8068 2022-07-04 jrick return 1
361 2eeb8068 2022-07-04 jrick fi
362 2eeb8068 2022-07-04 jrick
363 2eeb8068 2022-07-04 jrick # Later tests expect validation to work
364 2eeb8068 2022-07-04 jrick echo -n > $testroot/revoked_signers
365 2eeb8068 2022-07-04 jrick
366 4d5ee956 2022-07-02 jrick # Ensure that Git recognizes and verifies the tag Got has created
367 4d5ee956 2022-07-02 jrick (cd $testroot/repo && git checkout -q $tag)
368 4d5ee956 2022-07-02 jrick ret=$?
369 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
370 4d5ee956 2022-07-02 jrick echo "git checkout command failed unexpectedly"
371 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
372 4d5ee956 2022-07-02 jrick return 1
373 4d5ee956 2022-07-02 jrick fi
374 4d5ee956 2022-07-02 jrick (cd $testroot/repo && git config --local gpg.ssh.allowedSignersFile \
375 4d5ee956 2022-07-02 jrick $testroot/allowed_signers)
376 4d5ee956 2022-07-02 jrick GIT_STDERR=$(cd $testroot/repo && git tag -v $tag 2>&1 1>/dev/null)
377 4d5ee956 2022-07-02 jrick if ! echo "$GIT_STDERR" | grep -q "^$GOOD_SIG"; then
378 4d5ee956 2022-07-02 jrick echo "git tag command failed to validate signature"
379 4d5ee956 2022-07-02 jrick test_done "$testroot" "1"
380 4d5ee956 2022-07-02 jrick return 1
381 4d5ee956 2022-07-02 jrick fi
382 4d5ee956 2022-07-02 jrick
383 4d5ee956 2022-07-02 jrick # Ensure Got recognizes the new tag
384 4d5ee956 2022-07-02 jrick got checkout -c $tag $testroot/repo $testroot/wt >/dev/null
385 4d5ee956 2022-07-02 jrick ret=$?
386 4d5ee956 2022-07-02 jrick if [ $ret -ne 0 ]; then
387 4d5ee956 2022-07-02 jrick echo "got checkout command failed unexpectedly"
388 48f19407 2022-07-04 stsp test_done "$testroot" "$ret"
389 48f19407 2022-07-04 stsp return 1
390 4d5ee956 2022-07-02 jrick fi
391 48f19407 2022-07-04 stsp
392 48f19407 2022-07-04 stsp # Create another signed tag with a SHA1 commit ID
393 48f19407 2022-07-04 stsp got tag -s $testroot/id_ed25519 -m 'test' -r $testroot/repo \
394 48f19407 2022-07-04 stsp -c $commit_id $tag2 > $testroot/stdout
395 d68f2c0e 2022-07-05 jrick
396 d68f2c0e 2022-07-05 jrick # Create another signed tag with key defined in got.conf(5)
397 d68f2c0e 2022-07-05 jrick echo "signer_id \"$testroot/id_ed25519\"" >> \
398 d68f2c0e 2022-07-05 jrick $testroot/repo/.git/got.conf
399 d68f2c0e 2022-07-05 jrick got tag -m 'test' -r $testroot/repo -c HEAD $tag3 > $testroot/stdout
400 d68f2c0e 2022-07-05 jrick ret=$?
401 d68f2c0e 2022-07-05 jrick if [ $ret -ne 0 ]; then
402 d68f2c0e 2022-07-05 jrick echo "got tag command failed unexpectedly"
403 d68f2c0e 2022-07-05 jrick test_done "$testroot" "$ret"
404 d68f2c0e 2022-07-05 jrick return 1
405 d68f2c0e 2022-07-05 jrick fi
406 48f19407 2022-07-04 stsp
407 48f19407 2022-07-04 stsp # got tag -V behaves like got tag -l, but with verification enabled.
408 48f19407 2022-07-04 stsp got tag -l -r $testroot/repo > $testroot/stdout.list
409 48f19407 2022-07-04 stsp got tag -V -r $testroot/repo > $testroot/stdout.verify
410 48f19407 2022-07-04 stsp diff -U0 $testroot/stdout.list $testroot/stdout.verify |
411 48f19407 2022-07-04 stsp sed -e '/^--- /d' -e '/^+++ /d' > $testroot/stdout
412 48f19407 2022-07-04 stsp echo "@@ -5,0 +6 @@" > $testroot/stdout.expected
413 48f19407 2022-07-04 stsp echo -n "+signature: $GOOD_SIG" >> $testroot/stdout.expected
414 48f19407 2022-07-04 stsp ssh-keygen -l -f $testroot/id_ed25519.pub | cut -d' ' -f 2 \
415 48f19407 2022-07-04 stsp >> $testroot/stdout.expected
416 48f19407 2022-07-04 stsp echo "@@ -19,0 +21 @@" >> $testroot/stdout.expected
417 48f19407 2022-07-04 stsp echo -n "+signature: $GOOD_SIG" >> $testroot/stdout.expected
418 48f19407 2022-07-04 stsp ssh-keygen -l -f $testroot/id_ed25519.pub | cut -d' ' -f 2 \
419 48f19407 2022-07-04 stsp >> $testroot/stdout.expected
420 d68f2c0e 2022-07-05 jrick echo "@@ -33,0 +36 @@" >> $testroot/stdout.expected
421 d68f2c0e 2022-07-05 jrick echo -n "+signature: $GOOD_SIG" >> $testroot/stdout.expected
422 d68f2c0e 2022-07-05 jrick ssh-keygen -l -f $testroot/id_ed25519.pub | cut -d' ' -f 2 \
423 d68f2c0e 2022-07-05 jrick >> $testroot/stdout.expected
424 48f19407 2022-07-04 stsp cmp -s $testroot/stdout $testroot/stdout.expected
425 48f19407 2022-07-04 stsp ret=$?
426 48f19407 2022-07-04 stsp if [ $ret -ne 0 ]; then
427 48f19407 2022-07-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
428 48f19407 2022-07-04 stsp fi
429 4d5ee956 2022-07-02 jrick test_done "$testroot" "$ret"
430 4d5ee956 2022-07-02 jrick }
431 91d845ad 2022-07-03 jrick
432 91d845ad 2022-07-03 jrick test_tag_create_ssh_signed_missing_key() {
433 91d845ad 2022-07-03 jrick local testroot=`test_init tag_create`
434 91d845ad 2022-07-03 jrick local commit_id=`git_show_head $testroot/repo`
435 91d845ad 2022-07-03 jrick local tag=1.0.0
436 91d845ad 2022-07-03 jrick
437 91d845ad 2022-07-03 jrick # Fail to create a signed tag due to a missing SSH key
438 91d845ad 2022-07-03 jrick got tag -s $testroot/bogus -m 'test' -r $testroot/repo \
439 91d845ad 2022-07-03 jrick -c HEAD $tag > $testroot/stdout 2> $testroot/stderr
440 91d845ad 2022-07-03 jrick ret=$?
441 91d845ad 2022-07-03 jrick if [ $ret -eq 0 ]; then
442 91d845ad 2022-07-03 jrick echo "got tag command succeeded unexpectedly"
443 91d845ad 2022-07-03 jrick test_done "$testroot" 1
444 91d845ad 2022-07-03 jrick return 1
445 91d845ad 2022-07-03 jrick fi
446 4d5ee956 2022-07-02 jrick
447 91d845ad 2022-07-03 jrick got ref -r $testroot/repo -l > $testroot/stdout
448 91d845ad 2022-07-03 jrick echo "HEAD: refs/heads/master" > $testroot/stdout.expected
449 91d845ad 2022-07-03 jrick echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
450 91d845ad 2022-07-03 jrick cmp -s $testroot/stdout $testroot/stdout.expected
451 91d845ad 2022-07-03 jrick ret=$?
452 91d845ad 2022-07-03 jrick if [ $ret -ne 0 ]; then
453 91d845ad 2022-07-03 jrick diff -u $testroot/stdout.expected $testroot/stdout
454 91d845ad 2022-07-03 jrick test_done "$testroot" "$ret"
455 91d845ad 2022-07-03 jrick return 1
456 91d845ad 2022-07-03 jrick fi
457 91d845ad 2022-07-03 jrick printf "Couldn't load public key $testroot/bogus: " \
458 a82759bb 2022-07-03 jrick >> $testroot/stderr.expected
459 91d845ad 2022-07-03 jrick printf "No such file or directory\r\n" >> $testroot/stderr.expected
460 a82759bb 2022-07-03 jrick echo "got: unable to sign tag" >> $testroot/stderr.expected
461 91d845ad 2022-07-03 jrick cmp -s $testroot/stderr $testroot/stderr.expected
462 91d845ad 2022-07-03 jrick ret=$?
463 91d845ad 2022-07-03 jrick if [ $ret -ne 0 ]; then
464 91d845ad 2022-07-03 jrick diff -u $testroot/stderr.expected $testroot/stderr
465 91d845ad 2022-07-03 jrick fi
466 91d845ad 2022-07-03 jrick test_done "$testroot" "$ret"
467 91d845ad 2022-07-03 jrick }
468 91d845ad 2022-07-03 jrick
469 7fb414ae 2020-08-08 stsp test_parseargs "$@"
470 8e7bd50a 2019-08-22 stsp run_test test_tag_create
471 8e7bd50a 2019-08-22 stsp run_test test_tag_list
472 d4efa91b 2020-01-14 stsp run_test test_tag_list_lightweight
473 4d5ee956 2022-07-02 jrick run_test test_tag_create_ssh_signed
474 a82759bb 2022-07-03 jrick run_test test_tag_create_ssh_signed_missing_key