Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_tag_create() {
20 local testroot=`test_init tag_create`
21 local commit_id=`git_show_head $testroot/repo`
22 local tag=1.0.0
23 local tag2=2.0.0
25 # Create a tag based on repository's HEAD reference
26 got tag -m 'test' -r $testroot/repo -c HEAD $tag > $testroot/stdout
27 ret="$?"
28 if [ "$ret" != "0" ]; then
29 echo "got ref command failed unexpectedly"
30 test_done "$testroot" "$ret"
31 return 1
32 fi
34 tag_id=`got ref -r $testroot/repo -l \
35 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
36 echo "Created tag $tag_id" > $testroot/stdout.expected
37 cmp -s $testroot/stdout $testroot/stdout.expected
38 ret="$?"
39 if [ "$ret" != "0" ]; then
40 diff -u $testroot/stdout.expected $testroot/stdout
41 test_done "$testroot" "$ret"
42 return 1
43 fi
45 # Ensure that Git recognizes the tag Got has created
46 (cd $testroot/repo && git checkout -q $tag)
47 ret="$?"
48 if [ "$ret" != "0" ]; then
49 echo "git checkout command failed unexpectedly"
50 test_done "$testroot" "$ret"
51 return 1
52 fi
54 # Ensure Got recognizes the new tag
55 got checkout -c $tag $testroot/repo $testroot/wt >/dev/null
56 ret="$?"
57 if [ "$ret" != "0" ]; then
58 echo "got checkout command failed unexpectedly"
59 test_done "$testroot" "$ret"
60 return 1
61 fi
63 # Create a tag based on implied worktree HEAD ref
64 (cd $testroot/wt && got tag -m 'test' $tag2 > $testroot/stdout)
65 ret="$?"
66 if [ "$ret" != "0" ]; then
67 test_done "$testroot" "$ret"
68 return 1
69 fi
71 tag_id2=`got ref -r $testroot/repo -l \
72 | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
73 echo "Created tag $tag_id2" > $testroot/stdout.expected
74 cmp -s $testroot/stdout $testroot/stdout.expected
75 ret="$?"
76 if [ "$ret" != "0" ]; then
77 diff -u $testroot/stdout.expected $testroot/stdout
78 test_done "$testroot" "$ret"
79 return 1
80 fi
82 (cd $testroot/repo && git checkout -q $tag2)
83 ret="$?"
84 if [ "$ret" != "0" ]; then
85 echo "git checkout command failed unexpectedly"
86 test_done "$testroot" "$ret"
87 return 1
88 fi
90 # Attempt to create a tag pointing at a non-commit
91 local tree_id=`git_show_tree $testroot/repo`
92 (cd $testroot/wt && got tag -m 'test' -c $tree_id foobar \
93 2> $testroot/stderr)
94 ret="$?"
95 if [ "$ret" = "0" ]; then
96 echo "git tag command succeeded unexpectedly"
97 test_done "$testroot" "1"
98 return 1
99 fi
101 echo "got: commit $tree_id: object not found" \
102 > $testroot/stderr.expected
103 cmp -s $testroot/stderr $testroot/stderr.expected
104 ret="$?"
105 if [ "$ret" != "0" ]; then
106 diff -u $testroot/stderr.expected $testroot/stderr
107 test_done "$testroot" "$ret"
108 return 1
109 fi
111 got ref -r $testroot/repo -l > $testroot/stdout
112 echo "HEAD: $commit_id" > $testroot/stdout.expected
113 echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
114 cat $testroot/wt/.got/uuid | tr -d '\n' >> $testroot/stdout.expected
115 echo ": $commit_id" >> $testroot/stdout.expected
116 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
117 echo "refs/tags/$tag: $tag_id" >> $testroot/stdout.expected
118 echo "refs/tags/$tag2: $tag_id2" >> $testroot/stdout.expected
119 cmp -s $testroot/stdout $testroot/stdout.expected
120 ret="$?"
121 if [ "$ret" != "0" ]; then
122 diff -u $testroot/stdout.expected $testroot/stdout
123 fi
124 test_done "$testroot" "$ret"
127 test_tag_list() {
128 local testroot=`test_init tag_list`
129 local commit_id=`git_show_head $testroot/repo`
130 local tag=1.0.0
131 local tag2=2.0.0
133 # create tag with Git
134 (cd $testroot/repo && git tag -a -m 'test' $tag)
135 # create tag with Got
136 (cd $testroot/repo && got tag -m 'test' $tag2 > /dev/null)
138 tag_id=`got ref -r $testroot/repo -l \
139 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
140 local tagger_time=`git_show_tagger_time $testroot/repo $tag`
142 local prev_LC_TIME=$LC_TIME
143 export LC_TIME=C
144 d1=`date -u -d "@$tagger_time" +"%a %b %e %X %Y UTC"`
145 LC_TIME="$prev_LC_TIME"
147 tag_id2=`got ref -r $testroot/repo -l \
148 | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
149 local tagger_time2=`git_show_tagger_time $testroot/repo $tag2`
151 prev_LC_TIME="$LC_TIME"
152 export LC_TIME=C
153 d2=`date -u -d "@$tagger_time2" +"%a %b %e %X %Y UTC"`
154 LC_TIME="$prev_LC_TIME"
156 got tag -r $testroot/repo -l > $testroot/stdout
158 echo "-----------------------------------------------" \
159 > $testroot/stdout.expected
160 echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
161 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
162 echo "date: $d2" >> $testroot/stdout.expected
163 echo "object: commit $commit_id" >> $testroot/stdout.expected
164 echo " " >> $testroot/stdout.expected
165 echo " test" >> $testroot/stdout.expected
166 echo " " >> $testroot/stdout.expected
167 echo "-----------------------------------------------" \
168 >> $testroot/stdout.expected
169 echo "tag $tag $tag_id" >> $testroot/stdout.expected
170 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
171 echo "date: $d1" >> $testroot/stdout.expected
172 echo "object: commit $commit_id" >> $testroot/stdout.expected
173 echo " " >> $testroot/stdout.expected
174 echo " test" >> $testroot/stdout.expected
175 echo " " >> $testroot/stdout.expected
176 cmp -s $testroot/stdout $testroot/stdout.expected
177 ret="$?"
178 if [ "$ret" != "0" ]; then
179 diff -u $testroot/stdout.expected $testroot/stdout
180 fi
181 test_done "$testroot" "$ret"
184 test_tag_list_lightweight() {
185 local testroot=`test_init tag_list_lightweight`
186 local commit_id=`git_show_head $testroot/repo`
187 local tag=1.0.0
188 local tag2=2.0.0
190 # create "lightweight" tag with Git
191 (cd $testroot/repo && git tag $tag)
192 (cd $testroot/repo && git tag $tag2)
194 tag_id=`got ref -r $testroot/repo -l \
195 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
196 local tagger_time=`git_show_author_time $testroot/repo $tag`
197 local prev_LC_TIME=$LC_TIME
198 export LC_TIME=C
199 d1=`date -u -d "@$tagger_time" +"%a %b %e %X %Y UTC"`
200 LC_TIME="$prev_LC_TIME"
201 tag_id2=`got ref -r $testroot/repo -l \
202 | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
203 local tagger_time2=`git_show_author_time $testroot/repo $tag2`
205 export LC_TIME=C
206 d2=`date -u -d "@$tagger_time2" +"%a %b %e %X %Y UTC"`
207 LC_TIME="$prev_LC_TIME"
209 got tag -r $testroot/repo -l > $testroot/stdout
211 echo "-----------------------------------------------" \
212 > $testroot/stdout.expected
213 echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
214 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
215 echo "date: $d2" >> $testroot/stdout.expected
216 echo "object: commit $commit_id" >> $testroot/stdout.expected
217 echo " " >> $testroot/stdout.expected
218 echo " adding the test tree" >> $testroot/stdout.expected
219 echo " " >> $testroot/stdout.expected
220 echo "-----------------------------------------------" \
221 >> $testroot/stdout.expected
222 echo "tag $tag $tag_id" >> $testroot/stdout.expected
223 echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
224 echo "date: $d1" >> $testroot/stdout.expected
225 echo "object: commit $commit_id" >> $testroot/stdout.expected
226 echo " " >> $testroot/stdout.expected
227 echo " adding the test tree" >> $testroot/stdout.expected
228 echo " " >> $testroot/stdout.expected
229 cmp -s $testroot/stdout $testroot/stdout.expected
230 ret="$?"
231 if [ "$ret" != "0" ]; then
232 diff -u $testroot/stdout.expected $testroot/stdout
233 fi
234 test_done "$testroot" "$ret"
237 test_parseargs "$@"
238 run_test test_tag_create
239 run_test test_tag_list
240 run_test test_tag_list_lightweight