Blame


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