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