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