cvsserver: fix "cvs diff" in a subdirectory
[git.git] / t / annotate-tests.sh
blob8baf2fef69ba6a67641d2b9ba4dc44468aa31ada
1 # This file isn't used as a test script directly, instead it is
2 # sourced from t8001-annotate.sh and t8001-blame.sh.
4 check_count () {
5 head=
6 case "$1" in -h) head="$2"; shift; shift ;; esac
7 $PROG file $head >.result || return 1
8 cat .result | perl -e '
9 my %expect = (@ARGV);
10 my %count = ();
11 while (<STDIN>) {
12 if (/^[0-9a-f]+\t\(([^\t]+)\t/) {
13 my $author = $1;
14 for ($author) { s/^\s*//; s/\s*$//; }
15 if (exists $expect{$author}) {
16 $count{$author}++;
20 my $bad = 0;
21 while (my ($author, $count) = each %count) {
22 my $ok;
23 if ($expect{$author} != $count) {
24 $bad = 1;
25 $ok = "bad";
27 else {
28 $ok = "good";
30 print STDERR "Author $author (expected $expect{$author}, attributed $count) $ok\n";
32 exit($bad);
33 ' "$@"
36 test_expect_success \
37 'prepare reference tree' \
38 'echo "1A quick brown fox jumps over the" >file &&
39 echo "lazy dog" >>file &&
40 git add file
41 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
43 test_expect_success \
44 'check all lines blamed on A' \
45 'check_count A 2'
47 test_expect_success \
48 'Setup new lines blamed on B' \
49 'echo "2A quick brown fox jumps over the" >>file &&
50 echo "lazy dog" >> file &&
51 GIT_AUTHOR_NAME="B" git commit -a -m "Second."'
53 test_expect_success \
54 'Two lines blamed on A, two on B' \
55 'check_count A 2 B 2'
57 test_expect_success \
58 'merge-setup part 1' \
59 'git checkout -b branch1 master &&
60 echo "3A slow green fox jumps into the" >> file &&
61 echo "well." >> file &&
62 GIT_AUTHOR_NAME="B1" git commit -a -m "Branch1-1"'
64 test_expect_success \
65 'Two lines blamed on A, two on B, two on B1' \
66 'check_count A 2 B 2 B1 2'
68 test_expect_success \
69 'merge-setup part 2' \
70 'git checkout -b branch2 master &&
71 sed -e "s/2A quick brown/4A quick brown lazy dog/" < file > file.new &&
72 mv file.new file &&
73 GIT_AUTHOR_NAME="B2" git commit -a -m "Branch2-1"'
75 test_expect_success \
76 'Two lines blamed on A, one on B, one on B2' \
77 'check_count A 2 B 1 B2 1'
79 test_expect_success \
80 'merge-setup part 3' \
81 'git pull . branch1'
83 test_expect_success \
84 'Two lines blamed on A, one on B, two on B1, one on B2' \
85 'check_count A 2 B 1 B1 2 B2 1'
87 test_expect_success \
88 'Annotating an old revision works' \
89 'check_count -h master A 2 B 2'
91 test_expect_success \
92 'Annotating an old revision works' \
93 'check_count -h master^ A 2'
95 test_expect_success \
96 'merge-setup part 4' \
97 'echo "evil merge." >>file &&
98 git commit -a --amend'
100 test_expect_success \
101 'Two lines blamed on A, one on B, two on B1, one on B2, one on A U Thor' \
102 'check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1'
104 test_expect_success \
105 'an incomplete line added' \
106 'echo "incomplete" | tr -d "\\012" >>file &&
107 GIT_AUTHOR_NAME="C" git commit -a -m "Incomplete"'
109 test_expect_success \
110 'With incomplete lines.' \
111 'check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1'
113 test_expect_success \
114 'some edit' \
115 'perl -p -i.orig -e "s/^1A.*\n$//; s/^3A/99/" file &&
116 GIT_AUTHOR_NAME="D" git commit -a -m "edit"'
118 test_expect_success \
119 'some edit' \
120 'check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1'