Blame


1 c970ea82 2019-07-27 stsp #!/bin/sh
2 c970ea82 2019-07-27 stsp #
3 c970ea82 2019-07-27 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 c970ea82 2019-07-27 stsp #
5 c970ea82 2019-07-27 stsp # Permission to use, copy, modify, and distribute this software for any
6 c970ea82 2019-07-27 stsp # purpose with or without fee is hereby granted, provided that the above
7 c970ea82 2019-07-27 stsp # copyright notice and this permission notice appear in all copies.
8 c970ea82 2019-07-27 stsp #
9 c970ea82 2019-07-27 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 c970ea82 2019-07-27 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 c970ea82 2019-07-27 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 c970ea82 2019-07-27 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 c970ea82 2019-07-27 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 c970ea82 2019-07-27 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 c970ea82 2019-07-27 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 c970ea82 2019-07-27 stsp
17 c970ea82 2019-07-27 stsp . ./common.sh
18 c970ea82 2019-07-27 stsp
19 f6cae3ed 2020-09-13 naddy blame_cmp() {
20 b24db1c1 2019-08-19 stsp local testroot="$1"
21 b24db1c1 2019-08-19 stsp local file="$2"
22 16357e96 2019-08-19 stsp local xfail="$3"
23 b24db1c1 2019-08-19 stsp
24 b24db1c1 2019-08-19 stsp (cd $testroot/wt && got blame "$file" | cut -d ' ' -f 2 \
25 b24db1c1 2019-08-19 stsp > $testroot/${file}.blame.got)
26 b24db1c1 2019-08-19 stsp (cd $testroot/repo && git reset --hard master > /dev/null)
27 b24db1c1 2019-08-19 stsp (cd $testroot/repo && git blame "$file" | cut -d ' ' -f 1 \
28 b24db1c1 2019-08-19 stsp > $testroot/${file}.blame.git)
29 b24db1c1 2019-08-19 stsp
30 b24db1c1 2019-08-19 stsp cmp -s $testroot/${file}.blame.git $testroot/${file}.blame.got
31 49c543a6 2022-03-31 naddy ret=$?
32 49c543a6 2022-03-31 naddy if [ $ret -ne 0 -a "$xfail" = "" ]; then
33 b24db1c1 2019-08-19 stsp diff -u $testroot/${file}.blame.git $testroot/${file}.blame.got
34 b24db1c1 2019-08-19 stsp return 1
35 b24db1c1 2019-08-19 stsp fi
36 16357e96 2019-08-19 stsp return "$ret"
37 b24db1c1 2019-08-19 stsp }
38 b24db1c1 2019-08-19 stsp
39 f6cae3ed 2020-09-13 naddy test_blame_basic() {
40 c970ea82 2019-07-27 stsp local testroot=`test_init blame_basic`
41 c970ea82 2019-07-27 stsp
42 c970ea82 2019-07-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
43 49c543a6 2022-03-31 naddy ret=$?
44 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
45 c970ea82 2019-07-27 stsp test_done "$testroot" "$ret"
46 c970ea82 2019-07-27 stsp return 1
47 c970ea82 2019-07-27 stsp fi
48 c970ea82 2019-07-27 stsp
49 c970ea82 2019-07-27 stsp echo 1 > $testroot/wt/alpha
50 c970ea82 2019-07-27 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
51 c970ea82 2019-07-27 stsp local commit1=`git_show_head $testroot/repo`
52 c970ea82 2019-07-27 stsp
53 c970ea82 2019-07-27 stsp echo 2 >> $testroot/wt/alpha
54 c970ea82 2019-07-27 stsp (cd $testroot/wt && got commit -m "change 2" > /dev/null)
55 c970ea82 2019-07-27 stsp local commit2=`git_show_head $testroot/repo`
56 c970ea82 2019-07-27 stsp
57 c970ea82 2019-07-27 stsp echo 3 >> $testroot/wt/alpha
58 c970ea82 2019-07-27 stsp (cd $testroot/wt && got commit -m "change 3" > /dev/null)
59 c970ea82 2019-07-27 stsp local commit3=`git_show_head $testroot/repo`
60 bcb49d15 2019-08-14 stsp local author_time=`git_show_author_time $testroot/repo`
61 c970ea82 2019-07-27 stsp
62 c970ea82 2019-07-27 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
63 c970ea82 2019-07-27 stsp
64 c970ea82 2019-07-27 stsp local short_commit1=`trim_obj_id 32 $commit1`
65 c970ea82 2019-07-27 stsp local short_commit2=`trim_obj_id 32 $commit2`
66 c970ea82 2019-07-27 stsp local short_commit3=`trim_obj_id 32 $commit3`
67 c970ea82 2019-07-27 stsp
68 dc8256b6 2021-08-31 naddy d=`date -u -r $author_time +"%G-%m-%d"`
69 bcb49d15 2019-08-14 stsp echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
70 bcb49d15 2019-08-14 stsp echo "2) $short_commit2 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected
71 bcb49d15 2019-08-14 stsp echo "3) $short_commit3 $d $GOT_AUTHOR_8 3" >> $testroot/stdout.expected
72 c970ea82 2019-07-27 stsp
73 c970ea82 2019-07-27 stsp cmp -s $testroot/stdout.expected $testroot/stdout
74 49c543a6 2022-03-31 naddy ret=$?
75 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
76 c970ea82 2019-07-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
77 b24db1c1 2019-08-19 stsp test_done "$testroot" "$ret"
78 b24db1c1 2019-08-19 stsp return 1
79 c970ea82 2019-07-27 stsp fi
80 c970ea82 2019-07-27 stsp
81 b24db1c1 2019-08-19 stsp blame_cmp "$testroot" "alpha"
82 49c543a6 2022-03-31 naddy ret=$?
83 c970ea82 2019-07-27 stsp test_done "$testroot" "$ret"
84 c970ea82 2019-07-27 stsp }
85 c970ea82 2019-07-27 stsp
86 f6cae3ed 2020-09-13 naddy test_blame_tag() {
87 303e2782 2019-08-09 stsp local testroot=`test_init blame_tag`
88 303e2782 2019-08-09 stsp local tag=1.0.0
89 303e2782 2019-08-09 stsp
90 303e2782 2019-08-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
91 49c543a6 2022-03-31 naddy ret=$?
92 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
93 303e2782 2019-08-09 stsp test_done "$testroot" "$ret"
94 303e2782 2019-08-09 stsp return 1
95 303e2782 2019-08-09 stsp fi
96 303e2782 2019-08-09 stsp echo 1 > $testroot/wt/alpha
97 303e2782 2019-08-09 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
98 303e2782 2019-08-09 stsp local commit1=`git_show_head $testroot/repo`
99 303e2782 2019-08-09 stsp
100 303e2782 2019-08-09 stsp echo 2 >> $testroot/wt/alpha
101 303e2782 2019-08-09 stsp (cd $testroot/wt && got commit -m "change 2" > /dev/null)
102 303e2782 2019-08-09 stsp local commit2=`git_show_head $testroot/repo`
103 303e2782 2019-08-09 stsp
104 303e2782 2019-08-09 stsp (cd $testroot/repo && git tag -a -m "test" $tag)
105 303e2782 2019-08-09 stsp
106 303e2782 2019-08-09 stsp echo 3 >> $testroot/wt/alpha
107 303e2782 2019-08-09 stsp (cd $testroot/wt && got commit -m "change 3" > /dev/null)
108 303e2782 2019-08-09 stsp local commit3=`git_show_head $testroot/repo`
109 bcb49d15 2019-08-14 stsp local author_time=`git_show_author_time $testroot/repo`
110 303e2782 2019-08-09 stsp
111 303e2782 2019-08-09 stsp (cd $testroot/wt && got blame -c $tag alpha > $testroot/stdout)
112 303e2782 2019-08-09 stsp
113 303e2782 2019-08-09 stsp local short_commit1=`trim_obj_id 32 $commit1`
114 303e2782 2019-08-09 stsp local short_commit2=`trim_obj_id 32 $commit2`
115 303e2782 2019-08-09 stsp
116 dc8256b6 2021-08-31 naddy d=`date -u -r $author_time +"%G-%m-%d"`
117 bcb49d15 2019-08-14 stsp echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
118 bcb49d15 2019-08-14 stsp echo "2) $short_commit2 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected
119 303e2782 2019-08-09 stsp
120 303e2782 2019-08-09 stsp cmp -s $testroot/stdout.expected $testroot/stdout
121 49c543a6 2022-03-31 naddy ret=$?
122 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
123 303e2782 2019-08-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
124 b24db1c1 2019-08-19 stsp test_done "$testroot" "$ret"
125 b24db1c1 2019-08-19 stsp return 1
126 303e2782 2019-08-09 stsp fi
127 b24db1c1 2019-08-19 stsp
128 b24db1c1 2019-08-19 stsp blame_cmp "$testroot" "alpha"
129 49c543a6 2022-03-31 naddy ret=$?
130 303e2782 2019-08-09 stsp test_done "$testroot" "$ret"
131 303e2782 2019-08-09 stsp }
132 303e2782 2019-08-09 stsp
133 f6cae3ed 2020-09-13 naddy test_blame_file_single_line() {
134 78695fb7 2019-08-12 stsp local testroot=`test_init blame_file_single_line`
135 78695fb7 2019-08-12 stsp
136 78695fb7 2019-08-12 stsp got checkout $testroot/repo $testroot/wt > /dev/null
137 49c543a6 2022-03-31 naddy ret=$?
138 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
139 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
140 78695fb7 2019-08-12 stsp return 1
141 78695fb7 2019-08-12 stsp fi
142 78695fb7 2019-08-12 stsp
143 78695fb7 2019-08-12 stsp echo 1 > $testroot/wt/alpha
144 78695fb7 2019-08-12 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
145 78695fb7 2019-08-12 stsp local commit1=`git_show_head $testroot/repo`
146 bcb49d15 2019-08-14 stsp local author_time=`git_show_author_time $testroot/repo`
147 78695fb7 2019-08-12 stsp
148 78695fb7 2019-08-12 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
149 78695fb7 2019-08-12 stsp
150 78695fb7 2019-08-12 stsp local short_commit1=`trim_obj_id 32 $commit1`
151 78695fb7 2019-08-12 stsp
152 dc8256b6 2021-08-31 naddy d=`date -u -r $author_time +"%G-%m-%d"`
153 bcb49d15 2019-08-14 stsp echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
154 78695fb7 2019-08-12 stsp
155 78695fb7 2019-08-12 stsp cmp -s $testroot/stdout.expected $testroot/stdout
156 49c543a6 2022-03-31 naddy ret=$?
157 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
158 78695fb7 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
159 b24db1c1 2019-08-19 stsp test_done "$testroot" "$ret"
160 b24db1c1 2019-08-19 stsp return 1
161 78695fb7 2019-08-12 stsp fi
162 b24db1c1 2019-08-19 stsp
163 b24db1c1 2019-08-19 stsp blame_cmp "$testroot" "alpha"
164 49c543a6 2022-03-31 naddy ret=$?
165 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
166 78695fb7 2019-08-12 stsp }
167 78695fb7 2019-08-12 stsp
168 f6cae3ed 2020-09-13 naddy test_blame_file_single_line_no_newline() {
169 78695fb7 2019-08-12 stsp local testroot=`test_init blame_file_single_line_no_newline`
170 78695fb7 2019-08-12 stsp
171 78695fb7 2019-08-12 stsp got checkout $testroot/repo $testroot/wt > /dev/null
172 49c543a6 2022-03-31 naddy ret=$?
173 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
174 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
175 78695fb7 2019-08-12 stsp return 1
176 78695fb7 2019-08-12 stsp fi
177 78695fb7 2019-08-12 stsp
178 78695fb7 2019-08-12 stsp echo -n 1 > $testroot/wt/alpha
179 78695fb7 2019-08-12 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
180 78695fb7 2019-08-12 stsp local commit1=`git_show_head $testroot/repo`
181 bcb49d15 2019-08-14 stsp local author_time=`git_show_author_time $testroot/repo`
182 78695fb7 2019-08-12 stsp
183 78695fb7 2019-08-12 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
184 78695fb7 2019-08-12 stsp
185 78695fb7 2019-08-12 stsp local short_commit1=`trim_obj_id 32 $commit1`
186 78695fb7 2019-08-12 stsp
187 dc8256b6 2021-08-31 naddy d=`date -u -r $author_time +"%G-%m-%d"`
188 bcb49d15 2019-08-14 stsp echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
189 78695fb7 2019-08-12 stsp
190 78695fb7 2019-08-12 stsp cmp -s $testroot/stdout.expected $testroot/stdout
191 49c543a6 2022-03-31 naddy ret=$?
192 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
193 78695fb7 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
194 78695fb7 2019-08-12 stsp fi
195 78695fb7 2019-08-12 stsp test_done "$testroot" "$ret"
196 78695fb7 2019-08-12 stsp }
197 78695fb7 2019-08-12 stsp
198 f6cae3ed 2020-09-13 naddy test_blame_all_lines_replaced() {
199 8d725ae1 2019-08-18 stsp local testroot=`test_init blame_all_lines_replaced`
200 8d725ae1 2019-08-18 stsp
201 8d725ae1 2019-08-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
202 49c543a6 2022-03-31 naddy ret=$?
203 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
204 8d725ae1 2019-08-18 stsp test_done "$testroot" "$ret"
205 8d725ae1 2019-08-18 stsp return 1
206 8d725ae1 2019-08-18 stsp fi
207 8d725ae1 2019-08-18 stsp
208 8d725ae1 2019-08-18 stsp jot 8 > $testroot/wt/alpha
209 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
210 8d725ae1 2019-08-18 stsp local commit1=`git_show_head $testroot/repo`
211 8d725ae1 2019-08-18 stsp local short_commit1=`trim_obj_id 32 $commit1`
212 8d725ae1 2019-08-18 stsp local author_time=`git_show_author_time $testroot/repo`
213 8d725ae1 2019-08-18 stsp
214 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
215 8d725ae1 2019-08-18 stsp
216 dc8256b6 2021-08-31 naddy d=`date -u -r $author_time +"%G-%m-%d"`
217 8d725ae1 2019-08-18 stsp echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
218 8d725ae1 2019-08-18 stsp echo "2) $short_commit1 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected
219 8d725ae1 2019-08-18 stsp echo "3) $short_commit1 $d $GOT_AUTHOR_8 3" >> $testroot/stdout.expected
220 8d725ae1 2019-08-18 stsp echo "4) $short_commit1 $d $GOT_AUTHOR_8 4" >> $testroot/stdout.expected
221 8d725ae1 2019-08-18 stsp echo "5) $short_commit1 $d $GOT_AUTHOR_8 5" >> $testroot/stdout.expected
222 8d725ae1 2019-08-18 stsp echo "6) $short_commit1 $d $GOT_AUTHOR_8 6" >> $testroot/stdout.expected
223 8d725ae1 2019-08-18 stsp echo "7) $short_commit1 $d $GOT_AUTHOR_8 7" >> $testroot/stdout.expected
224 8d725ae1 2019-08-18 stsp echo "8) $short_commit1 $d $GOT_AUTHOR_8 8" >> $testroot/stdout.expected
225 8d725ae1 2019-08-18 stsp
226 8d725ae1 2019-08-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
227 49c543a6 2022-03-31 naddy ret=$?
228 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
229 8d725ae1 2019-08-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
230 8d725ae1 2019-08-18 stsp fi
231 8d725ae1 2019-08-18 stsp test_done "$testroot" "$ret"
232 8d725ae1 2019-08-18 stsp
233 8d725ae1 2019-08-18 stsp }
234 8d725ae1 2019-08-18 stsp
235 f6cae3ed 2020-09-13 naddy test_blame_lines_shifted_up() {
236 8d725ae1 2019-08-18 stsp local testroot=`test_init blame_lines_shifted_up`
237 8d725ae1 2019-08-18 stsp
238 8d725ae1 2019-08-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
239 49c543a6 2022-03-31 naddy ret=$?
240 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
241 8d725ae1 2019-08-18 stsp test_done "$testroot" "$ret"
242 8d725ae1 2019-08-18 stsp return 1
243 8d725ae1 2019-08-18 stsp fi
244 8d725ae1 2019-08-18 stsp
245 8d725ae1 2019-08-18 stsp jot 8 > $testroot/wt/alpha
246 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
247 8d725ae1 2019-08-18 stsp local commit1=`git_show_head $testroot/repo`
248 8d725ae1 2019-08-18 stsp local short_commit1=`trim_obj_id 32 $commit1`
249 8d725ae1 2019-08-18 stsp local author_time=`git_show_author_time $testroot/repo`
250 8d725ae1 2019-08-18 stsp
251 885e96df 2023-03-06 naddy ed -s $testroot/wt/alpha <<-\EOF
252 885e96df 2023-03-06 naddy g/^[345]$/d
253 885e96df 2023-03-06 naddy w
254 885e96df 2023-03-06 naddy EOF
255 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got commit -m "change 2" > /dev/null)
256 8d725ae1 2019-08-18 stsp local commit2=`git_show_head $testroot/repo`
257 8d725ae1 2019-08-18 stsp local short_commit2=`trim_obj_id 32 $commit2`
258 8d725ae1 2019-08-18 stsp
259 8d725ae1 2019-08-18 stsp jot 2 > $testroot/wt/alpha
260 8d725ae1 2019-08-18 stsp echo foo >> $testroot/wt/alpha
261 8d725ae1 2019-08-18 stsp echo bar >> $testroot/wt/alpha
262 8d725ae1 2019-08-18 stsp echo baz >> $testroot/wt/alpha
263 8d725ae1 2019-08-18 stsp jot 8 6 8 1 >> $testroot/wt/alpha
264 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got commit -m "change 3" > /dev/null)
265 8d725ae1 2019-08-18 stsp local commit3=`git_show_head $testroot/repo`
266 8d725ae1 2019-08-18 stsp local short_commit3=`trim_obj_id 32 $commit3`
267 8d725ae1 2019-08-18 stsp local author_time=`git_show_author_time $testroot/repo`
268 8d725ae1 2019-08-18 stsp
269 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
270 8d725ae1 2019-08-18 stsp
271 dc8256b6 2021-08-31 naddy d=`date -u -r $author_time +"%G-%m-%d"`
272 8d725ae1 2019-08-18 stsp echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
273 8d725ae1 2019-08-18 stsp echo "2) $short_commit1 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected
274 8d725ae1 2019-08-18 stsp echo "3) $short_commit3 $d $GOT_AUTHOR_8 foo" >> $testroot/stdout.expected
275 8d725ae1 2019-08-18 stsp echo "4) $short_commit3 $d $GOT_AUTHOR_8 bar" >> $testroot/stdout.expected
276 8d725ae1 2019-08-18 stsp echo "5) $short_commit3 $d $GOT_AUTHOR_8 baz" >> $testroot/stdout.expected
277 8d725ae1 2019-08-18 stsp echo "6) $short_commit1 $d $GOT_AUTHOR_8 6" >> $testroot/stdout.expected
278 8d725ae1 2019-08-18 stsp echo "7) $short_commit1 $d $GOT_AUTHOR_8 7" >> $testroot/stdout.expected
279 8d725ae1 2019-08-18 stsp echo "8) $short_commit1 $d $GOT_AUTHOR_8 8" >> $testroot/stdout.expected
280 8d725ae1 2019-08-18 stsp
281 8d725ae1 2019-08-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
282 49c543a6 2022-03-31 naddy ret=$?
283 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
284 8d725ae1 2019-08-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
285 b24db1c1 2019-08-19 stsp test_done "$testroot" "$ret"
286 b24db1c1 2019-08-19 stsp return 1
287 8d725ae1 2019-08-18 stsp fi
288 8d725ae1 2019-08-18 stsp
289 b24db1c1 2019-08-19 stsp blame_cmp "$testroot" "alpha"
290 49c543a6 2022-03-31 naddy ret=$?
291 8d725ae1 2019-08-18 stsp test_done "$testroot" "$ret"
292 8d725ae1 2019-08-18 stsp }
293 8d725ae1 2019-08-18 stsp
294 f6cae3ed 2020-09-13 naddy test_blame_lines_shifted_down() {
295 8d725ae1 2019-08-18 stsp local testroot=`test_init blame_lines_shifted_down`
296 8d725ae1 2019-08-18 stsp
297 8d725ae1 2019-08-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
298 49c543a6 2022-03-31 naddy ret=$?
299 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
300 8d725ae1 2019-08-18 stsp test_done "$testroot" "$ret"
301 8d725ae1 2019-08-18 stsp return 1
302 8d725ae1 2019-08-18 stsp fi
303 8d725ae1 2019-08-18 stsp
304 8d725ae1 2019-08-18 stsp jot 8 > $testroot/wt/alpha
305 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
306 8d725ae1 2019-08-18 stsp local commit1=`git_show_head $testroot/repo`
307 8d725ae1 2019-08-18 stsp local short_commit1=`trim_obj_id 32 $commit1`
308 8d725ae1 2019-08-18 stsp local author_time=`git_show_author_time $testroot/repo`
309 8d725ae1 2019-08-18 stsp
310 885e96df 2023-03-06 naddy ed -s $testroot/wt/alpha <<-\EOF
311 885e96df 2023-03-06 naddy g/^8$/d
312 885e96df 2023-03-06 naddy w
313 885e96df 2023-03-06 naddy EOF
314 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got commit -m "change 2" > /dev/null)
315 8d725ae1 2019-08-18 stsp local commit2=`git_show_head $testroot/repo`
316 8d725ae1 2019-08-18 stsp local short_commit2=`trim_obj_id 32 $commit2`
317 8d725ae1 2019-08-18 stsp
318 8d725ae1 2019-08-18 stsp jot 2 > $testroot/wt/alpha
319 8d725ae1 2019-08-18 stsp echo foo >> $testroot/wt/alpha
320 8d725ae1 2019-08-18 stsp echo bar >> $testroot/wt/alpha
321 8d725ae1 2019-08-18 stsp echo baz >> $testroot/wt/alpha
322 8d725ae1 2019-08-18 stsp jot 8 3 8 1 >> $testroot/wt/alpha
323 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got commit -m "change 3" > /dev/null)
324 8d725ae1 2019-08-18 stsp local commit3=`git_show_head $testroot/repo`
325 8d725ae1 2019-08-18 stsp local short_commit3=`trim_obj_id 32 $commit3`
326 8d725ae1 2019-08-18 stsp local author_time=`git_show_author_time $testroot/repo`
327 8d725ae1 2019-08-18 stsp
328 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
329 8d725ae1 2019-08-18 stsp
330 dc8256b6 2021-08-31 naddy d=`date -u -r $author_time +"%G-%m-%d"`
331 8d725ae1 2019-08-18 stsp echo "01) $short_commit1 $d $GOT_AUTHOR_8 1" \
332 8d725ae1 2019-08-18 stsp > $testroot/stdout.expected
333 8d725ae1 2019-08-18 stsp echo "02) $short_commit1 $d $GOT_AUTHOR_8 2" \
334 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
335 8d725ae1 2019-08-18 stsp echo "03) $short_commit3 $d $GOT_AUTHOR_8 foo" \
336 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
337 8d725ae1 2019-08-18 stsp echo "04) $short_commit3 $d $GOT_AUTHOR_8 bar" \
338 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
339 8d725ae1 2019-08-18 stsp echo "05) $short_commit3 $d $GOT_AUTHOR_8 baz" \
340 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
341 8d725ae1 2019-08-18 stsp echo "06) $short_commit1 $d $GOT_AUTHOR_8 3" \
342 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
343 8d725ae1 2019-08-18 stsp echo "07) $short_commit1 $d $GOT_AUTHOR_8 4" \
344 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
345 8d725ae1 2019-08-18 stsp echo "08) $short_commit1 $d $GOT_AUTHOR_8 5" \
346 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
347 8d725ae1 2019-08-18 stsp echo "09) $short_commit1 $d $GOT_AUTHOR_8 6" \
348 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
349 8d725ae1 2019-08-18 stsp echo "10) $short_commit1 $d $GOT_AUTHOR_8 7" \
350 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
351 8d725ae1 2019-08-18 stsp echo "11) $short_commit3 $d $GOT_AUTHOR_8 8" \
352 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
353 8d725ae1 2019-08-18 stsp
354 8d725ae1 2019-08-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
355 49c543a6 2022-03-31 naddy ret=$?
356 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
357 8d725ae1 2019-08-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
358 b24db1c1 2019-08-19 stsp test_done "$testroot" "$ret"
359 b24db1c1 2019-08-19 stsp return 1
360 8d725ae1 2019-08-18 stsp fi
361 8d725ae1 2019-08-18 stsp
362 b24db1c1 2019-08-19 stsp blame_cmp "$testroot" "alpha"
363 49c543a6 2022-03-31 naddy ret=$?
364 8d725ae1 2019-08-18 stsp test_done "$testroot" "$ret"
365 8d725ae1 2019-08-18 stsp }
366 8d725ae1 2019-08-18 stsp
367 f6cae3ed 2020-09-13 naddy test_blame_commit_subsumed() {
368 8d725ae1 2019-08-18 stsp local testroot=`test_init blame_commit_subsumed`
369 8d725ae1 2019-08-18 stsp
370 8d725ae1 2019-08-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
371 49c543a6 2022-03-31 naddy ret=$?
372 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
373 8d725ae1 2019-08-18 stsp test_done "$testroot" "$ret"
374 8d725ae1 2019-08-18 stsp return 1
375 8d725ae1 2019-08-18 stsp fi
376 8d725ae1 2019-08-18 stsp
377 8d725ae1 2019-08-18 stsp cat > $testroot/wt/alpha <<EOF
378 8d725ae1 2019-08-18 stsp SUBDIRS = ext modules codedocs docs
379 8d725ae1 2019-08-18 stsp
380 8d725ae1 2019-08-18 stsp if WITH_PDNS_SERVER
381 8d725ae1 2019-08-18 stsp SUBDIRS += pdns
382 8d725ae1 2019-08-18 stsp endif
383 8d725ae1 2019-08-18 stsp
384 8d725ae1 2019-08-18 stsp EXTRA_DIST =
385 8d725ae1 2019-08-18 stsp INSTALL
386 8d725ae1 2019-08-18 stsp NOTICE
387 8d725ae1 2019-08-18 stsp README
388 8d725ae1 2019-08-18 stsp .version
389 8d725ae1 2019-08-18 stsp build-aux/gen-version
390 8d725ae1 2019-08-18 stsp codedocs/doxygen.conf
391 8d725ae1 2019-08-18 stsp contrib/powerdns.solaris.init.d
392 8d725ae1 2019-08-18 stsp pdns/named.conf.parsertest
393 8d725ae1 2019-08-18 stsp regression-tests/zones/unit.test
394 8d725ae1 2019-08-18 stsp
395 8d725ae1 2019-08-18 stsp ACLOCAL_AMFLAGS = -I m4
396 8d725ae1 2019-08-18 stsp
397 8d725ae1 2019-08-18 stsp dvi: # do nothing to build dvi
398 8d725ae1 2019-08-18 stsp EOF
399 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
400 8d725ae1 2019-08-18 stsp local commit1=`git_show_head $testroot/repo`
401 8d725ae1 2019-08-18 stsp local short_commit1=`trim_obj_id 32 $commit1`
402 8d725ae1 2019-08-18 stsp local author_time1=`git_show_author_time $testroot/repo`
403 dc8256b6 2021-08-31 naddy local d1=`date -u -r $author_time1 +"%G-%m-%d"`
404 8d725ae1 2019-08-18 stsp
405 8d725ae1 2019-08-18 stsp cat > $testroot/wt/alpha <<EOF
406 8d725ae1 2019-08-18 stsp SUBDIRS = ext modules codedocs docs
407 8d725ae1 2019-08-18 stsp
408 8d725ae1 2019-08-18 stsp SUBDIRS += pdns
409 8d725ae1 2019-08-18 stsp
410 8d725ae1 2019-08-18 stsp EXTRA_DIST =
411 8d725ae1 2019-08-18 stsp INSTALL
412 8d725ae1 2019-08-18 stsp NOTICE
413 8d725ae1 2019-08-18 stsp README
414 8d725ae1 2019-08-18 stsp .version
415 8d725ae1 2019-08-18 stsp build-aux/gen-version
416 8d725ae1 2019-08-18 stsp codedocs/doxygen.conf
417 8d725ae1 2019-08-18 stsp contrib/powerdns.solaris.init.d
418 8d725ae1 2019-08-18 stsp pdns/named.conf.parsertest
419 8d725ae1 2019-08-18 stsp regression-tests/zones/unit.test
420 8d725ae1 2019-08-18 stsp
421 8d725ae1 2019-08-18 stsp ACLOCAL_AMFLAGS = -I m4
422 8d725ae1 2019-08-18 stsp
423 8d725ae1 2019-08-18 stsp dvi: # do nothing to build dvi
424 8d725ae1 2019-08-18 stsp EOF
425 8d725ae1 2019-08-18 stsp # all changes in this commit will be subsumed by later commits
426 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got commit -m "change 2" > /dev/null)
427 8d725ae1 2019-08-18 stsp local commit2=`git_show_head $testroot/repo`
428 8d725ae1 2019-08-18 stsp local short_commit2=`trim_obj_id 32 $commit2`
429 8d725ae1 2019-08-18 stsp local author_time2=`git_show_author_time $testroot/repo`
430 dc8256b6 2021-08-31 naddy local d2=`date -u -r $author_time2 +"%G-%m-%d"`
431 8d725ae1 2019-08-18 stsp
432 8d725ae1 2019-08-18 stsp cat > $testroot/wt/alpha <<EOF
433 8d725ae1 2019-08-18 stsp SUBDIRS = ext modules pdns codedocs docs
434 8d725ae1 2019-08-18 stsp
435 8d725ae1 2019-08-18 stsp EXTRA_DIST =
436 8d725ae1 2019-08-18 stsp INSTALL
437 8d725ae1 2019-08-18 stsp NOTICE
438 8d725ae1 2019-08-18 stsp README
439 8d725ae1 2019-08-18 stsp .version
440 8d725ae1 2019-08-18 stsp build-aux/gen-version
441 8d725ae1 2019-08-18 stsp codedocs/doxygen.conf
442 8d725ae1 2019-08-18 stsp contrib/powerdns.solaris.init.d
443 8d725ae1 2019-08-18 stsp pdns/named.conf.parsertest
444 8d725ae1 2019-08-18 stsp regression-tests/zones/unit.test
445 8d725ae1 2019-08-18 stsp
446 8d725ae1 2019-08-18 stsp ACLOCAL_AMFLAGS = -I m4
447 8d725ae1 2019-08-18 stsp
448 8d725ae1 2019-08-18 stsp dvi: # do nothing to build dvi
449 8d725ae1 2019-08-18 stsp EOF
450 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got commit -m "change 3" > /dev/null)
451 8d725ae1 2019-08-18 stsp local commit3=`git_show_head $testroot/repo`
452 8d725ae1 2019-08-18 stsp local short_commit3=`trim_obj_id 32 $commit3`
453 8d725ae1 2019-08-18 stsp local author_time3=`git_show_author_time $testroot/repo`
454 dc8256b6 2021-08-31 naddy local d3=`date -u -r $author_time3 +"%G-%m-%d"`
455 8d725ae1 2019-08-18 stsp
456 8d725ae1 2019-08-18 stsp cat > $testroot/wt/alpha <<EOF
457 8d725ae1 2019-08-18 stsp SUBDIRS = ext modules pdns codedocs docs
458 8d725ae1 2019-08-18 stsp
459 8d725ae1 2019-08-18 stsp EXTRA_DIST =
460 8d725ae1 2019-08-18 stsp INSTALL
461 8d725ae1 2019-08-18 stsp NOTICE
462 8d725ae1 2019-08-18 stsp README
463 8d725ae1 2019-08-18 stsp COPYING
464 8d725ae1 2019-08-18 stsp codedocs/doxygen.conf
465 8d725ae1 2019-08-18 stsp contrib/powerdns.solaris.init.d
466 8d725ae1 2019-08-18 stsp pdns/named.conf.parsertest
467 8d725ae1 2019-08-18 stsp regression-tests/zones/unit.test
468 8d725ae1 2019-08-18 stsp builder-support/gen-version
469 8d725ae1 2019-08-18 stsp
470 8d725ae1 2019-08-18 stsp ACLOCAL_AMFLAGS = -I m4
471 8d725ae1 2019-08-18 stsp
472 8d725ae1 2019-08-18 stsp dvi: # do nothing to build dvi
473 8d725ae1 2019-08-18 stsp EOF
474 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got commit -m "change 4" > /dev/null)
475 8d725ae1 2019-08-18 stsp local commit4=`git_show_head $testroot/repo`
476 8d725ae1 2019-08-18 stsp local short_commit4=`trim_obj_id 32 $commit4`
477 8d725ae1 2019-08-18 stsp local author_time4=`git_show_author_time $testroot/repo`
478 dc8256b6 2021-08-31 naddy local d4=`date -u -r $author_time4 +"%G-%m-%d"`
479 8d725ae1 2019-08-18 stsp
480 8d725ae1 2019-08-18 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
481 8d725ae1 2019-08-18 stsp
482 8d725ae1 2019-08-18 stsp echo -n "01) $short_commit3 $d3 $GOT_AUTHOR_8 " \
483 8d725ae1 2019-08-18 stsp > $testroot/stdout.expected
484 8d725ae1 2019-08-18 stsp echo "SUBDIRS = ext modules pdns codedocs docs" \
485 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
486 8d725ae1 2019-08-18 stsp echo "02) $short_commit1 $d1 $GOT_AUTHOR_8 " \
487 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
488 8d725ae1 2019-08-18 stsp echo -n "03) $short_commit1 $d1 $GOT_AUTHOR_8 " \
489 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
490 8d725ae1 2019-08-18 stsp echo 'EXTRA_DIST =' >> $testroot/stdout.expected
491 8d725ae1 2019-08-18 stsp echo -n "04) $short_commit1 $d1 $GOT_AUTHOR_8 " \
492 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
493 8d725ae1 2019-08-18 stsp printf "\tINSTALL\n" >> $testroot/stdout.expected
494 8d725ae1 2019-08-18 stsp echo -n "05) $short_commit1 $d1 $GOT_AUTHOR_8 " \
495 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
496 8d725ae1 2019-08-18 stsp printf "\tNOTICE\n" >> $testroot/stdout.expected
497 8d725ae1 2019-08-18 stsp echo -n "06) $short_commit1 $d1 $GOT_AUTHOR_8 " \
498 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
499 8d725ae1 2019-08-18 stsp printf "\tREADME\n" >> $testroot/stdout.expected
500 8d725ae1 2019-08-18 stsp echo -n "07) $short_commit4 $d4 $GOT_AUTHOR_8 " \
501 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
502 8d725ae1 2019-08-18 stsp printf "\tCOPYING\n" >> $testroot/stdout.expected
503 8d725ae1 2019-08-18 stsp echo -n "08) $short_commit1 $d1 $GOT_AUTHOR_8 " \
504 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
505 8d725ae1 2019-08-18 stsp printf "\tcodedocs/doxygen.conf\n" >> $testroot/stdout.expected
506 8d725ae1 2019-08-18 stsp echo -n "09) $short_commit1 $d1 $GOT_AUTHOR_8 " \
507 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
508 8d725ae1 2019-08-18 stsp printf "\tcontrib/powerdns.solaris.init.d\n" \
509 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
510 8d725ae1 2019-08-18 stsp echo -n "10) $short_commit1 $d1 $GOT_AUTHOR_8 " \
511 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
512 8d725ae1 2019-08-18 stsp printf "\tpdns/named.conf.parsertest\n" >> $testroot/stdout.expected
513 8d725ae1 2019-08-18 stsp echo -n "11) $short_commit1 $d1 $GOT_AUTHOR_8 " \
514 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
515 8d725ae1 2019-08-18 stsp printf "\tregression-tests/zones/unit.test\n" \
516 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
517 8d725ae1 2019-08-18 stsp echo -n "12) $short_commit4 $d4 $GOT_AUTHOR_8 " \
518 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
519 8d725ae1 2019-08-18 stsp printf "\tbuilder-support/gen-version\n" >> $testroot/stdout.expected
520 8d725ae1 2019-08-18 stsp echo "13) $short_commit1 $d1 $GOT_AUTHOR_8 " \
521 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
522 8d725ae1 2019-08-18 stsp echo -n "14) $short_commit1 $d1 $GOT_AUTHOR_8 " \
523 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
524 8d725ae1 2019-08-18 stsp echo "ACLOCAL_AMFLAGS = -I m4" \
525 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
526 8d725ae1 2019-08-18 stsp echo "15) $short_commit1 $d1 $GOT_AUTHOR_8 " \
527 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
528 8d725ae1 2019-08-18 stsp echo -n "16) $short_commit1 $d1 $GOT_AUTHOR_8 " \
529 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
530 8d725ae1 2019-08-18 stsp echo "dvi: # do nothing to build dvi" \
531 8d725ae1 2019-08-18 stsp >> $testroot/stdout.expected
532 8d725ae1 2019-08-18 stsp
533 8d725ae1 2019-08-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
534 49c543a6 2022-03-31 naddy ret=$?
535 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
536 548237bc 2019-08-19 stsp diff -u $testroot/stdout.expected $testroot/stdout
537 548237bc 2019-08-19 stsp test_done "$testroot" "$ret"
538 8d725ae1 2019-08-18 stsp return 1
539 8d725ae1 2019-08-18 stsp fi
540 b24db1c1 2019-08-19 stsp
541 b24db1c1 2019-08-19 stsp blame_cmp "$testroot" "alpha"
542 49c543a6 2022-03-31 naddy ret=$?
543 16357e96 2019-08-19 stsp test_done "$testroot" "$ret"
544 16357e96 2019-08-19 stsp }
545 16357e96 2019-08-19 stsp
546 f6cae3ed 2020-09-13 naddy test_blame_blame_h() {
547 16357e96 2019-08-19 stsp local testroot=`test_init blame_blame_h`
548 16357e96 2019-08-19 stsp
549 16357e96 2019-08-19 stsp got checkout $testroot/repo $testroot/wt > /dev/null
550 49c543a6 2022-03-31 naddy ret=$?
551 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
552 16357e96 2019-08-19 stsp test_done "$testroot" "$ret"
553 16357e96 2019-08-19 stsp return 1
554 16357e96 2019-08-19 stsp fi
555 16357e96 2019-08-19 stsp
556 16357e96 2019-08-19 stsp cat > $testroot/wt/got_blame.h <<EOF
557 16357e96 2019-08-19 stsp /*
558 16357e96 2019-08-19 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
559 16357e96 2019-08-19 stsp *
560 16357e96 2019-08-19 stsp * Permission to use, copy, modify, and distribute this software for any
561 16357e96 2019-08-19 stsp * purpose with or without fee is hereby granted, provided that the above
562 16357e96 2019-08-19 stsp * copyright notice and this permission notice appear in all copies.
563 16357e96 2019-08-19 stsp *
564 16357e96 2019-08-19 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
565 16357e96 2019-08-19 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
566 16357e96 2019-08-19 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
567 16357e96 2019-08-19 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
568 16357e96 2019-08-19 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
569 16357e96 2019-08-19 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
570 16357e96 2019-08-19 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
571 16357e96 2019-08-19 stsp */
572 16357e96 2019-08-19 stsp
573 16357e96 2019-08-19 stsp const struct got_error *got_blame(const char *, struct got_object_id *,
574 16357e96 2019-08-19 stsp struct got_repository *, FILE *);
575 16357e96 2019-08-19 stsp EOF
576 16357e96 2019-08-19 stsp (cd $testroot/wt && got add got_blame.h > /dev/null)
577 16357e96 2019-08-19 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
578 16357e96 2019-08-19 stsp
579 16357e96 2019-08-19 stsp cat > $testroot/wt/blame-2.patch <<EOF
580 16357e96 2019-08-19 stsp diff 63581804340e880bf611c6a4a59eda26c503799f 84451b3ef755f3226d0d79af367632e5f3a830e7
581 16357e96 2019-08-19 stsp blob - b53ca469a18871cc2f6af334dab25028599c6488
582 16357e96 2019-08-19 stsp blob + c787aadf05e2afab61bd34976f7349912252e6da
583 16357e96 2019-08-19 stsp --- got_blame.h
584 16357e96 2019-08-19 stsp +++ got_blame.h
585 16357e96 2019-08-19 stsp @@ -14,5 +14,22 @@
586 16357e96 2019-08-19 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
587 16357e96 2019-08-19 stsp */
588 5e91dae4 2022-08-30 stsp
589 16357e96 2019-08-19 stsp +/*
590 16357e96 2019-08-19 stsp + * Write an annotated version of a file at a given in-repository path,
591 16357e96 2019-08-19 stsp + * as found in the commit specified by ID, to the specified output file.
592 16357e96 2019-08-19 stsp + */
593 16357e96 2019-08-19 stsp const struct got_error *got_blame(const char *, struct got_object_id *,
594 16357e96 2019-08-19 stsp struct got_repository *, FILE *);
595 16357e96 2019-08-19 stsp +
596 16357e96 2019-08-19 stsp +/*
597 16357e96 2019-08-19 stsp + * Like got_blame() but instead of generating an output file invoke
598 16357e96 2019-08-19 stsp + * a callback whenever an annotation has been computed for a line.
599 16357e96 2019-08-19 stsp + *
600 16357e96 2019-08-19 stsp + * The callback receives the provided void * argument, the total number
601 16357e96 2019-08-19 stsp + * of lines of the annotated file, a line number, and the ID of the commit
602 16357e96 2019-08-19 stsp + * which last changed this line.
603 16357e96 2019-08-19 stsp + */
604 16357e96 2019-08-19 stsp +const struct got_error *got_blame_incremental(const char *,
605 16357e96 2019-08-19 stsp + struct got_object_id *, struct got_repository *,
606 16357e96 2019-08-19 stsp + const struct got_error *(*cb)(void *, int, int, struct got_object_id *),
607 16357e96 2019-08-19 stsp + void *);
608 16357e96 2019-08-19 stsp EOF
609 16357e96 2019-08-19 stsp (cd $testroot/wt && patch < blame-2.patch > /dev/null)
610 16357e96 2019-08-19 stsp (cd $testroot/wt && got commit -m "change 2" > /dev/null)
611 16357e96 2019-08-19 stsp
612 16357e96 2019-08-19 stsp cat > $testroot/wt/blame-3.patch <<EOF
613 16357e96 2019-08-19 stsp diff 75b7a700d9d14ef8eb902961255212acbedef164 d68a0a7de13af722c55099582019c03240e13320
614 16357e96 2019-08-19 stsp blob - c787aadf05e2afab61bd34976f7349912252e6da
615 16357e96 2019-08-19 stsp blob + 5255d076c915accf159940978b821d06803ff2f8
616 16357e96 2019-08-19 stsp --- got_blame.h
617 16357e96 2019-08-19 stsp +++ got_blame.h
618 16357e96 2019-08-19 stsp @@ -28,6 +28,15 @@ const struct got_error *got_blame(const char *, struct
619 16357e96 2019-08-19 stsp * The callback receives the provided void * argument, the total number
620 16357e96 2019-08-19 stsp * of lines of the annotated file, a line number, and the ID of the commit
621 16357e96 2019-08-19 stsp * which last changed this line.
622 16357e96 2019-08-19 stsp + *
623 16357e96 2019-08-19 stsp + * The callback is invoked for each commit as history is traversed.
624 16357e96 2019-08-19 stsp + * If no changes to the file were made in a commit, line number -1 and
625 16357e96 2019-08-19 stsp + * commit ID NULL will be reported.
626 16357e96 2019-08-19 stsp + *
627 16357e96 2019-08-19 stsp + * If the callback returns GOT_ERR_ITER_COMPLETED, the blame operation
628 16357e96 2019-08-19 stsp + * will be aborted and this function returns NULL.
629 16357e96 2019-08-19 stsp + * If the callback returns any other error, the blame operation will be
630 16357e96 2019-08-19 stsp + * aborted and the callback's error is returned from this function.
631 16357e96 2019-08-19 stsp */
632 16357e96 2019-08-19 stsp const struct got_error *got_blame_incremental(const char *,
633 16357e96 2019-08-19 stsp struct got_object_id *, struct got_repository *,
634 16357e96 2019-08-19 stsp EOF
635 16357e96 2019-08-19 stsp (cd $testroot/wt && patch < blame-3.patch > /dev/null)
636 16357e96 2019-08-19 stsp (cd $testroot/wt && got commit -m "change 3" > /dev/null)
637 16357e96 2019-08-19 stsp
638 16357e96 2019-08-19 stsp cat > $testroot/wt/blame-4.patch <<EOF
639 16357e96 2019-08-19 stsp diff 3f60a8ef49086101685260fcb829f578cdf6d320 3bf198ba335fa30c8d16efb5c8e496200ac99c05
640 16357e96 2019-08-19 stsp blob - 5255d076c915accf159940978b821d06803ff2f8
641 16357e96 2019-08-19 stsp blob + 39623c468e733ee08abb50eafe29202b2b0a04ef
642 16357e96 2019-08-19 stsp --- got_blame.h
643 16357e96 2019-08-19 stsp +++ got_blame.h
644 16357e96 2019-08-19 stsp @@ -30,8 +30,8 @@ const struct got_error *got_blame(const char *, struct
645 16357e96 2019-08-19 stsp * which last changed this line.
646 16357e96 2019-08-19 stsp *
647 16357e96 2019-08-19 stsp * The callback is invoked for each commit as history is traversed.
648 16357e96 2019-08-19 stsp - * If no changes to the file were made in a commit, line number -1 and
649 16357e96 2019-08-19 stsp - * commit ID NULL will be reported.
650 16357e96 2019-08-19 stsp + * If no changes to the file were made in a commit, line number -1 will
651 16357e96 2019-08-19 stsp + * be reported.
652 16357e96 2019-08-19 stsp *
653 16357e96 2019-08-19 stsp * If the callback returns GOT_ERR_ITER_COMPLETED, the blame operation
654 16357e96 2019-08-19 stsp * will be aborted and this function returns NULL.
655 16357e96 2019-08-19 stsp EOF
656 16357e96 2019-08-19 stsp (cd $testroot/wt && patch < blame-4.patch > /dev/null)
657 16357e96 2019-08-19 stsp (cd $testroot/wt && got commit -m "change 4" > /dev/null)
658 16357e96 2019-08-19 stsp
659 16357e96 2019-08-19 stsp cat > $testroot/wt/blame-5.patch <<EOF
660 16357e96 2019-08-19 stsp diff 28315671b93d195163b0468fcb3879e29b25759c e27a7222faaa171dcb086ea0b566dc7bebb74a0b
661 16357e96 2019-08-19 stsp blob - 39623c468e733ee08abb50eafe29202b2b0a04ef
662 16357e96 2019-08-19 stsp blob + 6075cadbd177e1802679c7353515bf4ceebb51d0
663 16357e96 2019-08-19 stsp --- got_blame.h
664 16357e96 2019-08-19 stsp +++ got_blame.h
665 16357e96 2019-08-19 stsp @@ -15,14 +15,7 @@
666 16357e96 2019-08-19 stsp */
667 5e91dae4 2022-08-30 stsp
668 16357e96 2019-08-19 stsp /*
669 16357e96 2019-08-19 stsp - * Write an annotated version of a file at a given in-repository path,
670 16357e96 2019-08-19 stsp - * as found in the commit specified by ID, to the specified output file.
671 16357e96 2019-08-19 stsp - */
672 16357e96 2019-08-19 stsp -const struct got_error *got_blame(const char *, struct got_object_id *,
673 16357e96 2019-08-19 stsp - struct got_repository *, FILE *);
674 16357e96 2019-08-19 stsp -
675 16357e96 2019-08-19 stsp -/*
676 16357e96 2019-08-19 stsp - * Like got_blame() but instead of generating an output file invoke
677 16357e96 2019-08-19 stsp + * Blame the blob at the specified path in the specified commit and invoke
678 16357e96 2019-08-19 stsp * a callback whenever an annotation has been computed for a line.
679 16357e96 2019-08-19 stsp *
680 16357e96 2019-08-19 stsp * The callback receives the provided void * argument, the total number
681 16357e96 2019-08-19 stsp EOF
682 16357e96 2019-08-19 stsp (cd $testroot/wt && patch < blame-5.patch > /dev/null)
683 16357e96 2019-08-19 stsp (cd $testroot/wt && got commit -m "change 5" > /dev/null)
684 16357e96 2019-08-19 stsp
685 4c9641fd 2019-08-21 stsp blame_cmp "$testroot" "got_blame.h"
686 49c543a6 2022-03-31 naddy ret=$?
687 8d725ae1 2019-08-18 stsp test_done "$testroot" "$ret"
688 8d725ae1 2019-08-18 stsp }
689 db32465d 2020-02-07 stsp
690 f6cae3ed 2020-09-13 naddy test_blame_added_on_branch() {
691 db32465d 2020-02-07 stsp local testroot=`test_init blame_added_on_branch`
692 db32465d 2020-02-07 stsp
693 db32465d 2020-02-07 stsp got branch -r $testroot/repo -c master newbranch
694 49c543a6 2022-03-31 naddy ret=$?
695 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
696 db32465d 2020-02-07 stsp test_done "$testroot" "$ret"
697 db32465d 2020-02-07 stsp return 1
698 db32465d 2020-02-07 stsp fi
699 8d725ae1 2019-08-18 stsp
700 db32465d 2020-02-07 stsp got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
701 49c543a6 2022-03-31 naddy ret=$?
702 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
703 db32465d 2020-02-07 stsp test_done "$testroot" "$ret"
704 db32465d 2020-02-07 stsp return 1
705 db32465d 2020-02-07 stsp fi
706 db32465d 2020-02-07 stsp
707 db32465d 2020-02-07 stsp echo 1 > $testroot/wt/new
708 db32465d 2020-02-07 stsp (cd $testroot/wt && got add new > /dev/null)
709 db32465d 2020-02-07 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
710 db32465d 2020-02-07 stsp local commit1=`git_show_branch_head $testroot/repo newbranch`
711 db32465d 2020-02-07 stsp
712 db32465d 2020-02-07 stsp echo 2 >> $testroot/wt/new
713 db32465d 2020-02-07 stsp (cd $testroot/wt && got commit -m "change 2" > /dev/null)
714 db32465d 2020-02-07 stsp local commit2=`git_show_branch_head $testroot/repo newbranch`
715 db32465d 2020-02-07 stsp
716 db32465d 2020-02-07 stsp echo 3 >> $testroot/wt/new
717 db32465d 2020-02-07 stsp (cd $testroot/wt && got commit -m "change 3" > /dev/null)
718 db32465d 2020-02-07 stsp local commit3=`git_show_branch_head $testroot/repo newbranch`
719 db32465d 2020-02-07 stsp local author_time=`git_show_author_time $testroot/repo`
720 db32465d 2020-02-07 stsp
721 db32465d 2020-02-07 stsp (cd $testroot/wt && got blame new > $testroot/stdout)
722 db32465d 2020-02-07 stsp
723 db32465d 2020-02-07 stsp local short_commit1=`trim_obj_id 32 $commit1`
724 db32465d 2020-02-07 stsp local short_commit2=`trim_obj_id 32 $commit2`
725 db32465d 2020-02-07 stsp local short_commit3=`trim_obj_id 32 $commit3`
726 db32465d 2020-02-07 stsp
727 dc8256b6 2021-08-31 naddy d=`date -u -r $author_time +"%G-%m-%d"`
728 db32465d 2020-02-07 stsp echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected
729 db32465d 2020-02-07 stsp echo "2) $short_commit2 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected
730 db32465d 2020-02-07 stsp echo "3) $short_commit3 $d $GOT_AUTHOR_8 3" >> $testroot/stdout.expected
731 db32465d 2020-02-07 stsp
732 db32465d 2020-02-07 stsp cmp -s $testroot/stdout.expected $testroot/stdout
733 49c543a6 2022-03-31 naddy ret=$?
734 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
735 db32465d 2020-02-07 stsp diff -u $testroot/stdout.expected $testroot/stdout
736 e7303626 2020-05-14 stsp fi
737 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
738 e7303626 2020-05-14 stsp }
739 e7303626 2020-05-14 stsp
740 f6cae3ed 2020-09-13 naddy test_blame_submodule() {
741 e7303626 2020-05-14 stsp local testroot=`test_init blame_submodule`
742 e7303626 2020-05-14 stsp local commit_id0=`git_show_head $testroot/repo`
743 e7303626 2020-05-14 stsp local author_time=`git_show_author_time $testroot/repo`
744 e7303626 2020-05-14 stsp
745 e7303626 2020-05-14 stsp make_single_file_repo $testroot/repo2 foo
746 e7303626 2020-05-14 stsp
747 f1aec6ed 2022-10-24 stsp (cd $testroot/repo && git -c protocol.file.allow=always \
748 f1aec6ed 2022-10-24 stsp submodule -q add ../repo2)
749 e7303626 2020-05-14 stsp (cd $testroot/repo && git commit -q -m 'adding submodule')
750 e7303626 2020-05-14 stsp
751 e7303626 2020-05-14 stsp # Attempt a (nonsensical) blame of a submodule.
752 e7303626 2020-05-14 stsp got blame -r $testroot/repo repo2 \
753 e7303626 2020-05-14 stsp > $testroot/stdout 2> $testroot/stderr
754 49c543a6 2022-03-31 naddy ret=$?
755 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
756 e7303626 2020-05-14 stsp echo "blame command succeeded unexpectedly" >&2
757 e7303626 2020-05-14 stsp test_done "$testroot" "1"
758 e7303626 2020-05-14 stsp return 1
759 db32465d 2020-02-07 stsp fi
760 e7303626 2020-05-14 stsp local submodule_id=$(got tree -r $testroot/repo -i | \
761 e7303626 2020-05-14 stsp grep 'repo2\$$' | cut -d ' ' -f1)
762 e7303626 2020-05-14 stsp echo "got: object $submodule_id not found" > $testroot/stderr.expected
763 e7303626 2020-05-14 stsp
764 e7303626 2020-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
765 49c543a6 2022-03-31 naddy ret=$?
766 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
767 e7303626 2020-05-14 stsp diff -u $testroot/stderr.expected $testroot/stderr
768 e7303626 2020-05-14 stsp fi
769 db32465d 2020-02-07 stsp test_done "$testroot" "$ret"
770 db32465d 2020-02-07 stsp }
771 0587e10c 2020-07-23 stsp
772 f6cae3ed 2020-09-13 naddy test_blame_symlink() {
773 0587e10c 2020-07-23 stsp local testroot=`test_init blame_symlink`
774 0587e10c 2020-07-23 stsp local commit_id0=`git_show_head $testroot/repo`
775 0587e10c 2020-07-23 stsp local short_commit0=`trim_obj_id 32 $commit_id0`
776 0587e10c 2020-07-23 stsp
777 0587e10c 2020-07-23 stsp (cd $testroot/repo && ln -s alpha alpha.link)
778 0587e10c 2020-07-23 stsp (cd $testroot/repo && ln -s epsilon epsilon.link)
779 0587e10c 2020-07-23 stsp (cd $testroot/repo && ln -s /etc/passwd passwd.link)
780 0587e10c 2020-07-23 stsp (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
781 0587e10c 2020-07-23 stsp (cd $testroot/repo && ln -s nonexistent nonexistent.link)
782 0587e10c 2020-07-23 stsp (cd $testroot/repo && git add .)
783 0587e10c 2020-07-23 stsp git_commit $testroot/repo -m "add symlinks"
784 0587e10c 2020-07-23 stsp
785 0587e10c 2020-07-23 stsp local commit_id1=`git_show_head $testroot/repo`
786 0587e10c 2020-07-23 stsp local short_commit1=`trim_obj_id 32 $commit_id1`
787 0587e10c 2020-07-23 stsp local author_time=`git_show_author_time $testroot/repo`
788 0587e10c 2020-07-23 stsp
789 0587e10c 2020-07-23 stsp # got blame dereferences symlink to a regular file
790 0587e10c 2020-07-23 stsp got blame -r $testroot/repo alpha.link > $testroot/stdout
791 49c543a6 2022-03-31 naddy ret=$?
792 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
793 0587e10c 2020-07-23 stsp echo "blame command failed unexpectedly" >&2
794 0587e10c 2020-07-23 stsp test_done "$testroot" "$ret"
795 0587e10c 2020-07-23 stsp return 1
796 0587e10c 2020-07-23 stsp fi
797 0587e10c 2020-07-23 stsp
798 dc8256b6 2021-08-31 naddy d=`date -u -r $author_time +"%G-%m-%d"`
799 0587e10c 2020-07-23 stsp echo "1) $short_commit0 $d $GOT_AUTHOR_8 alpha" \
800 0587e10c 2020-07-23 stsp > $testroot/stdout.expected
801 0587e10c 2020-07-23 stsp
802 0587e10c 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
803 49c543a6 2022-03-31 naddy ret=$?
804 49c543a6 2022-03-31 naddy if [ $ret -ne 0 -a "$xfail" = "" ]; then
805 0587e10c 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
806 0587e10c 2020-07-23 stsp test_done "$testroot" "1"
807 0587e10c 2020-07-23 stsp return 1
808 0587e10c 2020-07-23 stsp fi
809 db32465d 2020-02-07 stsp
810 0587e10c 2020-07-23 stsp # got blame dereferences symlink with relative path
811 0587e10c 2020-07-23 stsp got blame -r $testroot/repo epsilon/beta.link > $testroot/stdout
812 49c543a6 2022-03-31 naddy ret=$?
813 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
814 0587e10c 2020-07-23 stsp echo "blame command failed unexpectedly" >&2
815 0587e10c 2020-07-23 stsp test_done "$testroot" "$ret"
816 0587e10c 2020-07-23 stsp return 1
817 0587e10c 2020-07-23 stsp fi
818 0587e10c 2020-07-23 stsp
819 dc8256b6 2021-08-31 naddy d=`date -u -r $author_time +"%G-%m-%d"`
820 0587e10c 2020-07-23 stsp echo "1) $short_commit0 $d $GOT_AUTHOR_8 beta" \
821 0587e10c 2020-07-23 stsp > $testroot/stdout.expected
822 0587e10c 2020-07-23 stsp
823 0587e10c 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
824 49c543a6 2022-03-31 naddy ret=$?
825 49c543a6 2022-03-31 naddy if [ $ret -ne 0 -a "$xfail" = "" ]; then
826 0587e10c 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
827 0587e10c 2020-07-23 stsp test_done "$testroot" "1"
828 0587e10c 2020-07-23 stsp return 1
829 0587e10c 2020-07-23 stsp fi
830 0587e10c 2020-07-23 stsp
831 0587e10c 2020-07-23 stsp got blame -r $testroot/repo epsilon.link > $testroot/stdout \
832 0587e10c 2020-07-23 stsp 2> $testroot/stderr
833 49c543a6 2022-03-31 naddy ret=$?
834 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
835 0587e10c 2020-07-23 stsp echo "blame command succeeded unexpectedly" >&2
836 0587e10c 2020-07-23 stsp test_done "$testroot" "1"
837 0587e10c 2020-07-23 stsp return 1
838 0587e10c 2020-07-23 stsp fi
839 0587e10c 2020-07-23 stsp
840 0587e10c 2020-07-23 stsp # blame dereferences symlink to a directory
841 eb59b6d4 2020-07-23 stsp echo "got: /epsilon: wrong type of object" > $testroot/stderr.expected
842 0587e10c 2020-07-23 stsp cmp -s $testroot/stderr.expected $testroot/stderr
843 49c543a6 2022-03-31 naddy ret=$?
844 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
845 0587e10c 2020-07-23 stsp diff -u $testroot/stderr.expected $testroot/stderr
846 0587e10c 2020-07-23 stsp test_done "$testroot" "1"
847 0587e10c 2020-07-23 stsp return 1
848 0587e10c 2020-07-23 stsp fi
849 0587e10c 2020-07-23 stsp
850 0587e10c 2020-07-23 stsp # got blame fails if symlink target does not exist in repo
851 0587e10c 2020-07-23 stsp got blame -r $testroot/repo passwd.link > $testroot/stdout \
852 0587e10c 2020-07-23 stsp 2> $testroot/stderr
853 49c543a6 2022-03-31 naddy ret=$?
854 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
855 0587e10c 2020-07-23 stsp echo "blame command succeeded unexpectedly" >&2
856 a19f439c 2022-06-03 op test_done "$testroot" "1"
857 0587e10c 2020-07-23 stsp return 1
858 0587e10c 2020-07-23 stsp fi
859 0587e10c 2020-07-23 stsp
860 0587e10c 2020-07-23 stsp echo "got: /etc/passwd: no such entry found in tree" \
861 0587e10c 2020-07-23 stsp > $testroot/stderr.expected
862 0587e10c 2020-07-23 stsp cmp -s $testroot/stderr.expected $testroot/stderr
863 49c543a6 2022-03-31 naddy ret=$?
864 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
865 0587e10c 2020-07-23 stsp diff -u $testroot/stderr.expected $testroot/stderr
866 0587e10c 2020-07-23 stsp test_done "$testroot" "1"
867 0587e10c 2020-07-23 stsp return 1
868 0587e10c 2020-07-23 stsp fi
869 0587e10c 2020-07-23 stsp
870 0587e10c 2020-07-23 stsp got blame -r $testroot/repo nonexistent.link > $testroot/stdout \
871 0587e10c 2020-07-23 stsp 2> $testroot/stderr
872 49c543a6 2022-03-31 naddy ret=$?
873 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
874 0587e10c 2020-07-23 stsp echo "blame command succeeded unexpectedly" >&2
875 a19f439c 2022-06-03 op test_done "$testroot" "1"
876 0587e10c 2020-07-23 stsp return 1
877 0587e10c 2020-07-23 stsp fi
878 0587e10c 2020-07-23 stsp
879 0587e10c 2020-07-23 stsp echo "got: /nonexistent: no such entry found in tree" \
880 0587e10c 2020-07-23 stsp > $testroot/stderr.expected
881 0587e10c 2020-07-23 stsp cmp -s $testroot/stderr.expected $testroot/stderr
882 49c543a6 2022-03-31 naddy ret=$?
883 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
884 0587e10c 2020-07-23 stsp diff -u $testroot/stderr.expected $testroot/stderr
885 0587e10c 2020-07-23 stsp test_done "$testroot" "1"
886 0587e10c 2020-07-23 stsp return 1
887 0587e10c 2020-07-23 stsp fi
888 0587e10c 2020-07-23 stsp
889 0587e10c 2020-07-23 stsp test_done "$testroot" "$ret"
890 0587e10c 2020-07-23 stsp }
891 c27a5e66 2020-11-18 stsp
892 c27a5e66 2020-11-18 stsp test_blame_lines_shifted_skip() {
893 c27a5e66 2020-11-18 stsp local testroot=`test_init blame_lines_shifted_skip`
894 c27a5e66 2020-11-18 stsp
895 c27a5e66 2020-11-18 stsp got checkout $testroot/repo $testroot/wt > /dev/null
896 49c543a6 2022-03-31 naddy ret=$?
897 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
898 c27a5e66 2020-11-18 stsp test_done "$testroot" "$ret"
899 c27a5e66 2020-11-18 stsp return 1
900 c27a5e66 2020-11-18 stsp fi
901 c27a5e66 2020-11-18 stsp
902 c27a5e66 2020-11-18 stsp cat > $testroot/wt/alpha <<EOF
903 c27a5e66 2020-11-18 stsp A
904 c27a5e66 2020-11-18 stsp B
905 c27a5e66 2020-11-18 stsp C
906 c27a5e66 2020-11-18 stsp D
907 c27a5e66 2020-11-18 stsp EOF
908 c27a5e66 2020-11-18 stsp (cd $testroot/wt && got commit -m "change 1" > /dev/null)
909 c27a5e66 2020-11-18 stsp local commit1=`git_show_head $testroot/repo`
910 c27a5e66 2020-11-18 stsp local short_commit1=`trim_obj_id 32 $commit1`
911 ca6354ef 2023-05-12 stsp local author_time1=`git_show_author_time $testroot/repo`
912 0587e10c 2020-07-23 stsp
913 c27a5e66 2020-11-18 stsp cat > $testroot/wt/alpha <<EOF
914 c27a5e66 2020-11-18 stsp A
915 c27a5e66 2020-11-18 stsp B
916 c27a5e66 2020-11-18 stsp Y
917 c27a5e66 2020-11-18 stsp C
918 c27a5e66 2020-11-18 stsp P
919 c27a5e66 2020-11-18 stsp Q
920 c27a5e66 2020-11-18 stsp EOF
921 c27a5e66 2020-11-18 stsp (cd $testroot/wt && got commit -m "change 2" > /dev/null)
922 c27a5e66 2020-11-18 stsp local commit2=`git_show_head $testroot/repo`
923 c27a5e66 2020-11-18 stsp local short_commit2=`trim_obj_id 32 $commit2`
924 ca6354ef 2023-05-12 stsp local author_time2=`git_show_author_time $testroot/repo`
925 c27a5e66 2020-11-18 stsp
926 c27a5e66 2020-11-18 stsp cat > $testroot/wt/alpha <<EOF
927 c27a5e66 2020-11-18 stsp A
928 c27a5e66 2020-11-18 stsp B
929 c27a5e66 2020-11-18 stsp Y
930 c27a5e66 2020-11-18 stsp C
931 c27a5e66 2020-11-18 stsp D
932 c27a5e66 2020-11-18 stsp P
933 c27a5e66 2020-11-18 stsp Q
934 c27a5e66 2020-11-18 stsp EOF
935 c27a5e66 2020-11-18 stsp (cd $testroot/wt && got commit -m "change 3" > /dev/null)
936 c27a5e66 2020-11-18 stsp local commit3=`git_show_head $testroot/repo`
937 c27a5e66 2020-11-18 stsp local short_commit3=`trim_obj_id 32 $commit3`
938 ca6354ef 2023-05-12 stsp local author_time3=`git_show_author_time $testroot/repo`
939 c27a5e66 2020-11-18 stsp
940 c27a5e66 2020-11-18 stsp cat > $testroot/wt/alpha <<EOF
941 c27a5e66 2020-11-18 stsp A
942 c27a5e66 2020-11-18 stsp B
943 c27a5e66 2020-11-18 stsp C
944 c27a5e66 2020-11-18 stsp P
945 c27a5e66 2020-11-18 stsp Y
946 c27a5e66 2020-11-18 stsp Q
947 c27a5e66 2020-11-18 stsp EOF
948 c27a5e66 2020-11-18 stsp (cd $testroot/wt && got commit -m "change 4" > /dev/null)
949 c27a5e66 2020-11-18 stsp local commit4=`git_show_head $testroot/repo`
950 c27a5e66 2020-11-18 stsp local short_commit4=`trim_obj_id 32 $commit4`
951 ca6354ef 2023-05-12 stsp local author_time4=`git_show_author_time $testroot/repo`
952 c27a5e66 2020-11-18 stsp
953 c27a5e66 2020-11-18 stsp cat > $testroot/wt/alpha <<EOF
954 c27a5e66 2020-11-18 stsp X
955 c27a5e66 2020-11-18 stsp A
956 c27a5e66 2020-11-18 stsp B
957 c27a5e66 2020-11-18 stsp C
958 c27a5e66 2020-11-18 stsp P
959 c27a5e66 2020-11-18 stsp Y
960 c27a5e66 2020-11-18 stsp Q
961 c27a5e66 2020-11-18 stsp EOF
962 c27a5e66 2020-11-18 stsp (cd $testroot/wt && got commit -m "change 5" > /dev/null)
963 c27a5e66 2020-11-18 stsp local commit5=`git_show_head $testroot/repo`
964 c27a5e66 2020-11-18 stsp local short_commit5=`trim_obj_id 32 $commit5`
965 ca6354ef 2023-05-12 stsp local author_time5=`git_show_author_time $testroot/repo`
966 c27a5e66 2020-11-18 stsp
967 c27a5e66 2020-11-18 stsp (cd $testroot/wt && got blame alpha > $testroot/stdout)
968 c27a5e66 2020-11-18 stsp
969 ca6354ef 2023-05-12 stsp d1=`date -u -r $author_time1 +"%G-%m-%d"`
970 ca6354ef 2023-05-12 stsp d2=`date -u -r $author_time2 +"%G-%m-%d"`
971 ca6354ef 2023-05-12 stsp d4=`date -u -r $author_time4 +"%G-%m-%d"`
972 ca6354ef 2023-05-12 stsp d5=`date -u -r $author_time5 +"%G-%m-%d"`
973 ca6354ef 2023-05-12 stsp echo "1) $short_commit5 $d5 $GOT_AUTHOR_8 X" > $testroot/stdout.expected
974 ca6354ef 2023-05-12 stsp echo "2) $short_commit1 $d1 $GOT_AUTHOR_8 A" >> $testroot/stdout.expected
975 ca6354ef 2023-05-12 stsp echo "3) $short_commit1 $d1 $GOT_AUTHOR_8 B" >> $testroot/stdout.expected
976 ca6354ef 2023-05-12 stsp echo "4) $short_commit1 $d1 $GOT_AUTHOR_8 C" >> $testroot/stdout.expected
977 ca6354ef 2023-05-12 stsp echo "5) $short_commit2 $d2 $GOT_AUTHOR_8 P" >> $testroot/stdout.expected
978 ca6354ef 2023-05-12 stsp echo "6) $short_commit4 $d4 $GOT_AUTHOR_8 Y" >> $testroot/stdout.expected
979 ca6354ef 2023-05-12 stsp echo "7) $short_commit2 $d5 $GOT_AUTHOR_8 Q" >> $testroot/stdout.expected
980 c27a5e66 2020-11-18 stsp
981 c27a5e66 2020-11-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
982 49c543a6 2022-03-31 naddy ret=$?
983 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
984 c27a5e66 2020-11-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
985 c27a5e66 2020-11-18 stsp test_done "$testroot" "$ret"
986 c27a5e66 2020-11-18 stsp return 1
987 c27a5e66 2020-11-18 stsp fi
988 c27a5e66 2020-11-18 stsp
989 c27a5e66 2020-11-18 stsp blame_cmp "$testroot" "alpha"
990 49c543a6 2022-03-31 naddy ret=$?
991 c27a5e66 2020-11-18 stsp test_done "$testroot" "$ret"
992 c27a5e66 2020-11-18 stsp }
993 c27a5e66 2020-11-18 stsp
994 7fb414ae 2020-08-08 stsp test_parseargs "$@"
995 c970ea82 2019-07-27 stsp run_test test_blame_basic
996 303e2782 2019-08-09 stsp run_test test_blame_tag
997 78695fb7 2019-08-12 stsp run_test test_blame_file_single_line
998 78695fb7 2019-08-12 stsp run_test test_blame_file_single_line_no_newline
999 8d725ae1 2019-08-18 stsp run_test test_blame_all_lines_replaced
1000 8d725ae1 2019-08-18 stsp run_test test_blame_lines_shifted_up
1001 8d725ae1 2019-08-18 stsp run_test test_blame_lines_shifted_down
1002 8d725ae1 2019-08-18 stsp run_test test_blame_commit_subsumed
1003 16357e96 2019-08-19 stsp run_test test_blame_blame_h
1004 db32465d 2020-02-07 stsp run_test test_blame_added_on_branch
1005 e7303626 2020-05-14 stsp run_test test_blame_submodule
1006 0587e10c 2020-07-23 stsp run_test test_blame_symlink
1007 c27a5e66 2020-11-18 stsp run_test test_blame_lines_shifted_skip