Merge branch 'master' of git://repo.or.cz/alt-git
[git/mingw.git] / t / annotate-tests.sh
blobb1673b3e8f38d9961b8b2783e1f5c47a865638fb
1 # This file isn't used as a test script directly, instead it is
2 # sourced from t8001-annotate.sh and t8002-blame.sh.
4 if test_have_prereq MINGW
5 then
6 sanitize_L () {
7 echo "$1" | sed 'sX\(^-L\|,\)\^\?/X&\\;*Xg'
9 else
10 sanitize_L () {
11 echo "$1"
15 check_count () {
16 head= &&
17 file='file' &&
18 options= &&
19 while :
21 case "$1" in
22 -h) head="$2"; shift; shift ;;
23 -f) file="$2"; shift; shift ;;
24 -L*) options="$options $(sanitize_L "$1")"; shift ;;
25 -*) options="$options $1"; shift ;;
26 *) break ;;
27 esac
28 done &&
29 echo "$PROG $options $file $head" >&4 &&
30 $PROG $options $file $head >actual &&
31 perl -e '
32 my %expect = (@ARGV);
33 my %count = map { $_ => 0 } keys %expect;
34 while (<STDIN>) {
35 if (/^[0-9a-f]+\t\(([^\t]+)\t/) {
36 my $author = $1;
37 for ($author) { s/^\s*//; s/\s*$//; }
38 $count{$author}++;
41 my $bad = 0;
42 while (my ($author, $count) = each %count) {
43 my $ok;
44 my $value = 0;
45 $value = $expect{$author} if defined $expect{$author};
46 if ($value != $count) {
47 $bad = 1;
48 $ok = "bad";
50 else {
51 $ok = "good";
53 print STDERR "Author $author (expected $value, attributed $count) $ok\n";
55 exit($bad);
56 ' "$@" <actual
59 test_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."
67 test_expect_success 'blame 1 author' '
68 check_count A 2
71 test_expect_success 'setup B lines' '
72 echo "2A quick brown fox jumps over the" >>file &&
73 echo "lazy dog" >>file &&
74 GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" \
75 git commit -a -m "Second."
78 test_expect_success 'blame 2 authors' '
79 check_count A 2 B 2
82 test_expect_success 'setup B1 lines (branch1)' '
83 git checkout -b branch1 master &&
84 echo "3A slow green fox jumps into the" >>file &&
85 echo "well." >>file &&
86 GIT_AUTHOR_NAME="B1" GIT_AUTHOR_EMAIL="B1@test.git" \
87 git commit -a -m "Branch1-1"
90 test_expect_success 'blame 2 authors + 1 branch1 author' '
91 check_count A 2 B 2 B1 2
94 test_expect_success 'setup B2 lines (branch2)' '
95 git checkout -b branch2 master &&
96 sed -e "s/2A quick brown/4A quick brown lazy dog/" <file >file.new &&
97 mv file.new file &&
98 GIT_AUTHOR_NAME="B2" GIT_AUTHOR_EMAIL="B2@test.git" \
99 git commit -a -m "Branch2-1"
102 test_expect_success 'blame 2 authors + 1 branch2 author' '
103 check_count A 2 B 1 B2 1
106 test_expect_success 'merge branch1 & branch2' '
107 git merge branch1
110 test_expect_success 'blame 2 authors + 2 merged-in authors' '
111 check_count A 2 B 1 B1 2 B2 1
114 test_expect_success 'blame --first-parent blames merge for branch1' '
115 check_count --first-parent A 2 B 1 "A U Thor" 2 B2 1
118 test_expect_success 'blame ancestor' '
119 check_count -h master A 2 B 2
122 test_expect_success 'blame great-ancestor' '
123 check_count -h master^ A 2
126 test_expect_success 'setup evil merge' '
127 echo "evil merge." >>file &&
128 git commit -a --amend
131 test_expect_success 'blame evil merge' '
132 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1
135 test_expect_success 'blame huge graft' '
136 test_when_finished "git checkout branch2" &&
137 test_when_finished "rm -f .git/info/grafts" &&
138 graft= &&
139 for i in 0 1 2
141 for j in 0 1 2 3 4 5 6 7 8 9
143 git checkout --orphan "$i$j" &&
144 printf "%s\n" "$i" "$j" >file &&
145 test_tick &&
146 GIT_AUTHOR_NAME=$i$j GIT_AUTHOR_EMAIL=$i$j@test.git \
147 git commit -a -m "$i$j" &&
148 commit=$(git rev-parse --verify HEAD) &&
149 graft="$graft$commit "
150 done
151 done &&
152 printf "%s " $graft >.git/info/grafts &&
153 check_count -h 00 01 1 10 1
156 test_expect_success 'setup incomplete line' '
157 echo "incomplete" | tr -d "\\012" >>file &&
158 GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" \
159 git commit -a -m "Incomplete"
162 test_expect_success 'blame incomplete line' '
163 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1
166 test_expect_success 'setup edits' '
167 mv file file.orig &&
169 cat file.orig &&
170 echo
171 } | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" >file &&
172 echo "incomplete" | tr -d "\\012" >>file &&
173 GIT_AUTHOR_NAME="D" GIT_AUTHOR_EMAIL="D@test.git" \
174 git commit -a -m "edit"
177 test_expect_success 'blame edits' '
178 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1
181 test_expect_success 'setup obfuscated email' '
182 echo "No robots allowed" >file.new &&
183 cat file >>file.new &&
184 mv file.new file &&
185 GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" \
186 git commit -a -m "norobots"
189 test_expect_success 'blame obfuscated email' '
190 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
193 test_expect_success 'blame -L 1 (all)' '
194 check_count -L1 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
197 test_expect_success 'blame -L , (all)' '
198 check_count -L, A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
201 test_expect_success 'blame -L X (X to end)' '
202 check_count -L5 B1 1 C 1 D 1 "A U Thor" 1
205 test_expect_success 'blame -L X, (X to end)' '
206 check_count -L5, B1 1 C 1 D 1 "A U Thor" 1
209 test_expect_success 'blame -L ,Y (up to Y)' '
210 check_count -L,3 A 1 B2 1 E 1
213 test_expect_success 'blame -L X,X' '
214 check_count -L3,3 B2 1
217 test_expect_success 'blame -L X,Y' '
218 check_count -L3,6 B 1 B1 1 B2 1 D 1
221 test_expect_success 'blame -L Y,X (undocumented)' '
222 check_count -L6,3 B 1 B1 1 B2 1 D 1
225 test_expect_success 'blame -L -X' '
226 test_must_fail $PROG -L-1 file
229 test_expect_success 'blame -L 0' '
230 test_must_fail $PROG -L0 file
233 test_expect_success 'blame -L ,0' '
234 test_must_fail $PROG -L,0 file
237 test_expect_success 'blame -L ,+0' '
238 test_must_fail $PROG -L,+0 file
241 test_expect_success 'blame -L X,+0' '
242 test_must_fail $PROG -L1,+0 file
245 test_expect_success 'blame -L X,+1' '
246 check_count -L3,+1 B2 1
249 test_expect_success 'blame -L X,+N' '
250 check_count -L3,+4 B 1 B1 1 B2 1 D 1
253 test_expect_success 'blame -L ,-0' '
254 test_must_fail $PROG -L,-0 file
257 test_expect_success 'blame -L X,-0' '
258 test_must_fail $PROG -L1,-0 file
261 test_expect_success 'blame -L X,-1' '
262 check_count -L3,-1 B2 1
265 test_expect_success 'blame -L X,-N' '
266 check_count -L6,-4 B 1 B1 1 B2 1 D 1
269 test_expect_success 'blame -L /RE/ (RE to end)' '
270 check_count -L/evil/ C 1 "A U Thor" 1
273 test_expect_success 'blame -L /RE/,/RE2/' '
274 check_count -L/robot/,/green/ A 1 B 1 B2 1 D 1 E 1
277 test_expect_success 'blame -L X,/RE/' '
278 check_count -L5,/evil/ B1 1 D 1 "A U Thor" 1
281 test_expect_success 'blame -L /RE/,Y' '
282 check_count -L/99/,7 B1 1 D 1 "A U Thor" 1
285 test_expect_success 'blame -L /RE/,+N' '
286 check_count -L/99/,+3 B1 1 D 1 "A U Thor" 1
289 test_expect_success 'blame -L /RE/,-N' '
290 check_count -L/99/,-3 B 1 B2 1 D 1
293 # 'file' ends with an incomplete line, so 'wc' reports one fewer lines than
294 # git-blame sees, hence the last line is actually $(wc...)+1.
295 test_expect_success 'blame -L X (X == nlines)' '
296 n=$(expr $(wc -l <file) + 1) &&
297 check_count -L$n C 1
300 test_expect_success 'blame -L X (X == nlines + 1)' '
301 n=$(expr $(wc -l <file) + 2) &&
302 test_must_fail $PROG -L$n file
305 test_expect_success 'blame -L X (X > nlines)' '
306 test_must_fail $PROG -L12345 file
309 test_expect_success 'blame -L ,Y (Y == nlines)' '
310 n=$(expr $(wc -l <file) + 1) &&
311 check_count -L,$n A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
314 test_expect_success 'blame -L ,Y (Y == nlines + 1)' '
315 n=$(expr $(wc -l <file) + 2) &&
316 test_must_fail $PROG -L,$n file
319 test_expect_success 'blame -L ,Y (Y > nlines)' '
320 test_must_fail $PROG -L,12345 file
323 test_expect_success 'blame -L multiple (disjoint)' '
324 check_count -L2,3 -L6,7 A 1 B1 1 B2 1 "A U Thor" 1
327 test_expect_success 'blame -L multiple (disjoint: unordered)' '
328 check_count -L6,7 -L2,3 A 1 B1 1 B2 1 "A U Thor" 1
331 test_expect_success 'blame -L multiple (adjacent)' '
332 check_count -L2,3 -L4,5 A 1 B 1 B2 1 D 1
335 test_expect_success 'blame -L multiple (adjacent: unordered)' '
336 check_count -L4,5 -L2,3 A 1 B 1 B2 1 D 1
339 test_expect_success 'blame -L multiple (overlapping)' '
340 check_count -L2,4 -L3,5 A 1 B 1 B2 1 D 1
343 test_expect_success 'blame -L multiple (overlapping: unordered)' '
344 check_count -L3,5 -L2,4 A 1 B 1 B2 1 D 1
347 test_expect_success 'blame -L multiple (superset/subset)' '
348 check_count -L2,8 -L3,5 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
351 test_expect_success 'blame -L multiple (superset/subset: unordered)' '
352 check_count -L3,5 -L2,8 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
355 test_expect_success 'blame -L /RE/ (relative)' '
356 check_count -L3,3 -L/fox/ B1 1 B2 1 C 1 D 1 "A U Thor" 1
359 test_expect_success 'blame -L /RE/ (relative: no preceding range)' '
360 check_count -L/dog/ A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
363 test_expect_success 'blame -L /RE/ (relative: adjacent)' '
364 check_count -L1,1 -L/dog/,+1 A 1 E 1
367 test_expect_success 'blame -L /RE/ (relative: not found)' '
368 test_must_fail $PROG -L4,4 -L/dog/ file
371 test_expect_success 'blame -L /RE/ (relative: end-of-file)' '
372 test_must_fail $PROG -L, -L/$/ file
375 test_expect_success 'blame -L ^/RE/ (absolute)' '
376 check_count -L3,3 -L^/dog/,+2 A 1 B2 1
379 test_expect_success 'blame -L ^/RE/ (absolute: no preceding range)' '
380 check_count -L^/dog/,+2 A 1 B2 1
383 test_expect_success 'blame -L ^/RE/ (absolute: not found)' '
384 test_must_fail $PROG -L4,4 -L^/tambourine/ file
387 test_expect_success 'blame -L ^/RE/ (absolute: end-of-file)' '
388 n=$(expr $(wc -l <file) + 1) &&
389 check_count -L$n -L^/$/,+2 A 1 C 1 E 1
392 test_expect_success 'setup -L :regex' '
393 tr Q "\\t" >hello.c <<-\EOF &&
394 int main(int argc, const char *argv[])
396 Qputs("hello");
399 git add hello.c &&
400 GIT_AUTHOR_NAME="F" GIT_AUTHOR_EMAIL="F@test.git" \
401 git commit -m "hello" &&
403 mv hello.c hello.orig &&
404 sed -e "/}/ {x; s/$/Qputs(\"goodbye\");/; G;}" <hello.orig |
405 tr Q "\\t" >hello.c &&
406 GIT_AUTHOR_NAME="G" GIT_AUTHOR_EMAIL="G@test.git" \
407 git commit -a -m "goodbye" &&
409 mv hello.c hello.orig &&
410 echo "#include <stdio.h>" >hello.c &&
411 cat hello.orig >>hello.c &&
412 tr Q "\\t" >>hello.c <<-\EOF &&
413 void mail()
415 Qputs("mail");
418 GIT_AUTHOR_NAME="H" GIT_AUTHOR_EMAIL="H@test.git" \
419 git commit -a -m "mail"
422 test_expect_success 'blame -L :literal' '
423 check_count -f hello.c -L:main F 4 G 1
426 test_expect_success 'blame -L :regex' '
427 check_count -f hello.c "-L:m[a-z][a-z]l" H 4
430 test_expect_success 'blame -L :nomatch' '
431 test_must_fail $PROG -L:nomatch hello.c
434 test_expect_success 'blame -L :RE (relative)' '
435 check_count -f hello.c -L3,3 -L:ma.. F 1 H 4
438 test_expect_success 'blame -L :RE (relative: no preceding range)' '
439 check_count -f hello.c -L:ma.. F 4 G 1
442 test_expect_success 'blame -L :RE (relative: not found)' '
443 test_must_fail $PROG -L3,3 -L:tambourine hello.c
446 test_expect_success 'blame -L :RE (relative: end-of-file)' '
447 test_must_fail $PROG -L, -L:main hello.c
450 test_expect_success 'blame -L ^:RE (absolute)' '
451 check_count -f hello.c -L3,3 -L^:ma.. F 4 G 1
454 test_expect_success 'blame -L ^:RE (absolute: no preceding range)' '
455 check_count -f hello.c -L^:ma.. F 4 G 1
458 test_expect_success 'blame -L ^:RE (absolute: not found)' '
459 test_must_fail $PROG -L4,4 -L^:tambourine hello.c
462 test_expect_success 'blame -L ^:RE (absolute: end-of-file)' '
463 n=$(printf "%d" $(wc -l <hello.c)) &&
464 check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1
467 test_expect_success 'setup incremental' '
469 GIT_AUTHOR_NAME=I &&
470 export GIT_AUTHOR_NAME &&
471 GIT_AUTHOR_EMAIL=I@test.git &&
472 export GIT_AUTHOR_EMAIL &&
473 >incremental &&
474 git add incremental &&
475 git commit -m "step 0" &&
476 printf "partial" >>incremental &&
477 git commit -a -m "step 0.5" &&
478 echo >>incremental &&
479 git commit -a -m "step 1"
483 test_expect_success 'blame empty' '
484 check_count -h HEAD^^ -f incremental
487 test_expect_success 'blame -L 0 empty' '
488 test_must_fail $PROG -L0 incremental HEAD^^
491 test_expect_success 'blame -L 1 empty' '
492 test_must_fail $PROG -L1 incremental HEAD^^
495 test_expect_success 'blame -L 2 empty' '
496 test_must_fail $PROG -L2 incremental HEAD^^
499 test_expect_success 'blame half' '
500 check_count -h HEAD^ -f incremental I 1
503 test_expect_success 'blame -L 0 half' '
504 test_must_fail $PROG -L0 incremental HEAD^
507 test_expect_success 'blame -L 1 half' '
508 check_count -h HEAD^ -f incremental -L1 I 1
511 test_expect_success 'blame -L 2 half' '
512 test_must_fail $PROG -L2 incremental HEAD^
515 test_expect_success 'blame -L 3 half' '
516 test_must_fail $PROG -L3 incremental HEAD^
519 test_expect_success 'blame full' '
520 check_count -f incremental I 1
523 test_expect_success 'blame -L 0 full' '
524 test_must_fail $PROG -L0 incremental
527 test_expect_success 'blame -L 1 full' '
528 check_count -f incremental -L1 I 1
531 test_expect_success 'blame -L 2 full' '
532 test_must_fail $PROG -L2 incremental
535 test_expect_success 'blame -L 3 full' '
536 test_must_fail $PROG -L3 incremental
539 test_expect_success 'blame -L' '
540 test_must_fail $PROG -L file
543 test_expect_success 'blame -L X,+' '
544 test_must_fail $PROG -L1,+ file
547 test_expect_success 'blame -L X,-' '
548 test_must_fail $PROG -L1,- file
551 test_expect_success 'blame -L X (non-numeric X)' '
552 test_must_fail $PROG -LX file
555 test_expect_success 'blame -L X,Y (non-numeric Y)' '
556 test_must_fail $PROG -L1,Y file
559 test_expect_success 'blame -L X,+N (non-numeric N)' '
560 test_must_fail $PROG -L1,+N file
563 test_expect_success 'blame -L X,-N (non-numeric N)' '
564 test_must_fail $PROG -L1,-N file
567 test_expect_success 'blame -L ,^/RE/' '
568 test_must_fail $PROG -L1,^/99/ file