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 79c49d84 2023-07-24 mark set -- "$id"
89 c4df265e 2023-07-19 mark
90 c4df265e 2023-07-19 mark cat <<-EOF >$TOG_TEST_SCRIPT
91 c4df265e 2023-07-19 mark WAIT_FOR_UI wait for blame to finish
92 c4df265e 2023-07-19 mark SCREENDUMP
93 c4df265e 2023-07-19 mark EOF
94 c4df265e 2023-07-19 mark
95 c4df265e 2023-07-19 mark # :base requires work tree
96 c4df265e 2023-07-19 mark echo "tog: '-c :base' requires work tree" > "$testroot/stderr.expected"
97 c4df265e 2023-07-19 mark tog blame -r "$repo" -c:base alpha 2> "$testroot/stderr"
98 c4df265e 2023-07-19 mark ret=$?
99 c4df265e 2023-07-19 mark if [ $ret -eq 0 ]; then
100 c4df265e 2023-07-19 mark echo "blame command succeeded unexpectedly" >&2
101 c4df265e 2023-07-19 mark test_done "$testroot" "1"
102 c4df265e 2023-07-19 mark return 1
103 c4df265e 2023-07-19 mark fi
104 c4df265e 2023-07-19 mark
105 c4df265e 2023-07-19 mark cmp -s "$testroot/stderr.expected" "$testroot/stderr"
106 c4df265e 2023-07-19 mark ret=$?
107 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
108 c4df265e 2023-07-19 mark diff -u "$testroot/stderr.expected" "$testroot/stderr"
109 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
110 c4df265e 2023-07-19 mark return 1
111 c4df265e 2023-07-19 mark fi
112 c4df265e 2023-07-19 mark
113 c4df265e 2023-07-19 mark # :head keyword in repo
114 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
115 c4df265e 2023-07-19 mark commit $id
116 c4df265e 2023-07-19 mark [1/1] /alpha
117 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 1 $@)) alpha
118 c4df265e 2023-07-19 mark
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 EOF
126 c4df265e 2023-07-19 mark
127 c4df265e 2023-07-19 mark tog blame -r "$repo" -c:head alpha
128 c4df265e 2023-07-19 mark ret=$?
129 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
130 c4df265e 2023-07-19 mark echo "blame command failed unexpectedly" >&2
131 c4df265e 2023-07-19 mark test_done "$testroot" "1"
132 c4df265e 2023-07-19 mark return 1
133 c4df265e 2023-07-19 mark fi
134 c4df265e 2023-07-19 mark
135 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
136 c4df265e 2023-07-19 mark ret=$?
137 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
138 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
139 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
140 c4df265e 2023-07-19 mark return 1
141 c4df265e 2023-07-19 mark fi
142 c4df265e 2023-07-19 mark
143 c4df265e 2023-07-19 mark got checkout "$repo" "$wt" > /dev/null
144 c4df265e 2023-07-19 mark ret=$?
145 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
146 c4df265e 2023-07-19 mark echo "got checkout failed unexpectedly"
147 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
148 c4df265e 2023-07-19 mark return 1
149 c4df265e 2023-07-19 mark fi
150 c4df265e 2023-07-19 mark
151 c4df265e 2023-07-19 mark # move into the work tree (test is run in a subshell)
152 c4df265e 2023-07-19 mark cd "$wt"
153 c4df265e 2023-07-19 mark echo -n > alpha
154 c4df265e 2023-07-19 mark
155 c4df265e 2023-07-19 mark for i in $(seq 8); do
156 c4df265e 2023-07-19 mark echo "alpha $i" >> alpha
157 c4df265e 2023-07-19 mark
158 c4df265e 2023-07-19 mark got ci -m "commit $i" > /dev/null
159 c4df265e 2023-07-19 mark ret=$?
160 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
161 c4df265e 2023-07-19 mark echo "commit failed unexpectedly" >&2
162 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
163 c4df265e 2023-07-19 mark return 1
164 c4df265e 2023-07-19 mark fi
165 c4df265e 2023-07-19 mark
166 c4df265e 2023-07-19 mark id=$(git_show_head "$repo")
167 79c49d84 2023-07-24 mark set -- "$@" "$id"
168 c4df265e 2023-07-19 mark done
169 c4df265e 2023-07-19 mark
170 c4df265e 2023-07-19 mark author_time=$(git_show_author_time "$repo")
171 c4df265e 2023-07-19 mark ymd=$(date -u -r $author_time +"%G-%m-%d")
172 c4df265e 2023-07-19 mark
173 c4df265e 2023-07-19 mark # :base:- keyword in work tree
174 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
175 79c49d84 2023-07-24 mark commit $(pop_idx 8 $@)
176 c4df265e 2023-07-19 mark [1/7] /alpha
177 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 2 $@)) alpha 1
178 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 3 $@)) alpha 2
179 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 4 $@)) alpha 3
180 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 5 $@)) alpha 4
181 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 6 $@)) alpha 5
182 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 7 $@)) alpha 6
183 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 8 $@)) alpha 7
184 c4df265e 2023-07-19 mark
185 c4df265e 2023-07-19 mark EOF
186 c4df265e 2023-07-19 mark
187 c4df265e 2023-07-19 mark tog blame -c:base:- alpha
188 c4df265e 2023-07-19 mark ret=$?
189 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
190 c4df265e 2023-07-19 mark echo "blame command failed unexpectedly" >&2
191 c4df265e 2023-07-19 mark test_done "$testroot" "1"
192 c4df265e 2023-07-19 mark return 1
193 c4df265e 2023-07-19 mark fi
194 c4df265e 2023-07-19 mark
195 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
196 c4df265e 2023-07-19 mark ret=$?
197 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
198 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
199 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
200 c4df265e 2023-07-19 mark return 1
201 c4df265e 2023-07-19 mark fi
202 c4df265e 2023-07-19 mark
203 c4df265e 2023-07-19 mark # :head:-4 keyword in work tree
204 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
205 79c49d84 2023-07-24 mark commit $(pop_idx 5 $@)
206 c4df265e 2023-07-19 mark [1/4] /alpha
207 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 2 $@)) alpha 1
208 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 3 $@)) alpha 2
209 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 4 $@)) alpha 3
210 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 5 $@)) alpha 4
211 c4df265e 2023-07-19 mark
212 c4df265e 2023-07-19 mark
213 c4df265e 2023-07-19 mark
214 c4df265e 2023-07-19 mark
215 c4df265e 2023-07-19 mark EOF
216 c4df265e 2023-07-19 mark
217 c4df265e 2023-07-19 mark tog blame -c:head:-4 alpha
218 c4df265e 2023-07-19 mark ret=$?
219 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
220 c4df265e 2023-07-19 mark echo "blame command failed unexpectedly" >&2
221 c4df265e 2023-07-19 mark test_done "$testroot" "1"
222 c4df265e 2023-07-19 mark return 1
223 c4df265e 2023-07-19 mark fi
224 c4df265e 2023-07-19 mark
225 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
226 c4df265e 2023-07-19 mark ret=$?
227 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
228 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
229 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
230 c4df265e 2023-07-19 mark return 1
231 c4df265e 2023-07-19 mark fi
232 c4df265e 2023-07-19 mark
233 c4df265e 2023-07-19 mark # :base:+2 keyword in work tree
234 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
235 79c49d84 2023-07-24 mark commit $(pop_idx 5 $@)
236 c4df265e 2023-07-19 mark [1/4] /alpha
237 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 2 $@)) alpha 1
238 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 3 $@)) alpha 2
239 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 4 $@)) alpha 3
240 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 5 $@)) alpha 4
241 c4df265e 2023-07-19 mark
242 c4df265e 2023-07-19 mark
243 c4df265e 2023-07-19 mark
244 c4df265e 2023-07-19 mark
245 c4df265e 2023-07-19 mark EOF
246 c4df265e 2023-07-19 mark
247 c4df265e 2023-07-19 mark got up -c:head:-6 > /dev/null
248 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
249 c4df265e 2023-07-19 mark echo "update command failed unexpectedly" >&2
250 c4df265e 2023-07-19 mark test_done "$testroot" "1"
251 c4df265e 2023-07-19 mark return 1
252 c4df265e 2023-07-19 mark fi
253 c4df265e 2023-07-19 mark
254 c4df265e 2023-07-19 mark tog blame -c:base:+2 alpha
255 c4df265e 2023-07-19 mark ret=$?
256 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
257 c4df265e 2023-07-19 mark echo "blame command failed unexpectedly" >&2
258 c4df265e 2023-07-19 mark test_done "$testroot" "1"
259 c4df265e 2023-07-19 mark return 1
260 c4df265e 2023-07-19 mark fi
261 c4df265e 2023-07-19 mark
262 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
263 c4df265e 2023-07-19 mark ret=$?
264 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
265 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
266 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
267 c4df265e 2023-07-19 mark return 1
268 c4df265e 2023-07-19 mark fi
269 c4df265e 2023-07-19 mark
270 c4df265e 2023-07-19 mark # master:-99 keyword in work tree
271 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
272 79c49d84 2023-07-24 mark commit $(pop_idx 1 $@)
273 c4df265e 2023-07-19 mark [1/1] /alpha
274 79c49d84 2023-07-24 mark $(trim_obj_id 32 $(pop_idx 1 $@)) alpha
275 c4df265e 2023-07-19 mark
276 c4df265e 2023-07-19 mark
277 c4df265e 2023-07-19 mark
278 c4df265e 2023-07-19 mark
279 c4df265e 2023-07-19 mark
280 c4df265e 2023-07-19 mark
281 c4df265e 2023-07-19 mark
282 c4df265e 2023-07-19 mark EOF
283 c4df265e 2023-07-19 mark
284 c4df265e 2023-07-19 mark tog blame -cmaster:-99 alpha
285 c4df265e 2023-07-19 mark ret=$?
286 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
287 c4df265e 2023-07-19 mark echo "blame command failed unexpectedly" >&2
288 c4df265e 2023-07-19 mark test_done "$testroot" "1"
289 c4df265e 2023-07-19 mark return 1
290 c4df265e 2023-07-19 mark fi
291 c4df265e 2023-07-19 mark
292 c4df265e 2023-07-19 mark cmp -s $testroot/view.expected $testroot/view
293 c4df265e 2023-07-19 mark ret=$?
294 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
295 c4df265e 2023-07-19 mark diff -u $testroot/view.expected $testroot/view
296 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
297 c4df265e 2023-07-19 mark return 1
298 c4df265e 2023-07-19 mark fi
299 c4df265e 2023-07-19 mark
300 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
301 c4df265e 2023-07-19 mark }
302 c4df265e 2023-07-19 mark
303 8d212112 2023-04-16 mark test_parseargs "$@"
304 8d212112 2023-04-16 mark run_test test_blame_basic
305 c4df265e 2023-07-19 mark run_test test_blame_commit_keywords