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