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 8e7bd50a 2019-08-22 stsp (cd $testroot/wt && got tag -m 'test' $tag2 > $testroot/stdout)
65 49c543a6 2022-03-31 naddy ret=$?
66 49c543a6 2022-03-31 naddy 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 49c543a6 2022-03-31 naddy ret=$?
76 49c543a6 2022-03-31 naddy 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 49c543a6 2022-03-31 naddy ret=$?
84 49c543a6 2022-03-31 naddy 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 49c543a6 2022-03-31 naddy ret=$?
95 49c543a6 2022-03-31 naddy 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 138e4f47 2021-10-09 stsp echo "got: commit $tree_id: object not found" \
102 138e4f47 2021-10-09 stsp > $testroot/stderr.expected
103 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stderr $testroot/stderr.expected
104 49c543a6 2022-03-31 naddy ret=$?
105 49c543a6 2022-03-31 naddy 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 49c543a6 2022-03-31 naddy ret=$?
121 49c543a6 2022-03-31 naddy 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 3a6b8760 2021-08-31 naddy d1=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
142 8e7bd50a 2019-08-22 stsp tag_id2=`got ref -r $testroot/repo -l \
143 8e7bd50a 2019-08-22 stsp | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
144 8e7bd50a 2019-08-22 stsp local tagger_time2=`git_show_tagger_time $testroot/repo $tag2`
145 3a6b8760 2021-08-31 naddy d2=`date -u -r $tagger_time2 +"%a %b %e %X %Y UTC"`
146 8e7bd50a 2019-08-22 stsp
147 8e7bd50a 2019-08-22 stsp got tag -r $testroot/repo -l > $testroot/stdout
148 8e7bd50a 2019-08-22 stsp
149 8e7bd50a 2019-08-22 stsp echo "-----------------------------------------------" \
150 8e7bd50a 2019-08-22 stsp > $testroot/stdout.expected
151 b8bad2ba 2019-08-23 stsp echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
152 8e7bd50a 2019-08-22 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
153 ac03cf6d 2020-01-17 stsp echo "date: $d2" >> $testroot/stdout.expected
154 2417344c 2019-08-23 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
155 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
156 8e7bd50a 2019-08-22 stsp echo " test" >> $testroot/stdout.expected
157 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
158 8e7bd50a 2019-08-22 stsp echo "-----------------------------------------------" \
159 8e7bd50a 2019-08-22 stsp >> $testroot/stdout.expected
160 b8bad2ba 2019-08-23 stsp echo "tag $tag $tag_id" >> $testroot/stdout.expected
161 8e7bd50a 2019-08-22 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
162 ac03cf6d 2020-01-17 stsp echo "date: $d1" >> $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 cmp -s $testroot/stdout $testroot/stdout.expected
168 49c543a6 2022-03-31 naddy ret=$?
169 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
170 8e7bd50a 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
171 8c4a6db8 2022-06-29 stsp test_done "$testroot" "$ret"
172 8c4a6db8 2022-06-29 stsp return 1
173 8e7bd50a 2019-08-22 stsp fi
174 8c4a6db8 2022-06-29 stsp
175 8c4a6db8 2022-06-29 stsp got tag -r $testroot/repo -l $tag > $testroot/stdout
176 8c4a6db8 2022-06-29 stsp
177 8c4a6db8 2022-06-29 stsp echo "-----------------------------------------------" \
178 8c4a6db8 2022-06-29 stsp > $testroot/stdout.expected
179 8c4a6db8 2022-06-29 stsp echo "tag $tag $tag_id" >> $testroot/stdout.expected
180 8c4a6db8 2022-06-29 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
181 8c4a6db8 2022-06-29 stsp echo "date: $d1" >> $testroot/stdout.expected
182 8c4a6db8 2022-06-29 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
183 8c4a6db8 2022-06-29 stsp echo " " >> $testroot/stdout.expected
184 8c4a6db8 2022-06-29 stsp echo " test" >> $testroot/stdout.expected
185 8c4a6db8 2022-06-29 stsp echo " " >> $testroot/stdout.expected
186 8c4a6db8 2022-06-29 stsp cmp -s $testroot/stdout $testroot/stdout.expected
187 8c4a6db8 2022-06-29 stsp ret=$?
188 8c4a6db8 2022-06-29 stsp if [ $ret -ne 0 ]; then
189 8c4a6db8 2022-06-29 stsp diff -u $testroot/stdout.expected $testroot/stdout
190 8c4a6db8 2022-06-29 stsp test_done "$testroot" "$ret"
191 8c4a6db8 2022-06-29 stsp return 1
192 8c4a6db8 2022-06-29 stsp fi
193 8c4a6db8 2022-06-29 stsp
194 8c4a6db8 2022-06-29 stsp got tag -r $testroot/repo -l $tag2 > $testroot/stdout
195 8c4a6db8 2022-06-29 stsp
196 8c4a6db8 2022-06-29 stsp echo "-----------------------------------------------" \
197 8c4a6db8 2022-06-29 stsp > $testroot/stdout.expected
198 8c4a6db8 2022-06-29 stsp echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
199 8c4a6db8 2022-06-29 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
200 8c4a6db8 2022-06-29 stsp echo "date: $d2" >> $testroot/stdout.expected
201 8c4a6db8 2022-06-29 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
202 8c4a6db8 2022-06-29 stsp echo " " >> $testroot/stdout.expected
203 8c4a6db8 2022-06-29 stsp echo " test" >> $testroot/stdout.expected
204 8c4a6db8 2022-06-29 stsp echo " " >> $testroot/stdout.expected
205 8c4a6db8 2022-06-29 stsp cmp -s $testroot/stdout $testroot/stdout.expected
206 8c4a6db8 2022-06-29 stsp ret=$?
207 8c4a6db8 2022-06-29 stsp if [ $ret -ne 0 ]; then
208 8c4a6db8 2022-06-29 stsp diff -u $testroot/stdout.expected $testroot/stdout
209 8c4a6db8 2022-06-29 stsp fi
210 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
211 8e7bd50a 2019-08-22 stsp }
212 8e7bd50a 2019-08-22 stsp
213 f6cae3ed 2020-09-13 naddy test_tag_list_lightweight() {
214 d4efa91b 2020-01-14 stsp local testroot=`test_init tag_list_lightweight`
215 d4efa91b 2020-01-14 stsp local commit_id=`git_show_head $testroot/repo`
216 d4efa91b 2020-01-14 stsp local tag=1.0.0
217 d4efa91b 2020-01-14 stsp local tag2=2.0.0
218 d4efa91b 2020-01-14 stsp
219 d4efa91b 2020-01-14 stsp # create "lightweight" tag with Git
220 d4efa91b 2020-01-14 stsp (cd $testroot/repo && git tag $tag)
221 d4efa91b 2020-01-14 stsp (cd $testroot/repo && git tag $tag2)
222 d4efa91b 2020-01-14 stsp
223 d4efa91b 2020-01-14 stsp tag_id=`got ref -r $testroot/repo -l \
224 d4efa91b 2020-01-14 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
225 d4efa91b 2020-01-14 stsp local tagger_time=`git_show_author_time $testroot/repo $tag`
226 3a6b8760 2021-08-31 naddy d1=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
227 d4efa91b 2020-01-14 stsp tag_id2=`got ref -r $testroot/repo -l \
228 d4efa91b 2020-01-14 stsp | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
229 d4efa91b 2020-01-14 stsp local tagger_time2=`git_show_author_time $testroot/repo $tag2`
230 3a6b8760 2021-08-31 naddy d2=`date -u -r $tagger_time2 +"%a %b %e %X %Y UTC"`
231 d4efa91b 2020-01-14 stsp
232 d4efa91b 2020-01-14 stsp got tag -r $testroot/repo -l > $testroot/stdout
233 d4efa91b 2020-01-14 stsp
234 d4efa91b 2020-01-14 stsp echo "-----------------------------------------------" \
235 d4efa91b 2020-01-14 stsp > $testroot/stdout.expected
236 d4efa91b 2020-01-14 stsp echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
237 d4efa91b 2020-01-14 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
238 ac03cf6d 2020-01-17 stsp echo "date: $d2" >> $testroot/stdout.expected
239 d4efa91b 2020-01-14 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
240 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
241 d4efa91b 2020-01-14 stsp echo " adding the test tree" >> $testroot/stdout.expected
242 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
243 d4efa91b 2020-01-14 stsp echo "-----------------------------------------------" \
244 d4efa91b 2020-01-14 stsp >> $testroot/stdout.expected
245 d4efa91b 2020-01-14 stsp echo "tag $tag $tag_id" >> $testroot/stdout.expected
246 d4efa91b 2020-01-14 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
247 ac03cf6d 2020-01-17 stsp echo "date: $d1" >> $testroot/stdout.expected
248 d4efa91b 2020-01-14 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
249 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
250 d4efa91b 2020-01-14 stsp echo " adding the test tree" >> $testroot/stdout.expected
251 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
252 d4efa91b 2020-01-14 stsp cmp -s $testroot/stdout $testroot/stdout.expected
253 49c543a6 2022-03-31 naddy ret=$?
254 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
255 d4efa91b 2020-01-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
256 d4efa91b 2020-01-14 stsp fi
257 d4efa91b 2020-01-14 stsp test_done "$testroot" "$ret"
258 d4efa91b 2020-01-14 stsp }
259 d4efa91b 2020-01-14 stsp
260 7fb414ae 2020-08-08 stsp test_parseargs "$@"
261 8e7bd50a 2019-08-22 stsp run_test test_tag_create
262 8e7bd50a 2019-08-22 stsp run_test test_tag_list
263 d4efa91b 2020-01-14 stsp run_test test_tag_list_lightweight