Blame


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