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