doc: describe git svn init --ignore-refs
[git/git-svn.git] / t / annotate-tests.sh
blob093832fef1541906b735d162a76c8ffa773d236c
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 'blame by tag objects' '
72 git tag -m "test tag" testTag &&
73 git tag -m "test tag #2" testTag2 testTag &&
74 check_count -h testTag A 2 &&
75 check_count -h testTag2 A 2
78 test_expect_success 'setup B lines' '
79 echo "2A quick brown fox jumps over the" >>file &&
80 echo "lazy dog" >>file &&
81 GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" \
82 git commit -a -m "Second."
85 test_expect_success 'blame 2 authors' '
86 check_count A 2 B 2
89 test_expect_success 'setup B1 lines (branch1)' '
90 git checkout -b branch1 master &&
91 echo "3A slow green fox jumps into the" >>file &&
92 echo "well." >>file &&
93 GIT_AUTHOR_NAME="B1" GIT_AUTHOR_EMAIL="B1@test.git" \
94 git commit -a -m "Branch1-1"
97 test_expect_success 'blame 2 authors + 1 branch1 author' '
98 check_count A 2 B 2 B1 2
101 test_expect_success 'setup B2 lines (branch2)' '
102 git checkout -b branch2 master &&
103 sed -e "s/2A quick brown/4A quick brown lazy dog/" <file >file.new &&
104 mv file.new file &&
105 GIT_AUTHOR_NAME="B2" GIT_AUTHOR_EMAIL="B2@test.git" \
106 git commit -a -m "Branch2-1"
109 test_expect_success 'blame 2 authors + 1 branch2 author' '
110 check_count A 2 B 1 B2 1
113 test_expect_success 'merge branch1 & branch2' '
114 git merge branch1
117 test_expect_success 'blame 2 authors + 2 merged-in authors' '
118 check_count A 2 B 1 B1 2 B2 1
121 test_expect_success 'blame --first-parent blames merge for branch1' '
122 check_count --first-parent A 2 B 1 "A U Thor" 2 B2 1
125 test_expect_success 'blame ancestor' '
126 check_count -h master A 2 B 2
129 test_expect_success 'blame great-ancestor' '
130 check_count -h master^ A 2
133 test_expect_success 'setup evil merge' '
134 echo "evil merge." >>file &&
135 git commit -a --amend
138 test_expect_success 'blame evil merge' '
139 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1
142 test_expect_success 'blame huge graft' '
143 test_when_finished "git checkout branch2" &&
144 test_when_finished "rm -f .git/info/grafts" &&
145 graft= &&
146 for i in 0 1 2
148 for j in 0 1 2 3 4 5 6 7 8 9
150 git checkout --orphan "$i$j" &&
151 printf "%s\n" "$i" "$j" >file &&
152 test_tick &&
153 GIT_AUTHOR_NAME=$i$j GIT_AUTHOR_EMAIL=$i$j@test.git \
154 git commit -a -m "$i$j" &&
155 commit=$(git rev-parse --verify HEAD) &&
156 graft="$graft$commit "
157 done
158 done &&
159 printf "%s " $graft >.git/info/grafts &&
160 check_count -h 00 01 1 10 1
163 test_expect_success 'setup incomplete line' '
164 echo "incomplete" | tr -d "\\012" >>file &&
165 GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" \
166 git commit -a -m "Incomplete"
169 test_expect_success 'blame incomplete line' '
170 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1
173 test_expect_success 'setup edits' '
174 mv file file.orig &&
176 cat file.orig &&
177 echo
178 } | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" >file &&
179 echo "incomplete" | tr -d "\\012" >>file &&
180 GIT_AUTHOR_NAME="D" GIT_AUTHOR_EMAIL="D@test.git" \
181 git commit -a -m "edit"
184 test_expect_success 'blame edits' '
185 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1
188 test_expect_success 'setup obfuscated email' '
189 echo "No robots allowed" >file.new &&
190 cat file >>file.new &&
191 mv file.new file &&
192 GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" \
193 git commit -a -m "norobots"
196 test_expect_success 'blame obfuscated email' '
197 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
200 test_expect_success 'blame -L 1 (all)' '
201 check_count -L1 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
204 test_expect_success 'blame -L , (all)' '
205 check_count -L, A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
208 test_expect_success 'blame -L X (X to end)' '
209 check_count -L5 B1 1 C 1 D 1 "A U Thor" 1
212 test_expect_success 'blame -L X, (X to end)' '
213 check_count -L5, B1 1 C 1 D 1 "A U Thor" 1
216 test_expect_success 'blame -L ,Y (up to Y)' '
217 check_count -L,3 A 1 B2 1 E 1
220 test_expect_success 'blame -L X,X' '
221 check_count -L3,3 B2 1
224 test_expect_success 'blame -L X,Y' '
225 check_count -L3,6 B 1 B1 1 B2 1 D 1
228 test_expect_success 'blame -L Y,X (undocumented)' '
229 check_count -L6,3 B 1 B1 1 B2 1 D 1
232 test_expect_success 'blame -L -X' '
233 test_must_fail $PROG -L-1 file
236 test_expect_success 'blame -L 0' '
237 test_must_fail $PROG -L0 file
240 test_expect_success 'blame -L ,0' '
241 test_must_fail $PROG -L,0 file
244 test_expect_success 'blame -L ,+0' '
245 test_must_fail $PROG -L,+0 file
248 test_expect_success 'blame -L X,+0' '
249 test_must_fail $PROG -L1,+0 file
252 test_expect_success 'blame -L X,+1' '
253 check_count -L3,+1 B2 1
256 test_expect_success 'blame -L X,+N' '
257 check_count -L3,+4 B 1 B1 1 B2 1 D 1
260 test_expect_success 'blame -L ,-0' '
261 test_must_fail $PROG -L,-0 file
264 test_expect_success 'blame -L X,-0' '
265 test_must_fail $PROG -L1,-0 file
268 test_expect_success 'blame -L X,-1' '
269 check_count -L3,-1 B2 1
272 test_expect_success 'blame -L X,-N' '
273 check_count -L6,-4 B 1 B1 1 B2 1 D 1
276 test_expect_success 'blame -L /RE/ (RE to end)' '
277 check_count -L/evil/ C 1 "A U Thor" 1
280 test_expect_success 'blame -L /RE/,/RE2/' '
281 check_count -L/robot/,/green/ A 1 B 1 B2 1 D 1 E 1
284 test_expect_success 'blame -L X,/RE/' '
285 check_count -L5,/evil/ B1 1 D 1 "A U Thor" 1
288 test_expect_success 'blame -L /RE/,Y' '
289 check_count -L/99/,7 B1 1 D 1 "A U Thor" 1
292 test_expect_success 'blame -L /RE/,+N' '
293 check_count -L/99/,+3 B1 1 D 1 "A U Thor" 1
296 test_expect_success 'blame -L /RE/,-N' '
297 check_count -L/99/,-3 B 1 B2 1 D 1
300 # 'file' ends with an incomplete line, so 'wc' reports one fewer lines than
301 # git-blame sees, hence the last line is actually $(wc...)+1.
302 test_expect_success 'blame -L X (X == nlines)' '
303 n=$(expr $(wc -l <file) + 1) &&
304 check_count -L$n C 1
307 test_expect_success 'blame -L X (X == nlines + 1)' '
308 n=$(expr $(wc -l <file) + 2) &&
309 test_must_fail $PROG -L$n file
312 test_expect_success 'blame -L X (X > nlines)' '
313 test_must_fail $PROG -L12345 file
316 test_expect_success 'blame -L ,Y (Y == nlines)' '
317 n=$(expr $(wc -l <file) + 1) &&
318 check_count -L,$n A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
321 test_expect_success 'blame -L ,Y (Y == nlines + 1)' '
322 n=$(expr $(wc -l <file) + 2) &&
323 test_must_fail $PROG -L,$n file
326 test_expect_success 'blame -L ,Y (Y > nlines)' '
327 test_must_fail $PROG -L,12345 file
330 test_expect_success 'blame -L multiple (disjoint)' '
331 check_count -L2,3 -L6,7 A 1 B1 1 B2 1 "A U Thor" 1
334 test_expect_success 'blame -L multiple (disjoint: unordered)' '
335 check_count -L6,7 -L2,3 A 1 B1 1 B2 1 "A U Thor" 1
338 test_expect_success 'blame -L multiple (adjacent)' '
339 check_count -L2,3 -L4,5 A 1 B 1 B2 1 D 1
342 test_expect_success 'blame -L multiple (adjacent: unordered)' '
343 check_count -L4,5 -L2,3 A 1 B 1 B2 1 D 1
346 test_expect_success 'blame -L multiple (overlapping)' '
347 check_count -L2,4 -L3,5 A 1 B 1 B2 1 D 1
350 test_expect_success 'blame -L multiple (overlapping: unordered)' '
351 check_count -L3,5 -L2,4 A 1 B 1 B2 1 D 1
354 test_expect_success 'blame -L multiple (superset/subset)' '
355 check_count -L2,8 -L3,5 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
358 test_expect_success 'blame -L multiple (superset/subset: unordered)' '
359 check_count -L3,5 -L2,8 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
362 test_expect_success 'blame -L /RE/ (relative)' '
363 check_count -L3,3 -L/fox/ B1 1 B2 1 C 1 D 1 "A U Thor" 1
366 test_expect_success 'blame -L /RE/ (relative: no preceding range)' '
367 check_count -L/dog/ A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
370 test_expect_success 'blame -L /RE/ (relative: adjacent)' '
371 check_count -L1,1 -L/dog/,+1 A 1 E 1
374 test_expect_success 'blame -L /RE/ (relative: not found)' '
375 test_must_fail $PROG -L4,4 -L/dog/ file
378 test_expect_success 'blame -L /RE/ (relative: end-of-file)' '
379 test_must_fail $PROG -L, -L/$/ file
382 test_expect_success 'blame -L ^/RE/ (absolute)' '
383 check_count -L3,3 -L^/dog/,+2 A 1 B2 1
386 test_expect_success 'blame -L ^/RE/ (absolute: no preceding range)' '
387 check_count -L^/dog/,+2 A 1 B2 1
390 test_expect_success 'blame -L ^/RE/ (absolute: not found)' '
391 test_must_fail $PROG -L4,4 -L^/tambourine/ file
394 test_expect_success 'blame -L ^/RE/ (absolute: end-of-file)' '
395 n=$(expr $(wc -l <file) + 1) &&
396 check_count -L$n -L^/$/,+2 A 1 C 1 E 1
399 test_expect_success 'setup -L :regex' '
400 tr Q "\\t" >hello.c <<-\EOF &&
401 int main(int argc, const char *argv[])
403 Qputs("hello");
406 git add hello.c &&
407 GIT_AUTHOR_NAME="F" GIT_AUTHOR_EMAIL="F@test.git" \
408 git commit -m "hello" &&
410 mv hello.c hello.orig &&
411 sed -e "/}/ {x; s/$/Qputs(\"goodbye\");/; G;}" <hello.orig |
412 tr Q "\\t" >hello.c &&
413 GIT_AUTHOR_NAME="G" GIT_AUTHOR_EMAIL="G@test.git" \
414 git commit -a -m "goodbye" &&
416 mv hello.c hello.orig &&
417 echo "#include <stdio.h>" >hello.c &&
418 cat hello.orig >>hello.c &&
419 tr Q "\\t" >>hello.c <<-\EOF &&
420 void mail()
422 Qputs("mail");
425 GIT_AUTHOR_NAME="H" GIT_AUTHOR_EMAIL="H@test.git" \
426 git commit -a -m "mail"
429 test_expect_success 'blame -L :literal' '
430 check_count -f hello.c -L:main F 4 G 1
433 test_expect_success 'blame -L :regex' '
434 check_count -f hello.c "-L:m[a-z][a-z]l" H 4
437 test_expect_success 'blame -L :nomatch' '
438 test_must_fail $PROG -L:nomatch hello.c
441 test_expect_success 'blame -L :RE (relative)' '
442 check_count -f hello.c -L3,3 -L:ma.. F 1 H 4
445 test_expect_success 'blame -L :RE (relative: no preceding range)' '
446 check_count -f hello.c -L:ma.. F 4 G 1
449 test_expect_success 'blame -L :RE (relative: not found)' '
450 test_must_fail $PROG -L3,3 -L:tambourine hello.c
453 test_expect_success 'blame -L :RE (relative: end-of-file)' '
454 test_must_fail $PROG -L, -L:main hello.c
457 test_expect_success 'blame -L ^:RE (absolute)' '
458 check_count -f hello.c -L3,3 -L^:ma.. F 4 G 1
461 test_expect_success 'blame -L ^:RE (absolute: no preceding range)' '
462 check_count -f hello.c -L^:ma.. F 4 G 1
465 test_expect_success 'blame -L ^:RE (absolute: not found)' '
466 test_must_fail $PROG -L4,4 -L^:tambourine hello.c
469 test_expect_success 'blame -L ^:RE (absolute: end-of-file)' '
470 n=$(printf "%d" $(wc -l <hello.c)) &&
471 check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1
474 test_expect_success 'setup incremental' '
476 GIT_AUTHOR_NAME=I &&
477 export GIT_AUTHOR_NAME &&
478 GIT_AUTHOR_EMAIL=I@test.git &&
479 export GIT_AUTHOR_EMAIL &&
480 >incremental &&
481 git add incremental &&
482 git commit -m "step 0" &&
483 printf "partial" >>incremental &&
484 git commit -a -m "step 0.5" &&
485 echo >>incremental &&
486 git commit -a -m "step 1"
490 test_expect_success 'blame empty' '
491 check_count -h HEAD^^ -f incremental
494 test_expect_success 'blame -L 0 empty' '
495 test_must_fail $PROG -L0 incremental HEAD^^
498 test_expect_success 'blame -L 1 empty' '
499 test_must_fail $PROG -L1 incremental HEAD^^
502 test_expect_success 'blame -L 2 empty' '
503 test_must_fail $PROG -L2 incremental HEAD^^
506 test_expect_success 'blame half' '
507 check_count -h HEAD^ -f incremental I 1
510 test_expect_success 'blame -L 0 half' '
511 test_must_fail $PROG -L0 incremental HEAD^
514 test_expect_success 'blame -L 1 half' '
515 check_count -h HEAD^ -f incremental -L1 I 1
518 test_expect_success 'blame -L 2 half' '
519 test_must_fail $PROG -L2 incremental HEAD^
522 test_expect_success 'blame -L 3 half' '
523 test_must_fail $PROG -L3 incremental HEAD^
526 test_expect_success 'blame full' '
527 check_count -f incremental I 1
530 test_expect_success 'blame -L 0 full' '
531 test_must_fail $PROG -L0 incremental
534 test_expect_success 'blame -L 1 full' '
535 check_count -f incremental -L1 I 1
538 test_expect_success 'blame -L 2 full' '
539 test_must_fail $PROG -L2 incremental
542 test_expect_success 'blame -L 3 full' '
543 test_must_fail $PROG -L3 incremental
546 test_expect_success 'blame -L' '
547 test_must_fail $PROG -L file
550 test_expect_success 'blame -L X,+' '
551 test_must_fail $PROG -L1,+ file
554 test_expect_success 'blame -L X,-' '
555 test_must_fail $PROG -L1,- file
558 test_expect_success 'blame -L X (non-numeric X)' '
559 test_must_fail $PROG -LX file
562 test_expect_success 'blame -L X,Y (non-numeric Y)' '
563 test_must_fail $PROG -L1,Y file
566 test_expect_success 'blame -L X,+N (non-numeric N)' '
567 test_must_fail $PROG -L1,+N file
570 test_expect_success 'blame -L X,-N (non-numeric N)' '
571 test_must_fail $PROG -L1,-N file
574 test_expect_success 'blame -L ,^/RE/' '
575 test_must_fail $PROG -L1,^/99/ file