Blame


1 a184c764 2023-04-22 thomas #!/bin/sh
2 a184c764 2023-04-22 thomas #
3 a184c764 2023-04-22 thomas # Copyright (c) 2023 Mark Jamsek <mark@jamsek.dev>
4 a184c764 2023-04-22 thomas #
5 a184c764 2023-04-22 thomas # Permission to use, copy, modify, and distribute this software for any
6 a184c764 2023-04-22 thomas # purpose with or without fee is hereby granted, provided that the above
7 a184c764 2023-04-22 thomas # copyright notice and this permission notice appear in all copies.
8 a184c764 2023-04-22 thomas #
9 a184c764 2023-04-22 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 a184c764 2023-04-22 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 a184c764 2023-04-22 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 a184c764 2023-04-22 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 a184c764 2023-04-22 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 a184c764 2023-04-22 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 a184c764 2023-04-22 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 a184c764 2023-04-22 thomas
17 a184c764 2023-04-22 thomas . ./common.sh
18 a184c764 2023-04-22 thomas
19 a184c764 2023-04-22 thomas test_tree_basic()
20 a184c764 2023-04-22 thomas {
21 a184c764 2023-04-22 thomas test_init tree_basic 48 8
22 a184c764 2023-04-22 thomas
23 a184c764 2023-04-22 thomas local head_id=`git_show_head $testroot/repo`
24 a184c764 2023-04-22 thomas
25 a184c764 2023-04-22 thomas cat <<EOF >$TOG_TEST_SCRIPT
26 a184c764 2023-04-22 thomas SCREENDUMP
27 a184c764 2023-04-22 thomas EOF
28 a184c764 2023-04-22 thomas
29 a184c764 2023-04-22 thomas cat <<EOF >$testroot/view.expected
30 a184c764 2023-04-22 thomas commit $head_id
31 a184c764 2023-04-22 thomas [1/4] /
32 a184c764 2023-04-22 thomas
33 a184c764 2023-04-22 thomas alpha
34 a184c764 2023-04-22 thomas beta
35 a184c764 2023-04-22 thomas epsilon/
36 a184c764 2023-04-22 thomas gamma/
37 a184c764 2023-04-22 thomas
38 a184c764 2023-04-22 thomas EOF
39 a184c764 2023-04-22 thomas
40 a184c764 2023-04-22 thomas cd $testroot/repo && tog tree
41 a184c764 2023-04-22 thomas cmp -s $testroot/view.expected $testroot/view
42 a184c764 2023-04-22 thomas ret=$?
43 a184c764 2023-04-22 thomas if [ $ret -ne 0 ]; then
44 a184c764 2023-04-22 thomas diff -u $testroot/view.expected $testroot/view
45 a184c764 2023-04-22 thomas test_done "$testroot" "$ret"
46 a184c764 2023-04-22 thomas return 1
47 a184c764 2023-04-22 thomas fi
48 a184c764 2023-04-22 thomas
49 a184c764 2023-04-22 thomas test_done "$testroot" "$ret"
50 a184c764 2023-04-22 thomas }
51 a184c764 2023-04-22 thomas
52 a184c764 2023-04-22 thomas test_tree_vsplit_blame()
53 a184c764 2023-04-22 thomas {
54 a184c764 2023-04-22 thomas test_init tree_vsplit_blame 120 8
55 a184c764 2023-04-22 thomas
56 a184c764 2023-04-22 thomas local head_id=`git_show_head $testroot/repo`
57 a184c764 2023-04-22 thomas local head_id_truncated=`trim_obj_id 8 $head_id`
58 a184c764 2023-04-22 thomas local head_id_short=`trim_obj_id 32 $head_id`
59 a184c764 2023-04-22 thomas
60 a184c764 2023-04-22 thomas cat <<EOF >$TOG_TEST_SCRIPT
61 a184c764 2023-04-22 thomas KEY_ENTER
62 a184c764 2023-04-22 thomas WAIT_FOR_UI wait for blame to finish
63 a184c764 2023-04-22 thomas SCREENDUMP
64 a184c764 2023-04-22 thomas EOF
65 a184c764 2023-04-22 thomas
66 a184c764 2023-04-22 thomas cat <<EOF >$testroot/view.expected
67 a184c764 2023-04-22 thomas commit $head_id_truncated|commit $head_id
68 a184c764 2023-04-22 thomas [1/4] / |[1/1] /alpha
69 a184c764 2023-04-22 thomas |$head_id_short alpha
70 a184c764 2023-04-22 thomas alpha |
71 a184c764 2023-04-22 thomas beta |
72 a184c764 2023-04-22 thomas epsilon/ |
73 a184c764 2023-04-22 thomas gamma/ |
74 a184c764 2023-04-22 thomas |
75 a184c764 2023-04-22 thomas EOF
76 a184c764 2023-04-22 thomas
77 a184c764 2023-04-22 thomas cd $testroot/repo && tog tree
78 a184c764 2023-04-22 thomas cmp -s $testroot/view.expected $testroot/view
79 a184c764 2023-04-22 thomas ret=$?
80 a184c764 2023-04-22 thomas if [ $ret -ne 0 ]; then
81 a184c764 2023-04-22 thomas diff -u $testroot/view.expected $testroot/view
82 a184c764 2023-04-22 thomas test_done "$testroot" "$ret"
83 a184c764 2023-04-22 thomas return 1
84 a184c764 2023-04-22 thomas fi
85 a184c764 2023-04-22 thomas
86 a184c764 2023-04-22 thomas test_done "$testroot" "$ret"
87 a184c764 2023-04-22 thomas }
88 a184c764 2023-04-22 thomas
89 a184c764 2023-04-22 thomas test_tree_hsplit_blame()
90 a184c764 2023-04-22 thomas {
91 a184c764 2023-04-22 thomas test_init tree_hsplit_blame 48 24
92 a184c764 2023-04-22 thomas
93 a184c764 2023-04-22 thomas local head_id=`git_show_head $testroot/repo`
94 a184c764 2023-04-22 thomas local head_id_truncated=`trim_obj_id 8 $head_id`
95 a184c764 2023-04-22 thomas local head_id_short=`trim_obj_id 32 $head_id`
96 a184c764 2023-04-22 thomas
97 a184c764 2023-04-22 thomas cat <<EOF >$TOG_TEST_SCRIPT
98 a184c764 2023-04-22 thomas j
99 a184c764 2023-04-22 thomas KEY_ENTER
100 a184c764 2023-04-22 thomas S toggle horizontal split
101 a184c764 2023-04-22 thomas 4- 4x decrease blame split
102 a184c764 2023-04-22 thomas WAIT_FOR_UI wait for blame to finish
103 a184c764 2023-04-22 thomas SCREENDUMP
104 a184c764 2023-04-22 thomas EOF
105 a184c764 2023-04-22 thomas
106 a184c764 2023-04-22 thomas cat <<EOF >$testroot/view.expected
107 a184c764 2023-04-22 thomas commit $head_id
108 a184c764 2023-04-22 thomas [2/4] /
109 a184c764 2023-04-22 thomas
110 a184c764 2023-04-22 thomas alpha
111 a184c764 2023-04-22 thomas beta
112 a184c764 2023-04-22 thomas epsilon/
113 a184c764 2023-04-22 thomas gamma/
114 a184c764 2023-04-22 thomas
115 a184c764 2023-04-22 thomas
116 a184c764 2023-04-22 thomas
117 a184c764 2023-04-22 thomas ------------------------------------------------
118 a184c764 2023-04-22 thomas commit $head_id
119 a184c764 2023-04-22 thomas [1/1] /beta
120 a184c764 2023-04-22 thomas $head_id_short beta
121 a184c764 2023-04-22 thomas
122 a184c764 2023-04-22 thomas
123 a184c764 2023-04-22 thomas
124 a184c764 2023-04-22 thomas
125 a184c764 2023-04-22 thomas
126 a184c764 2023-04-22 thomas
127 a184c764 2023-04-22 thomas
128 a184c764 2023-04-22 thomas
129 a184c764 2023-04-22 thomas
130 a184c764 2023-04-22 thomas
131 a184c764 2023-04-22 thomas EOF
132 a184c764 2023-04-22 thomas
133 a184c764 2023-04-22 thomas cd $testroot/repo && tog tree
134 a184c764 2023-04-22 thomas cmp -s $testroot/view.expected $testroot/view
135 a184c764 2023-04-22 thomas ret=$?
136 a184c764 2023-04-22 thomas if [ $ret -ne 0 ]; then
137 a184c764 2023-04-22 thomas diff -u $testroot/view.expected $testroot/view
138 a184c764 2023-04-22 thomas test_done "$testroot" "$ret"
139 a184c764 2023-04-22 thomas return 1
140 a184c764 2023-04-22 thomas fi
141 a184c764 2023-04-22 thomas
142 a184c764 2023-04-22 thomas test_done "$testroot" "$ret"
143 a184c764 2023-04-22 thomas }
144 a184c764 2023-04-22 thomas
145 94d1a66a 2023-06-25 thomas test_tree_symlink()
146 94d1a66a 2023-06-25 thomas {
147 94d1a66a 2023-06-25 thomas test_init tree_symlink 48 8
148 94d1a66a 2023-06-25 thomas
149 94d1a66a 2023-06-25 thomas (cd $testroot/repo && ln -s alpha symlink)
150 94d1a66a 2023-06-25 thomas (cd $testroot/repo && git add symlink)
151 94d1a66a 2023-06-25 thomas git_commit $testroot/repo -m "symlink to alpha"
152 94d1a66a 2023-06-25 thomas local head_id=`git_show_head $testroot/repo`
153 94d1a66a 2023-06-25 thomas
154 94d1a66a 2023-06-25 thomas cat <<EOF >$TOG_TEST_SCRIPT
155 94d1a66a 2023-06-25 thomas SCREENDUMP
156 94d1a66a 2023-06-25 thomas EOF
157 94d1a66a 2023-06-25 thomas
158 94d1a66a 2023-06-25 thomas cat <<EOF >$testroot/view.expected
159 94d1a66a 2023-06-25 thomas commit $head_id
160 94d1a66a 2023-06-25 thomas [1/5] /
161 94d1a66a 2023-06-25 thomas
162 94d1a66a 2023-06-25 thomas alpha
163 94d1a66a 2023-06-25 thomas beta
164 94d1a66a 2023-06-25 thomas epsilon/
165 94d1a66a 2023-06-25 thomas gamma/
166 94d1a66a 2023-06-25 thomas symlink@ -> alpha
167 94d1a66a 2023-06-25 thomas EOF
168 94d1a66a 2023-06-25 thomas
169 94d1a66a 2023-06-25 thomas cd $testroot/repo && tog tree
170 94d1a66a 2023-06-25 thomas cmp -s $testroot/view.expected $testroot/view
171 94d1a66a 2023-06-25 thomas ret=$?
172 94d1a66a 2023-06-25 thomas if [ $ret -ne 0 ]; then
173 94d1a66a 2023-06-25 thomas diff -u $testroot/view.expected $testroot/view
174 94d1a66a 2023-06-25 thomas test_done "$testroot" "$ret"
175 94d1a66a 2023-06-25 thomas return 1
176 94d1a66a 2023-06-25 thomas fi
177 94d1a66a 2023-06-25 thomas
178 94d1a66a 2023-06-25 thomas test_done "$testroot" "$ret"
179 94d1a66a 2023-06-25 thomas }
180 94d1a66a 2023-06-25 thomas
181 66b04f8f 2023-07-19 thomas test_tree_commit_keywords()
182 66b04f8f 2023-07-19 thomas {
183 66b04f8f 2023-07-19 thomas test_init tree_commit_keywords 48 11
184 66b04f8f 2023-07-19 thomas local repo="$testroot/repo"
185 66b04f8f 2023-07-19 thomas local wt="$testroot/wt"
186 66b04f8f 2023-07-19 thomas local id=$(git_show_head "$repo")
187 66b04f8f 2023-07-19 thomas
188 8642913b 2023-07-26 thomas set -- "$id"
189 66b04f8f 2023-07-19 thomas
190 66b04f8f 2023-07-19 thomas got checkout "$repo" "$wt" > /dev/null
191 66b04f8f 2023-07-19 thomas ret=$?
192 66b04f8f 2023-07-19 thomas if [ $ret -ne 0 ]; then
193 66b04f8f 2023-07-19 thomas echo "got checkout failed unexpectedly"
194 66b04f8f 2023-07-19 thomas test_done "$testroot" "$ret"
195 66b04f8f 2023-07-19 thomas return 1
196 66b04f8f 2023-07-19 thomas fi
197 66b04f8f 2023-07-19 thomas
198 66b04f8f 2023-07-19 thomas # move into the work tree (test is run in a subshell)
199 66b04f8f 2023-07-19 thomas cd "$wt"
200 66b04f8f 2023-07-19 thomas
201 66b04f8f 2023-07-19 thomas for i in $(seq 8); do
202 66b04f8f 2023-07-19 thomas if [ $(( i % 2 )) -eq 0 ]; then
203 66b04f8f 2023-07-19 thomas echo "file${i}" > "file${i}"
204 66b04f8f 2023-07-19 thomas got add "file${i}" > /dev/null
205 66b04f8f 2023-07-19 thomas else
206 66b04f8f 2023-07-19 thomas echo "alpha $i" > alpha
207 66b04f8f 2023-07-19 thomas fi
208 66b04f8f 2023-07-19 thomas
209 66b04f8f 2023-07-19 thomas got ci -m "commit $i" > /dev/null
210 66b04f8f 2023-07-19 thomas ret=$?
211 66b04f8f 2023-07-19 thomas if [ $ret -ne 0 ]; then
212 66b04f8f 2023-07-19 thomas echo "commit failed unexpectedly" >&2
213 66b04f8f 2023-07-19 thomas test_done "$testroot" "$ret"
214 66b04f8f 2023-07-19 thomas return 1
215 66b04f8f 2023-07-19 thomas fi
216 66b04f8f 2023-07-19 thomas
217 66b04f8f 2023-07-19 thomas id=$(git_show_head "$repo")
218 8642913b 2023-07-26 thomas set -- "$@" "$id"
219 66b04f8f 2023-07-19 thomas done
220 66b04f8f 2023-07-19 thomas
221 66b04f8f 2023-07-19 thomas
222 66b04f8f 2023-07-19 thomas cat <<-EOF >$TOG_TEST_SCRIPT
223 66b04f8f 2023-07-19 thomas SCREENDUMP
224 66b04f8f 2023-07-19 thomas EOF
225 66b04f8f 2023-07-19 thomas
226 66b04f8f 2023-07-19 thomas cat <<-EOF >$testroot/view.expected
227 8642913b 2023-07-26 thomas commit $(pop_idx 8 $@)
228 66b04f8f 2023-07-19 thomas [1/7] /
229 66b04f8f 2023-07-19 thomas
230 66b04f8f 2023-07-19 thomas alpha
231 66b04f8f 2023-07-19 thomas beta
232 66b04f8f 2023-07-19 thomas epsilon/
233 66b04f8f 2023-07-19 thomas file2
234 66b04f8f 2023-07-19 thomas file4
235 66b04f8f 2023-07-19 thomas file6
236 66b04f8f 2023-07-19 thomas gamma/
237 66b04f8f 2023-07-19 thomas
238 66b04f8f 2023-07-19 thomas EOF
239 66b04f8f 2023-07-19 thomas
240 66b04f8f 2023-07-19 thomas tog tree -c:base:-
241 66b04f8f 2023-07-19 thomas cmp -s $testroot/view.expected $testroot/view
242 66b04f8f 2023-07-19 thomas ret=$?
243 66b04f8f 2023-07-19 thomas if [ $ret -ne 0 ]; then
244 66b04f8f 2023-07-19 thomas diff -u $testroot/view.expected $testroot/view
245 66b04f8f 2023-07-19 thomas test_done "$testroot" "$ret"
246 66b04f8f 2023-07-19 thomas return 1
247 66b04f8f 2023-07-19 thomas fi
248 66b04f8f 2023-07-19 thomas
249 66b04f8f 2023-07-19 thomas cat <<-EOF >$testroot/view.expected
250 8642913b 2023-07-26 thomas commit $(pop_idx 6 $@)
251 66b04f8f 2023-07-19 thomas [1/6] /
252 66b04f8f 2023-07-19 thomas
253 66b04f8f 2023-07-19 thomas alpha
254 66b04f8f 2023-07-19 thomas beta
255 66b04f8f 2023-07-19 thomas epsilon/
256 66b04f8f 2023-07-19 thomas file2
257 66b04f8f 2023-07-19 thomas file4
258 66b04f8f 2023-07-19 thomas gamma/
259 66b04f8f 2023-07-19 thomas
260 66b04f8f 2023-07-19 thomas
261 66b04f8f 2023-07-19 thomas EOF
262 66b04f8f 2023-07-19 thomas
263 66b04f8f 2023-07-19 thomas tog tree -cmaster:-3
264 66b04f8f 2023-07-19 thomas cmp -s $testroot/view.expected $testroot/view
265 66b04f8f 2023-07-19 thomas ret=$?
266 66b04f8f 2023-07-19 thomas if [ $ret -ne 0 ]; then
267 66b04f8f 2023-07-19 thomas diff -u $testroot/view.expected $testroot/view
268 66b04f8f 2023-07-19 thomas test_done "$testroot" "$ret"
269 66b04f8f 2023-07-19 thomas return 1
270 66b04f8f 2023-07-19 thomas fi
271 66b04f8f 2023-07-19 thomas
272 66b04f8f 2023-07-19 thomas cat <<-EOF >$testroot/view.expected
273 8642913b 2023-07-26 thomas commit $(pop_idx 9 $@)
274 66b04f8f 2023-07-19 thomas [1/8] /
275 66b04f8f 2023-07-19 thomas
276 66b04f8f 2023-07-19 thomas alpha
277 66b04f8f 2023-07-19 thomas beta
278 66b04f8f 2023-07-19 thomas epsilon/
279 66b04f8f 2023-07-19 thomas file2
280 66b04f8f 2023-07-19 thomas file4
281 66b04f8f 2023-07-19 thomas file6
282 66b04f8f 2023-07-19 thomas file8
283 66b04f8f 2023-07-19 thomas gamma/
284 66b04f8f 2023-07-19 thomas EOF
285 66b04f8f 2023-07-19 thomas
286 66b04f8f 2023-07-19 thomas got up -c:head:-99 > /dev/null
287 66b04f8f 2023-07-19 thomas tog tree -c:base:+99
288 66b04f8f 2023-07-19 thomas cmp -s $testroot/view.expected $testroot/view
289 66b04f8f 2023-07-19 thomas ret=$?
290 66b04f8f 2023-07-19 thomas if [ $ret -ne 0 ]; then
291 66b04f8f 2023-07-19 thomas diff -u $testroot/view.expected $testroot/view
292 66b04f8f 2023-07-19 thomas test_done "$testroot" "$ret"
293 66b04f8f 2023-07-19 thomas return 1
294 66b04f8f 2023-07-19 thomas fi
295 66b04f8f 2023-07-19 thomas
296 66b04f8f 2023-07-19 thomas cat <<-EOF >$testroot/view.expected
297 8642913b 2023-07-26 thomas commit $(pop_idx 4 $@)
298 66b04f8f 2023-07-19 thomas [1/5] /
299 66b04f8f 2023-07-19 thomas
300 66b04f8f 2023-07-19 thomas alpha
301 66b04f8f 2023-07-19 thomas beta
302 66b04f8f 2023-07-19 thomas epsilon/
303 66b04f8f 2023-07-19 thomas file2
304 66b04f8f 2023-07-19 thomas gamma/
305 66b04f8f 2023-07-19 thomas
306 66b04f8f 2023-07-19 thomas
307 66b04f8f 2023-07-19 thomas
308 66b04f8f 2023-07-19 thomas EOF
309 66b04f8f 2023-07-19 thomas
310 66b04f8f 2023-07-19 thomas tog tree -c:head:-5
311 66b04f8f 2023-07-19 thomas cmp -s $testroot/view.expected $testroot/view
312 66b04f8f 2023-07-19 thomas ret=$?
313 66b04f8f 2023-07-19 thomas if [ $ret -ne 0 ]; then
314 66b04f8f 2023-07-19 thomas diff -u $testroot/view.expected $testroot/view
315 66b04f8f 2023-07-19 thomas test_done "$testroot" "$ret"
316 66b04f8f 2023-07-19 thomas return 1
317 66b04f8f 2023-07-19 thomas fi
318 66b04f8f 2023-07-19 thomas
319 66b04f8f 2023-07-19 thomas cat <<-EOF >$testroot/view.expected
320 8642913b 2023-07-26 thomas commit $(pop_idx 1 $@)
321 66b04f8f 2023-07-19 thomas [1/4] /
322 66b04f8f 2023-07-19 thomas
323 66b04f8f 2023-07-19 thomas alpha
324 66b04f8f 2023-07-19 thomas beta
325 66b04f8f 2023-07-19 thomas epsilon/
326 66b04f8f 2023-07-19 thomas gamma/
327 66b04f8f 2023-07-19 thomas
328 66b04f8f 2023-07-19 thomas
329 66b04f8f 2023-07-19 thomas
330 66b04f8f 2023-07-19 thomas
331 66b04f8f 2023-07-19 thomas EOF
332 66b04f8f 2023-07-19 thomas
333 66b04f8f 2023-07-19 thomas tog tree -r "$repo" -cmaster:-99
334 66b04f8f 2023-07-19 thomas cmp -s $testroot/view.expected $testroot/view
335 66b04f8f 2023-07-19 thomas ret=$?
336 66b04f8f 2023-07-19 thomas if [ $ret -ne 0 ]; then
337 66b04f8f 2023-07-19 thomas diff -u $testroot/view.expected $testroot/view
338 66b04f8f 2023-07-19 thomas test_done "$testroot" "$ret"
339 66b04f8f 2023-07-19 thomas return 1
340 66b04f8f 2023-07-19 thomas fi
341 66b04f8f 2023-07-19 thomas test_done "$testroot" "$ret"
342 66b04f8f 2023-07-19 thomas }
343 66b04f8f 2023-07-19 thomas
344 a184c764 2023-04-22 thomas test_parseargs "$@"
345 a184c764 2023-04-22 thomas run_test test_tree_basic
346 a184c764 2023-04-22 thomas run_test test_tree_vsplit_blame
347 a184c764 2023-04-22 thomas run_test test_tree_hsplit_blame
348 94d1a66a 2023-06-25 thomas run_test test_tree_symlink
349 66b04f8f 2023-07-19 thomas run_test test_tree_commit_keywords