diagnose.c: add option to configure archive contents
[alt-git.git] / t / annotate-tests.sh
blobf1b9a6ce4daee67c7aadfd2a9d19cb1c4033224c
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 get_progress_result () {
60 tr '\015' '\012' | tail -n 1
63 test_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."
71 test_expect_success 'blame 1 author' '
72 check_count A 2
75 test_expect_success 'blame in a bare repo without starting commit' '
76 git clone --bare . bare.git &&
78 cd bare.git &&
79 check_count A 2
83 test_expect_success 'blame by tag objects' '
84 git tag -m "test tag" testTag &&
85 git tag -m "test tag #2" testTag2 testTag &&
86 check_count -h testTag A 2 &&
87 check_count -h testTag2 A 2
90 test_expect_success 'setup B lines' '
91 echo "2A quick brown fox jumps over the" >>file &&
92 echo "lazy dog" >>file &&
93 GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" \
94 git commit -a -m "Second."
97 test_expect_success 'blame 2 authors' '
98 check_count A 2 B 2
101 test_expect_success 'setup B1 lines (branch1)' '
102 git checkout -b branch1 main &&
103 echo "3A slow green fox jumps into the" >>file &&
104 echo "well." >>file &&
105 GIT_AUTHOR_NAME="B1" GIT_AUTHOR_EMAIL="B1@test.git" \
106 git commit -a -m "Branch1-1"
109 test_expect_success 'blame 2 authors + 1 branch1 author' '
110 check_count A 2 B 2 B1 2
113 test_expect_success 'setup B2 lines (branch2)' '
114 git checkout -b branch2 main &&
115 sed -e "s/2A quick brown/4A quick brown lazy dog/" <file >file.new &&
116 mv file.new file &&
117 GIT_AUTHOR_NAME="B2" GIT_AUTHOR_EMAIL="B2@test.git" \
118 git commit -a -m "Branch2-1"
121 test_expect_success 'blame 2 authors + 1 branch2 author' '
122 check_count A 2 B 1 B2 1
125 test_expect_success 'merge branch1 & branch2' '
126 git merge branch1
129 test_expect_success 'blame 2 authors + 2 merged-in authors' '
130 check_count A 2 B 1 B1 2 B2 1
133 test_expect_success 'blame --first-parent blames merge for branch1' '
134 check_count --first-parent A 2 B 1 "A U Thor" 2 B2 1
137 test_expect_success 'blame ancestor' '
138 check_count -h main A 2 B 2
141 test_expect_success 'blame great-ancestor' '
142 check_count -h main^ A 2
145 test_expect_success 'setup evil merge' '
146 echo "evil merge." >>file &&
147 git commit -a --amend
150 test_expect_success 'blame evil merge' '
151 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1
154 test_expect_success 'blame huge graft' '
155 test_when_finished "git checkout branch2" &&
156 test_when_finished "rm -rf .git/info" &&
157 graft= &&
158 for i in 0 1 2
160 for j in 0 1 2 3 4 5 6 7 8 9
162 git checkout --orphan "$i$j" &&
163 printf "%s\n" "$i" "$j" >file &&
164 test_tick &&
165 GIT_AUTHOR_NAME=$i$j GIT_AUTHOR_EMAIL=$i$j@test.git \
166 git commit -a -m "$i$j" &&
167 commit=$(git rev-parse --verify HEAD) &&
168 graft="$graft$commit " || return 1
169 done
170 done &&
171 mkdir .git/info &&
172 printf "%s " $graft >.git/info/grafts &&
173 check_count -h 00 01 1 10 1
176 test_expect_success 'setup incomplete line' '
177 echo "incomplete" | tr -d "\\012" >>file &&
178 GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" \
179 git commit -a -m "Incomplete"
182 test_expect_success 'blame incomplete line' '
183 check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1
186 test_expect_success 'setup edits' '
187 mv file file.orig &&
189 cat file.orig &&
190 echo
191 } | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" >file &&
192 echo "incomplete" | tr -d "\\012" >>file &&
193 GIT_AUTHOR_NAME="D" GIT_AUTHOR_EMAIL="D@test.git" \
194 git commit -a -m "edit"
197 test_expect_success 'blame edits' '
198 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1
201 test_expect_success 'setup obfuscated email' '
202 echo "No robots allowed" >file.new &&
203 cat file >>file.new &&
204 mv file.new file &&
205 GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" \
206 git commit -a -m "norobots"
209 test_expect_success 'blame obfuscated email' '
210 check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
213 test_expect_success 'blame -L 1 (all)' '
214 check_count -L1 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
217 test_expect_success 'blame -L , (all)' '
218 check_count -L, A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
221 test_expect_success 'blame -L X (X to end)' '
222 check_count -L5 B1 1 C 1 D 1 "A U Thor" 1
225 test_expect_success 'blame -L X, (X to end)' '
226 check_count -L5, B1 1 C 1 D 1 "A U Thor" 1
229 test_expect_success 'blame -L ,Y (up to Y)' '
230 check_count -L,3 A 1 B2 1 E 1
233 test_expect_success 'blame -L X,X' '
234 check_count -L3,3 B2 1
237 test_expect_success 'blame -L X,Y' '
238 check_count -L3,6 B 1 B1 1 B2 1 D 1
241 test_expect_success 'blame -L Y,X (undocumented)' '
242 check_count -L6,3 B 1 B1 1 B2 1 D 1
245 test_expect_success 'blame -L -X' '
246 test_must_fail $PROG -L-1 file
249 test_expect_success 'blame -L 0' '
250 test_must_fail $PROG -L0 file
253 test_expect_success 'blame -L ,0' '
254 test_must_fail $PROG -L,0 file
257 test_expect_success 'blame -L ,+0' '
258 test_must_fail $PROG -L,+0 file
261 test_expect_success 'blame -L X,+0' '
262 test_must_fail $PROG -L1,+0 file
265 test_expect_success 'blame -L X,+1' '
266 check_count -L3,+1 B2 1
269 test_expect_success 'blame -L X,+N' '
270 check_count -L3,+4 B 1 B1 1 B2 1 D 1
273 test_expect_success 'blame -L ,-0' '
274 test_must_fail $PROG -L,-0 file
277 test_expect_success 'blame -L X,-0' '
278 test_must_fail $PROG -L1,-0 file
281 test_expect_success 'blame -L X,-1' '
282 check_count -L3,-1 B2 1
285 test_expect_success 'blame -L X,-N' '
286 check_count -L6,-4 B 1 B1 1 B2 1 D 1
289 test_expect_success 'blame -L /RE/ (RE to end)' '
290 check_count -L/evil/ C 1 "A U Thor" 1
293 test_expect_success 'blame -L /RE/,/RE2/' '
294 check_count -L/robot/,/green/ A 1 B 1 B2 1 D 1 E 1
297 test_expect_success 'blame -L X,/RE/' '
298 check_count -L5,/evil/ B1 1 D 1 "A U Thor" 1
301 test_expect_success 'blame -L /RE/,Y' '
302 check_count -L/99/,7 B1 1 D 1 "A U Thor" 1
305 test_expect_success 'blame -L /RE/,+N' '
306 check_count -L/99/,+3 B1 1 D 1 "A U Thor" 1
309 test_expect_success 'blame -L /RE/,-N' '
310 check_count -L/99/,-3 B 1 B2 1 D 1
313 # 'file' ends with an incomplete line, so 'wc' reports one fewer lines than
314 # git-blame sees, hence the last line is actually $(wc...)+1.
315 test_expect_success 'blame -L X (X == nlines)' '
316 n=$(expr $(wc -l <file) + 1) &&
317 check_count -L$n C 1
320 test_expect_success 'blame -L X (X == nlines + 1)' '
321 n=$(expr $(wc -l <file) + 2) &&
322 test_must_fail $PROG -L$n file
325 test_expect_success 'blame -L X (X > nlines)' '
326 test_must_fail $PROG -L12345 file
329 test_expect_success 'blame -L ,Y (Y == nlines)' '
330 n=$(expr $(wc -l <file) + 1) &&
331 check_count -L,$n A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
334 test_expect_success 'blame -L ,Y (Y == nlines + 1)' '
335 n=$(expr $(wc -l <file) + 2) &&
336 check_count -L,$n A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
339 test_expect_success 'blame -L ,Y (Y > nlines)' '
340 check_count -L,12345 A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1
343 test_expect_success 'blame -L multiple (disjoint)' '
344 check_count -L2,3 -L6,7 A 1 B1 1 B2 1 "A U Thor" 1
347 test_expect_success 'blame -L multiple (disjoint: unordered)' '
348 check_count -L6,7 -L2,3 A 1 B1 1 B2 1 "A U Thor" 1
351 test_expect_success 'blame -L multiple (adjacent)' '
352 check_count -L2,3 -L4,5 A 1 B 1 B2 1 D 1
355 test_expect_success 'blame -L multiple (adjacent: unordered)' '
356 check_count -L4,5 -L2,3 A 1 B 1 B2 1 D 1
359 test_expect_success 'blame -L multiple (overlapping)' '
360 check_count -L2,4 -L3,5 A 1 B 1 B2 1 D 1
363 test_expect_success 'blame -L multiple (overlapping: unordered)' '
364 check_count -L3,5 -L2,4 A 1 B 1 B2 1 D 1
367 test_expect_success 'blame -L multiple (superset/subset)' '
368 check_count -L2,8 -L3,5 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
371 test_expect_success 'blame -L multiple (superset/subset: unordered)' '
372 check_count -L3,5 -L2,8 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
375 test_expect_success 'blame -L /RE/ (relative)' '
376 check_count -L3,3 -L/fox/ B1 1 B2 1 C 1 D 1 "A U Thor" 1
379 test_expect_success 'blame -L /RE/ (relative: no preceding range)' '
380 check_count -L/dog/ A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
383 test_expect_success 'blame -L /RE/ (relative: adjacent)' '
384 check_count -L1,1 -L/dog/,+1 A 1 E 1
387 test_expect_success 'blame -L /RE/ (relative: not found)' '
388 test_must_fail $PROG -L4,4 -L/dog/ file
391 test_expect_success 'blame -L /RE/ (relative: end-of-file)' '
392 test_must_fail $PROG -L, -L/$/ file
395 test_expect_success 'blame -L ^/RE/ (absolute)' '
396 check_count -L3,3 -L^/dog/,+2 A 1 B2 1
399 test_expect_success 'blame -L ^/RE/ (absolute: no preceding range)' '
400 check_count -L^/dog/,+2 A 1 B2 1
403 test_expect_success 'blame -L ^/RE/ (absolute: not found)' '
404 test_must_fail $PROG -L4,4 -L^/tambourine/ file
407 test_expect_success 'blame -L ^/RE/ (absolute: end-of-file)' '
408 n=$(expr $(wc -l <file) + 1) &&
409 check_count -L$n -L^/$/,+2 A 1 C 1 E 1
412 test_expect_success 'setup -L :regex' '
413 tr Q "\\t" >hello.c <<-\EOF &&
414 int main(int argc, const char *argv[])
416 Qputs("hello");
419 git add hello.c &&
420 GIT_AUTHOR_NAME="F" GIT_AUTHOR_EMAIL="F@test.git" \
421 git commit -m "hello" &&
423 mv hello.c hello.orig &&
424 sed -e "/}/ {x; s/$/Qputs(\"goodbye\");/; G;}" <hello.orig |
425 tr Q "\\t" >hello.c &&
426 GIT_AUTHOR_NAME="G" GIT_AUTHOR_EMAIL="G@test.git" \
427 git commit -a -m "goodbye" &&
429 mv hello.c hello.orig &&
430 echo "#include <stdio.h>" >hello.c &&
431 cat hello.orig >>hello.c &&
432 tr Q "\\t" >>hello.c <<-\EOF &&
433 void mail()
435 Qputs("mail");
438 GIT_AUTHOR_NAME="H" GIT_AUTHOR_EMAIL="H@test.git" \
439 git commit -a -m "mail"
442 test_expect_success 'blame -L :literal' '
443 check_count -f hello.c -L:main F 4 G 1
446 test_expect_success 'blame -L :regex' '
447 check_count -f hello.c "-L:m[a-z][a-z]l" H 4
450 test_expect_success 'blame -L :nomatch' '
451 test_must_fail $PROG -L:nomatch hello.c
454 test_expect_success 'blame -L :RE (relative)' '
455 check_count -f hello.c -L3,3 -L:ma.. F 1 H 4
458 test_expect_success 'blame -L :RE (relative: no preceding range)' '
459 check_count -f hello.c -L:ma.. F 4 G 1
462 test_expect_success 'blame -L :RE (relative: not found)' '
463 test_must_fail $PROG -L3,3 -L:tambourine hello.c
466 test_expect_success 'blame -L :RE (relative: end-of-file)' '
467 test_must_fail $PROG -L, -L:main hello.c
470 test_expect_success 'blame -L ^:RE (absolute)' '
471 check_count -f hello.c -L3,3 -L^:ma.. F 4 G 1
474 test_expect_success 'blame -L ^:RE (absolute: no preceding range)' '
475 check_count -f hello.c -L^:ma.. F 4 G 1
478 test_expect_success 'blame -L ^:RE (absolute: not found)' '
479 test_must_fail $PROG -L4,4 -L^:tambourine hello.c
482 test_expect_success 'blame -L ^:RE (absolute: end-of-file)' '
483 n=$(printf "%d" $(wc -l <hello.c)) &&
484 check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1
487 test_expect_success 'blame -L :funcname with userdiff driver' '
488 cat >file.template <<-\EOF &&
489 DO NOT MATCH THIS LINE
490 function RIGHT(a, b) result(c)
491 AS THE DEFAULT DRIVER WOULD
493 integer, intent(in) :: ChangeMe
496 fortran_file=file.f03 &&
497 test_when_finished "rm .gitattributes" &&
498 echo "$fortran_file diff=fortran" >.gitattributes &&
500 test_commit --author "A <A@test.git>" \
501 "add" "$fortran_file" \
502 "$(cat file.template)" &&
503 test_commit --author "B <B@test.git>" \
504 "change" "$fortran_file" \
505 "$(cat file.template | sed -e s/ChangeMe/IWasChanged/)" &&
506 check_count -f "$fortran_file" -L:RIGHT A 3 B 1
509 test_expect_success 'setup incremental' '
511 GIT_AUTHOR_NAME=I &&
512 export GIT_AUTHOR_NAME &&
513 GIT_AUTHOR_EMAIL=I@test.git &&
514 export GIT_AUTHOR_EMAIL &&
515 >incremental &&
516 git add incremental &&
517 git commit -m "step 0" &&
518 printf "partial" >>incremental &&
519 git commit -a -m "step 0.5" &&
520 echo >>incremental &&
521 git commit -a -m "step 1"
525 test_expect_success 'blame empty' '
526 check_count -h HEAD^^ -f incremental
529 test_expect_success 'blame -L 0 empty' '
530 test_must_fail $PROG -L0 incremental HEAD^^
533 test_expect_success 'blame -L 1 empty' '
534 test_must_fail $PROG -L1 incremental HEAD^^
537 test_expect_success 'blame -L 2 empty' '
538 test_must_fail $PROG -L2 incremental HEAD^^
541 test_expect_success 'blame half' '
542 check_count -h HEAD^ -f incremental I 1
545 test_expect_success 'blame -L 0 half' '
546 test_must_fail $PROG -L0 incremental HEAD^
549 test_expect_success 'blame -L 1 half' '
550 check_count -h HEAD^ -f incremental -L1 I 1
553 test_expect_success 'blame -L 2 half' '
554 test_must_fail $PROG -L2 incremental HEAD^
557 test_expect_success 'blame -L 3 half' '
558 test_must_fail $PROG -L3 incremental HEAD^
561 test_expect_success 'blame full' '
562 check_count -f incremental I 1
565 test_expect_success 'blame -L 0 full' '
566 test_must_fail $PROG -L0 incremental
569 test_expect_success 'blame -L 1 full' '
570 check_count -f incremental -L1 I 1
573 test_expect_success 'blame -L 2 full' '
574 test_must_fail $PROG -L2 incremental
577 test_expect_success 'blame -L 3 full' '
578 test_must_fail $PROG -L3 incremental
581 test_expect_success 'blame -L' '
582 test_must_fail $PROG -L file
585 test_expect_success 'blame -L X,+' '
586 test_must_fail $PROG -L1,+ file
589 test_expect_success 'blame -L X,-' '
590 test_must_fail $PROG -L1,- file
593 test_expect_success 'blame -L X (non-numeric X)' '
594 test_must_fail $PROG -LX file
597 test_expect_success 'blame -L X,Y (non-numeric Y)' '
598 test_must_fail $PROG -L1,Y file
601 test_expect_success 'blame -L X,+N (non-numeric N)' '
602 test_must_fail $PROG -L1,+N file
605 test_expect_success 'blame -L X,-N (non-numeric N)' '
606 test_must_fail $PROG -L1,-N file
609 test_expect_success 'blame -L ,^/RE/' '
610 test_must_fail $PROG -L1,^/99/ file
613 test_expect_success 'blame progress on a full file' '
614 cat >expect <<-\EOF &&
615 Blaming lines: 100% (10/10), done.
618 GIT_PROGRESS_DELAY=0 \
619 git blame --progress hello.c 2>stderr &&
621 get_progress_result <stderr >actual &&
622 test_cmp expect actual
625 test_expect_success 'blame progress on a single range' '
626 cat >expect <<-\EOF &&
627 Blaming lines: 100% (4/4), done.
630 GIT_PROGRESS_DELAY=0 \
631 git blame --progress -L 3,6 hello.c 2>stderr &&
633 get_progress_result <stderr >actual &&
634 test_cmp expect actual
637 test_expect_success 'blame progress on multiple ranges' '
638 cat >expect <<-\EOF &&
639 Blaming lines: 100% (7/7), done.
642 GIT_PROGRESS_DELAY=0 \
643 git blame --progress -L 3,6 -L 8,10 hello.c 2>stderr &&
645 get_progress_result <stderr >actual &&
646 test_cmp expect actual