Merge branch 'mg/push-repo-option-doc' into maint
[git/mingw.git] / t / annotate-tests.sh
blob071e4d7d3ee9729b5caeb34ffd54ae88b7e1e0d8
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 ancestor' '
115 check_count -h master A 2 B 2
118 test_expect_success 'blame great-ancestor' '
119 check_count -h master^ A 2
122 test_expect_success 'setup evil merge' '
123 echo "evil merge." >>file &&
124 git commit -a --amend
127 test_expect_success 'blame evil merge' '
128 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1
131 test_expect_success 'blame huge graft' '
132 test_when_finished "git checkout branch2" &&
133 test_when_finished "rm -f .git/info/grafts" &&
134 graft= &&
135 for i in 0 1 2
137 for j in 0 1 2 3 4 5 6 7 8 9
139 git checkout --orphan "$i$j" &&
140 printf "%s\n" "$i" "$j" >file &&
141 test_tick &&
142 GIT_AUTHOR_NAME=$i$j GIT_AUTHOR_EMAIL=$i$j@test.git \
143 git commit -a -m "$i$j" &&
144 commit=$(git rev-parse --verify HEAD) &&
145 graft="$graft$commit "
146 done
147 done &&
148 printf "%s " $graft >.git/info/grafts &&
149 check_count -h 00 01 1 10 1
152 test_expect_success 'setup incomplete line' '
153 echo "incomplete" | tr -d "\\012" >>file &&
154 GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" \
155 git commit -a -m "Incomplete"
158 test_expect_success 'blame incomplete line' '
159 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1
162 test_expect_success 'setup edits' '
163 mv file file.orig &&
165 cat file.orig &&
166 echo
167 } | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" >file &&
168 echo "incomplete" | tr -d "\\012" >>file &&
169 GIT_AUTHOR_NAME="D" GIT_AUTHOR_EMAIL="D@test.git" \
170 git commit -a -m "edit"
173 test_expect_success 'blame edits' '
174 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1
177 test_expect_success 'setup obfuscated email' '
178 echo "No robots allowed" >file.new &&
179 cat file >>file.new &&
180 mv file.new file &&
181 GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" \
182 git commit -a -m "norobots"
185 test_expect_success 'blame obfuscated email' '
186 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
189 test_expect_success 'blame -L 1 (all)' '
190 check_count -L1 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
193 test_expect_success 'blame -L , (all)' '
194 check_count -L, A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
197 test_expect_success 'blame -L X (X to end)' '
198 check_count -L5 B1 1 C 1 D 1 "A U Thor" 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 ,Y (up to Y)' '
206 check_count -L,3 A 1 B2 1 E 1
209 test_expect_success 'blame -L X,X' '
210 check_count -L3,3 B2 1
213 test_expect_success 'blame -L X,Y' '
214 check_count -L3,6 B 1 B1 1 B2 1 D 1
217 test_expect_success 'blame -L Y,X (undocumented)' '
218 check_count -L6,3 B 1 B1 1 B2 1 D 1
221 test_expect_success 'blame -L -X' '
222 test_must_fail $PROG -L-1 file
225 test_expect_success 'blame -L 0' '
226 test_must_fail $PROG -L0 file
229 test_expect_success 'blame -L ,0' '
230 test_must_fail $PROG -L,0 file
233 test_expect_success 'blame -L ,+0' '
234 test_must_fail $PROG -L,+0 file
237 test_expect_success 'blame -L X,+0' '
238 test_must_fail $PROG -L1,+0 file
241 test_expect_success 'blame -L X,+1' '
242 check_count -L3,+1 B2 1
245 test_expect_success 'blame -L X,+N' '
246 check_count -L3,+4 B 1 B1 1 B2 1 D 1
249 test_expect_success 'blame -L ,-0' '
250 test_must_fail $PROG -L,-0 file
253 test_expect_success 'blame -L X,-0' '
254 test_must_fail $PROG -L1,-0 file
257 test_expect_success 'blame -L X,-1' '
258 check_count -L3,-1 B2 1
261 test_expect_success 'blame -L X,-N' '
262 check_count -L6,-4 B 1 B1 1 B2 1 D 1
265 test_expect_success 'blame -L /RE/ (RE to end)' '
266 check_count -L/evil/ C 1 "A U Thor" 1
269 test_expect_success 'blame -L /RE/,/RE2/' '
270 check_count -L/robot/,/green/ A 1 B 1 B2 1 D 1 E 1
273 test_expect_success 'blame -L X,/RE/' '
274 check_count -L5,/evil/ B1 1 D 1 "A U Thor" 1
277 test_expect_success 'blame -L /RE/,Y' '
278 check_count -L/99/,7 B1 1 D 1 "A U Thor" 1
281 test_expect_success 'blame -L /RE/,+N' '
282 check_count -L/99/,+3 B1 1 D 1 "A U Thor" 1
285 test_expect_success 'blame -L /RE/,-N' '
286 check_count -L/99/,-3 B 1 B2 1 D 1
289 # 'file' ends with an incomplete line, so 'wc' reports one fewer lines than
290 # git-blame sees, hence the last line is actually $(wc...)+1.
291 test_expect_success 'blame -L X (X == nlines)' '
292 n=$(expr $(wc -l <file) + 1) &&
293 check_count -L$n C 1
296 test_expect_success 'blame -L X (X == nlines + 1)' '
297 n=$(expr $(wc -l <file) + 2) &&
298 test_must_fail $PROG -L$n file
301 test_expect_success 'blame -L X (X > nlines)' '
302 test_must_fail $PROG -L12345 file
305 test_expect_success 'blame -L ,Y (Y == nlines)' '
306 n=$(expr $(wc -l <file) + 1) &&
307 check_count -L,$n A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
310 test_expect_success 'blame -L ,Y (Y == nlines + 1)' '
311 n=$(expr $(wc -l <file) + 2) &&
312 test_must_fail $PROG -L,$n file
315 test_expect_success 'blame -L ,Y (Y > nlines)' '
316 test_must_fail $PROG -L,12345 file
319 test_expect_success 'blame -L multiple (disjoint)' '
320 check_count -L2,3 -L6,7 A 1 B1 1 B2 1 "A U Thor" 1
323 test_expect_success 'blame -L multiple (disjoint: unordered)' '
324 check_count -L6,7 -L2,3 A 1 B1 1 B2 1 "A U Thor" 1
327 test_expect_success 'blame -L multiple (adjacent)' '
328 check_count -L2,3 -L4,5 A 1 B 1 B2 1 D 1
331 test_expect_success 'blame -L multiple (adjacent: unordered)' '
332 check_count -L4,5 -L2,3 A 1 B 1 B2 1 D 1
335 test_expect_success 'blame -L multiple (overlapping)' '
336 check_count -L2,4 -L3,5 A 1 B 1 B2 1 D 1
339 test_expect_success 'blame -L multiple (overlapping: unordered)' '
340 check_count -L3,5 -L2,4 A 1 B 1 B2 1 D 1
343 test_expect_success 'blame -L multiple (superset/subset)' '
344 check_count -L2,8 -L3,5 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
347 test_expect_success 'blame -L multiple (superset/subset: unordered)' '
348 check_count -L3,5 -L2,8 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
351 test_expect_success 'blame -L /RE/ (relative)' '
352 check_count -L3,3 -L/fox/ B1 1 B2 1 C 1 D 1 "A U Thor" 1
355 test_expect_success 'blame -L /RE/ (relative: no preceding range)' '
356 check_count -L/dog/ A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
359 test_expect_success 'blame -L /RE/ (relative: adjacent)' '
360 check_count -L1,1 -L/dog/,+1 A 1 E 1
363 test_expect_success 'blame -L /RE/ (relative: not found)' '
364 test_must_fail $PROG -L4,4 -L/dog/ file
367 test_expect_success 'blame -L /RE/ (relative: end-of-file)' '
368 test_must_fail $PROG -L, -L/$/ file
371 test_expect_success 'blame -L ^/RE/ (absolute)' '
372 check_count -L3,3 -L^/dog/,+2 A 1 B2 1
375 test_expect_success 'blame -L ^/RE/ (absolute: no preceding range)' '
376 check_count -L^/dog/,+2 A 1 B2 1
379 test_expect_success 'blame -L ^/RE/ (absolute: not found)' '
380 test_must_fail $PROG -L4,4 -L^/tambourine/ file
383 test_expect_success 'blame -L ^/RE/ (absolute: end-of-file)' '
384 n=$(expr $(wc -l <file) + 1) &&
385 check_count -L$n -L^/$/,+2 A 1 C 1 E 1
388 test_expect_success 'setup -L :regex' '
389 tr Q "\\t" >hello.c <<-\EOF &&
390 int main(int argc, const char *argv[])
392 Qputs("hello");
395 git add hello.c &&
396 GIT_AUTHOR_NAME="F" GIT_AUTHOR_EMAIL="F@test.git" \
397 git commit -m "hello" &&
399 mv hello.c hello.orig &&
400 sed -e "/}/ {x; s/$/Qputs(\"goodbye\");/; G;}" <hello.orig |
401 tr Q "\\t" >hello.c &&
402 GIT_AUTHOR_NAME="G" GIT_AUTHOR_EMAIL="G@test.git" \
403 git commit -a -m "goodbye" &&
405 mv hello.c hello.orig &&
406 echo "#include <stdio.h>" >hello.c &&
407 cat hello.orig >>hello.c &&
408 tr Q "\\t" >>hello.c <<-\EOF
409 void mail()
411 Qputs("mail");
414 GIT_AUTHOR_NAME="H" GIT_AUTHOR_EMAIL="H@test.git" \
415 git commit -a -m "mail"
418 test_expect_success 'blame -L :literal' '
419 check_count -f hello.c -L:main F 4 G 1
422 test_expect_success 'blame -L :regex' '
423 check_count -f hello.c "-L:m[a-z][a-z]l" H 4
426 test_expect_success 'blame -L :nomatch' '
427 test_must_fail $PROG -L:nomatch hello.c
430 test_expect_success 'blame -L :RE (relative)' '
431 check_count -f hello.c -L3,3 -L:ma.. F 1 H 4
434 test_expect_success 'blame -L :RE (relative: no preceding range)' '
435 check_count -f hello.c -L:ma.. F 4 G 1
438 test_expect_success 'blame -L :RE (relative: not found)' '
439 test_must_fail $PROG -L3,3 -L:tambourine hello.c
442 test_expect_success 'blame -L :RE (relative: end-of-file)' '
443 test_must_fail $PROG -L, -L:main hello.c
446 test_expect_success 'blame -L ^:RE (absolute)' '
447 check_count -f hello.c -L3,3 -L^:ma.. F 4 G 1
450 test_expect_success 'blame -L ^:RE (absolute: no preceding range)' '
451 check_count -f hello.c -L^:ma.. F 4 G 1
454 test_expect_success 'blame -L ^:RE (absolute: not found)' '
455 test_must_fail $PROG -L4,4 -L^:tambourine hello.c
458 test_expect_success 'blame -L ^:RE (absolute: end-of-file)' '
459 n=$(printf "%d" $(wc -l <hello.c)) &&
460 check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1
463 test_expect_success 'setup incremental' '
465 GIT_AUTHOR_NAME=I &&
466 export GIT_AUTHOR_NAME &&
467 GIT_AUTHOR_EMAIL=I@test.git &&
468 export GIT_AUTHOR_EMAIL &&
469 >incremental &&
470 git add incremental &&
471 git commit -m "step 0" &&
472 printf "partial" >>incremental &&
473 git commit -a -m "step 0.5" &&
474 echo >>incremental &&
475 git commit -a -m "step 1"
479 test_expect_success 'blame empty' '
480 check_count -h HEAD^^ -f incremental
483 test_expect_success 'blame -L 0 empty' '
484 test_must_fail $PROG -L0 incremental HEAD^^
487 test_expect_success 'blame -L 1 empty' '
488 test_must_fail $PROG -L1 incremental HEAD^^
491 test_expect_success 'blame -L 2 empty' '
492 test_must_fail $PROG -L2 incremental HEAD^^
495 test_expect_success 'blame half' '
496 check_count -h HEAD^ -f incremental I 1
499 test_expect_success 'blame -L 0 half' '
500 test_must_fail $PROG -L0 incremental HEAD^
503 test_expect_success 'blame -L 1 half' '
504 check_count -h HEAD^ -f incremental -L1 I 1
507 test_expect_success 'blame -L 2 half' '
508 test_must_fail $PROG -L2 incremental HEAD^
511 test_expect_success 'blame -L 3 half' '
512 test_must_fail $PROG -L3 incremental HEAD^
515 test_expect_success 'blame full' '
516 check_count -f incremental I 1
519 test_expect_success 'blame -L 0 full' '
520 test_must_fail $PROG -L0 incremental
523 test_expect_success 'blame -L 1 full' '
524 check_count -f incremental -L1 I 1
527 test_expect_success 'blame -L 2 full' '
528 test_must_fail $PROG -L2 incremental
531 test_expect_success 'blame -L 3 full' '
532 test_must_fail $PROG -L3 incremental
535 test_expect_success 'blame -L' '
536 test_must_fail $PROG -L file
539 test_expect_success 'blame -L X,+' '
540 test_must_fail $PROG -L1,+ file
543 test_expect_success 'blame -L X,-' '
544 test_must_fail $PROG -L1,- file
547 test_expect_success 'blame -L X (non-numeric X)' '
548 test_must_fail $PROG -LX file
551 test_expect_success 'blame -L X,Y (non-numeric Y)' '
552 test_must_fail $PROG -L1,Y file
555 test_expect_success 'blame -L X,+N (non-numeric N)' '
556 test_must_fail $PROG -L1,+N 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 ,^/RE/' '
564 test_must_fail $PROG -L1,^/99/ file