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 8e7bd50a 2019-08-22 stsp function 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 8e7bd50a 2019-08-22 stsp got tag -m 'test' -r $testroot/repo $tag HEAD > $testroot/stdout
27 8e7bd50a 2019-08-22 stsp ret="$?"
28 8e7bd50a 2019-08-22 stsp if [ "$ret" != "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 8e7bd50a 2019-08-22 stsp ret="$?"
39 8e7bd50a 2019-08-22 stsp if [ "$ret" != "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 8e7bd50a 2019-08-22 stsp ret="$?"
48 8e7bd50a 2019-08-22 stsp if [ "$ret" != "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 8e7bd50a 2019-08-22 stsp ret="$?"
57 8e7bd50a 2019-08-22 stsp if [ "$ret" != "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 8e7bd50a 2019-08-22 stsp ret="$?"
66 8e7bd50a 2019-08-22 stsp if [ "$ret" != "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 8e7bd50a 2019-08-22 stsp ret="$?"
76 8e7bd50a 2019-08-22 stsp if [ "$ret" != "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 8e7bd50a 2019-08-22 stsp ret="$?"
84 8e7bd50a 2019-08-22 stsp if [ "$ret" != "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 8e7bd50a 2019-08-22 stsp fi
88 8e7bd50a 2019-08-22 stsp
89 8e7bd50a 2019-08-22 stsp # Attempt to create a tag pointing at a non-commit
90 8e7bd50a 2019-08-22 stsp local tree_id=`git_show_tree $testroot/repo`
91 8e7bd50a 2019-08-22 stsp (cd $testroot/wt && got tag -m 'test' foobar $tree_id \
92 8e7bd50a 2019-08-22 stsp 2> $testroot/stderr)
93 8e7bd50a 2019-08-22 stsp ret="$?"
94 8e7bd50a 2019-08-22 stsp if [ "$ret" == "0" ]; then
95 8e7bd50a 2019-08-22 stsp echo "git tag command succeeded unexpectedly"
96 8e7bd50a 2019-08-22 stsp test_done "$testroot" "1"
97 8e7bd50a 2019-08-22 stsp return 1
98 8e7bd50a 2019-08-22 stsp fi
99 8e7bd50a 2019-08-22 stsp
100 8e7bd50a 2019-08-22 stsp echo "got: object not found" > $testroot/stderr.expected
101 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stderr $testroot/stderr.expected
102 8e7bd50a 2019-08-22 stsp ret="$?"
103 8e7bd50a 2019-08-22 stsp if [ "$ret" != "0" ]; then
104 8e7bd50a 2019-08-22 stsp diff -u $testroot/stderr.expected $testroot/stderr
105 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
106 8e7bd50a 2019-08-22 stsp return 1
107 8e7bd50a 2019-08-22 stsp fi
108 8e7bd50a 2019-08-22 stsp
109 8e7bd50a 2019-08-22 stsp got ref -r $testroot/repo -l > $testroot/stdout
110 8e7bd50a 2019-08-22 stsp echo "HEAD: $commit_id" > $testroot/stdout.expected
111 8e7bd50a 2019-08-22 stsp echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
112 8e7bd50a 2019-08-22 stsp cat $testroot/wt/.got/uuid | tr -d '\n' >> $testroot/stdout.expected
113 8e7bd50a 2019-08-22 stsp echo ": $commit_id" >> $testroot/stdout.expected
114 8e7bd50a 2019-08-22 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
115 8e7bd50a 2019-08-22 stsp echo "refs/tags/$tag: $tag_id" >> $testroot/stdout.expected
116 8e7bd50a 2019-08-22 stsp echo "refs/tags/$tag2: $tag_id2" >> $testroot/stdout.expected
117 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
118 8e7bd50a 2019-08-22 stsp ret="$?"
119 8e7bd50a 2019-08-22 stsp if [ "$ret" != "0" ]; then
120 8e7bd50a 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
121 8e7bd50a 2019-08-22 stsp fi
122 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
123 8e7bd50a 2019-08-22 stsp }
124 8e7bd50a 2019-08-22 stsp
125 8e7bd50a 2019-08-22 stsp function test_tag_list {
126 8e7bd50a 2019-08-22 stsp local testroot=`test_init tag_list`
127 8e7bd50a 2019-08-22 stsp local commit_id=`git_show_head $testroot/repo`
128 8e7bd50a 2019-08-22 stsp local tag=1.0.0
129 8e7bd50a 2019-08-22 stsp local tag2=2.0.0
130 8e7bd50a 2019-08-22 stsp
131 e8039a4a 2019-08-23 stsp # create tag with Git
132 8e7bd50a 2019-08-22 stsp (cd $testroot/repo && git tag -a -m 'test' $tag)
133 e8039a4a 2019-08-23 stsp # create tag with Got
134 e8039a4a 2019-08-23 stsp (cd $testroot/repo && got tag -m 'test' $tag2 > /dev/null)
135 8e7bd50a 2019-08-22 stsp
136 8e7bd50a 2019-08-22 stsp tag_id=`got ref -r $testroot/repo -l \
137 8e7bd50a 2019-08-22 stsp | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
138 8e7bd50a 2019-08-22 stsp local tagger_time=`git_show_tagger_time $testroot/repo $tag`
139 dca75039 2019-09-02 stsp d1=`env TZ=UTC date -r $tagger_time +"%a %b %e %X %Y UTC"`
140 8e7bd50a 2019-08-22 stsp tag_id2=`got ref -r $testroot/repo -l \
141 8e7bd50a 2019-08-22 stsp | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2`
142 8e7bd50a 2019-08-22 stsp local tagger_time2=`git_show_tagger_time $testroot/repo $tag2`
143 dca75039 2019-09-02 stsp d2=`env TZ=UTC date -r $tagger_time2 +"%a %b %e %X %Y UTC"`
144 8e7bd50a 2019-08-22 stsp
145 8e7bd50a 2019-08-22 stsp got tag -r $testroot/repo -l > $testroot/stdout
146 8e7bd50a 2019-08-22 stsp
147 8e7bd50a 2019-08-22 stsp echo "-----------------------------------------------" \
148 8e7bd50a 2019-08-22 stsp > $testroot/stdout.expected
149 b8bad2ba 2019-08-23 stsp echo "tag $tag2 $tag_id2" >> $testroot/stdout.expected
150 8e7bd50a 2019-08-22 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
151 8e7bd50a 2019-08-22 stsp echo "date: $d1" >> $testroot/stdout.expected
152 2417344c 2019-08-23 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
153 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
154 8e7bd50a 2019-08-22 stsp echo " test" >> $testroot/stdout.expected
155 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
156 8e7bd50a 2019-08-22 stsp echo "-----------------------------------------------" \
157 8e7bd50a 2019-08-22 stsp >> $testroot/stdout.expected
158 b8bad2ba 2019-08-23 stsp echo "tag $tag $tag_id" >> $testroot/stdout.expected
159 8e7bd50a 2019-08-22 stsp echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
160 8e7bd50a 2019-08-22 stsp echo "date: $d2" >> $testroot/stdout.expected
161 2417344c 2019-08-23 stsp echo "object: commit $commit_id" >> $testroot/stdout.expected
162 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
163 8e7bd50a 2019-08-22 stsp echo " test" >> $testroot/stdout.expected
164 8e7bd50a 2019-08-22 stsp echo " " >> $testroot/stdout.expected
165 8e7bd50a 2019-08-22 stsp cmp -s $testroot/stdout $testroot/stdout.expected
166 8e7bd50a 2019-08-22 stsp ret="$?"
167 8e7bd50a 2019-08-22 stsp if [ "$ret" != "0" ]; then
168 8e7bd50a 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
169 8e7bd50a 2019-08-22 stsp fi
170 8e7bd50a 2019-08-22 stsp test_done "$testroot" "$ret"
171 8e7bd50a 2019-08-22 stsp }
172 8e7bd50a 2019-08-22 stsp
173 8e7bd50a 2019-08-22 stsp run_test test_tag_create
174 8e7bd50a 2019-08-22 stsp run_test test_tag_list