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 2e8c69d1 2020-05-04 stsp
286 2e8c69d1 2020-05-04 stsp function test_log_patch_added_file {
287 2e8c69d1 2020-05-04 stsp local testroot=`test_init log_patch_added_file`
288 2e8c69d1 2020-05-04 stsp local commit_id0=`git_show_head $testroot/repo`
289 5175b31a 2020-01-04 stsp
290 2e8c69d1 2020-05-04 stsp got checkout $testroot/repo $testroot/wt > /dev/null
291 2e8c69d1 2020-05-04 stsp ret="$?"
292 2e8c69d1 2020-05-04 stsp if [ "$ret" != "0" ]; then
293 2e8c69d1 2020-05-04 stsp test_done "$testroot" "$ret"
294 2e8c69d1 2020-05-04 stsp return 1
295 2e8c69d1 2020-05-04 stsp fi
296 2e8c69d1 2020-05-04 stsp
297 2e8c69d1 2020-05-04 stsp echo "new file" > $testroot/wt/new
298 2e8c69d1 2020-05-04 stsp (cd $testroot/wt && got add new >/dev/null)
299 2e8c69d1 2020-05-04 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
300 2e8c69d1 2020-05-04 stsp local commit_id1=`git_show_head $testroot/repo`
301 2e8c69d1 2020-05-04 stsp
302 2e8c69d1 2020-05-04 stsp echo "commit $commit_id1 (master)" > $testroot/stdout.expected
303 2e8c69d1 2020-05-04 stsp # This used to fail with 'got: no such entry found in tree'
304 2e8c69d1 2020-05-04 stsp (cd $testroot/wt && got log -l1 -p new > $testroot/stdout.patch)
305 2e8c69d1 2020-05-04 stsp ret="$?"
306 2e8c69d1 2020-05-04 stsp if [ "$ret" != "0" ]; then
307 2e8c69d1 2020-05-04 stsp echo "got log command failed unexpectedly" >&2
308 2e8c69d1 2020-05-04 stsp test_done "$testroot" "$ret"
309 2e8c69d1 2020-05-04 stsp return 1
310 2e8c69d1 2020-05-04 stsp fi
311 2e8c69d1 2020-05-04 stsp grep ^commit $testroot/stdout.patch > $testroot/stdout
312 2e8c69d1 2020-05-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
313 2e8c69d1 2020-05-04 stsp ret="$?"
314 2e8c69d1 2020-05-04 stsp if [ "$ret" != "0" ]; then
315 2e8c69d1 2020-05-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
316 2e8c69d1 2020-05-04 stsp fi
317 2e8c69d1 2020-05-04 stsp test_done "$testroot" "$ret"
318 2e8c69d1 2020-05-04 stsp }
319 2e8c69d1 2020-05-04 stsp
320 5175b31a 2020-01-04 stsp function test_log_nonexistent_path {
321 5175b31a 2020-01-04 stsp local testroot=`test_init log_nonexistent_path`
322 5175b31a 2020-01-04 stsp local head_rev=`git_show_head $testroot/repo`
323 5175b31a 2020-01-04 stsp
324 5175b31a 2020-01-04 stsp echo "commit $head_rev (master)" > $testroot/stdout.expected
325 b1ebc001 2019-08-13 stsp
326 5175b31a 2020-01-04 stsp (cd $testroot/repo && got log this/does/not/exist \
327 5175b31a 2020-01-04 stsp > $testroot/stdout 2> $testroot/stderr)
328 5175b31a 2020-01-04 stsp ret="$?"
329 5175b31a 2020-01-04 stsp if [ "$ret" == "0" ]; then
330 5175b31a 2020-01-04 stsp echo "log command succeeded unexpectedly" >&2
331 5175b31a 2020-01-04 stsp test_done "$testroot" "1"
332 5175b31a 2020-01-04 stsp return 1
333 5175b31a 2020-01-04 stsp fi
334 5175b31a 2020-01-04 stsp
335 5175b31a 2020-01-04 stsp echo -n > $testroot/stdout.expected
336 5175b31a 2020-01-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
337 5175b31a 2020-01-04 stsp ret="$?"
338 5175b31a 2020-01-04 stsp if [ "$ret" != "0" ]; then
339 5175b31a 2020-01-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
340 5175b31a 2020-01-04 stsp test_done "$testroot" "$ret"
341 5175b31a 2020-01-04 stsp return 1
342 5175b31a 2020-01-04 stsp fi
343 5175b31a 2020-01-04 stsp
344 5175b31a 2020-01-04 stsp echo "got: this/does/not/exist: no such entry found in tree" \
345 5175b31a 2020-01-04 stsp > $testroot/stderr.expected
346 5175b31a 2020-01-04 stsp cmp -s $testroot/stderr.expected $testroot/stderr
347 5175b31a 2020-01-04 stsp ret="$?"
348 5175b31a 2020-01-04 stsp if [ "$ret" != "0" ]; then
349 5175b31a 2020-01-04 stsp diff -u $testroot/stderr.expected $testroot/stderr
350 5175b31a 2020-01-04 stsp fi
351 5175b31a 2020-01-04 stsp test_done "$testroot" "$ret"
352 5175b31a 2020-01-04 stsp }
353 d1fe46f9 2020-04-18 stsp
354 d1fe46f9 2020-04-18 stsp function test_log_end_at_commit {
355 d1fe46f9 2020-04-18 stsp local testroot=`test_init log_end_at_commit`
356 d1fe46f9 2020-04-18 stsp local commit_id0=`git_show_head $testroot/repo`
357 d1fe46f9 2020-04-18 stsp
358 d1fe46f9 2020-04-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
359 d1fe46f9 2020-04-18 stsp ret="$?"
360 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
361 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
362 d1fe46f9 2020-04-18 stsp return 1
363 d1fe46f9 2020-04-18 stsp fi
364 d1fe46f9 2020-04-18 stsp
365 d1fe46f9 2020-04-18 stsp echo "modified alpha" > $testroot/wt/alpha
366 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
367 d1fe46f9 2020-04-18 stsp local commit_id1=`git_show_head $testroot/repo`
368 d1fe46f9 2020-04-18 stsp
369 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got rm beta >/dev/null)
370 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
371 d1fe46f9 2020-04-18 stsp local commit_id2=`git_show_head $testroot/repo`
372 d1fe46f9 2020-04-18 stsp
373 d1fe46f9 2020-04-18 stsp echo "new file" > $testroot/wt/new
374 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got add new >/dev/null)
375 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
376 d1fe46f9 2020-04-18 stsp local commit_id3=`git_show_head $testroot/repo`
377 5175b31a 2020-01-04 stsp
378 d1fe46f9 2020-04-18 stsp # Print commit 3 only
379 d1fe46f9 2020-04-18 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
380 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got log -x $commit_id3 | grep ^commit \
381 d1fe46f9 2020-04-18 stsp > $testroot/stdout)
382 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
383 d1fe46f9 2020-04-18 stsp ret="$?"
384 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
385 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
386 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
387 d1fe46f9 2020-04-18 stsp return 1
388 d1fe46f9 2020-04-18 stsp fi
389 d1fe46f9 2020-04-18 stsp
390 d1fe46f9 2020-04-18 stsp # Print commit 3 up to commit 1 inclusive
391 d1fe46f9 2020-04-18 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
392 d1fe46f9 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
393 d1fe46f9 2020-04-18 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
394 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got log -c $commit_id3 -x $commit_id1 | \
395 d1fe46f9 2020-04-18 stsp grep ^commit > $testroot/stdout)
396 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
397 d1fe46f9 2020-04-18 stsp ret="$?"
398 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
399 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
400 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
401 d1fe46f9 2020-04-18 stsp return 1
402 d1fe46f9 2020-04-18 stsp fi
403 d1fe46f9 2020-04-18 stsp
404 d1fe46f9 2020-04-18 stsp # Create commits on an unrelated branch
405 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got br foo > /dev/null)
406 d1fe46f9 2020-04-18 stsp echo bar >> $testroot/wt/alpha
407 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got commit -m "change on branch foo" >/dev/null)
408 d1fe46f9 2020-04-18 stsp local commit_id4=`git_show_branch_head $testroot/repo foo`
409 d1fe46f9 2020-04-18 stsp
410 d1fe46f9 2020-04-18 stsp # Print commit 4 only (in work tree)
411 d1fe46f9 2020-04-18 stsp echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
412 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got log -x foo | grep ^commit \
413 d1fe46f9 2020-04-18 stsp > $testroot/stdout)
414 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
415 d1fe46f9 2020-04-18 stsp ret="$?"
416 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
417 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
418 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
419 d1fe46f9 2020-04-18 stsp return 1
420 d1fe46f9 2020-04-18 stsp fi
421 d1fe46f9 2020-04-18 stsp
422 d1fe46f9 2020-04-18 stsp # Print commit 4 only (in repository)
423 d1fe46f9 2020-04-18 stsp echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
424 d1fe46f9 2020-04-18 stsp (cd $testroot/repo && got log -c foo -x foo | grep ^commit \
425 d1fe46f9 2020-04-18 stsp > $testroot/stdout)
426 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
427 d1fe46f9 2020-04-18 stsp ret="$?"
428 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
429 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
430 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
431 d1fe46f9 2020-04-18 stsp return 1
432 d1fe46f9 2020-04-18 stsp fi
433 d1fe46f9 2020-04-18 stsp
434 d1fe46f9 2020-04-18 stsp # Repository's HEAD is on master branch so -x foo without an explicit
435 d1fe46f9 2020-04-18 stsp # '-c foo' start commit has no effect there
436 d1fe46f9 2020-04-18 stsp echo "commit $commit_id3 (master)" > $testroot/stdout.expected
437 d1fe46f9 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
438 d1fe46f9 2020-04-18 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
439 d1fe46f9 2020-04-18 stsp echo "commit $commit_id0" >> $testroot/stdout.expected
440 d1fe46f9 2020-04-18 stsp (cd $testroot/repo && got log -x foo | grep ^commit \
441 d1fe46f9 2020-04-18 stsp > $testroot/stdout)
442 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
443 d1fe46f9 2020-04-18 stsp ret="$?"
444 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
445 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
446 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
447 d1fe46f9 2020-04-18 stsp return 1
448 d1fe46f9 2020-04-18 stsp fi
449 d1fe46f9 2020-04-18 stsp
450 d1fe46f9 2020-04-18 stsp # got will refuse -x with a non-existent commit
451 d1fe46f9 2020-04-18 stsp (cd $testroot/wt && got log -x nonexistent \
452 d1fe46f9 2020-04-18 stsp > $testroot/stdout 2> $testroot/stderr)
453 d1fe46f9 2020-04-18 stsp ret="$?"
454 d1fe46f9 2020-04-18 stsp if [ "$ret" == "0" ]; then
455 d1fe46f9 2020-04-18 stsp echo "log command succeeded unexpectedly" >&2
456 d1fe46f9 2020-04-18 stsp test_done "$testroot" "1"
457 d1fe46f9 2020-04-18 stsp return 1
458 d1fe46f9 2020-04-18 stsp fi
459 d1fe46f9 2020-04-18 stsp echo -n > $testroot/stdout.expected
460 d1fe46f9 2020-04-18 stsp echo "got: nonexistent: bad object id string" \
461 d1fe46f9 2020-04-18 stsp > $testroot/stderr.expected
462 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stderr.expected $testroot/stderr
463 d1fe46f9 2020-04-18 stsp ret="$?"
464 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
465 d1fe46f9 2020-04-18 stsp diff -u $testroot/stderr.expected $testroot/stderr
466 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
467 d1fe46f9 2020-04-18 stsp return 1
468 d1fe46f9 2020-04-18 stsp fi
469 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
470 d1fe46f9 2020-04-18 stsp ret="$?"
471 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
472 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
473 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
474 d1fe46f9 2020-04-18 stsp return 1
475 d1fe46f9 2020-04-18 stsp fi
476 d1fe46f9 2020-04-18 stsp
477 d1fe46f9 2020-04-18 stsp # try the same with the hash of an empty string which is very
478 d1fe46f9 2020-04-18 stsp # unlikely to match any object
479 b90c3048 2020-04-19 stsp local empty_sha1=da39a3ee5e6b4b0d3255bfef95601890afd80709
480 b90c3048 2020-04-19 stsp (cd $testroot/wt && got log -x $empty_sha1 \
481 d1fe46f9 2020-04-18 stsp > $testroot/stdout 2> $testroot/stderr)
482 d1fe46f9 2020-04-18 stsp ret="$?"
483 d1fe46f9 2020-04-18 stsp if [ "$ret" == "0" ]; then
484 d1fe46f9 2020-04-18 stsp echo "log command succeeded unexpectedly" >&2
485 d1fe46f9 2020-04-18 stsp test_done "$testroot" "1"
486 d1fe46f9 2020-04-18 stsp return 1
487 d1fe46f9 2020-04-18 stsp fi
488 d1fe46f9 2020-04-18 stsp echo -n > $testroot/stdout.expected
489 b90c3048 2020-04-19 stsp echo "got: $empty_sha1: object not found" > $testroot/stderr.expected
490 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stderr.expected $testroot/stderr
491 d1fe46f9 2020-04-18 stsp ret="$?"
492 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
493 d1fe46f9 2020-04-18 stsp diff -u $testroot/stderr.expected $testroot/stderr
494 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
495 d1fe46f9 2020-04-18 stsp return 1
496 d1fe46f9 2020-04-18 stsp fi
497 d1fe46f9 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
498 d1fe46f9 2020-04-18 stsp ret="$?"
499 d1fe46f9 2020-04-18 stsp if [ "$ret" != "0" ]; then
500 d1fe46f9 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
501 d1fe46f9 2020-04-18 stsp test_done "$testroot" "$ret"
502 d1fe46f9 2020-04-18 stsp return 1
503 d1fe46f9 2020-04-18 stsp fi
504 d1fe46f9 2020-04-18 stsp
505 d1fe46f9 2020-04-18 stsp test_done "$testroot" "0"
506 d1fe46f9 2020-04-18 stsp }
507 dbec59df 2020-04-18 stsp
508 dbec59df 2020-04-18 stsp function test_log_reverse_display {
509 dbec59df 2020-04-18 stsp local testroot=`test_init log_reverse_display`
510 dbec59df 2020-04-18 stsp local commit_id0=`git_show_head $testroot/repo`
511 dbec59df 2020-04-18 stsp
512 dbec59df 2020-04-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
513 dbec59df 2020-04-18 stsp ret="$?"
514 dbec59df 2020-04-18 stsp if [ "$ret" != "0" ]; then
515 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
516 dbec59df 2020-04-18 stsp return 1
517 dbec59df 2020-04-18 stsp fi
518 dbec59df 2020-04-18 stsp
519 dbec59df 2020-04-18 stsp echo "modified alpha" > $testroot/wt/alpha
520 dbec59df 2020-04-18 stsp (cd $testroot/wt && got commit -m 'commit1' > /dev/null)
521 dbec59df 2020-04-18 stsp local commit_id1=`git_show_head $testroot/repo`
522 dbec59df 2020-04-18 stsp
523 dbec59df 2020-04-18 stsp (cd $testroot/wt && got rm beta >/dev/null)
524 dbec59df 2020-04-18 stsp (cd $testroot/wt && got commit -m 'commit2' > /dev/null)
525 dbec59df 2020-04-18 stsp local commit_id2=`git_show_head $testroot/repo`
526 dbec59df 2020-04-18 stsp
527 dbec59df 2020-04-18 stsp echo "new file" > $testroot/wt/new
528 dbec59df 2020-04-18 stsp (cd $testroot/wt && got add new >/dev/null)
529 dbec59df 2020-04-18 stsp (cd $testroot/wt && got commit -m 'commit3' > /dev/null)
530 dbec59df 2020-04-18 stsp local commit_id3=`git_show_head $testroot/repo`
531 d1fe46f9 2020-04-18 stsp
532 dbec59df 2020-04-18 stsp # -R alone should display all commits in reverse
533 dbec59df 2020-04-18 stsp echo "commit $commit_id0" > $testroot/stdout.expected
534 dbec59df 2020-04-18 stsp echo "commit $commit_id1" >> $testroot/stdout.expected
535 dbec59df 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
536 dbec59df 2020-04-18 stsp echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
537 dbec59df 2020-04-18 stsp (cd $testroot/wt && got log -R | grep ^commit > $testroot/stdout)
538 dbec59df 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
539 dbec59df 2020-04-18 stsp ret="$?"
540 dbec59df 2020-04-18 stsp if [ "$ret" != "0" ]; then
541 dbec59df 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
542 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
543 dbec59df 2020-04-18 stsp return 1
544 dbec59df 2020-04-18 stsp fi
545 dbec59df 2020-04-18 stsp
546 dbec59df 2020-04-18 stsp # -R takes effect after the -l commit traversal limit
547 dbec59df 2020-04-18 stsp echo "commit $commit_id2" > $testroot/stdout.expected
548 dbec59df 2020-04-18 stsp echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
549 dbec59df 2020-04-18 stsp (cd $testroot/wt && got log -R -l2 | grep ^commit > $testroot/stdout)
550 dbec59df 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
551 dbec59df 2020-04-18 stsp ret="$?"
552 dbec59df 2020-04-18 stsp if [ "$ret" != "0" ]; then
553 dbec59df 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
554 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
555 dbec59df 2020-04-18 stsp return 1
556 dbec59df 2020-04-18 stsp fi
557 dbec59df 2020-04-18 stsp
558 dbec59df 2020-04-18 stsp # -R works with commit ranges specified via -c and -x
559 dbec59df 2020-04-18 stsp echo "commit $commit_id1" > $testroot/stdout.expected
560 dbec59df 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
561 dbec59df 2020-04-18 stsp echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
562 dbec59df 2020-04-18 stsp (cd $testroot/wt && got log -R -c $commit_id3 -x $commit_id1 | \
563 dbec59df 2020-04-18 stsp grep ^commit > $testroot/stdout)
564 dbec59df 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
565 dbec59df 2020-04-18 stsp ret="$?"
566 dbec59df 2020-04-18 stsp if [ "$ret" != "0" ]; then
567 dbec59df 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
568 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
569 dbec59df 2020-04-18 stsp fi
570 dbec59df 2020-04-18 stsp
571 dbec59df 2020-04-18 stsp # commit matching with -s applies before -R
572 dbec59df 2020-04-18 stsp echo "commit $commit_id1" > $testroot/stdout.expected
573 dbec59df 2020-04-18 stsp echo "commit $commit_id2" >> $testroot/stdout.expected
574 dbec59df 2020-04-18 stsp (cd $testroot/wt && got log -R -s 'commit[12]' | \
575 dbec59df 2020-04-18 stsp grep ^commit > $testroot/stdout)
576 dbec59df 2020-04-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
577 dbec59df 2020-04-18 stsp ret="$?"
578 dbec59df 2020-04-18 stsp if [ "$ret" != "0" ]; then
579 dbec59df 2020-04-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
580 dbec59df 2020-04-18 stsp fi
581 dbec59df 2020-04-18 stsp test_done "$testroot" "$ret"
582 50f2fada 2020-04-24 stsp }
583 50f2fada 2020-04-24 stsp
584 50f2fada 2020-04-24 stsp function test_log_in_worktree_different_repo {
585 50f2fada 2020-04-24 stsp local testroot=`test_init log_in_worktree_different_repo 1`
586 50f2fada 2020-04-24 stsp
587 50f2fada 2020-04-24 stsp make_test_tree $testroot/repo
588 50f2fada 2020-04-24 stsp mkdir -p $testroot/repo/epsilon/d
589 50f2fada 2020-04-24 stsp echo foo > $testroot/repo/epsilon/d/foo
590 50f2fada 2020-04-24 stsp (cd $testroot/repo && git add .)
591 50f2fada 2020-04-24 stsp git_commit $testroot/repo -m "adding the test tree"
592 50f2fada 2020-04-24 stsp local head_commit=`git_show_head $testroot/repo`
593 50f2fada 2020-04-24 stsp
594 50f2fada 2020-04-24 stsp got init $testroot/other-repo
595 50f2fada 2020-04-24 stsp mkdir -p $testroot/tree
596 50f2fada 2020-04-24 stsp make_test_tree $testroot/tree
597 50f2fada 2020-04-24 stsp got import -mm -b foo -r $testroot/other-repo $testroot/tree >/dev/null
598 50f2fada 2020-04-24 stsp got checkout -b foo $testroot/other-repo $testroot/wt > /dev/null
599 50f2fada 2020-04-24 stsp ret="$?"
600 50f2fada 2020-04-24 stsp if [ "$ret" != "0" ]; then
601 50f2fada 2020-04-24 stsp test_done "$testroot" "$ret"
602 50f2fada 2020-04-24 stsp return 1
603 50f2fada 2020-04-24 stsp fi
604 50f2fada 2020-04-24 stsp
605 50f2fada 2020-04-24 stsp echo "commit $head_commit (master)" > $testroot/stdout.expected
606 50f2fada 2020-04-24 stsp
607 50f2fada 2020-04-24 stsp # 'got log' used to fail with "reference refs/heads/foo not found"
608 50f2fada 2020-04-24 stsp # even though that reference belongs to an unrelated repository
609 50f2fada 2020-04-24 stsp # found via a worktree via the current working directory
610 50f2fada 2020-04-24 stsp for p in "" alpha epsilon; do
611 50f2fada 2020-04-24 stsp (cd $testroot/wt && got log -r $testroot/repo $p | \
612 50f2fada 2020-04-24 stsp grep ^commit > $testroot/stdout)
613 50f2fada 2020-04-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
614 50f2fada 2020-04-24 stsp ret="$?"
615 50f2fada 2020-04-24 stsp if [ "$ret" != "0" ]; then
616 50f2fada 2020-04-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
617 50f2fada 2020-04-24 stsp test_done "$testroot" "$ret"
618 50f2fada 2020-04-24 stsp return 1
619 50f2fada 2020-04-24 stsp fi
620 50f2fada 2020-04-24 stsp done
621 50f2fada 2020-04-24 stsp
622 50f2fada 2020-04-24 stsp for p in "" epsilon/zeta; do
623 50f2fada 2020-04-24 stsp (cd $testroot/wt/epsilon && got log -r $testroot/repo $p | \
624 50f2fada 2020-04-24 stsp grep ^commit > $testroot/stdout)
625 50f2fada 2020-04-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
626 50f2fada 2020-04-24 stsp ret="$?"
627 50f2fada 2020-04-24 stsp if [ "$ret" != "0" ]; then
628 50f2fada 2020-04-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
629 50f2fada 2020-04-24 stsp test_done "$testroot" "$ret"
630 50f2fada 2020-04-24 stsp return 1
631 50f2fada 2020-04-24 stsp fi
632 50f2fada 2020-04-24 stsp done
633 50f2fada 2020-04-24 stsp
634 50f2fada 2020-04-24 stsp for p in "" foo; do
635 50f2fada 2020-04-24 stsp (cd $testroot/wt/epsilon && got log -r $testroot/repo epsilon/d/$p | \
636 50f2fada 2020-04-24 stsp grep ^commit > $testroot/stdout)
637 50f2fada 2020-04-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
638 50f2fada 2020-04-24 stsp ret="$?"
639 50f2fada 2020-04-24 stsp if [ "$ret" != "0" ]; then
640 50f2fada 2020-04-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
641 50f2fada 2020-04-24 stsp test_done "$testroot" "$ret"
642 50f2fada 2020-04-24 stsp return 1
643 50f2fada 2020-04-24 stsp fi
644 50f2fada 2020-04-24 stsp done
645 50f2fada 2020-04-24 stsp
646 50f2fada 2020-04-24 stsp test_done "$testroot" "0"
647 dbec59df 2020-04-18 stsp }
648 0208f208 2020-05-05 stsp
649 0208f208 2020-05-05 stsp function test_log_changed_paths {
650 0208f208 2020-05-05 stsp local testroot=`test_init log_changed_paths`
651 0208f208 2020-05-05 stsp local commit_id0=`git_show_head $testroot/repo`
652 0208f208 2020-05-05 stsp
653 0208f208 2020-05-05 stsp got checkout $testroot/repo $testroot/wt > /dev/null
654 0208f208 2020-05-05 stsp ret="$?"
655 0208f208 2020-05-05 stsp if [ "$ret" != "0" ]; then
656 0208f208 2020-05-05 stsp test_done "$testroot" "$ret"
657 0208f208 2020-05-05 stsp return 1
658 0208f208 2020-05-05 stsp fi
659 0208f208 2020-05-05 stsp
660 0208f208 2020-05-05 stsp echo "modified alpha" > $testroot/wt/alpha
661 0208f208 2020-05-05 stsp (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
662 0208f208 2020-05-05 stsp local commit_id1=`git_show_head $testroot/repo`
663 dbec59df 2020-04-18 stsp
664 0208f208 2020-05-05 stsp (cd $testroot/wt && got rm beta >/dev/null)
665 0208f208 2020-05-05 stsp (cd $testroot/wt && chmod +x epsilon/zeta >/dev/null)
666 0208f208 2020-05-05 stsp (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
667 0208f208 2020-05-05 stsp local commit_id2=`git_show_head $testroot/repo`
668 0208f208 2020-05-05 stsp
669 0208f208 2020-05-05 stsp echo "new file" > $testroot/wt/new
670 0208f208 2020-05-05 stsp (cd $testroot/wt && got add new >/dev/null)
671 0208f208 2020-05-05 stsp (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
672 0208f208 2020-05-05 stsp local commit_id3=`git_show_head $testroot/repo`
673 0208f208 2020-05-05 stsp
674 0208f208 2020-05-05 stsp (cd $testroot/wt && got log -P | grep '^ [MDmA]' > $testroot/stdout)
675 0208f208 2020-05-05 stsp
676 0208f208 2020-05-05 stsp echo " A new" > $testroot/stdout.expected
677 0208f208 2020-05-05 stsp echo " D beta" >> $testroot/stdout.expected
678 0208f208 2020-05-05 stsp echo " m epsilon/zeta" >> $testroot/stdout.expected
679 0208f208 2020-05-05 stsp echo " M alpha" >> $testroot/stdout.expected
680 0208f208 2020-05-05 stsp echo " A alpha" >> $testroot/stdout.expected
681 0208f208 2020-05-05 stsp echo " A beta" >> $testroot/stdout.expected
682 0208f208 2020-05-05 stsp echo " A epsilon/zeta" >> $testroot/stdout.expected
683 0208f208 2020-05-05 stsp echo " A gamma/delta" >> $testroot/stdout.expected
684 e7303626 2020-05-14 stsp
685 e7303626 2020-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
686 e7303626 2020-05-14 stsp ret="$?"
687 e7303626 2020-05-14 stsp if [ "$ret" != "0" ]; then
688 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
689 e7303626 2020-05-14 stsp fi
690 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
691 e7303626 2020-05-14 stsp }
692 e7303626 2020-05-14 stsp
693 e7303626 2020-05-14 stsp function test_log_submodule {
694 e7303626 2020-05-14 stsp local testroot=`test_init log_submodule`
695 e7303626 2020-05-14 stsp
696 e7303626 2020-05-14 stsp make_single_file_repo $testroot/repo2 foo
697 e7303626 2020-05-14 stsp
698 e7303626 2020-05-14 stsp (cd $testroot/repo && git submodule -q add ../repo2)
699 e7303626 2020-05-14 stsp (cd $testroot/repo && git commit -q -m 'adding submodule')
700 e7303626 2020-05-14 stsp local head_commit=`git_show_head $testroot/repo`
701 e7303626 2020-05-14 stsp
702 e7303626 2020-05-14 stsp echo "commit $head_commit (master)" > $testroot/stdout.expected
703 e7303626 2020-05-14 stsp
704 e7303626 2020-05-14 stsp got log -r $testroot/repo -l1 repo2 | grep ^commit > $testroot/stdout
705 e7303626 2020-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
706 e7303626 2020-05-14 stsp ret="$?"
707 e7303626 2020-05-14 stsp if [ "$ret" != "0" ]; then
708 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
709 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
710 e7303626 2020-05-14 stsp return 1
711 e7303626 2020-05-14 stsp fi
712 e7303626 2020-05-14 stsp
713 e7303626 2020-05-14 stsp echo " A .gitmodules" > $testroot/stdout.expected
714 e7303626 2020-05-14 stsp
715 e7303626 2020-05-14 stsp got log -r $testroot/repo -l1 -P repo2 | grep '^ [MDmA]' \
716 e7303626 2020-05-14 stsp > $testroot/stdout
717 e7303626 2020-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
718 e7303626 2020-05-14 stsp ret="$?"
719 e7303626 2020-05-14 stsp if [ "$ret" != "0" ]; then
720 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
721 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
722 e7303626 2020-05-14 stsp return 1
723 e7303626 2020-05-14 stsp fi
724 e7303626 2020-05-14 stsp
725 e7303626 2020-05-14 stsp got log -p -r $testroot/repo -l1 repo2 \
726 e7303626 2020-05-14 stsp > $testroot/stdout 2> $testroot/stderr
727 e7303626 2020-05-14 stsp ret="$?"
728 e7303626 2020-05-14 stsp if [ "$ret" == "0" ]; then
729 e7303626 2020-05-14 stsp echo "log command succeeded unexpectedly" >&2
730 e7303626 2020-05-14 stsp test_done "$testroot" "1"
731 e7303626 2020-05-14 stsp return 1
732 e7303626 2020-05-14 stsp fi
733 e7303626 2020-05-14 stsp local submodule_id=$(got tree -r $testroot/repo -i | \
734 e7303626 2020-05-14 stsp grep 'repo2\$$' | cut -d ' ' -f1)
735 e7303626 2020-05-14 stsp echo "got: object $submodule_id not found" > $testroot/stderr.expected
736 0208f208 2020-05-05 stsp
737 e7303626 2020-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
738 e7303626 2020-05-14 stsp ret="$?"
739 e7303626 2020-05-14 stsp if [ "$ret" != "0" ]; then
740 e7303626 2020-05-14 stsp diff -u $testroot/stderr.expected $testroot/stderr
741 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
742 e7303626 2020-05-14 stsp return 1
743 e7303626 2020-05-14 stsp fi
744 e7303626 2020-05-14 stsp
745 e7303626 2020-05-14 stsp echo "modified foo" > $testroot/repo2/foo
746 e7303626 2020-05-14 stsp (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
747 e7303626 2020-05-14 stsp
748 e7303626 2020-05-14 stsp # Update the repo/repo2 submodule link
749 e7303626 2020-05-14 stsp (cd $testroot/repo && git -C repo2 pull -q)
750 e7303626 2020-05-14 stsp (cd $testroot/repo && git add repo2)
751 e7303626 2020-05-14 stsp git_commit $testroot/repo -m "changed submodule link"
752 e7303626 2020-05-14 stsp
753 e7303626 2020-05-14 stsp # log -P does not show the changed submodule path
754 e7303626 2020-05-14 stsp got log -P -r $testroot/repo -l1 repo2 > $testroot/stdout.full
755 e7303626 2020-05-14 stsp ret="$?"
756 e7303626 2020-05-14 stsp if [ "$ret" != "0" ]; then
757 e7303626 2020-05-14 stsp echo "log command failed unexpectedly" >&2
758 e7303626 2020-05-14 stsp test_done "$testroot" "1"
759 e7303626 2020-05-14 stsp return 1
760 e7303626 2020-05-14 stsp fi
761 e7303626 2020-05-14 stsp grep '^ [MDmA]' $testroot/stdout.full > $testroot/stdout
762 e7303626 2020-05-14 stsp
763 e7303626 2020-05-14 stsp echo -n > $testroot/stdout.expected
764 0208f208 2020-05-05 stsp cmp -s $testroot/stdout.expected $testroot/stdout
765 0208f208 2020-05-05 stsp ret="$?"
766 0208f208 2020-05-05 stsp if [ "$ret" != "0" ]; then
767 0208f208 2020-05-05 stsp diff -u $testroot/stdout.expected $testroot/stdout
768 0208f208 2020-05-05 stsp fi
769 0208f208 2020-05-05 stsp test_done "$testroot" "$ret"
770 0208f208 2020-05-05 stsp }
771 0208f208 2020-05-05 stsp
772 e7301579 2019-03-18 stsp run_test test_log_in_repo
773 b70703ad 2019-03-18 stsp run_test test_log_in_bare_repo
774 cbd1af7a 2019-03-18 stsp run_test test_log_in_worktree
775 dfe70b4b 2019-08-27 stsp run_test test_log_in_worktree_with_path_prefix
776 303e2782 2019-08-09 stsp run_test test_log_tag
777 b1ebc001 2019-08-13 stsp run_test test_log_limit
778 2e8c69d1 2020-05-04 stsp run_test test_log_patch_added_file
779 5175b31a 2020-01-04 stsp run_test test_log_nonexistent_path
780 d1fe46f9 2020-04-18 stsp run_test test_log_end_at_commit
781 dbec59df 2020-04-18 stsp run_test test_log_reverse_display
782 50f2fada 2020-04-24 stsp run_test test_log_in_worktree_different_repo
783 0208f208 2020-05-05 stsp run_test test_log_changed_paths
784 e7303626 2020-05-14 stsp run_test test_log_submodule