blob: 87572459e4b873cdc78f36867ba782e022eb13f4 [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
Edmundo Carmona Antoranze5f5d7d2022-04-06 20:13:20 +020059get_progress_result () {
60 tr '\015' '\012' | tail -n 1
61}
62
Eric Sunshinee37f39c2013-07-17 17:25:28 -040063test_expect_success 'setup A lines' '
64 echo "1A quick brown fox jumps over the" >file &&
65 echo "lazy dog" >>file &&
66 git add file &&
67 GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" \
68 git commit -a -m "Initial."
69'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010070
Eric Sunshinee37f39c2013-07-17 17:25:28 -040071test_expect_success 'blame 1 author' '
72 check_count A 2
73'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010074
Jacob Keller603d0fd2023-04-24 12:35:08 -070075test_expect_success 'blame working copy' '
76 test_when_finished "git restore file" &&
77 echo "1A quick brown fox jumps over the" >file &&
78 echo "another lazy dog" >>file &&
79 check_count A 1 "Not Committed Yet" 1
80'
81
Jacob Keller1a3119e2023-03-24 10:08:00 -070082test_expect_success 'blame with --contents' '
83 check_count --contents=file A 2
84'
85
Han Young835950b2023-07-21 11:57:58 +080086test_expect_success 'blame with --contents in a bare repo' '
87 git clone --bare . bare-contents.git &&
88 (
89 cd bare-contents.git &&
90 echo "1A quick brown fox jumps over the" >contents &&
91 check_count --contents=contents A 1
92 )
93'
94
Jacob Keller1a3119e2023-03-24 10:08:00 -070095test_expect_success 'blame with --contents changed' '
96 echo "1A quick brown fox jumps over the" >contents &&
97 echo "another lazy dog" >>contents &&
Jacob Keller603d0fd2023-04-24 12:35:08 -070098 check_count --contents=contents A 1 "External file (--contents)" 1
Jacob Keller1a3119e2023-03-24 10:08:00 -070099'
100
SZEDER Gábora544fb02019-04-08 01:43:27 +0200101test_expect_success 'blame in a bare repo without starting commit' '
102 git clone --bare . bare.git &&
103 (
104 cd bare.git &&
105 check_count A 2
106 )
107'
108
Jeff King7cb5f7c2015-11-17 18:22:37 -0500109test_expect_success 'blame by tag objects' '
110 git tag -m "test tag" testTag &&
111 git tag -m "test tag #2" testTag2 testTag &&
112 check_count -h testTag A 2 &&
113 check_count -h testTag2 A 2
114'
115
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400116test_expect_success 'setup B lines' '
117 echo "2A quick brown fox jumps over the" >>file &&
118 echo "lazy dog" >>file &&
119 GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" \
120 git commit -a -m "Second."
121'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100122
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400123test_expect_success 'blame 2 authors' '
124 check_count A 2 B 2
125'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100126
Jacob Keller1a3119e2023-03-24 10:08:00 -0700127test_expect_success 'blame with --contents and revision' '
Jacob Keller603d0fd2023-04-24 12:35:08 -0700128 check_count -h testTag --contents=file A 2 "External file (--contents)" 2
Jacob Keller1a3119e2023-03-24 10:08:00 -0700129'
130
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400131test_expect_success 'setup B1 lines (branch1)' '
Johannes Schindelin747f6c62020-11-18 23:44:41 +0000132 git checkout -b branch1 main &&
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400133 echo "3A slow green fox jumps into the" >>file &&
134 echo "well." >>file &&
135 GIT_AUTHOR_NAME="B1" GIT_AUTHOR_EMAIL="B1@test.git" \
136 git commit -a -m "Branch1-1"
137'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100138
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400139test_expect_success 'blame 2 authors + 1 branch1 author' '
140 check_count A 2 B 2 B1 2
141'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100142
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400143test_expect_success 'setup B2 lines (branch2)' '
Johannes Schindelin747f6c62020-11-18 23:44:41 +0000144 git checkout -b branch2 main &&
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400145 sed -e "s/2A quick brown/4A quick brown lazy dog/" <file >file.new &&
146 mv file.new file &&
147 GIT_AUTHOR_NAME="B2" GIT_AUTHOR_EMAIL="B2@test.git" \
148 git commit -a -m "Branch2-1"
149'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100150
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400151test_expect_success 'blame 2 authors + 1 branch2 author' '
152 check_count A 2 B 1 B2 1
153'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100154
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400155test_expect_success 'merge branch1 & branch2' '
Felipe Contreras501a75a2013-10-31 03:25:33 -0600156 git merge branch1
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400157'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100158
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400159test_expect_success 'blame 2 authors + 2 merged-in authors' '
160 check_count A 2 B 1 B1 2 B2 1
161'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100162
Jeff King95a4fb02015-09-15 06:05:39 -0400163test_expect_success 'blame --first-parent blames merge for branch1' '
164 check_count --first-parent A 2 B 1 "A U Thor" 2 B2 1
165'
166
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400167test_expect_success 'blame ancestor' '
Johannes Schindelin747f6c62020-11-18 23:44:41 +0000168 check_count -h main A 2 B 2
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400169'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100170
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400171test_expect_success 'blame great-ancestor' '
Johannes Schindelin747f6c62020-11-18 23:44:41 +0000172 check_count -h main^ A 2
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400173'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +0100174
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400175test_expect_success 'setup evil merge' '
176 echo "evil merge." >>file &&
177 git commit -a --amend
178'
Junio C Hamanoce5b6e72006-03-05 22:37:15 -0800179
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400180test_expect_success 'blame evil merge' '
181 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1
182'
Junio C Hamanoce5b6e72006-03-05 22:37:15 -0800183
Johannes Schindeline228c172013-12-27 21:49:57 +0100184test_expect_success 'blame huge graft' '
185 test_when_finished "git checkout branch2" &&
Ævar Arnfjörð Bjarmason93e02b62022-06-03 13:15:05 +0200186 test_when_finished "rm -rf .git/info" &&
Johannes Schindeline228c172013-12-27 21:49:57 +0100187 graft= &&
188 for i in 0 1 2
189 do
190 for j in 0 1 2 3 4 5 6 7 8 9
191 do
192 git checkout --orphan "$i$j" &&
193 printf "%s\n" "$i" "$j" >file &&
194 test_tick &&
195 GIT_AUTHOR_NAME=$i$j GIT_AUTHOR_EMAIL=$i$j@test.git \
196 git commit -a -m "$i$j" &&
197 commit=$(git rev-parse --verify HEAD) &&
Eric Sunshine0c51d6b2021-12-09 00:11:15 -0500198 graft="$graft$commit " || return 1
Johannes Schindeline228c172013-12-27 21:49:57 +0100199 done
200 done &&
Ævar Arnfjörð Bjarmason93e02b62022-06-03 13:15:05 +0200201 mkdir .git/info &&
Johannes Schindeline228c172013-12-27 21:49:57 +0100202 printf "%s " $graft >.git/info/grafts &&
203 check_count -h 00 01 1 10 1
204'
205
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400206test_expect_success 'setup incomplete line' '
207 echo "incomplete" | tr -d "\\012" >>file &&
208 GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" \
209 git commit -a -m "Incomplete"
210'
Junio C Hamano12426422006-03-06 00:41:17 -0800211
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400212test_expect_success 'blame incomplete line' '
213 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1
214'
Junio C Hamano12426422006-03-06 00:41:17 -0800215
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400216test_expect_success 'setup edits' '
217 mv file file.orig &&
218 {
219 cat file.orig &&
220 echo
221 } | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" >file &&
222 echo "incomplete" | tr -d "\\012" >>file &&
223 GIT_AUTHOR_NAME="D" GIT_AUTHOR_EMAIL="D@test.git" \
224 git commit -a -m "edit"
225'
Junio C Hamano12426422006-03-06 00:41:17 -0800226
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400227test_expect_success 'blame edits' '
228 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1
229'
Josh Stone9b01f002011-04-21 15:07:36 -0700230
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400231test_expect_success 'setup obfuscated email' '
232 echo "No robots allowed" >file.new &&
233 cat file >>file.new &&
234 mv file.new file &&
235 GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" \
236 git commit -a -m "norobots"
237'
Josh Stone9b01f002011-04-21 15:07:36 -0700238
Eric Sunshinee37f39c2013-07-17 17:25:28 -0400239test_expect_success 'blame obfuscated email' '
240 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
241'
Eric Sunshine03e15fc2013-07-17 17:25:29 -0400242
243test_expect_success 'blame -L 1 (all)' '
244 check_count -L1 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
245'
246
247test_expect_success 'blame -L , (all)' '
248 check_count -L, A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
249'
250
251test_expect_success 'blame -L X (X to end)' '
252 check_count -L5 B1 1 C 1 D 1 "A U Thor" 1
253'
254
255test_expect_success 'blame -L X, (X to end)' '
256 check_count -L5, B1 1 C 1 D 1 "A U Thor" 1
257'
258
259test_expect_success 'blame -L ,Y (up to Y)' '
260 check_count -L,3 A 1 B2 1 E 1
261'
262
263test_expect_success 'blame -L X,X' '
264 check_count -L3,3 B2 1
265'
266
267test_expect_success 'blame -L X,Y' '
268 check_count -L3,6 B 1 B1 1 B2 1 D 1
269'
270
271test_expect_success 'blame -L Y,X (undocumented)' '
272 check_count -L6,3 B 1 B1 1 B2 1 D 1
273'
274
Eric Sunshine5ce922a2013-08-06 09:59:49 -0400275test_expect_success 'blame -L -X' '
Eric Sunshine95276042013-08-06 09:59:48 -0400276 test_must_fail $PROG -L-1 file
277'
278
Eric Sunshine5ce922a2013-08-06 09:59:49 -0400279test_expect_success 'blame -L 0' '
Eric Sunshine95276042013-08-06 09:59:48 -0400280 test_must_fail $PROG -L0 file
281'
282
Eric Sunshine5ce922a2013-08-06 09:59:49 -0400283test_expect_success 'blame -L ,0' '
Eric Sunshine95276042013-08-06 09:59:48 -0400284 test_must_fail $PROG -L,0 file
285'
286
Eric Sunshine5d57cac2013-07-31 04:15:45 -0400287test_expect_success 'blame -L ,+0' '
Eric Sunshine82cd7e52013-07-31 04:15:44 -0400288 test_must_fail $PROG -L,+0 file
289'
290
Eric Sunshineabba3532013-07-31 04:15:43 -0400291test_expect_success 'blame -L X,+0' '
Eric Sunshinededb9122013-07-31 04:15:42 -0400292 test_must_fail $PROG -L1,+0 file
293'
294
Eric Sunshine03e15fc2013-07-17 17:25:29 -0400295test_expect_success 'blame -L X,+1' '
296 check_count -L3,+1 B2 1
297'
298
299test_expect_success 'blame -L X,+N' '
300 check_count -L3,+4 B 1 B1 1 B2 1 D 1
301'
302
Eric Sunshine5d57cac2013-07-31 04:15:45 -0400303test_expect_success 'blame -L ,-0' '
Eric Sunshine82cd7e52013-07-31 04:15:44 -0400304 test_must_fail $PROG -L,-0 file
305'
306
Eric Sunshineabba3532013-07-31 04:15:43 -0400307test_expect_success 'blame -L X,-0' '
Eric Sunshinededb9122013-07-31 04:15:42 -0400308 test_must_fail $PROG -L1,-0 file
309'
310
Eric Sunshine03e15fc2013-07-17 17:25:29 -0400311test_expect_success 'blame -L X,-1' '
312 check_count -L3,-1 B2 1
313'
314
315test_expect_success 'blame -L X,-N' '
316 check_count -L6,-4 B 1 B1 1 B2 1 D 1
317'
318
319test_expect_success 'blame -L /RE/ (RE to end)' '
320 check_count -L/evil/ C 1 "A U Thor" 1
321'
322
323test_expect_success 'blame -L /RE/,/RE2/' '
324 check_count -L/robot/,/green/ A 1 B 1 B2 1 D 1 E 1
325'
326
327test_expect_success 'blame -L X,/RE/' '
328 check_count -L5,/evil/ B1 1 D 1 "A U Thor" 1
329'
330
331test_expect_success 'blame -L /RE/,Y' '
332 check_count -L/99/,7 B1 1 D 1 "A U Thor" 1
333'
334
335test_expect_success 'blame -L /RE/,+N' '
336 check_count -L/99/,+3 B1 1 D 1 "A U Thor" 1
337'
338
339test_expect_success 'blame -L /RE/,-N' '
340 check_count -L/99/,-3 B 1 B2 1 D 1
341'
342
Eric Sunshine580b4f32013-07-31 04:15:36 -0400343# 'file' ends with an incomplete line, so 'wc' reports one fewer lines than
344# git-blame sees, hence the last line is actually $(wc...)+1.
345test_expect_success 'blame -L X (X == nlines)' '
346 n=$(expr $(wc -l <file) + 1) &&
347 check_count -L$n C 1
348'
349
Eric Sunshine164a9cf2013-07-31 04:15:38 -0400350test_expect_success 'blame -L X (X == nlines + 1)' '
Eric Sunshine580b4f32013-07-31 04:15:36 -0400351 n=$(expr $(wc -l <file) + 2) &&
352 test_must_fail $PROG -L$n file
353'
354
Eric Sunshine03e15fc2013-07-17 17:25:29 -0400355test_expect_success 'blame -L X (X > nlines)' '
356 test_must_fail $PROG -L12345 file
357'
358
Eric Sunshine580b4f32013-07-31 04:15:36 -0400359test_expect_success 'blame -L ,Y (Y == nlines)' '
360 n=$(expr $(wc -l <file) + 1) &&
361 check_count -L,$n A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
362'
363
364test_expect_success 'blame -L ,Y (Y == nlines + 1)' '
365 n=$(expr $(wc -l <file) + 2) &&
Isabella Stephens96cfa942018-06-15 16:29:27 +1000366 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 -0400367'
368
Eric Sunshine03e15fc2013-07-17 17:25:29 -0400369test_expect_success 'blame -L ,Y (Y > nlines)' '
Isabella Stephens96cfa942018-06-15 16:29:27 +1000370 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 -0400371'
372
Eric Sunshine91b54942013-08-06 09:59:39 -0400373test_expect_success 'blame -L multiple (disjoint)' '
374 check_count -L2,3 -L6,7 A 1 B1 1 B2 1 "A U Thor" 1
375'
376
377test_expect_success 'blame -L multiple (disjoint: unordered)' '
378 check_count -L6,7 -L2,3 A 1 B1 1 B2 1 "A U Thor" 1
379'
380
381test_expect_success 'blame -L multiple (adjacent)' '
382 check_count -L2,3 -L4,5 A 1 B 1 B2 1 D 1
383'
384
385test_expect_success 'blame -L multiple (adjacent: unordered)' '
386 check_count -L4,5 -L2,3 A 1 B 1 B2 1 D 1
387'
388
389test_expect_success 'blame -L multiple (overlapping)' '
390 check_count -L2,4 -L3,5 A 1 B 1 B2 1 D 1
391'
392
393test_expect_success 'blame -L multiple (overlapping: unordered)' '
394 check_count -L3,5 -L2,4 A 1 B 1 B2 1 D 1
395'
396
397test_expect_success 'blame -L multiple (superset/subset)' '
398 check_count -L2,8 -L3,5 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
399'
400
401test_expect_success 'blame -L multiple (superset/subset: unordered)' '
402 check_count -L3,5 -L2,8 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
403'
404
Eric Sunshine52f4d122013-08-06 09:59:42 -0400405test_expect_success 'blame -L /RE/ (relative)' '
406 check_count -L3,3 -L/fox/ B1 1 B2 1 C 1 D 1 "A U Thor" 1
407'
408
409test_expect_success 'blame -L /RE/ (relative: no preceding range)' '
410 check_count -L/dog/ A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
411'
412
413test_expect_success 'blame -L /RE/ (relative: adjacent)' '
414 check_count -L1,1 -L/dog/,+1 A 1 E 1
415'
416
417test_expect_success 'blame -L /RE/ (relative: not found)' '
418 test_must_fail $PROG -L4,4 -L/dog/ file
419'
420
421test_expect_success 'blame -L /RE/ (relative: end-of-file)' '
422 test_must_fail $PROG -L, -L/$/ file
423'
424
Eric Sunshinea6ac5f92013-08-06 09:59:45 -0400425test_expect_success 'blame -L ^/RE/ (absolute)' '
426 check_count -L3,3 -L^/dog/,+2 A 1 B2 1
427'
428
429test_expect_success 'blame -L ^/RE/ (absolute: no preceding range)' '
430 check_count -L^/dog/,+2 A 1 B2 1
431'
432
433test_expect_success 'blame -L ^/RE/ (absolute: not found)' '
434 test_must_fail $PROG -L4,4 -L^/tambourine/ file
435'
436
437test_expect_success 'blame -L ^/RE/ (absolute: end-of-file)' '
438 n=$(expr $(wc -l <file) + 1) &&
439 check_count -L$n -L^/$/,+2 A 1 C 1 E 1
440'
441
Eric Sunshine5a9830c2013-07-17 17:25:30 -0400442test_expect_success 'setup -L :regex' '
443 tr Q "\\t" >hello.c <<-\EOF &&
444 int main(int argc, const char *argv[])
445 {
446 Qputs("hello");
447 }
448 EOF
449 git add hello.c &&
450 GIT_AUTHOR_NAME="F" GIT_AUTHOR_EMAIL="F@test.git" \
451 git commit -m "hello" &&
452
453 mv hello.c hello.orig &&
René Scharfe3a4fc212013-08-05 17:21:17 +0200454 sed -e "/}/ {x; s/$/Qputs(\"goodbye\");/; G;}" <hello.orig |
455 tr Q "\\t" >hello.c &&
Eric Sunshine5a9830c2013-07-17 17:25:30 -0400456 GIT_AUTHOR_NAME="G" GIT_AUTHOR_EMAIL="G@test.git" \
457 git commit -a -m "goodbye" &&
458
459 mv hello.c hello.orig &&
460 echo "#include <stdio.h>" >hello.c &&
461 cat hello.orig >>hello.c &&
Jeff King99094a72015-03-20 06:07:15 -0400462 tr Q "\\t" >>hello.c <<-\EOF &&
Eric Sunshine5a9830c2013-07-17 17:25:30 -0400463 void mail()
464 {
465 Qputs("mail");
466 }
467 EOF
468 GIT_AUTHOR_NAME="H" GIT_AUTHOR_EMAIL="H@test.git" \
469 git commit -a -m "mail"
470'
471
472test_expect_success 'blame -L :literal' '
473 check_count -f hello.c -L:main F 4 G 1
474'
475
476test_expect_success 'blame -L :regex' '
477 check_count -f hello.c "-L:m[a-z][a-z]l" H 4
478'
479
480test_expect_success 'blame -L :nomatch' '
481 test_must_fail $PROG -L:nomatch hello.c
482'
483
Eric Sunshine1ce761a2013-08-06 09:59:46 -0400484test_expect_success 'blame -L :RE (relative)' '
485 check_count -f hello.c -L3,3 -L:ma.. F 1 H 4
486'
487
488test_expect_success 'blame -L :RE (relative: no preceding range)' '
489 check_count -f hello.c -L:ma.. F 4 G 1
490'
491
492test_expect_success 'blame -L :RE (relative: not found)' '
493 test_must_fail $PROG -L3,3 -L:tambourine hello.c
494'
495
496test_expect_success 'blame -L :RE (relative: end-of-file)' '
497 test_must_fail $PROG -L, -L:main hello.c
498'
499
Eric Sunshine215e76c2013-08-06 09:59:47 -0400500test_expect_success 'blame -L ^:RE (absolute)' '
501 check_count -f hello.c -L3,3 -L^:ma.. F 4 G 1
502'
503
504test_expect_success 'blame -L ^:RE (absolute: no preceding range)' '
505 check_count -f hello.c -L^:ma.. F 4 G 1
506'
507
508test_expect_success 'blame -L ^:RE (absolute: not found)' '
509 test_must_fail $PROG -L4,4 -L^:tambourine hello.c
510'
511
512test_expect_success 'blame -L ^:RE (absolute: end-of-file)' '
513 n=$(printf "%d" $(wc -l <hello.c)) &&
514 check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1
515'
516
Ævar Arnfjörð Bjarmasonf08b4012021-04-08 17:04:24 +0200517test_expect_success 'blame -L :funcname with userdiff driver' '
518 cat >file.template <<-\EOF &&
519 DO NOT MATCH THIS LINE
Ævar Arnfjörð Bjarmasonb2694412021-04-08 17:04:23 +0200520 function RIGHT(a, b) result(c)
Ævar Arnfjörð Bjarmasonf08b4012021-04-08 17:04:24 +0200521 AS THE DEFAULT DRIVER WOULD
Ævar Arnfjörð Bjarmasonb2694412021-04-08 17:04:23 +0200522
523 integer, intent(in) :: ChangeMe
Ævar Arnfjörð Bjarmasonb2694412021-04-08 17:04:23 +0200524 EOF
Philippe Blain9466e382020-11-01 17:28:45 +0000525
Ævar Arnfjörð Bjarmasonf08b4012021-04-08 17:04:24 +0200526 fortran_file=file.f03 &&
527 test_when_finished "rm .gitattributes" &&
528 echo "$fortran_file diff=fortran" >.gitattributes &&
529
530 test_commit --author "A <A@test.git>" \
531 "add" "$fortran_file" \
532 "$(cat file.template)" &&
533 test_commit --author "B <B@test.git>" \
534 "change" "$fortran_file" \
Beat Bolli47c0f242024-03-15 20:46:01 +0100535 "$(sed -e s/ChangeMe/IWasChanged/ file.template)" &&
Ævar Arnfjörð Bjarmasonf08b4012021-04-08 17:04:24 +0200536 check_count -f "$fortran_file" -L:RIGHT A 3 B 1
Philippe Blain9466e382020-11-01 17:28:45 +0000537'
538
Eric Sunshinea8fa8ec2013-07-31 04:15:37 -0400539test_expect_success 'setup incremental' '
540 (
541 GIT_AUTHOR_NAME=I &&
542 export GIT_AUTHOR_NAME &&
543 GIT_AUTHOR_EMAIL=I@test.git &&
544 export GIT_AUTHOR_EMAIL &&
545 >incremental &&
546 git add incremental &&
547 git commit -m "step 0" &&
548 printf "partial" >>incremental &&
549 git commit -a -m "step 0.5" &&
550 echo >>incremental &&
551 git commit -a -m "step 1"
552 )
553'
554
555test_expect_success 'blame empty' '
556 check_count -h HEAD^^ -f incremental
557'
558
Eric Sunshine5ce922a2013-08-06 09:59:49 -0400559test_expect_success 'blame -L 0 empty' '
560 test_must_fail $PROG -L0 incremental HEAD^^
Eric Sunshinea8fa8ec2013-07-31 04:15:37 -0400561'
562
Eric Sunshine164a9cf2013-07-31 04:15:38 -0400563test_expect_success 'blame -L 1 empty' '
Eric Sunshinea8fa8ec2013-07-31 04:15:37 -0400564 test_must_fail $PROG -L1 incremental HEAD^^
565'
566
567test_expect_success 'blame -L 2 empty' '
568 test_must_fail $PROG -L2 incremental HEAD^^
569'
570
571test_expect_success 'blame half' '
572 check_count -h HEAD^ -f incremental I 1
573'
574
Eric Sunshine5ce922a2013-08-06 09:59:49 -0400575test_expect_success 'blame -L 0 half' '
576 test_must_fail $PROG -L0 incremental HEAD^
Eric Sunshinea8fa8ec2013-07-31 04:15:37 -0400577'
578
579test_expect_success 'blame -L 1 half' '
580 check_count -h HEAD^ -f incremental -L1 I 1
581'
582
Eric Sunshine164a9cf2013-07-31 04:15:38 -0400583test_expect_success 'blame -L 2 half' '
Eric Sunshinea8fa8ec2013-07-31 04:15:37 -0400584 test_must_fail $PROG -L2 incremental HEAD^
585'
586
587test_expect_success 'blame -L 3 half' '
588 test_must_fail $PROG -L3 incremental HEAD^
589'
590
591test_expect_success 'blame full' '
592 check_count -f incremental I 1
593'
594
Eric Sunshine5ce922a2013-08-06 09:59:49 -0400595test_expect_success 'blame -L 0 full' '
596 test_must_fail $PROG -L0 incremental
Eric Sunshinea8fa8ec2013-07-31 04:15:37 -0400597'
598
599test_expect_success 'blame -L 1 full' '
600 check_count -f incremental -L1 I 1
601'
602
Eric Sunshine164a9cf2013-07-31 04:15:38 -0400603test_expect_success 'blame -L 2 full' '
Eric Sunshinea8fa8ec2013-07-31 04:15:37 -0400604 test_must_fail $PROG -L2 incremental
605'
606
607test_expect_success 'blame -L 3 full' '
608 test_must_fail $PROG -L3 incremental
609'
610
Eric Sunshinef350cf92013-07-31 04:15:35 -0400611test_expect_success 'blame -L' '
612 test_must_fail $PROG -L file
613'
614
615test_expect_success 'blame -L X,+' '
616 test_must_fail $PROG -L1,+ file
617'
618
619test_expect_success 'blame -L X,-' '
620 test_must_fail $PROG -L1,- file
621'
622
623test_expect_success 'blame -L X (non-numeric X)' '
624 test_must_fail $PROG -LX file
625'
626
627test_expect_success 'blame -L X,Y (non-numeric Y)' '
628 test_must_fail $PROG -L1,Y file
629'
630
631test_expect_success 'blame -L X,+N (non-numeric N)' '
632 test_must_fail $PROG -L1,+N file
633'
634
635test_expect_success 'blame -L X,-N (non-numeric N)' '
Eric Sunshine03e15fc2013-07-17 17:25:29 -0400636 test_must_fail $PROG -L1,-N file
637'
Eric Sunshinea6ac5f92013-08-06 09:59:45 -0400638
639test_expect_success 'blame -L ,^/RE/' '
640 test_must_fail $PROG -L1,^/99/ file
641'
Edmundo Carmona Antoranze5f5d7d2022-04-06 20:13:20 +0200642
643test_expect_success 'blame progress on a full file' '
644 cat >expect <<-\EOF &&
645 Blaming lines: 100% (10/10), done.
646 EOF
647
648 GIT_PROGRESS_DELAY=0 \
649 git blame --progress hello.c 2>stderr &&
650
651 get_progress_result <stderr >actual &&
652 test_cmp expect actual
653'
654
655test_expect_success 'blame progress on a single range' '
656 cat >expect <<-\EOF &&
657 Blaming lines: 100% (4/4), done.
658 EOF
659
660 GIT_PROGRESS_DELAY=0 \
661 git blame --progress -L 3,6 hello.c 2>stderr &&
662
663 get_progress_result <stderr >actual &&
664 test_cmp expect actual
665'
666
667test_expect_success 'blame progress on multiple ranges' '
668 cat >expect <<-\EOF &&
669 Blaming lines: 100% (7/7), done.
670 EOF
671
672 GIT_PROGRESS_DELAY=0 \
673 git blame --progress -L 3,6 -L 8,10 hello.c 2>stderr &&
674
675 get_progress_result <stderr >actual &&
676 test_cmp expect actual
677'