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 8e7bd50a 2019-08-22 stsp fi
172 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
173 8e7bd50a 2019-08-22 stsp }
174 8e7bd50a 2019-08-22 stsp
175 f6cae3ed 2020-09-13 naddy test_tag_list_lightweight() {
176 d4efa91b 2020-01-14 stsp local testroot=`test_init tag_list_lightweight`
177 d4efa91b 2020-01-14 stsp local commit_id=`git_show_head $testroot/repo`
178 d4efa91b 2020-01-14 stsp local tag=1.0.0
179 d4efa91b 2020-01-14 stsp local tag2=2.0.0
180 d4efa91b 2020-01-14 stsp
181 d4efa91b 2020-01-14 stsp # create "lightweight" tag with Git
182 d4efa91b 2020-01-14 stsp (cd $testroot/repo && git tag $tag)
183 d4efa91b 2020-01-14 stsp (cd $testroot/repo && git tag $tag2)
184 d4efa91b 2020-01-14 stsp
185 d4efa91b 2020-01-14 stsp tag_id=`got ref -r $testroot/repo -l \
186 d4efa91b 2020-01-14 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
187 d4efa91b 2020-01-14 stsp local tagger_time=`git_show_author_time $testroot/repo $tag`
188 3a6b8760 2021-08-31 naddy d1=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
189 d4efa91b 2020-01-14 stsp tag_id2=`got ref -r $testroot/repo -l \
190 d4efa91b 2020-01-14 stsp | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
191 d4efa91b 2020-01-14 stsp local tagger_time2=`git_show_author_time $testroot/repo $tag2`
192 3a6b8760 2021-08-31 naddy d2=`date -u -r $tagger_time2 +"%a %b %e %X %Y UTC"`
193 d4efa91b 2020-01-14 stsp
194 d4efa91b 2020-01-14 stsp got tag -r $testroot/repo -l > $testroot/stdout
195 d4efa91b 2020-01-14 stsp
196 d4efa91b 2020-01-14 stsp echo "-----------------------------------------------" \
197 d4efa91b 2020-01-14 stsp > $testroot/stdout.expected
198 d4efa91b 2020-01-14 stsp echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
199 d4efa91b 2020-01-14 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
200 ac03cf6d 2020-01-17 stsp echo "date: $d2" >> $testroot/stdout.expected
201 d4efa91b 2020-01-14 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
202 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
203 d4efa91b 2020-01-14 stsp echo " adding the test tree" >> $testroot/stdout.expected
204 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
205 d4efa91b 2020-01-14 stsp echo "-----------------------------------------------" \
206 d4efa91b 2020-01-14 stsp >> $testroot/stdout.expected
207 d4efa91b 2020-01-14 stsp echo "tag $tag $tag_id" >> $testroot/stdout.expected
208 d4efa91b 2020-01-14 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
209 ac03cf6d 2020-01-17 stsp echo "date: $d1" >> $testroot/stdout.expected
210 d4efa91b 2020-01-14 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
211 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
212 d4efa91b 2020-01-14 stsp echo " adding the test tree" >> $testroot/stdout.expected
213 d4efa91b 2020-01-14 stsp echo " " >> $testroot/stdout.expected
214 d4efa91b 2020-01-14 stsp cmp -s $testroot/stdout $testroot/stdout.expected
215 49c543a6 2022-03-31 naddy ret=$?
216 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
217 d4efa91b 2020-01-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
218 d4efa91b 2020-01-14 stsp fi
219 d4efa91b 2020-01-14 stsp test_done "$testroot" "$ret"
220 d4efa91b 2020-01-14 stsp }
221 d4efa91b 2020-01-14 stsp
222 7fb414ae 2020-08-08 stsp test_parseargs "$@"
223 8e7bd50a 2019-08-22 stsp run_test test_tag_create
224 8e7bd50a 2019-08-22 stsp run_test test_tag_list
225 d4efa91b 2020-01-14 stsp run_test test_tag_list_lightweight