3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
19 function test_log_in_repo {
20 local testroot=`test_init log_in_repo`
21 local head_rev=`git_show_head $testroot/repo`
23 echo "commit $head_rev (master)" > $testroot/stdout.expected
25 for p in "" "." alpha epsilon epsilon/zeta; do
26 (cd $testroot/repo && got log $p | \
27 grep ^commit > $testroot/stdout)
28 cmp -s $testroot/stdout.expected $testroot/stdout
30 if [ "$ret" != "0" ]; then
31 diff -u $testroot/stdout.expected $testroot/stdout
32 test_done "$testroot" "$ret"
37 for p in "" "." zeta; do
38 (cd $testroot/repo/epsilon && got log $p | \
39 grep ^commit > $testroot/stdout)
40 cmp -s $testroot/stdout.expected $testroot/stdout
42 if [ "$ret" != "0" ]; then
43 diff -u $testroot/stdout.expected $testroot/stdout
44 test_done "$testroot" "$ret"
49 test_done "$testroot" "0"
52 function test_log_in_bare_repo {
53 local testroot=`test_init log_in_bare_repo`
54 local head_rev=`git_show_head $testroot/repo`
56 echo "commit $head_rev (master)" > $testroot/stdout.expected
58 for p in "" "." alpha epsilon epsilon/zeta; do
59 (cd $testroot/repo/.git && got log $p | \
60 grep ^commit > $testroot/stdout)
61 cmp -s $testroot/stdout.expected $testroot/stdout
63 if [ "$ret" != "0" ]; then
64 diff -u $testroot/stdout.expected $testroot/stdout
65 test_done "$testroot" "$ret"
70 test_done "$testroot" "0"
73 function test_log_in_worktree {
74 local testroot=`test_init log_in_worktree`
75 local head_rev=`git_show_head $testroot/repo`
77 got checkout $testroot/repo $testroot/wt > /dev/null
79 if [ "$ret" != "0" ]; then
80 test_done "$testroot" "$ret"
84 echo "commit $head_rev (master)" > $testroot/stdout.expected
86 for p in "" "." alpha epsilon; do
87 (cd $testroot/wt && got log $p | \
88 grep ^commit > $testroot/stdout)
89 cmp -s $testroot/stdout.expected $testroot/stdout
91 if [ "$ret" != "0" ]; then
92 diff -u $testroot/stdout.expected $testroot/stdout
93 test_done "$testroot" "$ret"
98 for p in "" "." zeta; do
99 (cd $testroot/wt/epsilon && got log $p | \
100 grep ^commit > $testroot/stdout)
101 cmp -s $testroot/stdout.expected $testroot/stdout
103 if [ "$ret" != "0" ]; then
104 diff -u $testroot/stdout.expected $testroot/stdout
105 test_done "$testroot" "$ret"
110 test_done "$testroot" "0"
113 function test_log_tag {
114 local testroot=`test_init log_tag`
115 local commit_id=`git_show_head $testroot/repo`
119 got checkout $testroot/repo $testroot/wt > /dev/null
121 if [ "$ret" != "0" ]; then
122 test_done "$testroot" "$ret"
126 (cd $testroot/repo && git tag -a -m "test" $tag)
128 echo "commit $commit_id (master, tags/$tag)" > $testroot/stdout.expected
129 (cd $testroot/wt && got log -l1 -c $tag | grep ^commit \
131 cmp -s $testroot/stdout.expected $testroot/stdout
133 if [ "$ret" != "0" ]; then
134 diff -u $testroot/stdout.expected $testroot/stdout
135 test_done "$testroot" "$ret"
139 # test a "leightweight" tag
140 (cd $testroot/repo && git tag $tag2)
142 echo "commit $commit_id (master, tags/$tag, tags/$tag2)" \
143 > $testroot/stdout.expected
144 (cd $testroot/wt && got log -l1 -c $tag2 | grep ^commit \
146 cmp -s $testroot/stdout.expected $testroot/stdout
148 if [ "$ret" != "0" ]; then
149 diff -u $testroot/stdout.expected $testroot/stdout
151 test_done "$testroot" "$ret"
154 function test_log_limit {
155 local testroot=`test_init log_limit`
156 local commit_id0=`git_show_head $testroot/repo`
158 got checkout $testroot/repo $testroot/wt > /dev/null
160 if [ "$ret" != "0" ]; then
161 test_done "$testroot" "$ret"
165 echo "modified alpha" > $testroot/wt/alpha
166 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
167 local commit_id1=`git_show_head $testroot/repo`
169 (cd $testroot/wt && got rm beta >/dev/null)
170 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
171 local commit_id2=`git_show_head $testroot/repo`
173 echo "new file" > $testroot/wt/new
174 (cd $testroot/wt && got add new >/dev/null)
175 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
176 local commit_id3=`git_show_head $testroot/repo`
178 # -l1 should print the first commit only
179 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
180 (cd $testroot/wt && got log -l1 | grep ^commit > $testroot/stdout)
181 cmp -s $testroot/stdout.expected $testroot/stdout
183 if [ "$ret" != "0" ]; then
184 diff -u $testroot/stdout.expected $testroot/stdout
185 test_done "$testroot" "$ret"
189 # env var can be used to set a log limit without -l option
190 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
191 echo "commit $commit_id2" >> $testroot/stdout.expected
192 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=2 got log | \
193 grep ^commit > $testroot/stdout)
194 cmp -s $testroot/stdout.expected $testroot/stdout
196 if [ "$ret" != "0" ]; then
197 diff -u $testroot/stdout.expected $testroot/stdout
198 test_done "$testroot" "$ret"
202 # non-numeric env var is ignored
203 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=foobar got log | \
204 grep ^commit > $testroot/stdout)
205 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
206 echo "commit $commit_id2" >> $testroot/stdout.expected
207 echo "commit $commit_id1" >> $testroot/stdout.expected
208 echo "commit $commit_id0" >> $testroot/stdout.expected
209 cmp -s $testroot/stdout.expected $testroot/stdout
211 if [ "$ret" != "0" ]; then
212 diff -u $testroot/stdout.expected $testroot/stdout
213 test_done "$testroot" "$ret"
217 # -l option takes precedence over env var
218 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
219 echo "commit $commit_id2" >> $testroot/stdout.expected
220 echo "commit $commit_id1" >> $testroot/stdout.expected
221 echo "commit $commit_id0" >> $testroot/stdout.expected
222 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=1 got log -l0 | \
223 grep ^commit > $testroot/stdout)
224 cmp -s $testroot/stdout.expected $testroot/stdout
226 if [ "$ret" != "0" ]; then
227 diff -u $testroot/stdout.expected $testroot/stdout
229 test_done "$testroot" "0"
232 run_test test_log_in_repo
233 run_test test_log_in_bare_repo
234 run_test test_log_in_worktree
235 run_test test_log_tag
236 run_test test_log_limit