Blame


1 cbd1af7a 2019-03-18 stsp #!/bin/sh
2 cbd1af7a 2019-03-18 stsp #
3 cbd1af7a 2019-03-18 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 cbd1af7a 2019-03-18 stsp #
5 cbd1af7a 2019-03-18 stsp # Permission to use, copy, modify, and distribute this software for any
6 cbd1af7a 2019-03-18 stsp # purpose with or without fee is hereby granted, provided that the above
7 cbd1af7a 2019-03-18 stsp # copyright notice and this permission notice appear in all copies.
8 cbd1af7a 2019-03-18 stsp #
9 cbd1af7a 2019-03-18 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 cbd1af7a 2019-03-18 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 cbd1af7a 2019-03-18 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 cbd1af7a 2019-03-18 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 cbd1af7a 2019-03-18 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 cbd1af7a 2019-03-18 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 cbd1af7a 2019-03-18 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 cbd1af7a 2019-03-18 stsp
17 cbd1af7a 2019-03-18 stsp . ./common.sh
18 cbd1af7a 2019-03-18 stsp
19 e7301579 2019-03-18 stsp function test_log_in_repo {
20 e7301579 2019-03-18 stsp local testroot=`test_init log_in_repo`
21 e7301579 2019-03-18 stsp local head_rev=`git_show_head $testroot/repo`
22 e7301579 2019-03-18 stsp
23 e7301579 2019-03-18 stsp echo "commit $head_rev (master)" > $testroot/stdout.expected
24 e7301579 2019-03-18 stsp
25 e7301579 2019-03-18 stsp for p in "" "." alpha epsilon epsilon/zeta; do
26 e7301579 2019-03-18 stsp (cd $testroot/repo && got log $p | \
27 e7301579 2019-03-18 stsp grep ^commit > $testroot/stdout)
28 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
29 e7301579 2019-03-18 stsp ret="$?"
30 e7301579 2019-03-18 stsp if [ "$ret" != "0" ]; then
31 e7301579 2019-03-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
32 e7301579 2019-03-18 stsp test_done "$testroot" "$ret"
33 e7301579 2019-03-18 stsp return 1
34 e7301579 2019-03-18 stsp fi
35 e7301579 2019-03-18 stsp done
36 e7301579 2019-03-18 stsp
37 b70703ad 2019-03-18 stsp for p in "" "." zeta; do
38 b70703ad 2019-03-18 stsp (cd $testroot/repo/epsilon && got log $p | \
39 b70703ad 2019-03-18 stsp grep ^commit > $testroot/stdout)
40 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
41 b70703ad 2019-03-18 stsp ret="$?"
42 b70703ad 2019-03-18 stsp if [ "$ret" != "0" ]; then
43 b70703ad 2019-03-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
44 b70703ad 2019-03-18 stsp test_done "$testroot" "$ret"
45 b70703ad 2019-03-18 stsp return 1
46 b70703ad 2019-03-18 stsp fi
47 b70703ad 2019-03-18 stsp done
48 b70703ad 2019-03-18 stsp
49 e7301579 2019-03-18 stsp test_done "$testroot" "0"
50 e7301579 2019-03-18 stsp }
51 e7301579 2019-03-18 stsp
52 b70703ad 2019-03-18 stsp function test_log_in_bare_repo {
53 b70703ad 2019-03-18 stsp local testroot=`test_init log_in_bare_repo`
54 b70703ad 2019-03-18 stsp local head_rev=`git_show_head $testroot/repo`
55 b70703ad 2019-03-18 stsp
56 b70703ad 2019-03-18 stsp echo "commit $head_rev (master)" > $testroot/stdout.expected
57 b70703ad 2019-03-18 stsp
58 b70703ad 2019-03-18 stsp for p in "" "." alpha epsilon epsilon/zeta; do
59 b70703ad 2019-03-18 stsp (cd $testroot/repo/.git && got log $p | \
60 b70703ad 2019-03-18 stsp grep ^commit > $testroot/stdout)
61 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
62 b70703ad 2019-03-18 stsp ret="$?"
63 b70703ad 2019-03-18 stsp if [ "$ret" != "0" ]; then
64 b70703ad 2019-03-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
65 b70703ad 2019-03-18 stsp test_done "$testroot" "$ret"
66 b70703ad 2019-03-18 stsp return 1
67 b70703ad 2019-03-18 stsp fi
68 b70703ad 2019-03-18 stsp done
69 b70703ad 2019-03-18 stsp
70 b70703ad 2019-03-18 stsp test_done "$testroot" "0"
71 b70703ad 2019-03-18 stsp }
72 b70703ad 2019-03-18 stsp
73 cbd1af7a 2019-03-18 stsp function test_log_in_worktree {
74 cbd1af7a 2019-03-18 stsp local testroot=`test_init log_in_worktree`
75 cbd1af7a 2019-03-18 stsp local head_rev=`git_show_head $testroot/repo`
76 cbd1af7a 2019-03-18 stsp
77 cbd1af7a 2019-03-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
78 cbd1af7a 2019-03-18 stsp ret="$?"
79 cbd1af7a 2019-03-18 stsp if [ "$ret" != "0" ]; then
80 cbd1af7a 2019-03-18 stsp test_done "$testroot" "$ret"
81 cbd1af7a 2019-03-18 stsp return 1
82 cbd1af7a 2019-03-18 stsp fi
83 cbd1af7a 2019-03-18 stsp
84 cbd1af7a 2019-03-18 stsp echo "commit $head_rev (master)" > $testroot/stdout.expected
85 cbd1af7a 2019-03-18 stsp
86 cbd1af7a 2019-03-18 stsp for p in "" "." alpha epsilon; do
87 cbd1af7a 2019-03-18 stsp (cd $testroot/wt && got log $p | \
88 cbd1af7a 2019-03-18 stsp grep ^commit > $testroot/stdout)
89 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
90 cbd1af7a 2019-03-18 stsp ret="$?"
91 cbd1af7a 2019-03-18 stsp if [ "$ret" != "0" ]; then
92 cbd1af7a 2019-03-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
93 cbd1af7a 2019-03-18 stsp test_done "$testroot" "$ret"
94 cbd1af7a 2019-03-18 stsp return 1
95 cbd1af7a 2019-03-18 stsp fi
96 cbd1af7a 2019-03-18 stsp done
97 cbd1af7a 2019-03-18 stsp
98 cbd1af7a 2019-03-18 stsp for p in "" "." zeta; do
99 cbd1af7a 2019-03-18 stsp (cd $testroot/wt/epsilon && got log $p | \
100 cbd1af7a 2019-03-18 stsp grep ^commit > $testroot/stdout)
101 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
102 cbd1af7a 2019-03-18 stsp ret="$?"
103 cbd1af7a 2019-03-18 stsp if [ "$ret" != "0" ]; then
104 cbd1af7a 2019-03-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
105 cbd1af7a 2019-03-18 stsp test_done "$testroot" "$ret"
106 cbd1af7a 2019-03-18 stsp return 1
107 cbd1af7a 2019-03-18 stsp fi
108 cbd1af7a 2019-03-18 stsp done
109 cbd1af7a 2019-03-18 stsp
110 cbd1af7a 2019-03-18 stsp test_done "$testroot" "0"
111 cbd1af7a 2019-03-18 stsp }
112 cbd1af7a 2019-03-18 stsp
113 dfe70b4b 2019-08-27 stsp function test_log_in_worktree_with_path_prefix {
114 0cfcb52d 2019-08-27 stsp local testroot=`test_init log_in_prefixed_worktree`
115 0cfcb52d 2019-08-27 stsp local head_rev=`git_show_head $testroot/repo`
116 0cfcb52d 2019-08-27 stsp
117 0cfcb52d 2019-08-27 stsp echo "modified zeta" > $testroot/repo/epsilon/zeta
118 0cfcb52d 2019-08-27 stsp git_commit $testroot/repo -m "modified zeta"
119 0cfcb52d 2019-08-27 stsp local zeta_rev=`git_show_head $testroot/repo`
120 0cfcb52d 2019-08-27 stsp
121 0cfcb52d 2019-08-27 stsp echo "modified delta" > $testroot/repo/gamma/delta
122 0cfcb52d 2019-08-27 stsp git_commit $testroot/repo -m "modified delta"
123 0cfcb52d 2019-08-27 stsp
124 0cfcb52d 2019-08-27 stsp got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
125 0cfcb52d 2019-08-27 stsp ret="$?"
126 0cfcb52d 2019-08-27 stsp if [ "$ret" != "0" ]; then
127 0cfcb52d 2019-08-27 stsp test_done "$testroot" "$ret"
128 0cfcb52d 2019-08-27 stsp return 1
129 0cfcb52d 2019-08-27 stsp fi
130 0cfcb52d 2019-08-27 stsp
131 0cfcb52d 2019-08-27 stsp echo "commit $zeta_rev" > $testroot/stdout.expected
132 0cfcb52d 2019-08-27 stsp echo "commit $head_rev" >> $testroot/stdout.expected
133 0cfcb52d 2019-08-27 stsp
134 0cfcb52d 2019-08-27 stsp for p in "" "." zeta; do
135 0cfcb52d 2019-08-27 stsp (cd $testroot/wt && got log $p | \
136 0cfcb52d 2019-08-27 stsp grep ^commit > $testroot/stdout)
137 0cfcb52d 2019-08-27 stsp cmp -s $testroot/stdout.expected $testroot/stdout
138 0cfcb52d 2019-08-27 stsp ret="$?"
139 0cfcb52d 2019-08-27 stsp if [ "$ret" != "0" ]; then
140 0cfcb52d 2019-08-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
141 0cfcb52d 2019-08-27 stsp test_done "$testroot" "$ret"
142 0cfcb52d 2019-08-27 stsp return 1
143 0cfcb52d 2019-08-27 stsp fi
144 0cfcb52d 2019-08-27 stsp done
145 0cfcb52d 2019-08-27 stsp
146 0cfcb52d 2019-08-27 stsp test_done "$testroot" "0"
147 0cfcb52d 2019-08-27 stsp }
148 0cfcb52d 2019-08-27 stsp
149 303e2782 2019-08-09 stsp function test_log_tag {
150 303e2782 2019-08-09 stsp local testroot=`test_init log_tag`
151 303e2782 2019-08-09 stsp local commit_id=`git_show_head $testroot/repo`
152 303e2782 2019-08-09 stsp local tag="1.0.0"
153 5a8ddf14 2019-08-13 stsp local tag2="2.0.0"
154 303e2782 2019-08-09 stsp
155 303e2782 2019-08-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
156 303e2782 2019-08-09 stsp ret="$?"
157 303e2782 2019-08-09 stsp if [ "$ret" != "0" ]; then
158 303e2782 2019-08-09 stsp test_done "$testroot" "$ret"
159 303e2782 2019-08-09 stsp return 1
160 303e2782 2019-08-09 stsp fi
161 303e2782 2019-08-09 stsp
162 303e2782 2019-08-09 stsp (cd $testroot/repo && git tag -a -m "test" $tag)
163 303e2782 2019-08-09 stsp
164 a436ad14 2019-08-13 stsp echo "commit $commit_id (master, tags/$tag)" > $testroot/stdout.expected
165 303e2782 2019-08-09 stsp (cd $testroot/wt && got log -l1 -c $tag | grep ^commit \
166 303e2782 2019-08-09 stsp > $testroot/stdout)
167 303e2782 2019-08-09 stsp cmp -s $testroot/stdout.expected $testroot/stdout
168 303e2782 2019-08-09 stsp ret="$?"
169 303e2782 2019-08-09 stsp if [ "$ret" != "0" ]; then
170 303e2782 2019-08-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
171 5a8ddf14 2019-08-13 stsp test_done "$testroot" "$ret"
172 5a8ddf14 2019-08-13 stsp return 1
173 303e2782 2019-08-09 stsp fi
174 5a8ddf14 2019-08-13 stsp
175 5a8ddf14 2019-08-13 stsp # test a "leightweight" tag
176 5a8ddf14 2019-08-13 stsp (cd $testroot/repo && git tag $tag2)
177 5a8ddf14 2019-08-13 stsp
178 5a8ddf14 2019-08-13 stsp echo "commit $commit_id (master, tags/$tag, tags/$tag2)" \
179 5a8ddf14 2019-08-13 stsp > $testroot/stdout.expected
180 5a8ddf14 2019-08-13 stsp (cd $testroot/wt && got log -l1 -c $tag2 | grep ^commit \
181 5a8ddf14 2019-08-13 stsp > $testroot/stdout)
182 5a8ddf14 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
183 5a8ddf14 2019-08-13 stsp ret="$?"
184 5a8ddf14 2019-08-13 stsp if [ "$ret" != "0" ]; then
185 5a8ddf14 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
186 5a8ddf14 2019-08-13 stsp fi
187 303e2782 2019-08-09 stsp test_done "$testroot" "$ret"
188 303e2782 2019-08-09 stsp }
189 303e2782 2019-08-09 stsp
190 b1ebc001 2019-08-13 stsp function test_log_limit {
191 b1ebc001 2019-08-13 stsp local testroot=`test_init log_limit`
192 b1ebc001 2019-08-13 stsp local commit_id0=`git_show_head $testroot/repo`
193 303e2782 2019-08-09 stsp
194 b1ebc001 2019-08-13 stsp got checkout $testroot/repo $testroot/wt > /dev/null
195 b1ebc001 2019-08-13 stsp ret="$?"
196 b1ebc001 2019-08-13 stsp if [ "$ret" != "0" ]; then
197 b1ebc001 2019-08-13 stsp test_done "$testroot" "$ret"
198 b1ebc001 2019-08-13 stsp return 1
199 b1ebc001 2019-08-13 stsp fi
200 b1ebc001 2019-08-13 stsp
201 b1ebc001 2019-08-13 stsp echo "modified alpha" > $testroot/wt/alpha
202 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
203 b1ebc001 2019-08-13 stsp local commit_id1=`git_show_head $testroot/repo`
204 b1ebc001 2019-08-13 stsp
205 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got rm beta >/dev/null)
206 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
207 b1ebc001 2019-08-13 stsp local commit_id2=`git_show_head $testroot/repo`
208 b1ebc001 2019-08-13 stsp
209 b1ebc001 2019-08-13 stsp echo "new file" > $testroot/wt/new
210 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got add new >/dev/null)
211 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
212 b1ebc001 2019-08-13 stsp local commit_id3=`git_show_head $testroot/repo`
213 b1ebc001 2019-08-13 stsp
214 b1ebc001 2019-08-13 stsp # -l1 should print the first commit only
215 b1ebc001 2019-08-13 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
216 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got log -l1 | grep ^commit > $testroot/stdout)
217 b1ebc001 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
218 b1ebc001 2019-08-13 stsp ret="$?"
219 b1ebc001 2019-08-13 stsp if [ "$ret" != "0" ]; then
220 b1ebc001 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
221 b1ebc001 2019-08-13 stsp test_done "$testroot" "$ret"
222 b1ebc001 2019-08-13 stsp return 1
223 b1ebc001 2019-08-13 stsp fi
224 b1ebc001 2019-08-13 stsp
225 b1ebc001 2019-08-13 stsp # env var can be used to set a log limit without -l option
226 b1ebc001 2019-08-13 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
227 b1ebc001 2019-08-13 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
228 b1ebc001 2019-08-13 stsp (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=2 got log | \
229 b1ebc001 2019-08-13 stsp grep ^commit > $testroot/stdout)
230 b1ebc001 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
231 b1ebc001 2019-08-13 stsp ret="$?"
232 b1ebc001 2019-08-13 stsp if [ "$ret" != "0" ]; then
233 b1ebc001 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
234 b1ebc001 2019-08-13 stsp test_done "$testroot" "$ret"
235 b1ebc001 2019-08-13 stsp return 1
236 b1ebc001 2019-08-13 stsp fi
237 b1ebc001 2019-08-13 stsp
238 b1ebc001 2019-08-13 stsp # non-numeric env var is ignored
239 b1ebc001 2019-08-13 stsp (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=foobar got log | \
240 b1ebc001 2019-08-13 stsp grep ^commit > $testroot/stdout)
241 b1ebc001 2019-08-13 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
242 b1ebc001 2019-08-13 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
243 b1ebc001 2019-08-13 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
244 b1ebc001 2019-08-13 stsp echo "commit $commit_id0" >> $testroot/stdout.expected
245 b1ebc001 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
246 b1ebc001 2019-08-13 stsp ret="$?"
247 b1ebc001 2019-08-13 stsp if [ "$ret" != "0" ]; then
248 b1ebc001 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
249 b1ebc001 2019-08-13 stsp test_done "$testroot" "$ret"
250 b1ebc001 2019-08-13 stsp return 1
251 b1ebc001 2019-08-13 stsp fi
252 b1ebc001 2019-08-13 stsp
253 b1ebc001 2019-08-13 stsp # -l option takes precedence over env var
254 b1ebc001 2019-08-13 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
255 b1ebc001 2019-08-13 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
256 b1ebc001 2019-08-13 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
257 b1ebc001 2019-08-13 stsp echo "commit $commit_id0" >> $testroot/stdout.expected
258 b1ebc001 2019-08-13 stsp (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=1 got log -l0 | \
259 b1ebc001 2019-08-13 stsp grep ^commit > $testroot/stdout)
260 b1ebc001 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
261 b1ebc001 2019-08-13 stsp ret="$?"
262 b1ebc001 2019-08-13 stsp if [ "$ret" != "0" ]; then
263 b1ebc001 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
264 b1ebc001 2019-08-13 stsp fi
265 b1ebc001 2019-08-13 stsp test_done "$testroot" "0"
266 b1ebc001 2019-08-13 stsp }
267 b1ebc001 2019-08-13 stsp
268 e7301579 2019-03-18 stsp run_test test_log_in_repo
269 b70703ad 2019-03-18 stsp run_test test_log_in_bare_repo
270 cbd1af7a 2019-03-18 stsp run_test test_log_in_worktree
271 dfe70b4b 2019-08-27 stsp run_test test_log_in_worktree_with_path_prefix
272 303e2782 2019-08-09 stsp run_test test_log_tag
273 b1ebc001 2019-08-13 stsp run_test test_log_limit