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 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
29 ret="$?"
30 if [ "$ret" != "0" ]; then
31 diff -u $testroot/stdout.expected $testroot/stdout
32 test_done "$testroot" "$ret"
33 return 1
34 fi
35 done
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
41 ret="$?"
42 if [ "$ret" != "0" ]; then
43 diff -u $testroot/stdout.expected $testroot/stdout
44 test_done "$testroot" "$ret"
45 return 1
46 fi
47 done
49 test_done "$testroot" "0"
50 }
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
62 ret="$?"
63 if [ "$ret" != "0" ]; then
64 diff -u $testroot/stdout.expected $testroot/stdout
65 test_done "$testroot" "$ret"
66 return 1
67 fi
68 done
70 test_done "$testroot" "0"
71 }
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
78 ret="$?"
79 if [ "$ret" != "0" ]; then
80 test_done "$testroot" "$ret"
81 return 1
82 fi
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
90 ret="$?"
91 if [ "$ret" != "0" ]; then
92 diff -u $testroot/stdout.expected $testroot/stdout
93 test_done "$testroot" "$ret"
94 return 1
95 fi
96 done
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
102 ret="$?"
103 if [ "$ret" != "0" ]; then
104 diff -u $testroot/stdout.expected $testroot/stdout
105 test_done "$testroot" "$ret"
106 return 1
107 fi
108 done
110 test_done "$testroot" "0"
113 function test_log_in_worktree_with_path_prefix {
114 local testroot=`test_init log_in_prefixed_worktree`
115 local head_rev=`git_show_head $testroot/repo`
117 echo "modified zeta" > $testroot/repo/epsilon/zeta
118 git_commit $testroot/repo -m "modified zeta"
119 local zeta_rev=`git_show_head $testroot/repo`
121 echo "modified delta" > $testroot/repo/gamma/delta
122 git_commit $testroot/repo -m "modified delta"
124 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
125 ret="$?"
126 if [ "$ret" != "0" ]; then
127 test_done "$testroot" "$ret"
128 return 1
129 fi
131 echo "commit $zeta_rev" > $testroot/stdout.expected
132 echo "commit $head_rev" >> $testroot/stdout.expected
134 for p in "" "." zeta; do
135 (cd $testroot/wt && got log $p | \
136 grep ^commit > $testroot/stdout)
137 cmp -s $testroot/stdout.expected $testroot/stdout
138 ret="$?"
139 if [ "$ret" != "0" ]; then
140 diff -u $testroot/stdout.expected $testroot/stdout
141 test_done "$testroot" "$ret"
142 return 1
143 fi
144 done
146 test_done "$testroot" "0"
149 function test_log_tag {
150 local testroot=`test_init log_tag`
151 local commit_id=`git_show_head $testroot/repo`
152 local tag="1.0.0"
153 local tag2="2.0.0"
155 got checkout $testroot/repo $testroot/wt > /dev/null
156 ret="$?"
157 if [ "$ret" != "0" ]; then
158 test_done "$testroot" "$ret"
159 return 1
160 fi
162 (cd $testroot/repo && git tag -a -m "test" $tag)
164 echo "commit $commit_id (master, tags/$tag)" > $testroot/stdout.expected
165 (cd $testroot/wt && got log -l1 -c $tag | grep ^commit \
166 > $testroot/stdout)
167 cmp -s $testroot/stdout.expected $testroot/stdout
168 ret="$?"
169 if [ "$ret" != "0" ]; then
170 diff -u $testroot/stdout.expected $testroot/stdout
171 test_done "$testroot" "$ret"
172 return 1
173 fi
175 # test a "leightweight" tag
176 (cd $testroot/repo && git tag $tag2)
178 echo "commit $commit_id (master, tags/$tag, tags/$tag2)" \
179 > $testroot/stdout.expected
180 (cd $testroot/wt && got log -l1 -c $tag2 | grep ^commit \
181 > $testroot/stdout)
182 cmp -s $testroot/stdout.expected $testroot/stdout
183 ret="$?"
184 if [ "$ret" != "0" ]; then
185 diff -u $testroot/stdout.expected $testroot/stdout
186 fi
187 test_done "$testroot" "$ret"
190 function test_log_limit {
191 local testroot=`test_init log_limit`
192 local commit_id0=`git_show_head $testroot/repo`
194 got checkout $testroot/repo $testroot/wt > /dev/null
195 ret="$?"
196 if [ "$ret" != "0" ]; then
197 test_done "$testroot" "$ret"
198 return 1
199 fi
201 echo "modified alpha" > $testroot/wt/alpha
202 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
203 local commit_id1=`git_show_head $testroot/repo`
205 (cd $testroot/wt && got rm beta >/dev/null)
206 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
207 local commit_id2=`git_show_head $testroot/repo`
209 echo "new file" > $testroot/wt/new
210 (cd $testroot/wt && got add new >/dev/null)
211 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
212 local commit_id3=`git_show_head $testroot/repo`
214 # -l1 should print the first commit only
215 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
216 (cd $testroot/wt && got log -l1 | grep ^commit > $testroot/stdout)
217 cmp -s $testroot/stdout.expected $testroot/stdout
218 ret="$?"
219 if [ "$ret" != "0" ]; then
220 diff -u $testroot/stdout.expected $testroot/stdout
221 test_done "$testroot" "$ret"
222 return 1
223 fi
225 # env var can be used to set a log limit without -l option
226 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
227 echo "commit $commit_id2" >> $testroot/stdout.expected
228 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=2 got log | \
229 grep ^commit > $testroot/stdout)
230 cmp -s $testroot/stdout.expected $testroot/stdout
231 ret="$?"
232 if [ "$ret" != "0" ]; then
233 diff -u $testroot/stdout.expected $testroot/stdout
234 test_done "$testroot" "$ret"
235 return 1
236 fi
238 # non-numeric env var is ignored
239 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=foobar got log | \
240 grep ^commit > $testroot/stdout)
241 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
242 echo "commit $commit_id2" >> $testroot/stdout.expected
243 echo "commit $commit_id1" >> $testroot/stdout.expected
244 echo "commit $commit_id0" >> $testroot/stdout.expected
245 cmp -s $testroot/stdout.expected $testroot/stdout
246 ret="$?"
247 if [ "$ret" != "0" ]; then
248 diff -u $testroot/stdout.expected $testroot/stdout
249 test_done "$testroot" "$ret"
250 return 1
251 fi
253 # -l option takes precedence over env var
254 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
255 echo "commit $commit_id2" >> $testroot/stdout.expected
256 echo "commit $commit_id1" >> $testroot/stdout.expected
257 echo "commit $commit_id0" >> $testroot/stdout.expected
258 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=1 got log -l0 | \
259 grep ^commit > $testroot/stdout)
260 cmp -s $testroot/stdout.expected $testroot/stdout
261 ret="$?"
262 if [ "$ret" != "0" ]; then
263 diff -u $testroot/stdout.expected $testroot/stdout
264 fi
265 test_done "$testroot" "0"
268 run_test test_log_in_repo
269 run_test test_log_in_bare_repo
270 run_test test_log_in_worktree
271 run_test test_log_in_worktree_with_path_prefix
272 run_test test_log_tag
273 run_test test_log_limit