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 fc414659 2022-04-16 thomas ret=$?
28 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
39 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
48 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
57 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
66 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
76 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
84 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
95 fc414659 2022-04-16 thomas 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 a3599220 2021-10-10 thomas echo "got: commit $tree_id: object not found" \
102 a3599220 2021-10-10 thomas > $testroot/stderr.expected
103 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stderr $testroot/stderr.expected
104 fc414659 2022-04-16 thomas ret=$?
105 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
121 fc414659 2022-04-16 thomas 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 fa37079f 2021-10-09 thomas
142 fa37079f 2021-10-09 thomas local prev_LC_TIME=$LC_TIME
143 fa37079f 2021-10-09 thomas export LC_TIME=C
144 fa37079f 2021-10-09 thomas d1=`date -u -d "@$tagger_time" +"%a %b %e %X %Y UTC"`
145 fa37079f 2021-10-09 thomas LC_TIME="$prev_LC_TIME"
146 fa37079f 2021-10-09 thomas
147 8e7bd50a 2019-08-22 stsp tag_id2=`got ref -r $testroot/repo -l \
148 8e7bd50a 2019-08-22 stsp | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
149 8e7bd50a 2019-08-22 stsp local tagger_time2=`git_show_tagger_time $testroot/repo $tag2`
150 fa37079f 2021-10-09 thomas
151 fa37079f 2021-10-09 thomas prev_LC_TIME="$LC_TIME"
152 fa37079f 2021-10-09 thomas export LC_TIME=C
153 fa37079f 2021-10-09 thomas d2=`date -u -d "@$tagger_time2" +"%a %b %e %X %Y UTC"`
154 fa37079f 2021-10-09 thomas LC_TIME="$prev_LC_TIME"
155 8e7bd50a 2019-08-22 stsp
156 8e7bd50a 2019-08-22 stsp got tag -r $testroot/repo -l > $testroot/stdout
157 8e7bd50a 2019-08-22 stsp
158 8e7bd50a 2019-08-22 stsp echo "-----------------------------------------------" \
159 8e7bd50a 2019-08-22 stsp > $testroot/stdout.expected
160 b8bad2ba 2019-08-23 stsp echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
161 8e7bd50a 2019-08-22 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
162 ac03cf6d 2020-01-17 stsp echo "date: $d2" >> $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 echo "-----------------------------------------------" \
168 8e7bd50a 2019-08-22 stsp >> $testroot/stdout.expected
169 68e8cedb 2022-07-01 thomas echo "tag $tag $tag_id" >> $testroot/stdout.expected
170 68e8cedb 2022-07-01 thomas echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
171 68e8cedb 2022-07-01 thomas echo "date: $d1" >> $testroot/stdout.expected
172 68e8cedb 2022-07-01 thomas echo "object: commit $commit_id" >> $testroot/stdout.expected
173 68e8cedb 2022-07-01 thomas echo " " >> $testroot/stdout.expected
174 68e8cedb 2022-07-01 thomas echo " test" >> $testroot/stdout.expected
175 68e8cedb 2022-07-01 thomas echo " " >> $testroot/stdout.expected
176 68e8cedb 2022-07-01 thomas cmp -s $testroot/stdout $testroot/stdout.expected
177 68e8cedb 2022-07-01 thomas ret=$?
178 68e8cedb 2022-07-01 thomas if [ $ret -ne 0 ]; then
179 68e8cedb 2022-07-01 thomas diff -u $testroot/stdout.expected $testroot/stdout
180 68e8cedb 2022-07-01 thomas test_done "$testroot" "$ret"
181 68e8cedb 2022-07-01 thomas return 1
182 68e8cedb 2022-07-01 thomas fi
183 68e8cedb 2022-07-01 thomas
184 68e8cedb 2022-07-01 thomas got tag -r $testroot/repo -l $tag > $testroot/stdout
185 68e8cedb 2022-07-01 thomas
186 68e8cedb 2022-07-01 thomas echo "-----------------------------------------------" \
187 68e8cedb 2022-07-01 thomas > $testroot/stdout.expected
188 b8bad2ba 2019-08-23 stsp echo "tag $tag $tag_id" >> $testroot/stdout.expected
189 8e7bd50a 2019-08-22 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
190 ac03cf6d 2020-01-17 stsp echo "date: $d1" >> $testroot/stdout.expected
191 2417344c 2019-08-23 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
192 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
193 8e7bd50a 2019-08-22 stsp echo " test" >> $testroot/stdout.expected
194 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
195 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
196 fc414659 2022-04-16 thomas ret=$?
197 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
198 8e7bd50a 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
199 68e8cedb 2022-07-01 thomas test_done "$testroot" "$ret"
200 68e8cedb 2022-07-01 thomas return 1
201 8e7bd50a 2019-08-22 stsp fi
202 68e8cedb 2022-07-01 thomas
203 68e8cedb 2022-07-01 thomas got tag -r $testroot/repo -l $tag2 > $testroot/stdout
204 68e8cedb 2022-07-01 thomas
205 68e8cedb 2022-07-01 thomas echo "-----------------------------------------------" \
206 68e8cedb 2022-07-01 thomas > $testroot/stdout.expected
207 68e8cedb 2022-07-01 thomas echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
208 68e8cedb 2022-07-01 thomas echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
209 68e8cedb 2022-07-01 thomas echo "date: $d2" >> $testroot/stdout.expected
210 68e8cedb 2022-07-01 thomas echo "object: commit $commit_id" >> $testroot/stdout.expected
211 68e8cedb 2022-07-01 thomas echo " " >> $testroot/stdout.expected
212 68e8cedb 2022-07-01 thomas echo " test" >> $testroot/stdout.expected
213 68e8cedb 2022-07-01 thomas echo " " >> $testroot/stdout.expected
214 68e8cedb 2022-07-01 thomas cmp -s $testroot/stdout $testroot/stdout.expected
215 68e8cedb 2022-07-01 thomas ret=$?
216 68e8cedb 2022-07-01 thomas if [ $ret -ne 0 ]; then
217 68e8cedb 2022-07-01 thomas diff -u $testroot/stdout.expected $testroot/stdout
218 68e8cedb 2022-07-01 thomas fi
219 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
220 8e7bd50a 2019-08-22 stsp }
221 8e7bd50a 2019-08-22 stsp
222 f6cae3ed 2020-09-13 naddy test_tag_list_lightweight() {
223 d4efa91b 2020-01-14 stsp local testroot=`test_init tag_list_lightweight`
224 d4efa91b 2020-01-14 stsp local commit_id=`git_show_head $testroot/repo`
225 d4efa91b 2020-01-14 stsp local tag=1.0.0
226 d4efa91b 2020-01-14 stsp local tag2=2.0.0
227 d4efa91b 2020-01-14 stsp
228 d4efa91b 2020-01-14 stsp # create "lightweight" tag with Git
229 d4efa91b 2020-01-14 stsp (cd $testroot/repo && git tag $tag)
230 d4efa91b 2020-01-14 stsp (cd $testroot/repo && git tag $tag2)
231 d4efa91b 2020-01-14 stsp
232 d4efa91b 2020-01-14 stsp tag_id=`got ref -r $testroot/repo -l \
233 d4efa91b 2020-01-14 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
234 d4efa91b 2020-01-14 stsp local tagger_time=`git_show_author_time $testroot/repo $tag`
235 fa37079f 2021-10-09 thomas local prev_LC_TIME=$LC_TIME
236 fa37079f 2021-10-09 thomas export LC_TIME=C
237 fa37079f 2021-10-09 thomas d1=`date -u -d "@$tagger_time" +"%a %b %e %X %Y UTC"`
238 fa37079f 2021-10-09 thomas LC_TIME="$prev_LC_TIME"
239 d4efa91b 2020-01-14 stsp tag_id2=`got ref -r $testroot/repo -l \
240 d4efa91b 2020-01-14 stsp | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
241 d4efa91b 2020-01-14 stsp local tagger_time2=`git_show_author_time $testroot/repo $tag2`
242 fa37079f 2021-10-09 thomas
243 fa37079f 2021-10-09 thomas export LC_TIME=C
244 fa37079f 2021-10-09 thomas d2=`date -u -d "@$tagger_time2" +"%a %b %e %X %Y UTC"`
245 fa37079f 2021-10-09 thomas LC_TIME="$prev_LC_TIME"
246 d4efa91b 2020-01-14 stsp
247 d4efa91b 2020-01-14 stsp got tag -r $testroot/repo -l > $testroot/stdout
248 d4efa91b 2020-01-14 stsp
249 d4efa91b 2020-01-14 stsp echo "-----------------------------------------------" \
250 d4efa91b 2020-01-14 stsp > $testroot/stdout.expected
251 d4efa91b 2020-01-14 stsp echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
252 d4efa91b 2020-01-14 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
253 ac03cf6d 2020-01-17 stsp echo "date: $d2" >> $testroot/stdout.expected
254 d4efa91b 2020-01-14 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
255 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
256 d4efa91b 2020-01-14 stsp echo " adding the test tree" >> $testroot/stdout.expected
257 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
258 d4efa91b 2020-01-14 stsp echo "-----------------------------------------------" \
259 d4efa91b 2020-01-14 stsp >> $testroot/stdout.expected
260 d4efa91b 2020-01-14 stsp echo "tag $tag $tag_id" >> $testroot/stdout.expected
261 d4efa91b 2020-01-14 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
262 ac03cf6d 2020-01-17 stsp echo "date: $d1" >> $testroot/stdout.expected
263 d4efa91b 2020-01-14 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
264 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
265 d4efa91b 2020-01-14 stsp echo " adding the test tree" >> $testroot/stdout.expected
266 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
267 d4efa91b 2020-01-14 stsp cmp -s $testroot/stdout $testroot/stdout.expected
268 fc414659 2022-04-16 thomas ret=$?
269 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
270 d4efa91b 2020-01-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
271 d4efa91b 2020-01-14 stsp fi
272 d4efa91b 2020-01-14 stsp test_done "$testroot" "$ret"
273 d4efa91b 2020-01-14 stsp }
274 871bd038 2022-07-03 thomas
275 871bd038 2022-07-03 thomas test_tag_create_ssh_signed() {
276 871bd038 2022-07-03 thomas local testroot=`test_init tag_create`
277 871bd038 2022-07-03 thomas local commit_id=`git_show_head $testroot/repo`
278 871bd038 2022-07-03 thomas local tag=1.0.0
279 871bd038 2022-07-03 thomas local tag2=2.0.0
280 ff5e1f09 2022-07-06 thomas local tag3=3.0.0
281 871bd038 2022-07-03 thomas
282 871bd038 2022-07-03 thomas ssh-keygen -q -N '' -t ed25519 -f $testroot/id_ed25519
283 871bd038 2022-07-03 thomas ret=$?
284 871bd038 2022-07-03 thomas if [ $ret -ne 0 ]; then
285 871bd038 2022-07-03 thomas echo "ssh-keygen failed unexpectedly"
286 871bd038 2022-07-03 thomas test_done "$testroot" "$ret"
287 871bd038 2022-07-03 thomas return 1
288 871bd038 2022-07-03 thomas fi
289 871bd038 2022-07-03 thomas touch $testroot/allowed_signers
290 c0805ce5 2022-07-04 thomas touch $testroot/revoked_signers
291 c0805ce5 2022-07-04 thomas echo "allowed_signers \"$testroot/allowed_signers\"" >> \
292 c0805ce5 2022-07-04 thomas $testroot/repo/.git/got.conf
293 c0805ce5 2022-07-04 thomas echo "revoked_signers \"$testroot/revoked_signers\"" >> \
294 871bd038 2022-07-03 thomas $testroot/repo/.git/got.conf
295 871bd038 2022-07-03 thomas
296 871bd038 2022-07-03 thomas # Create a signed tag based on repository's HEAD reference
297 871bd038 2022-07-03 thomas got tag -s $testroot/id_ed25519 -m 'test' -r $testroot/repo -c HEAD \
298 871bd038 2022-07-03 thomas $tag > $testroot/stdout
299 871bd038 2022-07-03 thomas ret=$?
300 871bd038 2022-07-03 thomas if [ $ret -ne 0 ]; then
301 871bd038 2022-07-03 thomas echo "got tag command failed unexpectedly"
302 871bd038 2022-07-03 thomas test_done "$testroot" "$ret"
303 871bd038 2022-07-03 thomas return 1
304 871bd038 2022-07-03 thomas fi
305 871bd038 2022-07-03 thomas
306 871bd038 2022-07-03 thomas tag_id=`got ref -r $testroot/repo -l \
307 871bd038 2022-07-03 thomas | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
308 871bd038 2022-07-03 thomas echo "Created tag $tag_id" > $testroot/stdout.expected
309 871bd038 2022-07-03 thomas cmp -s $testroot/stdout $testroot/stdout.expected
310 871bd038 2022-07-03 thomas ret=$?
311 871bd038 2022-07-03 thomas if [ $ret -ne 0 ]; then
312 871bd038 2022-07-03 thomas diff -u $testroot/stdout.expected $testroot/stdout
313 871bd038 2022-07-03 thomas test_done "$testroot" "$ret"
314 871bd038 2022-07-03 thomas return 1
315 871bd038 2022-07-03 thomas fi
316 871bd038 2022-07-03 thomas
317 871bd038 2022-07-03 thomas # Ensure validation fails when the key is not allowed
318 871bd038 2022-07-03 thomas echo "signature: Could not verify signature." > \
319 871bd038 2022-07-03 thomas $testroot/stdout.expected
320 871bd038 2022-07-03 thomas VERIFY_STDOUT=$(got tag -r $testroot/repo -V $tag 2> $testroot/stderr)
321 871bd038 2022-07-03 thomas ret=$?
322 871bd038 2022-07-03 thomas echo "$VERIFY_STDOUT" | grep '^signature: ' > $testroot/stdout
323 871bd038 2022-07-03 thomas if [ $ret -eq 0 ]; then
324 871bd038 2022-07-03 thomas diff -u $testroot/stdout.expected $testroot/stdout
325 871bd038 2022-07-03 thomas test_done "$testroot" "1"
326 871bd038 2022-07-03 thomas return 1
327 871bd038 2022-07-03 thomas fi
328 d4efa91b 2020-01-14 stsp
329 ebc58f12 2022-07-04 thomas GOOD_SIG='Good "git" signature for flan_hacker@openbsd.org with ED25519 key '
330 871bd038 2022-07-03 thomas
331 871bd038 2022-07-03 thomas # Validate the signature with the key allowed
332 871bd038 2022-07-03 thomas echo -n 'flan_hacker@openbsd.org ' > $testroot/allowed_signers
333 871bd038 2022-07-03 thomas cat $testroot/id_ed25519.pub >> $testroot/allowed_signers
334 871bd038 2022-07-03 thomas GOT_STDOUT=$(got tag -r $testroot/repo -V $tag 2> $testroot/stderr)
335 871bd038 2022-07-03 thomas ret=$?
336 871bd038 2022-07-03 thomas if [ $ret -ne 0 ]; then
337 871bd038 2022-07-03 thomas echo "got tag command failed unexpectedly"
338 871bd038 2022-07-03 thomas diff -u $testroot/stdout.expected $testroot/stdout
339 871bd038 2022-07-03 thomas test_done "$testroot" "$ret"
340 ebc58f12 2022-07-04 thomas return 1
341 ebc58f12 2022-07-04 thomas fi
342 ebc58f12 2022-07-04 thomas
343 ebc58f12 2022-07-04 thomas if ! echo "$GOT_STDOUT" | grep -q "^signature: $GOOD_SIG"; then
344 ebc58f12 2022-07-04 thomas echo "got tag command failed to validate signature"
345 ebc58f12 2022-07-04 thomas test_done "$testroot" "1"
346 871bd038 2022-07-03 thomas return 1
347 871bd038 2022-07-03 thomas fi
348 871bd038 2022-07-03 thomas
349 c0805ce5 2022-07-04 thomas # Ensure validation fails after revoking the key
350 c0805ce5 2022-07-04 thomas ssh-keygen -y -f $testroot/id_ed25519 >> $testroot/revoked_signers
351 c0805ce5 2022-07-04 thomas echo "signature: Could not verify signature." > \
352 c0805ce5 2022-07-04 thomas $testroot/stdout.expected
353 c0805ce5 2022-07-04 thomas VERIFY_STDOUT=$(got tag -r $testroot/repo -V $tag 2> $testroot/stderr)
354 c0805ce5 2022-07-04 thomas ret=$?
355 c0805ce5 2022-07-04 thomas echo "$VERIFY_STDOUT" | grep '^signature: ' > $testroot/stdout
356 c0805ce5 2022-07-04 thomas if [ $ret -eq 0 ]; then
357 c0805ce5 2022-07-04 thomas diff -u $testroot/stdout.expected $testroot/stdout
358 c0805ce5 2022-07-04 thomas test_done "$testroot" "1"
359 c0805ce5 2022-07-04 thomas return 1
360 c0805ce5 2022-07-04 thomas fi
361 c0805ce5 2022-07-04 thomas
362 c0805ce5 2022-07-04 thomas # Later tests expect validation to work
363 c0805ce5 2022-07-04 thomas echo -n > $testroot/revoked_signers
364 c0805ce5 2022-07-04 thomas
365 ebc58f12 2022-07-04 thomas # Ensure that Git recognizes and verifies the tag Got has created
366 ebc58f12 2022-07-04 thomas (cd $testroot/repo && git checkout -q $tag)
367 ebc58f12 2022-07-04 thomas ret=$?
368 ebc58f12 2022-07-04 thomas if [ $ret -ne 0 ]; then
369 ebc58f12 2022-07-04 thomas echo "git checkout command failed unexpectedly"
370 ebc58f12 2022-07-04 thomas test_done "$testroot" "$ret"
371 ebc58f12 2022-07-04 thomas return 1
372 ebc58f12 2022-07-04 thomas fi
373 ebc58f12 2022-07-04 thomas (cd $testroot/repo && git config --local gpg.ssh.allowedSignersFile \
374 ebc58f12 2022-07-04 thomas $testroot/allowed_signers)
375 ebc58f12 2022-07-04 thomas GIT_STDERR=$(cd $testroot/repo && git tag -v $tag 2>&1 1>/dev/null)
376 ebc58f12 2022-07-04 thomas if ! echo "$GIT_STDERR" | grep -q "^$GOOD_SIG"; then
377 ebc58f12 2022-07-04 thomas echo "git tag command failed to validate signature"
378 ebc58f12 2022-07-04 thomas test_done "$testroot" "1"
379 ebc58f12 2022-07-04 thomas return 1
380 ebc58f12 2022-07-04 thomas fi
381 ebc58f12 2022-07-04 thomas
382 ebc58f12 2022-07-04 thomas # Ensure Got recognizes the new tag
383 ebc58f12 2022-07-04 thomas got checkout -c $tag $testroot/repo $testroot/wt >/dev/null
384 ebc58f12 2022-07-04 thomas ret=$?
385 ebc58f12 2022-07-04 thomas if [ $ret -ne 0 ]; then
386 ebc58f12 2022-07-04 thomas echo "got checkout command failed unexpectedly"
387 ff5e1f09 2022-07-06 thomas test_done "$testroot" "$ret"
388 ff5e1f09 2022-07-06 thomas return 1
389 ff5e1f09 2022-07-06 thomas fi
390 ff5e1f09 2022-07-06 thomas
391 ff5e1f09 2022-07-06 thomas # Create another signed tag with a SHA1 commit ID
392 ff5e1f09 2022-07-06 thomas got tag -s $testroot/id_ed25519 -m 'test' -r $testroot/repo \
393 ff5e1f09 2022-07-06 thomas -c $commit_id $tag2 > $testroot/stdout
394 ff5e1f09 2022-07-06 thomas
395 ff5e1f09 2022-07-06 thomas # Create another signed tag with key defined in got.conf(5)
396 ff5e1f09 2022-07-06 thomas echo "signer_id \"$testroot/id_ed25519\"" >> \
397 ff5e1f09 2022-07-06 thomas $testroot/repo/.git/got.conf
398 ff5e1f09 2022-07-06 thomas got tag -m 'test' -r $testroot/repo -c HEAD $tag3 > $testroot/stdout
399 ff5e1f09 2022-07-06 thomas ret=$?
400 ff5e1f09 2022-07-06 thomas if [ $ret -ne 0 ]; then
401 ff5e1f09 2022-07-06 thomas echo "got tag command failed unexpectedly"
402 ff5e1f09 2022-07-06 thomas test_done "$testroot" "$ret"
403 ff5e1f09 2022-07-06 thomas return 1
404 ebc58f12 2022-07-04 thomas fi
405 ff5e1f09 2022-07-06 thomas
406 ff5e1f09 2022-07-06 thomas # got tag -V behaves like got tag -l, but with verification enabled.
407 ff5e1f09 2022-07-06 thomas got tag -l -r $testroot/repo > $testroot/stdout.list
408 ff5e1f09 2022-07-06 thomas got tag -V -r $testroot/repo > $testroot/stdout.verify
409 ff5e1f09 2022-07-06 thomas diff -U0 $testroot/stdout.list $testroot/stdout.verify |
410 ff5e1f09 2022-07-06 thomas sed -e '/^--- /d' -e '/^+++ /d' > $testroot/stdout
411 ff5e1f09 2022-07-06 thomas echo "@@ -5,0 +6 @@" > $testroot/stdout.expected
412 ff5e1f09 2022-07-06 thomas echo -n "+signature: $GOOD_SIG" >> $testroot/stdout.expected
413 ff5e1f09 2022-07-06 thomas ssh-keygen -l -f $testroot/id_ed25519.pub | cut -d' ' -f 2 \
414 ff5e1f09 2022-07-06 thomas >> $testroot/stdout.expected
415 ff5e1f09 2022-07-06 thomas echo "@@ -19,0 +21 @@" >> $testroot/stdout.expected
416 ff5e1f09 2022-07-06 thomas echo -n "+signature: $GOOD_SIG" >> $testroot/stdout.expected
417 ff5e1f09 2022-07-06 thomas ssh-keygen -l -f $testroot/id_ed25519.pub | cut -d' ' -f 2 \
418 ff5e1f09 2022-07-06 thomas >> $testroot/stdout.expected
419 ff5e1f09 2022-07-06 thomas echo "@@ -33,0 +36 @@" >> $testroot/stdout.expected
420 ff5e1f09 2022-07-06 thomas echo -n "+signature: $GOOD_SIG" >> $testroot/stdout.expected
421 ff5e1f09 2022-07-06 thomas ssh-keygen -l -f $testroot/id_ed25519.pub | cut -d' ' -f 2 \
422 ff5e1f09 2022-07-06 thomas >> $testroot/stdout.expected
423 ff5e1f09 2022-07-06 thomas cmp -s $testroot/stdout $testroot/stdout.expected
424 ff5e1f09 2022-07-06 thomas ret=$?
425 ff5e1f09 2022-07-06 thomas if [ $ret -ne 0 ]; then
426 ff5e1f09 2022-07-06 thomas diff -u $testroot/stdout.expected $testroot/stdout
427 ff5e1f09 2022-07-06 thomas fi
428 ebc58f12 2022-07-04 thomas test_done "$testroot" "$ret"
429 ebc58f12 2022-07-04 thomas }
430 ebc58f12 2022-07-04 thomas
431 64313a9c 2022-07-03 thomas test_tag_create_ssh_signed_missing_key() {
432 64313a9c 2022-07-03 thomas local testroot=`test_init tag_create`
433 64313a9c 2022-07-03 thomas local commit_id=`git_show_head $testroot/repo`
434 64313a9c 2022-07-03 thomas local tag=1.0.0
435 64313a9c 2022-07-03 thomas
436 64313a9c 2022-07-03 thomas # Fail to create a signed tag due to a missing SSH key
437 64313a9c 2022-07-03 thomas got tag -s $testroot/bogus -m 'test' -r $testroot/repo \
438 64313a9c 2022-07-03 thomas -c HEAD $tag > $testroot/stdout 2> $testroot/stderr
439 64313a9c 2022-07-03 thomas ret=$?
440 64313a9c 2022-07-03 thomas if [ $ret -eq 0 ]; then
441 64313a9c 2022-07-03 thomas echo "got tag command succeeded unexpectedly"
442 64313a9c 2022-07-03 thomas test_done "$testroot" 1
443 64313a9c 2022-07-03 thomas return 1
444 64313a9c 2022-07-03 thomas fi
445 871bd038 2022-07-03 thomas
446 64313a9c 2022-07-03 thomas got ref -r $testroot/repo -l > $testroot/stdout
447 64313a9c 2022-07-03 thomas echo "HEAD: refs/heads/master" > $testroot/stdout.expected
448 64313a9c 2022-07-03 thomas echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
449 64313a9c 2022-07-03 thomas cmp -s $testroot/stdout $testroot/stdout.expected
450 64313a9c 2022-07-03 thomas ret=$?
451 64313a9c 2022-07-03 thomas if [ $ret -ne 0 ]; then
452 64313a9c 2022-07-03 thomas diff -u $testroot/stdout.expected $testroot/stdout
453 64313a9c 2022-07-03 thomas test_done "$testroot" "$ret"
454 64313a9c 2022-07-03 thomas return 1
455 64313a9c 2022-07-03 thomas fi
456 64313a9c 2022-07-03 thomas printf "Couldn't load public key $testroot/bogus: " \
457 492a65d9 2022-07-04 thomas >> $testroot/stderr.expected
458 64313a9c 2022-07-03 thomas printf "No such file or directory\r\n" >> $testroot/stderr.expected
459 492a65d9 2022-07-04 thomas echo "got: unable to sign tag" >> $testroot/stderr.expected
460 64313a9c 2022-07-03 thomas cmp -s $testroot/stderr $testroot/stderr.expected
461 64313a9c 2022-07-03 thomas ret=$?
462 64313a9c 2022-07-03 thomas if [ $ret -ne 0 ]; then
463 64313a9c 2022-07-03 thomas diff -u $testroot/stderr.expected $testroot/stderr
464 64313a9c 2022-07-03 thomas fi
465 64313a9c 2022-07-03 thomas test_done "$testroot" "$ret"
466 64313a9c 2022-07-03 thomas }
467 64313a9c 2022-07-03 thomas
468 7fb414ae 2020-08-08 stsp test_parseargs "$@"
469 8e7bd50a 2019-08-22 stsp run_test test_tag_create
470 8e7bd50a 2019-08-22 stsp run_test test_tag_list
471 d4efa91b 2020-01-14 stsp run_test test_tag_list_lightweight
472 871bd038 2022-07-03 thomas run_test test_tag_create_ssh_signed
473 492a65d9 2022-07-04 thomas run_test test_tag_create_ssh_signed_missing_key