Blame


1 cbd1af7a 2019-03-18 stsp #!/bin/sh
2 cbd1af7a 2019-03-18 stsp #
3 5aa81393 2020-01-06 stsp # Copyright (c) 2019, 2020 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 f43793a4 2020-01-27 stsp local testroot=`test_init log_in_worktree 1`
75 cbd1af7a 2019-03-18 stsp
76 f43793a4 2020-01-27 stsp make_test_tree $testroot/repo
77 f43793a4 2020-01-27 stsp mkdir -p $testroot/repo/epsilon/d
78 f43793a4 2020-01-27 stsp echo foo > $testroot/repo/epsilon/d/foo
79 f43793a4 2020-01-27 stsp (cd $testroot/repo && git add .)
80 f43793a4 2020-01-27 stsp git_commit $testroot/repo -m "adding the test tree"
81 f43793a4 2020-01-27 stsp local head_commit=`git_show_head $testroot/repo`
82 f43793a4 2020-01-27 stsp
83 cbd1af7a 2019-03-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
84 cbd1af7a 2019-03-18 stsp ret="$?"
85 cbd1af7a 2019-03-18 stsp if [ "$ret" != "0" ]; then
86 cbd1af7a 2019-03-18 stsp test_done "$testroot" "$ret"
87 cbd1af7a 2019-03-18 stsp return 1
88 cbd1af7a 2019-03-18 stsp fi
89 cbd1af7a 2019-03-18 stsp
90 f43793a4 2020-01-27 stsp echo "commit $head_commit (master)" > $testroot/stdout.expected
91 cbd1af7a 2019-03-18 stsp
92 cbd1af7a 2019-03-18 stsp for p in "" "." alpha epsilon; do
93 cbd1af7a 2019-03-18 stsp (cd $testroot/wt && got log $p | \
94 cbd1af7a 2019-03-18 stsp grep ^commit > $testroot/stdout)
95 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
96 cbd1af7a 2019-03-18 stsp ret="$?"
97 cbd1af7a 2019-03-18 stsp if [ "$ret" != "0" ]; then
98 cbd1af7a 2019-03-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
99 cbd1af7a 2019-03-18 stsp test_done "$testroot" "$ret"
100 cbd1af7a 2019-03-18 stsp return 1
101 cbd1af7a 2019-03-18 stsp fi
102 cbd1af7a 2019-03-18 stsp done
103 cbd1af7a 2019-03-18 stsp
104 cbd1af7a 2019-03-18 stsp for p in "" "." zeta; do
105 cbd1af7a 2019-03-18 stsp (cd $testroot/wt/epsilon && got log $p | \
106 cbd1af7a 2019-03-18 stsp grep ^commit > $testroot/stdout)
107 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
108 cbd1af7a 2019-03-18 stsp ret="$?"
109 cbd1af7a 2019-03-18 stsp if [ "$ret" != "0" ]; then
110 cbd1af7a 2019-03-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
111 cbd1af7a 2019-03-18 stsp test_done "$testroot" "$ret"
112 cbd1af7a 2019-03-18 stsp return 1
113 cbd1af7a 2019-03-18 stsp fi
114 cbd1af7a 2019-03-18 stsp done
115 cbd1af7a 2019-03-18 stsp
116 f43793a4 2020-01-27 stsp for p in "" "." foo; do
117 f43793a4 2020-01-27 stsp (cd $testroot/wt/epsilon && got log d/$p | \
118 f43793a4 2020-01-27 stsp grep ^commit > $testroot/stdout)
119 f43793a4 2020-01-27 stsp cmp -s $testroot/stdout.expected $testroot/stdout
120 f43793a4 2020-01-27 stsp ret="$?"
121 f43793a4 2020-01-27 stsp if [ "$ret" != "0" ]; then
122 f43793a4 2020-01-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
123 f43793a4 2020-01-27 stsp test_done "$testroot" "$ret"
124 f43793a4 2020-01-27 stsp return 1
125 f43793a4 2020-01-27 stsp fi
126 f43793a4 2020-01-27 stsp done
127 f43793a4 2020-01-27 stsp
128 cbd1af7a 2019-03-18 stsp test_done "$testroot" "0"
129 cbd1af7a 2019-03-18 stsp }
130 cbd1af7a 2019-03-18 stsp
131 dfe70b4b 2019-08-27 stsp function test_log_in_worktree_with_path_prefix {
132 0cfcb52d 2019-08-27 stsp local testroot=`test_init log_in_prefixed_worktree`
133 0cfcb52d 2019-08-27 stsp local head_rev=`git_show_head $testroot/repo`
134 0cfcb52d 2019-08-27 stsp
135 0cfcb52d 2019-08-27 stsp echo "modified zeta" > $testroot/repo/epsilon/zeta
136 0cfcb52d 2019-08-27 stsp git_commit $testroot/repo -m "modified zeta"
137 0cfcb52d 2019-08-27 stsp local zeta_rev=`git_show_head $testroot/repo`
138 0cfcb52d 2019-08-27 stsp
139 0cfcb52d 2019-08-27 stsp echo "modified delta" > $testroot/repo/gamma/delta
140 0cfcb52d 2019-08-27 stsp git_commit $testroot/repo -m "modified delta"
141 0cfcb52d 2019-08-27 stsp
142 0cfcb52d 2019-08-27 stsp got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
143 0cfcb52d 2019-08-27 stsp ret="$?"
144 0cfcb52d 2019-08-27 stsp if [ "$ret" != "0" ]; then
145 0cfcb52d 2019-08-27 stsp test_done "$testroot" "$ret"
146 0cfcb52d 2019-08-27 stsp return 1
147 0cfcb52d 2019-08-27 stsp fi
148 0cfcb52d 2019-08-27 stsp
149 0cfcb52d 2019-08-27 stsp echo "commit $zeta_rev" > $testroot/stdout.expected
150 0cfcb52d 2019-08-27 stsp echo "commit $head_rev" >> $testroot/stdout.expected
151 0cfcb52d 2019-08-27 stsp
152 0cfcb52d 2019-08-27 stsp for p in "" "." zeta; do
153 0cfcb52d 2019-08-27 stsp (cd $testroot/wt && got log $p | \
154 0cfcb52d 2019-08-27 stsp grep ^commit > $testroot/stdout)
155 0cfcb52d 2019-08-27 stsp cmp -s $testroot/stdout.expected $testroot/stdout
156 0cfcb52d 2019-08-27 stsp ret="$?"
157 0cfcb52d 2019-08-27 stsp if [ "$ret" != "0" ]; then
158 0cfcb52d 2019-08-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
159 0cfcb52d 2019-08-27 stsp test_done "$testroot" "$ret"
160 0cfcb52d 2019-08-27 stsp return 1
161 0cfcb52d 2019-08-27 stsp fi
162 0cfcb52d 2019-08-27 stsp done
163 0cfcb52d 2019-08-27 stsp
164 0cfcb52d 2019-08-27 stsp test_done "$testroot" "0"
165 0cfcb52d 2019-08-27 stsp }
166 0cfcb52d 2019-08-27 stsp
167 303e2782 2019-08-09 stsp function test_log_tag {
168 303e2782 2019-08-09 stsp local testroot=`test_init log_tag`
169 303e2782 2019-08-09 stsp local commit_id=`git_show_head $testroot/repo`
170 303e2782 2019-08-09 stsp local tag="1.0.0"
171 5a8ddf14 2019-08-13 stsp local tag2="2.0.0"
172 303e2782 2019-08-09 stsp
173 303e2782 2019-08-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
174 303e2782 2019-08-09 stsp ret="$?"
175 303e2782 2019-08-09 stsp if [ "$ret" != "0" ]; then
176 303e2782 2019-08-09 stsp test_done "$testroot" "$ret"
177 303e2782 2019-08-09 stsp return 1
178 303e2782 2019-08-09 stsp fi
179 303e2782 2019-08-09 stsp
180 303e2782 2019-08-09 stsp (cd $testroot/repo && git tag -a -m "test" $tag)
181 303e2782 2019-08-09 stsp
182 a436ad14 2019-08-13 stsp echo "commit $commit_id (master, tags/$tag)" > $testroot/stdout.expected
183 303e2782 2019-08-09 stsp (cd $testroot/wt && got log -l1 -c $tag | grep ^commit \
184 303e2782 2019-08-09 stsp > $testroot/stdout)
185 303e2782 2019-08-09 stsp cmp -s $testroot/stdout.expected $testroot/stdout
186 303e2782 2019-08-09 stsp ret="$?"
187 303e2782 2019-08-09 stsp if [ "$ret" != "0" ]; then
188 303e2782 2019-08-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
189 5a8ddf14 2019-08-13 stsp test_done "$testroot" "$ret"
190 5a8ddf14 2019-08-13 stsp return 1
191 303e2782 2019-08-09 stsp fi
192 5a8ddf14 2019-08-13 stsp
193 992eb9d8 2020-02-07 tracey # test a "lightweight" tag
194 5a8ddf14 2019-08-13 stsp (cd $testroot/repo && git tag $tag2)
195 5a8ddf14 2019-08-13 stsp
196 5a8ddf14 2019-08-13 stsp echo "commit $commit_id (master, tags/$tag, tags/$tag2)" \
197 5a8ddf14 2019-08-13 stsp > $testroot/stdout.expected
198 5a8ddf14 2019-08-13 stsp (cd $testroot/wt && got log -l1 -c $tag2 | grep ^commit \
199 5a8ddf14 2019-08-13 stsp > $testroot/stdout)
200 5a8ddf14 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
201 5a8ddf14 2019-08-13 stsp ret="$?"
202 5a8ddf14 2019-08-13 stsp if [ "$ret" != "0" ]; then
203 5a8ddf14 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
204 5a8ddf14 2019-08-13 stsp fi
205 303e2782 2019-08-09 stsp test_done "$testroot" "$ret"
206 303e2782 2019-08-09 stsp }
207 303e2782 2019-08-09 stsp
208 b1ebc001 2019-08-13 stsp function test_log_limit {
209 b1ebc001 2019-08-13 stsp local testroot=`test_init log_limit`
210 b1ebc001 2019-08-13 stsp local commit_id0=`git_show_head $testroot/repo`
211 303e2782 2019-08-09 stsp
212 b1ebc001 2019-08-13 stsp got checkout $testroot/repo $testroot/wt > /dev/null
213 b1ebc001 2019-08-13 stsp ret="$?"
214 b1ebc001 2019-08-13 stsp if [ "$ret" != "0" ]; then
215 b1ebc001 2019-08-13 stsp test_done "$testroot" "$ret"
216 b1ebc001 2019-08-13 stsp return 1
217 b1ebc001 2019-08-13 stsp fi
218 b1ebc001 2019-08-13 stsp
219 b1ebc001 2019-08-13 stsp echo "modified alpha" > $testroot/wt/alpha
220 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
221 b1ebc001 2019-08-13 stsp local commit_id1=`git_show_head $testroot/repo`
222 b1ebc001 2019-08-13 stsp
223 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got rm beta >/dev/null)
224 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
225 b1ebc001 2019-08-13 stsp local commit_id2=`git_show_head $testroot/repo`
226 b1ebc001 2019-08-13 stsp
227 b1ebc001 2019-08-13 stsp echo "new file" > $testroot/wt/new
228 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got add new >/dev/null)
229 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
230 b1ebc001 2019-08-13 stsp local commit_id3=`git_show_head $testroot/repo`
231 b1ebc001 2019-08-13 stsp
232 b1ebc001 2019-08-13 stsp # -l1 should print the first commit only
233 b1ebc001 2019-08-13 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
234 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got log -l1 | grep ^commit > $testroot/stdout)
235 b1ebc001 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
236 b1ebc001 2019-08-13 stsp ret="$?"
237 b1ebc001 2019-08-13 stsp if [ "$ret" != "0" ]; then
238 b1ebc001 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
239 b1ebc001 2019-08-13 stsp test_done "$testroot" "$ret"
240 b1ebc001 2019-08-13 stsp return 1
241 b1ebc001 2019-08-13 stsp fi
242 b1ebc001 2019-08-13 stsp
243 b1ebc001 2019-08-13 stsp # env var can be used to set a log limit without -l option
244 b1ebc001 2019-08-13 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
245 b1ebc001 2019-08-13 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
246 b1ebc001 2019-08-13 stsp (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=2 got log | \
247 b1ebc001 2019-08-13 stsp grep ^commit > $testroot/stdout)
248 b1ebc001 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
249 b1ebc001 2019-08-13 stsp ret="$?"
250 b1ebc001 2019-08-13 stsp if [ "$ret" != "0" ]; then
251 b1ebc001 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
252 b1ebc001 2019-08-13 stsp test_done "$testroot" "$ret"
253 b1ebc001 2019-08-13 stsp return 1
254 b1ebc001 2019-08-13 stsp fi
255 b1ebc001 2019-08-13 stsp
256 b1ebc001 2019-08-13 stsp # non-numeric env var is ignored
257 b1ebc001 2019-08-13 stsp (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=foobar got log | \
258 b1ebc001 2019-08-13 stsp grep ^commit > $testroot/stdout)
259 b1ebc001 2019-08-13 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
260 b1ebc001 2019-08-13 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
261 b1ebc001 2019-08-13 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
262 b1ebc001 2019-08-13 stsp echo "commit $commit_id0" >> $testroot/stdout.expected
263 b1ebc001 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
264 b1ebc001 2019-08-13 stsp ret="$?"
265 b1ebc001 2019-08-13 stsp if [ "$ret" != "0" ]; then
266 b1ebc001 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
267 b1ebc001 2019-08-13 stsp test_done "$testroot" "$ret"
268 b1ebc001 2019-08-13 stsp return 1
269 b1ebc001 2019-08-13 stsp fi
270 b1ebc001 2019-08-13 stsp
271 b1ebc001 2019-08-13 stsp # -l option takes precedence over env var
272 b1ebc001 2019-08-13 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
273 b1ebc001 2019-08-13 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
274 b1ebc001 2019-08-13 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
275 b1ebc001 2019-08-13 stsp echo "commit $commit_id0" >> $testroot/stdout.expected
276 b1ebc001 2019-08-13 stsp (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=1 got log -l0 | \
277 b1ebc001 2019-08-13 stsp grep ^commit > $testroot/stdout)
278 b1ebc001 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
279 b1ebc001 2019-08-13 stsp ret="$?"
280 b1ebc001 2019-08-13 stsp if [ "$ret" != "0" ]; then
281 b1ebc001 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
282 b1ebc001 2019-08-13 stsp fi
283 b1ebc001 2019-08-13 stsp test_done "$testroot" "0"
284 b1ebc001 2019-08-13 stsp }
285 5175b31a 2020-01-04 stsp
286 5175b31a 2020-01-04 stsp function test_log_nonexistent_path {
287 5175b31a 2020-01-04 stsp local testroot=`test_init log_nonexistent_path`
288 5175b31a 2020-01-04 stsp local head_rev=`git_show_head $testroot/repo`
289 5175b31a 2020-01-04 stsp
290 5175b31a 2020-01-04 stsp echo "commit $head_rev (master)" > $testroot/stdout.expected
291 b1ebc001 2019-08-13 stsp
292 5175b31a 2020-01-04 stsp (cd $testroot/repo && got log this/does/not/exist \
293 5175b31a 2020-01-04 stsp > $testroot/stdout 2> $testroot/stderr)
294 5175b31a 2020-01-04 stsp ret="$?"
295 5175b31a 2020-01-04 stsp if [ "$ret" == "0" ]; then
296 5175b31a 2020-01-04 stsp echo "log command succeeded unexpectedly" >&2
297 5175b31a 2020-01-04 stsp test_done "$testroot" "1"
298 5175b31a 2020-01-04 stsp return 1
299 5175b31a 2020-01-04 stsp fi
300 5175b31a 2020-01-04 stsp
301 5175b31a 2020-01-04 stsp echo -n > $testroot/stdout.expected
302 5175b31a 2020-01-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
303 5175b31a 2020-01-04 stsp ret="$?"
304 5175b31a 2020-01-04 stsp if [ "$ret" != "0" ]; then
305 5175b31a 2020-01-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
306 5175b31a 2020-01-04 stsp test_done "$testroot" "$ret"
307 5175b31a 2020-01-04 stsp return 1
308 5175b31a 2020-01-04 stsp fi
309 5175b31a 2020-01-04 stsp
310 5175b31a 2020-01-04 stsp echo "got: this/does/not/exist: no such entry found in tree" \
311 5175b31a 2020-01-04 stsp > $testroot/stderr.expected
312 5175b31a 2020-01-04 stsp cmp -s $testroot/stderr.expected $testroot/stderr
313 5175b31a 2020-01-04 stsp ret="$?"
314 5175b31a 2020-01-04 stsp if [ "$ret" != "0" ]; then
315 5175b31a 2020-01-04 stsp diff -u $testroot/stderr.expected $testroot/stderr
316 5175b31a 2020-01-04 stsp fi
317 5175b31a 2020-01-04 stsp test_done "$testroot" "$ret"
318 5175b31a 2020-01-04 stsp }
319 d1fe46f9 2020-04-18 stsp
320 d1fe46f9 2020-04-18 stsp function test_log_end_at_commit {
321 d1fe46f9 2020-04-18 stsp local testroot=`test_init log_end_at_commit`
322 d1fe46f9 2020-04-18 stsp local commit_id0=`git_show_head $testroot/repo`
323 d1fe46f9 2020-04-18 stsp
324 d1fe46f9 2020-04-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
325 d1fe46f9 2020-04-18 stsp ret="$?"
326 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
327 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
328 d1fe46f9 2020-04-18 stsp return 1
329 d1fe46f9 2020-04-18 stsp fi
330 d1fe46f9 2020-04-18 stsp
331 d1fe46f9 2020-04-18 stsp echo "modified alpha" > $testroot/wt/alpha
332 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
333 d1fe46f9 2020-04-18 stsp local commit_id1=`git_show_head $testroot/repo`
334 d1fe46f9 2020-04-18 stsp
335 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got rm beta >/dev/null)
336 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
337 d1fe46f9 2020-04-18 stsp local commit_id2=`git_show_head $testroot/repo`
338 d1fe46f9 2020-04-18 stsp
339 d1fe46f9 2020-04-18 stsp echo "new file" > $testroot/wt/new
340 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got add new >/dev/null)
341 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
342 d1fe46f9 2020-04-18 stsp local commit_id3=`git_show_head $testroot/repo`
343 5175b31a 2020-01-04 stsp
344 d1fe46f9 2020-04-18 stsp # Print commit 3 only
345 d1fe46f9 2020-04-18 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
346 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got log -x $commit_id3 | grep ^commit \
347 d1fe46f9 2020-04-18 stsp > $testroot/stdout)
348 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
349 d1fe46f9 2020-04-18 stsp ret="$?"
350 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
351 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
352 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
353 d1fe46f9 2020-04-18 stsp return 1
354 d1fe46f9 2020-04-18 stsp fi
355 d1fe46f9 2020-04-18 stsp
356 d1fe46f9 2020-04-18 stsp # Print commit 3 up to commit 1 inclusive
357 d1fe46f9 2020-04-18 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
358 d1fe46f9 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
359 d1fe46f9 2020-04-18 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
360 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got log -c $commit_id3 -x $commit_id1 | \
361 d1fe46f9 2020-04-18 stsp grep ^commit > $testroot/stdout)
362 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
363 d1fe46f9 2020-04-18 stsp ret="$?"
364 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
365 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
366 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
367 d1fe46f9 2020-04-18 stsp return 1
368 d1fe46f9 2020-04-18 stsp fi
369 d1fe46f9 2020-04-18 stsp
370 d1fe46f9 2020-04-18 stsp # Create commits on an unrelated branch
371 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got br foo > /dev/null)
372 d1fe46f9 2020-04-18 stsp echo bar >> $testroot/wt/alpha
373 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got commit -m "change on branch foo" >/dev/null)
374 d1fe46f9 2020-04-18 stsp local commit_id4=`git_show_branch_head $testroot/repo foo`
375 d1fe46f9 2020-04-18 stsp
376 d1fe46f9 2020-04-18 stsp # Print commit 4 only (in work tree)
377 d1fe46f9 2020-04-18 stsp echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
378 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got log -x foo | grep ^commit \
379 d1fe46f9 2020-04-18 stsp > $testroot/stdout)
380 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
381 d1fe46f9 2020-04-18 stsp ret="$?"
382 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
383 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
384 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
385 d1fe46f9 2020-04-18 stsp return 1
386 d1fe46f9 2020-04-18 stsp fi
387 d1fe46f9 2020-04-18 stsp
388 d1fe46f9 2020-04-18 stsp # Print commit 4 only (in repository)
389 d1fe46f9 2020-04-18 stsp echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
390 d1fe46f9 2020-04-18 stsp (cd $testroot/repo && got log -c foo -x foo | grep ^commit \
391 d1fe46f9 2020-04-18 stsp > $testroot/stdout)
392 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
393 d1fe46f9 2020-04-18 stsp ret="$?"
394 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
395 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
396 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
397 d1fe46f9 2020-04-18 stsp return 1
398 d1fe46f9 2020-04-18 stsp fi
399 d1fe46f9 2020-04-18 stsp
400 d1fe46f9 2020-04-18 stsp # Repository's HEAD is on master branch so -x foo without an explicit
401 d1fe46f9 2020-04-18 stsp # '-c foo' start commit has no effect there
402 d1fe46f9 2020-04-18 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
403 d1fe46f9 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
404 d1fe46f9 2020-04-18 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
405 d1fe46f9 2020-04-18 stsp echo "commit $commit_id0" >> $testroot/stdout.expected
406 d1fe46f9 2020-04-18 stsp (cd $testroot/repo && got log -x foo | grep ^commit \
407 d1fe46f9 2020-04-18 stsp > $testroot/stdout)
408 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
409 d1fe46f9 2020-04-18 stsp ret="$?"
410 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
411 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
412 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
413 d1fe46f9 2020-04-18 stsp return 1
414 d1fe46f9 2020-04-18 stsp fi
415 d1fe46f9 2020-04-18 stsp
416 d1fe46f9 2020-04-18 stsp # got will refuse -x with a non-existent commit
417 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got log -x nonexistent \
418 d1fe46f9 2020-04-18 stsp > $testroot/stdout 2> $testroot/stderr)
419 d1fe46f9 2020-04-18 stsp ret="$?"
420 d1fe46f9 2020-04-18 stsp if [ "$ret" == "0" ]; then
421 d1fe46f9 2020-04-18 stsp echo "log command succeeded unexpectedly" >&2
422 d1fe46f9 2020-04-18 stsp test_done "$testroot" "1"
423 d1fe46f9 2020-04-18 stsp return 1
424 d1fe46f9 2020-04-18 stsp fi
425 d1fe46f9 2020-04-18 stsp echo -n > $testroot/stdout.expected
426 d1fe46f9 2020-04-18 stsp echo "got: nonexistent: bad object id string" \
427 d1fe46f9 2020-04-18 stsp > $testroot/stderr.expected
428 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stderr.expected $testroot/stderr
429 d1fe46f9 2020-04-18 stsp ret="$?"
430 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
431 d1fe46f9 2020-04-18 stsp diff -u $testroot/stderr.expected $testroot/stderr
432 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
433 d1fe46f9 2020-04-18 stsp return 1
434 d1fe46f9 2020-04-18 stsp fi
435 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
436 d1fe46f9 2020-04-18 stsp ret="$?"
437 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
438 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
439 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
440 d1fe46f9 2020-04-18 stsp return 1
441 d1fe46f9 2020-04-18 stsp fi
442 d1fe46f9 2020-04-18 stsp
443 d1fe46f9 2020-04-18 stsp # try the same with the hash of an empty string which is very
444 d1fe46f9 2020-04-18 stsp # unlikely to match any object
445 b90c3048 2020-04-19 stsp local empty_sha1=da39a3ee5e6b4b0d3255bfef95601890afd80709
446 b90c3048 2020-04-19 stsp (cd $testroot/wt && got log -x $empty_sha1 \
447 d1fe46f9 2020-04-18 stsp > $testroot/stdout 2> $testroot/stderr)
448 d1fe46f9 2020-04-18 stsp ret="$?"
449 d1fe46f9 2020-04-18 stsp if [ "$ret" == "0" ]; then
450 d1fe46f9 2020-04-18 stsp echo "log command succeeded unexpectedly" >&2
451 d1fe46f9 2020-04-18 stsp test_done "$testroot" "1"
452 d1fe46f9 2020-04-18 stsp return 1
453 d1fe46f9 2020-04-18 stsp fi
454 d1fe46f9 2020-04-18 stsp echo -n > $testroot/stdout.expected
455 b90c3048 2020-04-19 stsp echo "got: $empty_sha1: object not found" > $testroot/stderr.expected
456 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stderr.expected $testroot/stderr
457 d1fe46f9 2020-04-18 stsp ret="$?"
458 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
459 d1fe46f9 2020-04-18 stsp diff -u $testroot/stderr.expected $testroot/stderr
460 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
461 d1fe46f9 2020-04-18 stsp return 1
462 d1fe46f9 2020-04-18 stsp fi
463 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
464 d1fe46f9 2020-04-18 stsp ret="$?"
465 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
466 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
467 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
468 d1fe46f9 2020-04-18 stsp return 1
469 d1fe46f9 2020-04-18 stsp fi
470 d1fe46f9 2020-04-18 stsp
471 d1fe46f9 2020-04-18 stsp test_done "$testroot" "0"
472 d1fe46f9 2020-04-18 stsp }
473 dbec59df 2020-04-18 stsp
474 dbec59df 2020-04-18 stsp function test_log_reverse_display {
475 dbec59df 2020-04-18 stsp local testroot=`test_init log_reverse_display`
476 dbec59df 2020-04-18 stsp local commit_id0=`git_show_head $testroot/repo`
477 dbec59df 2020-04-18 stsp
478 dbec59df 2020-04-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
479 dbec59df 2020-04-18 stsp ret="$?"
480 dbec59df 2020-04-18 stsp if [ "$ret" != "0" ]; then
481 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
482 dbec59df 2020-04-18 stsp return 1
483 dbec59df 2020-04-18 stsp fi
484 dbec59df 2020-04-18 stsp
485 dbec59df 2020-04-18 stsp echo "modified alpha" > $testroot/wt/alpha
486 dbec59df 2020-04-18 stsp (cd $testroot/wt && got commit -m 'commit1' > /dev/null)
487 dbec59df 2020-04-18 stsp local commit_id1=`git_show_head $testroot/repo`
488 dbec59df 2020-04-18 stsp
489 dbec59df 2020-04-18 stsp (cd $testroot/wt && got rm beta >/dev/null)
490 dbec59df 2020-04-18 stsp (cd $testroot/wt && got commit -m 'commit2' > /dev/null)
491 dbec59df 2020-04-18 stsp local commit_id2=`git_show_head $testroot/repo`
492 dbec59df 2020-04-18 stsp
493 dbec59df 2020-04-18 stsp echo "new file" > $testroot/wt/new
494 dbec59df 2020-04-18 stsp (cd $testroot/wt && got add new >/dev/null)
495 dbec59df 2020-04-18 stsp (cd $testroot/wt && got commit -m 'commit3' > /dev/null)
496 dbec59df 2020-04-18 stsp local commit_id3=`git_show_head $testroot/repo`
497 d1fe46f9 2020-04-18 stsp
498 dbec59df 2020-04-18 stsp # -R alone should display all commits in reverse
499 dbec59df 2020-04-18 stsp echo "commit $commit_id0" > $testroot/stdout.expected
500 dbec59df 2020-04-18 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
501 dbec59df 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
502 dbec59df 2020-04-18 stsp echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
503 dbec59df 2020-04-18 stsp (cd $testroot/wt && got log -R | grep ^commit > $testroot/stdout)
504 dbec59df 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
505 dbec59df 2020-04-18 stsp ret="$?"
506 dbec59df 2020-04-18 stsp if [ "$ret" != "0" ]; then
507 dbec59df 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
508 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
509 dbec59df 2020-04-18 stsp return 1
510 dbec59df 2020-04-18 stsp fi
511 dbec59df 2020-04-18 stsp
512 dbec59df 2020-04-18 stsp # -R takes effect after the -l commit traversal limit
513 dbec59df 2020-04-18 stsp echo "commit $commit_id2" > $testroot/stdout.expected
514 dbec59df 2020-04-18 stsp echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
515 dbec59df 2020-04-18 stsp (cd $testroot/wt && got log -R -l2 | grep ^commit > $testroot/stdout)
516 dbec59df 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
517 dbec59df 2020-04-18 stsp ret="$?"
518 dbec59df 2020-04-18 stsp if [ "$ret" != "0" ]; then
519 dbec59df 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
520 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
521 dbec59df 2020-04-18 stsp return 1
522 dbec59df 2020-04-18 stsp fi
523 dbec59df 2020-04-18 stsp
524 dbec59df 2020-04-18 stsp # -R works with commit ranges specified via -c and -x
525 dbec59df 2020-04-18 stsp echo "commit $commit_id1" > $testroot/stdout.expected
526 dbec59df 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
527 dbec59df 2020-04-18 stsp echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
528 dbec59df 2020-04-18 stsp (cd $testroot/wt && got log -R -c $commit_id3 -x $commit_id1 | \
529 dbec59df 2020-04-18 stsp grep ^commit > $testroot/stdout)
530 dbec59df 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
531 dbec59df 2020-04-18 stsp ret="$?"
532 dbec59df 2020-04-18 stsp if [ "$ret" != "0" ]; then
533 dbec59df 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
534 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
535 dbec59df 2020-04-18 stsp fi
536 dbec59df 2020-04-18 stsp
537 dbec59df 2020-04-18 stsp # commit matching with -s applies before -R
538 dbec59df 2020-04-18 stsp echo "commit $commit_id1" > $testroot/stdout.expected
539 dbec59df 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
540 dbec59df 2020-04-18 stsp (cd $testroot/wt && got log -R -s 'commit[12]' | \
541 dbec59df 2020-04-18 stsp grep ^commit > $testroot/stdout)
542 dbec59df 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
543 dbec59df 2020-04-18 stsp ret="$?"
544 dbec59df 2020-04-18 stsp if [ "$ret" != "0" ]; then
545 dbec59df 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
546 dbec59df 2020-04-18 stsp fi
547 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
548 dbec59df 2020-04-18 stsp }
549 dbec59df 2020-04-18 stsp
550 e7301579 2019-03-18 stsp run_test test_log_in_repo
551 b70703ad 2019-03-18 stsp run_test test_log_in_bare_repo
552 cbd1af7a 2019-03-18 stsp run_test test_log_in_worktree
553 dfe70b4b 2019-08-27 stsp run_test test_log_in_worktree_with_path_prefix
554 303e2782 2019-08-09 stsp run_test test_log_tag
555 b1ebc001 2019-08-13 stsp run_test test_log_limit
556 5175b31a 2020-01-04 stsp run_test test_log_nonexistent_path
557 d1fe46f9 2020-04-18 stsp run_test test_log_end_at_commit
558 dbec59df 2020-04-18 stsp run_test test_log_reverse_display