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 f6cae3ed 2020-09-13 naddy 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 49c543a6 2022-03-31 naddy ret=$?
30 49c543a6 2022-03-31 naddy if [ $ret -ne 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 49c543a6 2022-03-31 naddy ret=$?
42 49c543a6 2022-03-31 naddy if [ $ret -ne 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 f6cae3ed 2020-09-13 naddy 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 49c543a6 2022-03-31 naddy ret=$?
63 49c543a6 2022-03-31 naddy if [ $ret -ne 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 f6cae3ed 2020-09-13 naddy 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 49c543a6 2022-03-31 naddy ret=$?
85 49c543a6 2022-03-31 naddy if [ $ret -ne 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 49c543a6 2022-03-31 naddy ret=$?
97 49c543a6 2022-03-31 naddy if [ $ret -ne 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 49c543a6 2022-03-31 naddy ret=$?
109 49c543a6 2022-03-31 naddy if [ $ret -ne 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 49c543a6 2022-03-31 naddy ret=$?
121 49c543a6 2022-03-31 naddy if [ $ret -ne 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 f6cae3ed 2020-09-13 naddy 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 603cdeb0 2020-10-22 stsp local delta_rev=`git_show_head $testroot/repo`
142 0cfcb52d 2019-08-27 stsp
143 0cfcb52d 2019-08-27 stsp got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
144 49c543a6 2022-03-31 naddy ret=$?
145 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
146 603cdeb0 2020-10-22 stsp test_done "$testroot" "$ret"
147 603cdeb0 2020-10-22 stsp return 1
148 603cdeb0 2020-10-22 stsp fi
149 603cdeb0 2020-10-22 stsp
150 603cdeb0 2020-10-22 stsp echo "commit $delta_rev (master)" > $testroot/stdout.expected
151 603cdeb0 2020-10-22 stsp echo "commit $zeta_rev" >> $testroot/stdout.expected
152 603cdeb0 2020-10-22 stsp echo "commit $head_rev" >> $testroot/stdout.expected
153 603cdeb0 2020-10-22 stsp
154 603cdeb0 2020-10-22 stsp (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
155 603cdeb0 2020-10-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
156 49c543a6 2022-03-31 naddy ret=$?
157 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
158 603cdeb0 2020-10-22 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
163 0cfcb52d 2019-08-27 stsp echo "commit $zeta_rev" > $testroot/stdout.expected
164 0cfcb52d 2019-08-27 stsp echo "commit $head_rev" >> $testroot/stdout.expected
165 0cfcb52d 2019-08-27 stsp
166 603cdeb0 2020-10-22 stsp for p in "." zeta; do
167 0cfcb52d 2019-08-27 stsp (cd $testroot/wt && got log $p | \
168 0cfcb52d 2019-08-27 stsp grep ^commit > $testroot/stdout)
169 0cfcb52d 2019-08-27 stsp cmp -s $testroot/stdout.expected $testroot/stdout
170 49c543a6 2022-03-31 naddy ret=$?
171 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
172 0cfcb52d 2019-08-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
173 0cfcb52d 2019-08-27 stsp test_done "$testroot" "$ret"
174 0cfcb52d 2019-08-27 stsp return 1
175 0cfcb52d 2019-08-27 stsp fi
176 0cfcb52d 2019-08-27 stsp done
177 0cfcb52d 2019-08-27 stsp
178 0cfcb52d 2019-08-27 stsp test_done "$testroot" "0"
179 0cfcb52d 2019-08-27 stsp }
180 0cfcb52d 2019-08-27 stsp
181 f6cae3ed 2020-09-13 naddy test_log_tag() {
182 303e2782 2019-08-09 stsp local testroot=`test_init log_tag`
183 303e2782 2019-08-09 stsp local commit_id=`git_show_head $testroot/repo`
184 303e2782 2019-08-09 stsp local tag="1.0.0"
185 5a8ddf14 2019-08-13 stsp local tag2="2.0.0"
186 303e2782 2019-08-09 stsp
187 303e2782 2019-08-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
188 49c543a6 2022-03-31 naddy ret=$?
189 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
190 303e2782 2019-08-09 stsp test_done "$testroot" "$ret"
191 303e2782 2019-08-09 stsp return 1
192 303e2782 2019-08-09 stsp fi
193 303e2782 2019-08-09 stsp
194 303e2782 2019-08-09 stsp (cd $testroot/repo && git tag -a -m "test" $tag)
195 303e2782 2019-08-09 stsp
196 a436ad14 2019-08-13 stsp echo "commit $commit_id (master, tags/$tag)" > $testroot/stdout.expected
197 303e2782 2019-08-09 stsp (cd $testroot/wt && got log -l1 -c $tag | grep ^commit \
198 303e2782 2019-08-09 stsp > $testroot/stdout)
199 303e2782 2019-08-09 stsp cmp -s $testroot/stdout.expected $testroot/stdout
200 49c543a6 2022-03-31 naddy ret=$?
201 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
202 303e2782 2019-08-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
203 5a8ddf14 2019-08-13 stsp test_done "$testroot" "$ret"
204 5a8ddf14 2019-08-13 stsp return 1
205 303e2782 2019-08-09 stsp fi
206 5a8ddf14 2019-08-13 stsp
207 992eb9d8 2020-02-07 tracey # test a "lightweight" tag
208 5a8ddf14 2019-08-13 stsp (cd $testroot/repo && git tag $tag2)
209 5a8ddf14 2019-08-13 stsp
210 5a8ddf14 2019-08-13 stsp echo "commit $commit_id (master, tags/$tag, tags/$tag2)" \
211 5a8ddf14 2019-08-13 stsp > $testroot/stdout.expected
212 5a8ddf14 2019-08-13 stsp (cd $testroot/wt && got log -l1 -c $tag2 | grep ^commit \
213 5a8ddf14 2019-08-13 stsp > $testroot/stdout)
214 5a8ddf14 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
215 49c543a6 2022-03-31 naddy ret=$?
216 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
217 5a8ddf14 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
218 5a8ddf14 2019-08-13 stsp fi
219 303e2782 2019-08-09 stsp test_done "$testroot" "$ret"
220 303e2782 2019-08-09 stsp }
221 303e2782 2019-08-09 stsp
222 f6cae3ed 2020-09-13 naddy test_log_limit() {
223 b1ebc001 2019-08-13 stsp local testroot=`test_init log_limit`
224 b1ebc001 2019-08-13 stsp local commit_id0=`git_show_head $testroot/repo`
225 303e2782 2019-08-09 stsp
226 b1ebc001 2019-08-13 stsp got checkout $testroot/repo $testroot/wt > /dev/null
227 49c543a6 2022-03-31 naddy ret=$?
228 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
229 b1ebc001 2019-08-13 stsp test_done "$testroot" "$ret"
230 b1ebc001 2019-08-13 stsp return 1
231 b1ebc001 2019-08-13 stsp fi
232 b1ebc001 2019-08-13 stsp
233 b1ebc001 2019-08-13 stsp echo "modified alpha" > $testroot/wt/alpha
234 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
235 b1ebc001 2019-08-13 stsp local commit_id1=`git_show_head $testroot/repo`
236 b1ebc001 2019-08-13 stsp
237 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got rm beta >/dev/null)
238 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
239 b1ebc001 2019-08-13 stsp local commit_id2=`git_show_head $testroot/repo`
240 b1ebc001 2019-08-13 stsp
241 b1ebc001 2019-08-13 stsp echo "new file" > $testroot/wt/new
242 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got add new >/dev/null)
243 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
244 b1ebc001 2019-08-13 stsp local commit_id3=`git_show_head $testroot/repo`
245 b1ebc001 2019-08-13 stsp
246 b1ebc001 2019-08-13 stsp # -l1 should print the first commit only
247 b1ebc001 2019-08-13 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
248 b1ebc001 2019-08-13 stsp (cd $testroot/wt && got log -l1 | grep ^commit > $testroot/stdout)
249 b1ebc001 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
250 49c543a6 2022-03-31 naddy ret=$?
251 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
252 b1ebc001 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
253 b1ebc001 2019-08-13 stsp test_done "$testroot" "$ret"
254 b1ebc001 2019-08-13 stsp return 1
255 b1ebc001 2019-08-13 stsp fi
256 b1ebc001 2019-08-13 stsp
257 b1ebc001 2019-08-13 stsp # env var can be used to set a log limit without -l option
258 b1ebc001 2019-08-13 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
259 b1ebc001 2019-08-13 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
260 b1ebc001 2019-08-13 stsp (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=2 got log | \
261 b1ebc001 2019-08-13 stsp grep ^commit > $testroot/stdout)
262 b1ebc001 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
263 49c543a6 2022-03-31 naddy ret=$?
264 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
265 b1ebc001 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
266 b1ebc001 2019-08-13 stsp test_done "$testroot" "$ret"
267 b1ebc001 2019-08-13 stsp return 1
268 b1ebc001 2019-08-13 stsp fi
269 b1ebc001 2019-08-13 stsp
270 b1ebc001 2019-08-13 stsp # non-numeric env var is ignored
271 b1ebc001 2019-08-13 stsp (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=foobar got log | \
272 b1ebc001 2019-08-13 stsp grep ^commit > $testroot/stdout)
273 b1ebc001 2019-08-13 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
274 b1ebc001 2019-08-13 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
275 b1ebc001 2019-08-13 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
276 b1ebc001 2019-08-13 stsp echo "commit $commit_id0" >> $testroot/stdout.expected
277 b1ebc001 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
278 49c543a6 2022-03-31 naddy ret=$?
279 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
280 b1ebc001 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
281 b1ebc001 2019-08-13 stsp test_done "$testroot" "$ret"
282 b1ebc001 2019-08-13 stsp return 1
283 b1ebc001 2019-08-13 stsp fi
284 b1ebc001 2019-08-13 stsp
285 b1ebc001 2019-08-13 stsp # -l option takes precedence over env var
286 b1ebc001 2019-08-13 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
287 b1ebc001 2019-08-13 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
288 b1ebc001 2019-08-13 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
289 b1ebc001 2019-08-13 stsp echo "commit $commit_id0" >> $testroot/stdout.expected
290 b1ebc001 2019-08-13 stsp (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=1 got log -l0 | \
291 b1ebc001 2019-08-13 stsp grep ^commit > $testroot/stdout)
292 b1ebc001 2019-08-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
293 49c543a6 2022-03-31 naddy ret=$?
294 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
295 b1ebc001 2019-08-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
296 b1ebc001 2019-08-13 stsp fi
297 b1ebc001 2019-08-13 stsp test_done "$testroot" "0"
298 b1ebc001 2019-08-13 stsp }
299 c1c775eb 2022-06-08 stsp
300 c1c775eb 2022-06-08 stsp test_log_oneline() {
301 c1c775eb 2022-06-08 stsp local testroot=`test_init log_oneline`
302 c1c775eb 2022-06-08 stsp local commit_id0=`git_show_head $testroot/repo`
303 c1c775eb 2022-06-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
304 c1c775eb 2022-06-08 stsp ret=$?
305 c1c775eb 2022-06-08 stsp if [ $ret -ne 0 ]; then
306 c1c775eb 2022-06-08 stsp test_done "$testroot" "$ret"
307 c1c775eb 2022-06-08 stsp return 1
308 c1c775eb 2022-06-08 stsp fi
309 2e8c69d1 2020-05-04 stsp
310 c1c775eb 2022-06-08 stsp echo "modified alpha" > $testroot/wt/alpha
311 c1c775eb 2022-06-08 stsp (cd $testroot/wt && got commit -m "test oneline
312 c1c775eb 2022-06-08 stsp no" > /dev/null)
313 c1c775eb 2022-06-08 stsp local commit_id1=`git_show_head $testroot/repo`
314 783ffc01 2022-06-13 stsp local author_time1=`git_show_author_time $testroot/repo`
315 c1c775eb 2022-06-08 stsp
316 c1c775eb 2022-06-08 stsp echo "modified beta" > $testroot/wt/beta
317 c1c775eb 2022-06-08 stsp (cd $testroot/wt && got commit -m " test oneline
318 c1c775eb 2022-06-08 stsp no" > /dev/null)
319 c1c775eb 2022-06-08 stsp local commit_id2=`git_show_head $testroot/repo`
320 783ffc01 2022-06-13 stsp local author_time2=`git_show_author_time $testroot/repo`
321 c1c775eb 2022-06-08 stsp
322 783ffc01 2022-06-13 stsp d=`date -u -r $author_time1 +"%G-%m-%d"`
323 783ffc01 2022-06-13 stsp printf "$d %-7s test oneline\n" master > $testroot/stdout.expected
324 783ffc01 2022-06-13 stsp d=`date -u -r $author_time2 +"%G-%m-%d"`
325 783ffc01 2022-06-13 stsp printf "$d %.7s test oneline\n" $commit_id1 >> $testroot/stdout.expected
326 c1c775eb 2022-06-08 stsp
327 c1c775eb 2022-06-08 stsp (cd $testroot/repo && got log -s | head -n 2 > $testroot/stdout)
328 c1c775eb 2022-06-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
329 c1c775eb 2022-06-08 stsp ret=$?
330 c1c775eb 2022-06-08 stsp if [ $ret -ne 0 ]; then
331 c1c775eb 2022-06-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
332 c1c775eb 2022-06-08 stsp test_done "$testroot" "$ret"
333 c1c775eb 2022-06-08 stsp return 1
334 c1c775eb 2022-06-08 stsp fi
335 c1c775eb 2022-06-08 stsp test_done "$testroot" "0"
336 c1c775eb 2022-06-08 stsp }
337 c1c775eb 2022-06-08 stsp
338 f6cae3ed 2020-09-13 naddy test_log_patch_added_file() {
339 2e8c69d1 2020-05-04 stsp local testroot=`test_init log_patch_added_file`
340 2e8c69d1 2020-05-04 stsp local commit_id0=`git_show_head $testroot/repo`
341 5175b31a 2020-01-04 stsp
342 2e8c69d1 2020-05-04 stsp got checkout $testroot/repo $testroot/wt > /dev/null
343 49c543a6 2022-03-31 naddy ret=$?
344 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
345 2e8c69d1 2020-05-04 stsp test_done "$testroot" "$ret"
346 2e8c69d1 2020-05-04 stsp return 1
347 2e8c69d1 2020-05-04 stsp fi
348 2e8c69d1 2020-05-04 stsp
349 2e8c69d1 2020-05-04 stsp echo "new file" > $testroot/wt/new
350 2e8c69d1 2020-05-04 stsp (cd $testroot/wt && got add new >/dev/null)
351 2e8c69d1 2020-05-04 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
352 2e8c69d1 2020-05-04 stsp local commit_id1=`git_show_head $testroot/repo`
353 2e8c69d1 2020-05-04 stsp
354 2e8c69d1 2020-05-04 stsp echo "commit $commit_id1 (master)" > $testroot/stdout.expected
355 2e8c69d1 2020-05-04 stsp # This used to fail with 'got: no such entry found in tree'
356 2e8c69d1 2020-05-04 stsp (cd $testroot/wt && got log -l1 -p new > $testroot/stdout.patch)
357 49c543a6 2022-03-31 naddy ret=$?
358 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
359 2e8c69d1 2020-05-04 stsp echo "got log command failed unexpectedly" >&2
360 2e8c69d1 2020-05-04 stsp test_done "$testroot" "$ret"
361 2e8c69d1 2020-05-04 stsp return 1
362 2e8c69d1 2020-05-04 stsp fi
363 2e8c69d1 2020-05-04 stsp grep ^commit $testroot/stdout.patch > $testroot/stdout
364 2e8c69d1 2020-05-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
365 49c543a6 2022-03-31 naddy ret=$?
366 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
367 2e8c69d1 2020-05-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
368 2e8c69d1 2020-05-04 stsp fi
369 2e8c69d1 2020-05-04 stsp test_done "$testroot" "$ret"
370 2e8c69d1 2020-05-04 stsp }
371 2e8c69d1 2020-05-04 stsp
372 f6cae3ed 2020-09-13 naddy test_log_nonexistent_path() {
373 5175b31a 2020-01-04 stsp local testroot=`test_init log_nonexistent_path`
374 5175b31a 2020-01-04 stsp local head_rev=`git_show_head $testroot/repo`
375 5175b31a 2020-01-04 stsp
376 5175b31a 2020-01-04 stsp echo "commit $head_rev (master)" > $testroot/stdout.expected
377 b1ebc001 2019-08-13 stsp
378 5175b31a 2020-01-04 stsp (cd $testroot/repo && got log this/does/not/exist \
379 5175b31a 2020-01-04 stsp > $testroot/stdout 2> $testroot/stderr)
380 49c543a6 2022-03-31 naddy ret=$?
381 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
382 5175b31a 2020-01-04 stsp echo "log command succeeded unexpectedly" >&2
383 5175b31a 2020-01-04 stsp test_done "$testroot" "1"
384 5175b31a 2020-01-04 stsp return 1
385 5175b31a 2020-01-04 stsp fi
386 5175b31a 2020-01-04 stsp
387 5175b31a 2020-01-04 stsp echo -n > $testroot/stdout.expected
388 5175b31a 2020-01-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
389 49c543a6 2022-03-31 naddy ret=$?
390 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
391 5175b31a 2020-01-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
392 5175b31a 2020-01-04 stsp test_done "$testroot" "$ret"
393 5175b31a 2020-01-04 stsp return 1
394 5175b31a 2020-01-04 stsp fi
395 5175b31a 2020-01-04 stsp
396 5175b31a 2020-01-04 stsp echo "got: this/does/not/exist: no such entry found in tree" \
397 5175b31a 2020-01-04 stsp > $testroot/stderr.expected
398 5175b31a 2020-01-04 stsp cmp -s $testroot/stderr.expected $testroot/stderr
399 49c543a6 2022-03-31 naddy ret=$?
400 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
401 5175b31a 2020-01-04 stsp diff -u $testroot/stderr.expected $testroot/stderr
402 5175b31a 2020-01-04 stsp fi
403 5175b31a 2020-01-04 stsp test_done "$testroot" "$ret"
404 5175b31a 2020-01-04 stsp }
405 d1fe46f9 2020-04-18 stsp
406 f6cae3ed 2020-09-13 naddy test_log_end_at_commit() {
407 d1fe46f9 2020-04-18 stsp local testroot=`test_init log_end_at_commit`
408 d1fe46f9 2020-04-18 stsp local commit_id0=`git_show_head $testroot/repo`
409 d1fe46f9 2020-04-18 stsp
410 d1fe46f9 2020-04-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
411 49c543a6 2022-03-31 naddy ret=$?
412 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
413 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
414 d1fe46f9 2020-04-18 stsp return 1
415 d1fe46f9 2020-04-18 stsp fi
416 d1fe46f9 2020-04-18 stsp
417 d1fe46f9 2020-04-18 stsp echo "modified alpha" > $testroot/wt/alpha
418 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
419 d1fe46f9 2020-04-18 stsp local commit_id1=`git_show_head $testroot/repo`
420 d1fe46f9 2020-04-18 stsp
421 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got rm beta >/dev/null)
422 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
423 d1fe46f9 2020-04-18 stsp local commit_id2=`git_show_head $testroot/repo`
424 d1fe46f9 2020-04-18 stsp
425 d1fe46f9 2020-04-18 stsp echo "new file" > $testroot/wt/new
426 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got add new >/dev/null)
427 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
428 d1fe46f9 2020-04-18 stsp local commit_id3=`git_show_head $testroot/repo`
429 5175b31a 2020-01-04 stsp
430 d1fe46f9 2020-04-18 stsp # Print commit 3 only
431 d1fe46f9 2020-04-18 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
432 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got log -x $commit_id3 | grep ^commit \
433 d1fe46f9 2020-04-18 stsp > $testroot/stdout)
434 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
435 49c543a6 2022-03-31 naddy ret=$?
436 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
437 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
438 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
439 d1fe46f9 2020-04-18 stsp return 1
440 d1fe46f9 2020-04-18 stsp fi
441 d1fe46f9 2020-04-18 stsp
442 d1fe46f9 2020-04-18 stsp # Print commit 3 up to commit 1 inclusive
443 d1fe46f9 2020-04-18 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
444 d1fe46f9 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
445 d1fe46f9 2020-04-18 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
446 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got log -c $commit_id3 -x $commit_id1 | \
447 d1fe46f9 2020-04-18 stsp grep ^commit > $testroot/stdout)
448 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
449 49c543a6 2022-03-31 naddy ret=$?
450 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
451 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
452 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
453 d1fe46f9 2020-04-18 stsp return 1
454 d1fe46f9 2020-04-18 stsp fi
455 d1fe46f9 2020-04-18 stsp
456 d1fe46f9 2020-04-18 stsp # Create commits on an unrelated branch
457 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got br foo > /dev/null)
458 d1fe46f9 2020-04-18 stsp echo bar >> $testroot/wt/alpha
459 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got commit -m "change on branch foo" >/dev/null)
460 d1fe46f9 2020-04-18 stsp local commit_id4=`git_show_branch_head $testroot/repo foo`
461 d1fe46f9 2020-04-18 stsp
462 d1fe46f9 2020-04-18 stsp # Print commit 4 only (in work tree)
463 d1fe46f9 2020-04-18 stsp echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
464 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got log -x foo | grep ^commit \
465 d1fe46f9 2020-04-18 stsp > $testroot/stdout)
466 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
467 49c543a6 2022-03-31 naddy ret=$?
468 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
469 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
470 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
471 d1fe46f9 2020-04-18 stsp return 1
472 d1fe46f9 2020-04-18 stsp fi
473 d1fe46f9 2020-04-18 stsp
474 d1fe46f9 2020-04-18 stsp # Print commit 4 only (in repository)
475 d1fe46f9 2020-04-18 stsp echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
476 d1fe46f9 2020-04-18 stsp (cd $testroot/repo && got log -c foo -x foo | grep ^commit \
477 d1fe46f9 2020-04-18 stsp > $testroot/stdout)
478 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
479 49c543a6 2022-03-31 naddy ret=$?
480 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
481 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
482 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
483 d1fe46f9 2020-04-18 stsp return 1
484 d1fe46f9 2020-04-18 stsp fi
485 d1fe46f9 2020-04-18 stsp
486 d1fe46f9 2020-04-18 stsp # Repository's HEAD is on master branch so -x foo without an explicit
487 d1fe46f9 2020-04-18 stsp # '-c foo' start commit has no effect there
488 d1fe46f9 2020-04-18 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
489 d1fe46f9 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
490 d1fe46f9 2020-04-18 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
491 d1fe46f9 2020-04-18 stsp echo "commit $commit_id0" >> $testroot/stdout.expected
492 d1fe46f9 2020-04-18 stsp (cd $testroot/repo && got log -x foo | grep ^commit \
493 d1fe46f9 2020-04-18 stsp > $testroot/stdout)
494 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
495 49c543a6 2022-03-31 naddy ret=$?
496 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
497 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
498 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
499 d1fe46f9 2020-04-18 stsp return 1
500 d1fe46f9 2020-04-18 stsp fi
501 d1fe46f9 2020-04-18 stsp
502 d1fe46f9 2020-04-18 stsp # got will refuse -x with a non-existent commit
503 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got log -x nonexistent \
504 d1fe46f9 2020-04-18 stsp > $testroot/stdout 2> $testroot/stderr)
505 49c543a6 2022-03-31 naddy ret=$?
506 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
507 d1fe46f9 2020-04-18 stsp echo "log command succeeded unexpectedly" >&2
508 d1fe46f9 2020-04-18 stsp test_done "$testroot" "1"
509 d1fe46f9 2020-04-18 stsp return 1
510 d1fe46f9 2020-04-18 stsp fi
511 d1fe46f9 2020-04-18 stsp echo -n > $testroot/stdout.expected
512 7f9bfb31 2020-11-01 stsp echo "got: reference nonexistent not found" \
513 d1fe46f9 2020-04-18 stsp > $testroot/stderr.expected
514 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stderr.expected $testroot/stderr
515 49c543a6 2022-03-31 naddy ret=$?
516 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
517 d1fe46f9 2020-04-18 stsp diff -u $testroot/stderr.expected $testroot/stderr
518 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
519 d1fe46f9 2020-04-18 stsp return 1
520 d1fe46f9 2020-04-18 stsp fi
521 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
522 49c543a6 2022-03-31 naddy ret=$?
523 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
524 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
525 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
526 d1fe46f9 2020-04-18 stsp return 1
527 d1fe46f9 2020-04-18 stsp fi
528 d1fe46f9 2020-04-18 stsp
529 d1fe46f9 2020-04-18 stsp # try the same with the hash of an empty string which is very
530 d1fe46f9 2020-04-18 stsp # unlikely to match any object
531 b90c3048 2020-04-19 stsp local empty_sha1=da39a3ee5e6b4b0d3255bfef95601890afd80709
532 b90c3048 2020-04-19 stsp (cd $testroot/wt && got log -x $empty_sha1 \
533 d1fe46f9 2020-04-18 stsp > $testroot/stdout 2> $testroot/stderr)
534 49c543a6 2022-03-31 naddy ret=$?
535 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
536 d1fe46f9 2020-04-18 stsp echo "log command succeeded unexpectedly" >&2
537 d1fe46f9 2020-04-18 stsp test_done "$testroot" "1"
538 d1fe46f9 2020-04-18 stsp return 1
539 d1fe46f9 2020-04-18 stsp fi
540 d1fe46f9 2020-04-18 stsp echo -n > $testroot/stdout.expected
541 138e4f47 2021-10-09 stsp echo "got: commit $empty_sha1: object not found" \
542 138e4f47 2021-10-09 stsp > $testroot/stderr.expected
543 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stderr.expected $testroot/stderr
544 49c543a6 2022-03-31 naddy ret=$?
545 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
546 d1fe46f9 2020-04-18 stsp diff -u $testroot/stderr.expected $testroot/stderr
547 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
548 d1fe46f9 2020-04-18 stsp return 1
549 d1fe46f9 2020-04-18 stsp fi
550 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
551 49c543a6 2022-03-31 naddy ret=$?
552 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
553 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
554 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
555 d1fe46f9 2020-04-18 stsp return 1
556 d1fe46f9 2020-04-18 stsp fi
557 d1fe46f9 2020-04-18 stsp
558 d1fe46f9 2020-04-18 stsp test_done "$testroot" "0"
559 d1fe46f9 2020-04-18 stsp }
560 dbec59df 2020-04-18 stsp
561 f6cae3ed 2020-09-13 naddy test_log_reverse_display() {
562 dbec59df 2020-04-18 stsp local testroot=`test_init log_reverse_display`
563 dbec59df 2020-04-18 stsp local commit_id0=`git_show_head $testroot/repo`
564 dbec59df 2020-04-18 stsp
565 dbec59df 2020-04-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
566 49c543a6 2022-03-31 naddy ret=$?
567 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
568 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
569 dbec59df 2020-04-18 stsp return 1
570 dbec59df 2020-04-18 stsp fi
571 dbec59df 2020-04-18 stsp
572 dbec59df 2020-04-18 stsp echo "modified alpha" > $testroot/wt/alpha
573 dbec59df 2020-04-18 stsp (cd $testroot/wt && got commit -m 'commit1' > /dev/null)
574 dbec59df 2020-04-18 stsp local commit_id1=`git_show_head $testroot/repo`
575 dbec59df 2020-04-18 stsp
576 dbec59df 2020-04-18 stsp (cd $testroot/wt && got rm beta >/dev/null)
577 dbec59df 2020-04-18 stsp (cd $testroot/wt && got commit -m 'commit2' > /dev/null)
578 dbec59df 2020-04-18 stsp local commit_id2=`git_show_head $testroot/repo`
579 dbec59df 2020-04-18 stsp
580 dbec59df 2020-04-18 stsp echo "new file" > $testroot/wt/new
581 dbec59df 2020-04-18 stsp (cd $testroot/wt && got add new >/dev/null)
582 dbec59df 2020-04-18 stsp (cd $testroot/wt && got commit -m 'commit3' > /dev/null)
583 dbec59df 2020-04-18 stsp local commit_id3=`git_show_head $testroot/repo`
584 d1fe46f9 2020-04-18 stsp
585 dbec59df 2020-04-18 stsp # -R alone should display all commits in reverse
586 dbec59df 2020-04-18 stsp echo "commit $commit_id0" > $testroot/stdout.expected
587 dbec59df 2020-04-18 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
588 dbec59df 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
589 dbec59df 2020-04-18 stsp echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
590 dbec59df 2020-04-18 stsp (cd $testroot/wt && got log -R | grep ^commit > $testroot/stdout)
591 dbec59df 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
592 49c543a6 2022-03-31 naddy ret=$?
593 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
594 dbec59df 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
595 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
596 dbec59df 2020-04-18 stsp return 1
597 dbec59df 2020-04-18 stsp fi
598 dbec59df 2020-04-18 stsp
599 dbec59df 2020-04-18 stsp # -R takes effect after the -l commit traversal limit
600 dbec59df 2020-04-18 stsp echo "commit $commit_id2" > $testroot/stdout.expected
601 dbec59df 2020-04-18 stsp echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
602 dbec59df 2020-04-18 stsp (cd $testroot/wt && got log -R -l2 | grep ^commit > $testroot/stdout)
603 dbec59df 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
604 49c543a6 2022-03-31 naddy ret=$?
605 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
606 dbec59df 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
607 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
608 dbec59df 2020-04-18 stsp return 1
609 dbec59df 2020-04-18 stsp fi
610 dbec59df 2020-04-18 stsp
611 dbec59df 2020-04-18 stsp # -R works with commit ranges specified via -c and -x
612 dbec59df 2020-04-18 stsp echo "commit $commit_id1" > $testroot/stdout.expected
613 dbec59df 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
614 dbec59df 2020-04-18 stsp echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
615 dbec59df 2020-04-18 stsp (cd $testroot/wt && got log -R -c $commit_id3 -x $commit_id1 | \
616 dbec59df 2020-04-18 stsp grep ^commit > $testroot/stdout)
617 dbec59df 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
618 49c543a6 2022-03-31 naddy ret=$?
619 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
620 dbec59df 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
621 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
622 a9662115 2021-08-29 naddy return 1
623 dbec59df 2020-04-18 stsp fi
624 dbec59df 2020-04-18 stsp
625 dbec59df 2020-04-18 stsp # commit matching with -s applies before -R
626 dbec59df 2020-04-18 stsp echo "commit $commit_id1" > $testroot/stdout.expected
627 dbec59df 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
628 c1c775eb 2022-06-08 stsp (cd $testroot/wt && got log -R -S 'commit[12]' | \
629 dbec59df 2020-04-18 stsp grep ^commit > $testroot/stdout)
630 dbec59df 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
631 49c543a6 2022-03-31 naddy ret=$?
632 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
633 dbec59df 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
634 502b9684 2020-07-31 stsp test_done "$testroot" "$ret"
635 502b9684 2020-07-31 stsp return 1
636 dbec59df 2020-04-18 stsp fi
637 502b9684 2020-07-31 stsp
638 502b9684 2020-07-31 stsp # -R works in combination with -P
639 502b9684 2020-07-31 stsp echo "" > $testroot/stdout.expected
640 502b9684 2020-07-31 stsp (cd $testroot/wt && got log -R -P | grep -E '^(commit| [MDmA])' \
641 502b9684 2020-07-31 stsp > $testroot/stdout)
642 502b9684 2020-07-31 stsp echo "commit $commit_id0" > $testroot/stdout.expected
643 502b9684 2020-07-31 stsp echo " A alpha" >> $testroot/stdout.expected
644 502b9684 2020-07-31 stsp echo " A beta" >> $testroot/stdout.expected
645 502b9684 2020-07-31 stsp echo " A epsilon/zeta" >> $testroot/stdout.expected
646 502b9684 2020-07-31 stsp echo " A gamma/delta" >> $testroot/stdout.expected
647 502b9684 2020-07-31 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
648 502b9684 2020-07-31 stsp echo " M alpha" >> $testroot/stdout.expected
649 502b9684 2020-07-31 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
650 502b9684 2020-07-31 stsp echo " D beta" >> $testroot/stdout.expected
651 502b9684 2020-07-31 stsp echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
652 502b9684 2020-07-31 stsp echo " A new" >> $testroot/stdout.expected
653 502b9684 2020-07-31 stsp cmp -s $testroot/stdout.expected $testroot/stdout
654 49c543a6 2022-03-31 naddy ret=$?
655 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
656 502b9684 2020-07-31 stsp diff -u $testroot/stdout.expected $testroot/stdout
657 502b9684 2020-07-31 stsp fi
658 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
659 50f2fada 2020-04-24 stsp }
660 50f2fada 2020-04-24 stsp
661 f6cae3ed 2020-09-13 naddy test_log_in_worktree_different_repo() {
662 50f2fada 2020-04-24 stsp local testroot=`test_init log_in_worktree_different_repo 1`
663 50f2fada 2020-04-24 stsp
664 50f2fada 2020-04-24 stsp make_test_tree $testroot/repo
665 50f2fada 2020-04-24 stsp mkdir -p $testroot/repo/epsilon/d
666 50f2fada 2020-04-24 stsp echo foo > $testroot/repo/epsilon/d/foo
667 50f2fada 2020-04-24 stsp (cd $testroot/repo && git add .)
668 50f2fada 2020-04-24 stsp git_commit $testroot/repo -m "adding the test tree"
669 50f2fada 2020-04-24 stsp local head_commit=`git_show_head $testroot/repo`
670 50f2fada 2020-04-24 stsp
671 50f2fada 2020-04-24 stsp got init $testroot/other-repo
672 50f2fada 2020-04-24 stsp mkdir -p $testroot/tree
673 50f2fada 2020-04-24 stsp make_test_tree $testroot/tree
674 50f2fada 2020-04-24 stsp got import -mm -b foo -r $testroot/other-repo $testroot/tree >/dev/null
675 50f2fada 2020-04-24 stsp got checkout -b foo $testroot/other-repo $testroot/wt > /dev/null
676 49c543a6 2022-03-31 naddy ret=$?
677 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
678 50f2fada 2020-04-24 stsp test_done "$testroot" "$ret"
679 50f2fada 2020-04-24 stsp return 1
680 50f2fada 2020-04-24 stsp fi
681 50f2fada 2020-04-24 stsp
682 50f2fada 2020-04-24 stsp echo "commit $head_commit (master)" > $testroot/stdout.expected
683 50f2fada 2020-04-24 stsp
684 50f2fada 2020-04-24 stsp # 'got log' used to fail with "reference refs/heads/foo not found"
685 50f2fada 2020-04-24 stsp # even though that reference belongs to an unrelated repository
686 50f2fada 2020-04-24 stsp # found via a worktree via the current working directory
687 50f2fada 2020-04-24 stsp for p in "" alpha epsilon; do
688 50f2fada 2020-04-24 stsp (cd $testroot/wt && got log -r $testroot/repo $p | \
689 50f2fada 2020-04-24 stsp grep ^commit > $testroot/stdout)
690 50f2fada 2020-04-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
691 49c543a6 2022-03-31 naddy ret=$?
692 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
693 50f2fada 2020-04-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
694 50f2fada 2020-04-24 stsp test_done "$testroot" "$ret"
695 50f2fada 2020-04-24 stsp return 1
696 50f2fada 2020-04-24 stsp fi
697 50f2fada 2020-04-24 stsp done
698 50f2fada 2020-04-24 stsp
699 50f2fada 2020-04-24 stsp for p in "" epsilon/zeta; do
700 50f2fada 2020-04-24 stsp (cd $testroot/wt/epsilon && got log -r $testroot/repo $p | \
701 50f2fada 2020-04-24 stsp grep ^commit > $testroot/stdout)
702 50f2fada 2020-04-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
703 49c543a6 2022-03-31 naddy ret=$?
704 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
705 50f2fada 2020-04-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
706 50f2fada 2020-04-24 stsp test_done "$testroot" "$ret"
707 50f2fada 2020-04-24 stsp return 1
708 50f2fada 2020-04-24 stsp fi
709 50f2fada 2020-04-24 stsp done
710 50f2fada 2020-04-24 stsp
711 50f2fada 2020-04-24 stsp for p in "" foo; do
712 50f2fada 2020-04-24 stsp (cd $testroot/wt/epsilon && got log -r $testroot/repo epsilon/d/$p | \
713 50f2fada 2020-04-24 stsp grep ^commit > $testroot/stdout)
714 50f2fada 2020-04-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
715 49c543a6 2022-03-31 naddy ret=$?
716 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
717 50f2fada 2020-04-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
718 50f2fada 2020-04-24 stsp test_done "$testroot" "$ret"
719 50f2fada 2020-04-24 stsp return 1
720 50f2fada 2020-04-24 stsp fi
721 50f2fada 2020-04-24 stsp done
722 50f2fada 2020-04-24 stsp
723 50f2fada 2020-04-24 stsp test_done "$testroot" "0"
724 dbec59df 2020-04-18 stsp }
725 0208f208 2020-05-05 stsp
726 f6cae3ed 2020-09-13 naddy test_log_changed_paths() {
727 0208f208 2020-05-05 stsp local testroot=`test_init log_changed_paths`
728 0208f208 2020-05-05 stsp local commit_id0=`git_show_head $testroot/repo`
729 0208f208 2020-05-05 stsp
730 0208f208 2020-05-05 stsp got checkout $testroot/repo $testroot/wt > /dev/null
731 49c543a6 2022-03-31 naddy ret=$?
732 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
733 0208f208 2020-05-05 stsp test_done "$testroot" "$ret"
734 0208f208 2020-05-05 stsp return 1
735 0208f208 2020-05-05 stsp fi
736 0208f208 2020-05-05 stsp
737 0208f208 2020-05-05 stsp echo "modified alpha" > $testroot/wt/alpha
738 0208f208 2020-05-05 stsp (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
739 0208f208 2020-05-05 stsp local commit_id1=`git_show_head $testroot/repo`
740 dbec59df 2020-04-18 stsp
741 0208f208 2020-05-05 stsp (cd $testroot/wt && got rm beta >/dev/null)
742 0208f208 2020-05-05 stsp (cd $testroot/wt && chmod +x epsilon/zeta >/dev/null)
743 0208f208 2020-05-05 stsp (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
744 0208f208 2020-05-05 stsp local commit_id2=`git_show_head $testroot/repo`
745 0208f208 2020-05-05 stsp
746 0208f208 2020-05-05 stsp echo "new file" > $testroot/wt/new
747 0208f208 2020-05-05 stsp (cd $testroot/wt && got add new >/dev/null)
748 0208f208 2020-05-05 stsp (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
749 0208f208 2020-05-05 stsp local commit_id3=`git_show_head $testroot/repo`
750 0208f208 2020-05-05 stsp
751 0208f208 2020-05-05 stsp (cd $testroot/wt && got log -P | grep '^ [MDmA]' > $testroot/stdout)
752 0208f208 2020-05-05 stsp
753 0208f208 2020-05-05 stsp echo " A new" > $testroot/stdout.expected
754 0208f208 2020-05-05 stsp echo " D beta" >> $testroot/stdout.expected
755 0208f208 2020-05-05 stsp echo " m epsilon/zeta" >> $testroot/stdout.expected
756 0208f208 2020-05-05 stsp echo " M alpha" >> $testroot/stdout.expected
757 0208f208 2020-05-05 stsp echo " A alpha" >> $testroot/stdout.expected
758 0208f208 2020-05-05 stsp echo " A beta" >> $testroot/stdout.expected
759 0208f208 2020-05-05 stsp echo " A epsilon/zeta" >> $testroot/stdout.expected
760 0208f208 2020-05-05 stsp echo " A gamma/delta" >> $testroot/stdout.expected
761 e7303626 2020-05-14 stsp
762 e7303626 2020-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
763 49c543a6 2022-03-31 naddy ret=$?
764 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
765 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
766 e7303626 2020-05-14 stsp fi
767 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
768 e7303626 2020-05-14 stsp }
769 e7303626 2020-05-14 stsp
770 f6cae3ed 2020-09-13 naddy test_log_submodule() {
771 e7303626 2020-05-14 stsp local testroot=`test_init log_submodule`
772 e7303626 2020-05-14 stsp
773 e7303626 2020-05-14 stsp make_single_file_repo $testroot/repo2 foo
774 e7303626 2020-05-14 stsp
775 e7303626 2020-05-14 stsp (cd $testroot/repo && git submodule -q add ../repo2)
776 e7303626 2020-05-14 stsp (cd $testroot/repo && git commit -q -m 'adding submodule')
777 e7303626 2020-05-14 stsp local head_commit=`git_show_head $testroot/repo`
778 e7303626 2020-05-14 stsp
779 e7303626 2020-05-14 stsp echo "commit $head_commit (master)" > $testroot/stdout.expected
780 e7303626 2020-05-14 stsp
781 e7303626 2020-05-14 stsp got log -r $testroot/repo -l1 repo2 | grep ^commit > $testroot/stdout
782 e7303626 2020-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
783 49c543a6 2022-03-31 naddy ret=$?
784 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
785 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
786 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
787 e7303626 2020-05-14 stsp return 1
788 e7303626 2020-05-14 stsp fi
789 e7303626 2020-05-14 stsp
790 e7303626 2020-05-14 stsp echo " A .gitmodules" > $testroot/stdout.expected
791 e7303626 2020-05-14 stsp
792 e7303626 2020-05-14 stsp got log -r $testroot/repo -l1 -P repo2 | grep '^ [MDmA]' \
793 e7303626 2020-05-14 stsp > $testroot/stdout
794 e7303626 2020-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
795 49c543a6 2022-03-31 naddy ret=$?
796 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
797 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
798 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
799 e7303626 2020-05-14 stsp return 1
800 e7303626 2020-05-14 stsp fi
801 e7303626 2020-05-14 stsp
802 e7303626 2020-05-14 stsp got log -p -r $testroot/repo -l1 repo2 \
803 e7303626 2020-05-14 stsp > $testroot/stdout 2> $testroot/stderr
804 49c543a6 2022-03-31 naddy ret=$?
805 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
806 e7303626 2020-05-14 stsp echo "log command succeeded unexpectedly" >&2
807 e7303626 2020-05-14 stsp test_done "$testroot" "1"
808 e7303626 2020-05-14 stsp return 1
809 e7303626 2020-05-14 stsp fi
810 e7303626 2020-05-14 stsp local submodule_id=$(got tree -r $testroot/repo -i | \
811 e7303626 2020-05-14 stsp grep 'repo2\$$' | cut -d ' ' -f1)
812 e7303626 2020-05-14 stsp echo "got: object $submodule_id not found" > $testroot/stderr.expected
813 0208f208 2020-05-05 stsp
814 e7303626 2020-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
815 49c543a6 2022-03-31 naddy ret=$?
816 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
817 e7303626 2020-05-14 stsp diff -u $testroot/stderr.expected $testroot/stderr
818 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
819 e7303626 2020-05-14 stsp return 1
820 e7303626 2020-05-14 stsp fi
821 e7303626 2020-05-14 stsp
822 e7303626 2020-05-14 stsp echo "modified foo" > $testroot/repo2/foo
823 e7303626 2020-05-14 stsp (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
824 e7303626 2020-05-14 stsp
825 e7303626 2020-05-14 stsp # Update the repo/repo2 submodule link
826 e7303626 2020-05-14 stsp (cd $testroot/repo && git -C repo2 pull -q)
827 e7303626 2020-05-14 stsp (cd $testroot/repo && git add repo2)
828 e7303626 2020-05-14 stsp git_commit $testroot/repo -m "changed submodule link"
829 e7303626 2020-05-14 stsp
830 e7303626 2020-05-14 stsp # log -P does not show the changed submodule path
831 e7303626 2020-05-14 stsp got log -P -r $testroot/repo -l1 repo2 > $testroot/stdout.full
832 49c543a6 2022-03-31 naddy ret=$?
833 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
834 e7303626 2020-05-14 stsp echo "log command failed unexpectedly" >&2
835 e7303626 2020-05-14 stsp test_done "$testroot" "1"
836 e7303626 2020-05-14 stsp return 1
837 e7303626 2020-05-14 stsp fi
838 e7303626 2020-05-14 stsp grep '^ [MDmA]' $testroot/stdout.full > $testroot/stdout
839 e7303626 2020-05-14 stsp
840 e7303626 2020-05-14 stsp echo -n > $testroot/stdout.expected
841 0208f208 2020-05-05 stsp cmp -s $testroot/stdout.expected $testroot/stdout
842 49c543a6 2022-03-31 naddy ret=$?
843 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
844 0208f208 2020-05-05 stsp diff -u $testroot/stdout.expected $testroot/stdout
845 0208f208 2020-05-05 stsp fi
846 0208f208 2020-05-05 stsp test_done "$testroot" "$ret"
847 0208f208 2020-05-05 stsp }
848 0208f208 2020-05-05 stsp
849 7fb414ae 2020-08-08 stsp test_parseargs "$@"
850 e7301579 2019-03-18 stsp run_test test_log_in_repo
851 b70703ad 2019-03-18 stsp run_test test_log_in_bare_repo
852 cbd1af7a 2019-03-18 stsp run_test test_log_in_worktree
853 dfe70b4b 2019-08-27 stsp run_test test_log_in_worktree_with_path_prefix
854 303e2782 2019-08-09 stsp run_test test_log_tag
855 b1ebc001 2019-08-13 stsp run_test test_log_limit
856 c1c775eb 2022-06-08 stsp run_test test_log_oneline
857 2e8c69d1 2020-05-04 stsp run_test test_log_patch_added_file
858 5175b31a 2020-01-04 stsp run_test test_log_nonexistent_path
859 d1fe46f9 2020-04-18 stsp run_test test_log_end_at_commit
860 dbec59df 2020-04-18 stsp run_test test_log_reverse_display
861 50f2fada 2020-04-24 stsp run_test test_log_in_worktree_different_repo
862 0208f208 2020-05-05 stsp run_test test_log_changed_paths
863 e7303626 2020-05-14 stsp run_test test_log_submodule