blob: 29ce89090d8554a1766c31e9b90cbb387d45c6f7 [file] [log] [blame]
Fredrik Kuivinen8752d112006-03-05 12:13:34 +01001# This file isn't used as a test script directly, instead it is
Josh Stone9b01f002011-04-21 15:07:36 -07002# sourced from t8001-annotate.sh and t8002-blame.sh.
Fredrik Kuivinen8752d112006-03-05 12:13:34 +01003
Karsten Bleese8d08872014-07-17 17:37:05 +02004if test_have_prereq MINGW
5then
6 sanitize_L () {
7 echo "$1" | sed 'sX\(^-L\|,\)\^\?/X&\\;*Xg'
8 }
9else
10 sanitize_L () {
11 echo "$1"
12 }
13fi
14
Junio C Hamano92a903a2006-03-05 22:07:37 -080015check_count () {
Eric Sunshinee37f39c2013-07-17 17:25:28 -040016 head= &&
Eric Sunshine5a9830c2013-07-17 17:25:30 -040017 file='file' &&
Eric Sunshine03e15fc2013-07-17 17:25:29 -040018 options= &&
19 while :
20 do
21 case "$1" in
22 -h) head="$2"; shift; shift ;;
Eric Sunshine5a9830c2013-07-17 17:25:30 -040023 -f) file="$2"; shift; shift ;;
Karsten Bleese8d08872014-07-17 17:37:05 +020024 -L*) options="$options $(sanitize_L "$1")"; shift ;;
Eric Sunshine03e15fc2013-07-17 17:25:29 -040025 -*) options="$options $1"; shift ;;
26 *) break ;;
27 esac
28 done &&
Eric Sunshine5a9830c2013-07-17 17:25:30 -040029 echo "$PROG $options $file $head" >&4 &&
30 $PROG $options $file $head >actual &&
Eric Sunshinee37f39c2013-07-17 17:25:28 -040031 perl -e '
Junio C Hamano92a903a2006-03-05 22:07:37 -080032 my %expect = (@ARGV);
Kevin Ballard27eea662010-10-16 04:09:20 -070033 my %count = map { $_ => 0 } keys %expect;
Junio C Hamano92a903a2006-03-05 22:07:37 -080034 while (<STDIN>) {
35 if (/^[0-9a-f]+\t\(([^\t]+)\t/) {
36 my $author = $1;
37 for ($author) { s/^\s*//; s/\s*$//; }
Kevin Ballard27eea662010-10-16 04:09:20 -070038 $count{$author}++;
Junio C Hamano92a903a2006-03-05 22:07:37 -080039 }
40 }
41 my $bad = 0;
42 while (my ($author, $count) = each %count) {
43 my $ok;
Kevin Ballard27eea662010-10-16 04:09:20 -070044 my $value = 0;
45 $value = $expect{$author} if defined $expect{$author};
46 if ($value != $count) {
Junio C Hamano92a903a2006-03-05 22:07:37 -080047 $bad = 1;
48 $ok = "bad";
49 }
50 else {
51 $ok = "good";
52 }
Kevin Ballard27eea662010-10-16 04:09:20 -070053 print STDERR "Author $author (expected $value, attributed $count) $ok\n";
Junio C Hamano92a903a2006-03-05 22:07:37 -080054 }
55 exit($bad);
Eric Sunshinee37f39c2013-07-17 17:25:28 -040056 ' "$@" <actual
Junio C Hamano92a903a2006-03-05 22:07:37 -080057}
58
Eric Sunshinee37f39c2013-07-17 17:25:28 -040059test_expect_success 'setup A lines' '
60 echo "1A quick brown fox jumps over the" >file &&
61 echo "lazy dog" >>file &&
62 git add file &&
63 GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" \
64 git commit -a -m "Initial."
65'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010066
Eric Sunshinee37f39c2013-07-17 17:25:28 -040067test_expect_success 'blame 1 author' '
68 check_count A 2
69'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010070
SZEDER Gábora544fb02019-04-08 01:43:27 +020071test_expect_success 'blame in a bare repo without starting commit' '
72 git clone --bare . bare.git &&
73 (
74 cd bare.git &&
75 check_count A 2
76 )
77'
78
Jeff King7cb5f7c2015-11-17 18:22:37 -050079test_expect_success 'blame by tag objects' '
80 git tag -m "test tag" testTag &&
81 git tag -m "test tag #2" testTag2 testTag &&
82 check_count -h testTag A 2 &&
83 check_count -h testTag2 A 2
84'
85
Eric Sunshinee37f39c2013-07-17 17:25:28 -040086test_expect_success 'setup B lines' '
87 echo "2A quick brown fox jumps over the" >>file &&
88 echo "lazy dog" >>file &&
89 GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" \
90 git commit -a -m "Second."
91'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010092
Eric Sunshinee37f39c2013-07-17 17:25:28 -040093test_expect_success 'blame 2 authors' '
94 check_count A 2 B 2
95'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010096
Eric Sunshinee37f39c2013-07-17 17:25:28 -040097test_expect_success 'setup B1 lines (branch1)' '
Johannes Schindelin747f6c62020-11-18 23:44:41 +000098 git checkout -b branch1 main &&
Eric Sunshinee37f39c2013-07-17 17:25:28 -040099 echo "3A slow green fox jumps into the" >>file &&
100 echo "well." >>file &&
101 GIT_AUTHOR_NAME="B1" GIT_AUTHOR_EMAIL="B1@test.git" \
102 git commit -a -m "Branch1-1"
103'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100104
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400105test_expect_success 'blame 2 authors + 1 branch1 author' '
106 check_count A 2 B 2 B1 2
107'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100108
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400109test_expect_success 'setup B2 lines (branch2)' '
Johannes Schindelin747f6c62020-11-18 23:44:41 +0000110 git checkout -b branch2 main &&
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400111 sed -e "s/2A quick brown/4A quick brown lazy dog/" <file >file.new &&
112 mv file.new file &&
113 GIT_AUTHOR_NAME="B2" GIT_AUTHOR_EMAIL="B2@test.git" \
114 git commit -a -m "Branch2-1"
115'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100116
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400117test_expect_success 'blame 2 authors + 1 branch2 author' '
118 check_count A 2 B 1 B2 1
119'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100120
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400121test_expect_success 'merge branch1 & branch2' '
Felipe Contreras501a75a2013-10-31 03:25:33 -0600122 git merge branch1
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400123'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100124
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400125test_expect_success 'blame 2 authors + 2 merged-in authors' '
126 check_count A 2 B 1 B1 2 B2 1
127'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100128
Jeff King95a4fb02015-09-15 06:05:39 -0400129test_expect_success 'blame --first-parent blames merge for branch1' '
130 check_count --first-parent A 2 B 1 "A U Thor" 2 B2 1
131'
132
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400133test_expect_success 'blame ancestor' '
Johannes Schindelin747f6c62020-11-18 23:44:41 +0000134 check_count -h main A 2 B 2
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400135'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100136
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400137test_expect_success 'blame great-ancestor' '
Johannes Schindelin747f6c62020-11-18 23:44:41 +0000138 check_count -h main^ A 2
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400139'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100140
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400141test_expect_success 'setup evil merge' '
142 echo "evil merge." >>file &&
143 git commit -a --amend
144'
Junio C Hamanoce5b6e72006-03-05 22:37:15 -0800145
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400146test_expect_success 'blame evil merge' '
147 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1
148'
Junio C Hamanoce5b6e72006-03-05 22:37:15 -0800149
Johannes Schindeline228c172013-12-27 21:49:57 +0100150test_expect_success 'blame huge graft' '
151 test_when_finished "git checkout branch2" &&
152 test_when_finished "rm -f .git/info/grafts" &&
153 graft= &&
154 for i in 0 1 2
155 do
156 for j in 0 1 2 3 4 5 6 7 8 9
157 do
158 git checkout --orphan "$i$j" &&
159 printf "%s\n" "$i" "$j" >file &&
160 test_tick &&
161 GIT_AUTHOR_NAME=$i$j GIT_AUTHOR_EMAIL=$i$j@test.git \
162 git commit -a -m "$i$j" &&
163 commit=$(git rev-parse --verify HEAD) &&
164 graft="$graft$commit "
165 done
166 done &&
167 printf "%s " $graft >.git/info/grafts &&
168 check_count -h 00 01 1 10 1
169'
170
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400171test_expect_success 'setup incomplete line' '
172 echo "incomplete" | tr -d "\\012" >>file &&
173 GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" \
174 git commit -a -m "Incomplete"
175'
Junio C Hamano12426422006-03-06 00:41:17 -0800176
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400177test_expect_success 'blame incomplete line' '
178 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1
179'
Junio C Hamano12426422006-03-06 00:41:17 -0800180
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400181test_expect_success 'setup edits' '
182 mv file file.orig &&
183 {
184 cat file.orig &&
185 echo
186 } | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" >file &&
187 echo "incomplete" | tr -d "\\012" >>file &&
188 GIT_AUTHOR_NAME="D" GIT_AUTHOR_EMAIL="D@test.git" \
189 git commit -a -m "edit"
190'
Junio C Hamano12426422006-03-06 00:41:17 -0800191
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400192test_expect_success 'blame edits' '
193 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1
194'
Josh Stone9b01f002011-04-21 15:07:36 -0700195
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400196test_expect_success 'setup obfuscated email' '
197 echo "No robots allowed" >file.new &&
198 cat file >>file.new &&
199 mv file.new file &&
200 GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" \
201 git commit -a -m "norobots"
202'
Josh Stone9b01f002011-04-21 15:07:36 -0700203
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400204test_expect_success 'blame obfuscated email' '
205 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
206'
Eric Sunshine03e15fc2013-07-17 17:25:29 -0400207
208test_expect_success 'blame -L 1 (all)' '
209 check_count -L1 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
210'
211
212test_expect_success 'blame -L , (all)' '
213 check_count -L, A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
214'
215
216test_expect_success 'blame -L X (X to end)' '
217 check_count -L5 B1 1 C 1 D 1 "A U Thor" 1
218'
219
220test_expect_success 'blame -L X, (X to end)' '
221 check_count -L5, B1 1 C 1 D 1 "A U Thor" 1
222'
223
224test_expect_success 'blame -L ,Y (up to Y)' '
225 check_count -L,3 A 1 B2 1 E 1
226'
227
228test_expect_success 'blame -L X,X' '
229 check_count -L3,3 B2 1
230'
231
232test_expect_success 'blame -L X,Y' '
233 check_count -L3,6 B 1 B1 1 B2 1 D 1
234'
235
236test_expect_success 'blame -L Y,X (undocumented)' '
237 check_count -L6,3 B 1 B1 1 B2 1 D 1
238'
239
Eric Sunshine5ce922a2013-08-06 09:59:49 -0400240test_expect_success 'blame -L -X' '
Eric Sunshine95276042013-08-06 09:59:48 -0400241 test_must_fail $PROG -L-1 file
242'
243
Eric Sunshine5ce922a2013-08-06 09:59:49 -0400244test_expect_success 'blame -L 0' '
Eric Sunshine95276042013-08-06 09:59:48 -0400245 test_must_fail $PROG -L0 file
246'
247
Eric Sunshine5ce922a2013-08-06 09:59:49 -0400248test_expect_success 'blame -L ,0' '
Eric Sunshine95276042013-08-06 09:59:48 -0400249 test_must_fail $PROG -L,0 file
250'
251
Eric Sunshine5d57cac2013-07-31 04:15:45 -0400252test_expect_success 'blame -L ,+0' '
Eric Sunshine82cd7e52013-07-31 04:15:44 -0400253 test_must_fail $PROG -L,+0 file
254'
255
Eric Sunshineabba3532013-07-31 04:15:43 -0400256test_expect_success 'blame -L X,+0' '
Eric Sunshinededb9122013-07-31 04:15:42 -0400257 test_must_fail $PROG -L1,+0 file
258'
259
Eric Sunshine03e15fc2013-07-17 17:25:29 -0400260test_expect_success 'blame -L X,+1' '
261 check_count -L3,+1 B2 1
262'
263
264test_expect_success 'blame -L X,+N' '
265 check_count -L3,+4 B 1 B1 1 B2 1 D 1
266'
267
Eric Sunshine5d57cac2013-07-31 04:15:45 -0400268test_expect_success 'blame -L ,-0' '
Eric Sunshine82cd7e52013-07-31 04:15:44 -0400269 test_must_fail $PROG -L,-0 file
270'
271
Eric Sunshineabba3532013-07-31 04:15:43 -0400272test_expect_success 'blame -L X,-0' '
Eric Sunshinededb9122013-07-31 04:15:42 -0400273 test_must_fail $PROG -L1,-0 file
274'
275
Eric Sunshine03e15fc2013-07-17 17:25:29 -0400276test_expect_success 'blame -L X,-1' '
277 check_count -L3,-1 B2 1
278'
279
280test_expect_success 'blame -L X,-N' '
281 check_count -L6,-4 B 1 B1 1 B2 1 D 1
282'
283
284test_expect_success 'blame -L /RE/ (RE to end)' '
285 check_count -L/evil/ C 1 "A U Thor" 1
286'
287
288test_expect_success 'blame -L /RE/,/RE2/' '
289 check_count -L/robot/,/green/ A 1 B 1 B2 1 D 1 E 1
290'
291
292test_expect_success 'blame -L X,/RE/' '
293 check_count -L5,/evil/ B1 1 D 1 "A U Thor" 1
294'
295
296test_expect_success 'blame -L /RE/,Y' '
297 check_count -L/99/,7 B1 1 D 1 "A U Thor" 1
298'
299
300test_expect_success 'blame -L /RE/,+N' '
301 check_count -L/99/,+3 B1 1 D 1 "A U Thor" 1
302'
303
304test_expect_success 'blame -L /RE/,-N' '
305 check_count -L/99/,-3 B 1 B2 1 D 1
306'
307
Eric Sunshine580b4f32013-07-31 04:15:36 -0400308# 'file' ends with an incomplete line, so 'wc' reports one fewer lines than
309# git-blame sees, hence the last line is actually $(wc...)+1.
310test_expect_success 'blame -L X (X == nlines)' '
311 n=$(expr $(wc -l <file) + 1) &&
312 check_count -L$n C 1
313'
314
Eric Sunshine164a9cf2013-07-31 04:15:38 -0400315test_expect_success 'blame -L X (X == nlines + 1)' '
Eric Sunshine580b4f32013-07-31 04:15:36 -0400316 n=$(expr $(wc -l <file) + 2) &&
317 test_must_fail $PROG -L$n file
318'
319
Eric Sunshine03e15fc2013-07-17 17:25:29 -0400320test_expect_success 'blame -L X (X > nlines)' '
321 test_must_fail $PROG -L12345 file
322'
323
Eric Sunshine580b4f32013-07-31 04:15:36 -0400324test_expect_success 'blame -L ,Y (Y == nlines)' '
325 n=$(expr $(wc -l <file) + 1) &&
326 check_count -L,$n A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
327'
328
329test_expect_success 'blame -L ,Y (Y == nlines + 1)' '
330 n=$(expr $(wc -l <file) + 2) &&
Isabella Stephens96cfa942018-06-15 16:29:27 +1000331 check_count -L,$n A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
Eric Sunshine580b4f32013-07-31 04:15:36 -0400332'
333
Eric Sunshine03e15fc2013-07-17 17:25:29 -0400334test_expect_success 'blame -L ,Y (Y > nlines)' '
Isabella Stephens96cfa942018-06-15 16:29:27 +1000335 check_count -L,12345 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
Eric Sunshine03e15fc2013-07-17 17:25:29 -0400336'
337
Eric Sunshine91b54942013-08-06 09:59:39 -0400338test_expect_success 'blame -L multiple (disjoint)' '
339 check_count -L2,3 -L6,7 A 1 B1 1 B2 1 "A U Thor" 1
340'
341
342test_expect_success 'blame -L multiple (disjoint: unordered)' '
343 check_count -L6,7 -L2,3 A 1 B1 1 B2 1 "A U Thor" 1
344'
345
346test_expect_success 'blame -L multiple (adjacent)' '
347 check_count -L2,3 -L4,5 A 1 B 1 B2 1 D 1
348'
349
350test_expect_success 'blame -L multiple (adjacent: unordered)' '
351 check_count -L4,5 -L2,3 A 1 B 1 B2 1 D 1
352'
353
354test_expect_success 'blame -L multiple (overlapping)' '
355 check_count -L2,4 -L3,5 A 1 B 1 B2 1 D 1
356'
357
358test_expect_success 'blame -L multiple (overlapping: unordered)' '
359 check_count -L3,5 -L2,4 A 1 B 1 B2 1 D 1
360'
361
362test_expect_success 'blame -L multiple (superset/subset)' '
363 check_count -L2,8 -L3,5 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
364'
365
366test_expect_success 'blame -L multiple (superset/subset: unordered)' '
367 check_count -L3,5 -L2,8 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
368'
369
Eric Sunshine52f4d122013-08-06 09:59:42 -0400370test_expect_success 'blame -L /RE/ (relative)' '
371 check_count -L3,3 -L/fox/ B1 1 B2 1 C 1 D 1 "A U Thor" 1
372'
373
374test_expect_success 'blame -L /RE/ (relative: no preceding range)' '
375 check_count -L/dog/ A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
376'
377
378test_expect_success 'blame -L /RE/ (relative: adjacent)' '
379 check_count -L1,1 -L/dog/,+1 A 1 E 1
380'
381
382test_expect_success 'blame -L /RE/ (relative: not found)' '
383 test_must_fail $PROG -L4,4 -L/dog/ file
384'
385
386test_expect_success 'blame -L /RE/ (relative: end-of-file)' '
387 test_must_fail $PROG -L, -L/$/ file
388'
389
Eric Sunshinea6ac5f92013-08-06 09:59:45 -0400390test_expect_success 'blame -L ^/RE/ (absolute)' '
391 check_count -L3,3 -L^/dog/,+2 A 1 B2 1
392'
393
394test_expect_success 'blame -L ^/RE/ (absolute: no preceding range)' '
395 check_count -L^/dog/,+2 A 1 B2 1
396'
397
398test_expect_success 'blame -L ^/RE/ (absolute: not found)' '
399 test_must_fail $PROG -L4,4 -L^/tambourine/ file
400'
401
402test_expect_success 'blame -L ^/RE/ (absolute: end-of-file)' '
403 n=$(expr $(wc -l <file) + 1) &&
404 check_count -L$n -L^/$/,+2 A 1 C 1 E 1
405'
406
Eric Sunshine5a9830c2013-07-17 17:25:30 -0400407test_expect_success 'setup -L :regex' '
408 tr Q "\\t" >hello.c <<-\EOF &&
409 int main(int argc, const char *argv[])
410 {
411 Qputs("hello");
412 }
413 EOF
414 git add hello.c &&
415 GIT_AUTHOR_NAME="F" GIT_AUTHOR_EMAIL="F@test.git" \
416 git commit -m "hello" &&
417
418 mv hello.c hello.orig &&
René Scharfe3a4fc212013-08-05 17:21:17 +0200419 sed -e "/}/ {x; s/$/Qputs(\"goodbye\");/; G;}" <hello.orig |
420 tr Q "\\t" >hello.c &&
Eric Sunshine5a9830c2013-07-17 17:25:30 -0400421 GIT_AUTHOR_NAME="G" GIT_AUTHOR_EMAIL="G@test.git" \
422 git commit -a -m "goodbye" &&
423
424 mv hello.c hello.orig &&
425 echo "#include <stdio.h>" >hello.c &&
426 cat hello.orig >>hello.c &&
Jeff King99094a72015-03-20 06:07:15 -0400427 tr Q "\\t" >>hello.c <<-\EOF &&
Eric Sunshine5a9830c2013-07-17 17:25:30 -0400428 void mail()
429 {
430 Qputs("mail");
431 }
432 EOF
433 GIT_AUTHOR_NAME="H" GIT_AUTHOR_EMAIL="H@test.git" \
434 git commit -a -m "mail"
435'
436
437test_expect_success 'blame -L :literal' '
438 check_count -f hello.c -L:main F 4 G 1
439'
440
441test_expect_success 'blame -L :regex' '
442 check_count -f hello.c "-L:m[a-z][a-z]l" H 4
443'
444
445test_expect_success 'blame -L :nomatch' '
446 test_must_fail $PROG -L:nomatch hello.c
447'
448
Eric Sunshine1ce761a2013-08-06 09:59:46 -0400449test_expect_success 'blame -L :RE (relative)' '
450 check_count -f hello.c -L3,3 -L:ma.. F 1 H 4
451'
452
453test_expect_success 'blame -L :RE (relative: no preceding range)' '
454 check_count -f hello.c -L:ma.. F 4 G 1
455'
456
457test_expect_success 'blame -L :RE (relative: not found)' '
458 test_must_fail $PROG -L3,3 -L:tambourine hello.c
459'
460
461test_expect_success 'blame -L :RE (relative: end-of-file)' '
462 test_must_fail $PROG -L, -L:main hello.c
463'
464
Eric Sunshine215e76c2013-08-06 09:59:47 -0400465test_expect_success 'blame -L ^:RE (absolute)' '
466 check_count -f hello.c -L3,3 -L^:ma.. F 4 G 1
467'
468
469test_expect_success 'blame -L ^:RE (absolute: no preceding range)' '
470 check_count -f hello.c -L^:ma.. F 4 G 1
471'
472
473test_expect_success 'blame -L ^:RE (absolute: not found)' '
474 test_must_fail $PROG -L4,4 -L^:tambourine hello.c
475'
476
477test_expect_success 'blame -L ^:RE (absolute: end-of-file)' '
478 n=$(printf "%d" $(wc -l <hello.c)) &&
479 check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1
480'
481
Philippe Blain9466e382020-11-01 17:28:45 +0000482test_expect_success 'setup -L :funcname with userdiff driver' '
483 echo "fortran-* diff=fortran" >.gitattributes &&
484 fortran_file=fortran-external-function &&
485 orig_file="$TEST_DIRECTORY/t4018/$fortran_file" &&
Johannes Sixt6eaf6242021-01-30 17:22:25 +0100486 cp "$orig_file" . &&
487 git add "$fortran_file" &&
Philippe Blain9466e382020-11-01 17:28:45 +0000488 GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" \
489 git commit -m "add fortran file" &&
Johannes Sixt6eaf6242021-01-30 17:22:25 +0100490 sed -e "s/ChangeMe/IWasChanged/" <"$orig_file" >"$fortran_file" &&
491 git add "$fortran_file" &&
Philippe Blain9466e382020-11-01 17:28:45 +0000492 GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" \
493 git commit -m "change fortran file"
494'
495
496test_expect_success 'blame -L :funcname with userdiff driver' '
497 check_count -f fortran-external-function -L:RIGHT A 7 B 1
498'
499
Eric Sunshinea8fa8ec2013-07-31 04:15:37 -0400500test_expect_success 'setup incremental' '
501 (
502 GIT_AUTHOR_NAME=I &&
503 export GIT_AUTHOR_NAME &&
504 GIT_AUTHOR_EMAIL=I@test.git &&
505 export GIT_AUTHOR_EMAIL &&
506 >incremental &&
507 git add incremental &&
508 git commit -m "step 0" &&
509 printf "partial" >>incremental &&
510 git commit -a -m "step 0.5" &&
511 echo >>incremental &&
512 git commit -a -m "step 1"
513 )
514'
515
516test_expect_success 'blame empty' '
517 check_count -h HEAD^^ -f incremental
518'
519
Eric Sunshine5ce922a2013-08-06 09:59:49 -0400520test_expect_success 'blame -L 0 empty' '
521 test_must_fail $PROG -L0 incremental HEAD^^
Eric Sunshinea8fa8ec2013-07-31 04:15:37 -0400522'
523
Eric Sunshine164a9cf2013-07-31 04:15:38 -0400524test_expect_success 'blame -L 1 empty' '
Eric Sunshinea8fa8ec2013-07-31 04:15:37 -0400525 test_must_fail $PROG -L1 incremental HEAD^^
526'
527
528test_expect_success 'blame -L 2 empty' '
529 test_must_fail $PROG -L2 incremental HEAD^^
530'
531
532test_expect_success 'blame half' '
533 check_count -h HEAD^ -f incremental I 1
534'
535
Eric Sunshine5ce922a2013-08-06 09:59:49 -0400536test_expect_success 'blame -L 0 half' '
537 test_must_fail $PROG -L0 incremental HEAD^
Eric Sunshinea8fa8ec2013-07-31 04:15:37 -0400538'
539
540test_expect_success 'blame -L 1 half' '
541 check_count -h HEAD^ -f incremental -L1 I 1
542'
543
Eric Sunshine164a9cf2013-07-31 04:15:38 -0400544test_expect_success 'blame -L 2 half' '
Eric Sunshinea8fa8ec2013-07-31 04:15:37 -0400545 test_must_fail $PROG -L2 incremental HEAD^
546'
547
548test_expect_success 'blame -L 3 half' '
549 test_must_fail $PROG -L3 incremental HEAD^
550'
551
552test_expect_success 'blame full' '
553 check_count -f incremental I 1
554'
555
Eric Sunshine5ce922a2013-08-06 09:59:49 -0400556test_expect_success 'blame -L 0 full' '
557 test_must_fail $PROG -L0 incremental
Eric Sunshinea8fa8ec2013-07-31 04:15:37 -0400558'
559
560test_expect_success 'blame -L 1 full' '
561 check_count -f incremental -L1 I 1
562'
563
Eric Sunshine164a9cf2013-07-31 04:15:38 -0400564test_expect_success 'blame -L 2 full' '
Eric Sunshinea8fa8ec2013-07-31 04:15:37 -0400565 test_must_fail $PROG -L2 incremental
566'
567
568test_expect_success 'blame -L 3 full' '
569 test_must_fail $PROG -L3 incremental
570'
571
Eric Sunshinef350cf92013-07-31 04:15:35 -0400572test_expect_success 'blame -L' '
573 test_must_fail $PROG -L file
574'
575
576test_expect_success 'blame -L X,+' '
577 test_must_fail $PROG -L1,+ file
578'
579
580test_expect_success 'blame -L X,-' '
581 test_must_fail $PROG -L1,- file
582'
583
584test_expect_success 'blame -L X (non-numeric X)' '
585 test_must_fail $PROG -LX file
586'
587
588test_expect_success 'blame -L X,Y (non-numeric Y)' '
589 test_must_fail $PROG -L1,Y file
590'
591
592test_expect_success 'blame -L X,+N (non-numeric N)' '
593 test_must_fail $PROG -L1,+N file
594'
595
596test_expect_success 'blame -L X,-N (non-numeric N)' '
Eric Sunshine03e15fc2013-07-17 17:25:29 -0400597 test_must_fail $PROG -L1,-N file
598'
Eric Sunshinea6ac5f92013-08-06 09:59:45 -0400599
600test_expect_success 'blame -L ,^/RE/' '
601 test_must_fail $PROG -L1,^/99/ file
602'