blob: c56a77d2378117006694d4b575445f89446ae80c [file] [log] [blame]
Fredrik Kuivinen8752d112006-03-05 12:13:34 +01001# This file isn't used as a test script directly, instead it is
Josh Stone9b01f002011-04-21 15:07:36 -07002# sourced from t8001-annotate.sh and t8002-blame.sh.
Fredrik Kuivinen8752d112006-03-05 12:13:34 +01003
Junio C Hamano92a903a2006-03-05 22:07:37 -08004check_count () {
5 head=
6 case "$1" in -h) head="$2"; shift; shift ;; esac
Junio C Hamanocee7f242006-10-19 16:00:04 -07007 echo "$PROG file $head" >&4
Ramsay Allan Jones1fd4da62006-07-29 17:20:41 +01008 $PROG file $head >.result || return 1
9 cat .result | perl -e '
Junio C Hamano92a903a2006-03-05 22:07:37 -080010 my %expect = (@ARGV);
Kevin Ballard27eea662010-10-16 04:09:20 -070011 my %count = map { $_ => 0 } keys %expect;
Junio C Hamano92a903a2006-03-05 22:07:37 -080012 while (<STDIN>) {
13 if (/^[0-9a-f]+\t\(([^\t]+)\t/) {
14 my $author = $1;
15 for ($author) { s/^\s*//; s/\s*$//; }
Kevin Ballard27eea662010-10-16 04:09:20 -070016 $count{$author}++;
Junio C Hamano92a903a2006-03-05 22:07:37 -080017 }
18 }
19 my $bad = 0;
20 while (my ($author, $count) = each %count) {
21 my $ok;
Kevin Ballard27eea662010-10-16 04:09:20 -070022 my $value = 0;
23 $value = $expect{$author} if defined $expect{$author};
24 if ($value != $count) {
Junio C Hamano92a903a2006-03-05 22:07:37 -080025 $bad = 1;
26 $ok = "bad";
27 }
28 else {
29 $ok = "good";
30 }
Kevin Ballard27eea662010-10-16 04:09:20 -070031 print STDERR "Author $author (expected $value, attributed $count) $ok\n";
Junio C Hamano92a903a2006-03-05 22:07:37 -080032 }
33 exit($bad);
34 ' "$@"
35}
36
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010037test_expect_success \
38 'prepare reference tree' \
39 'echo "1A quick brown fox jumps over the" >file &&
40 echo "lazy dog" >>file &&
Jonathan Niedera48fcd82010-10-30 20:46:54 -050041 git add file &&
Kevin Ballard1b8cdce2010-10-15 23:57:51 -070042 GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" git commit -a -m "Initial."'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010043
44test_expect_success \
45 'check all lines blamed on A' \
Junio C Hamano92a903a2006-03-05 22:07:37 -080046 'check_count A 2'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010047
48test_expect_success \
49 'Setup new lines blamed on B' \
50 'echo "2A quick brown fox jumps over the" >>file &&
51 echo "lazy dog" >> file &&
Kevin Ballard1b8cdce2010-10-15 23:57:51 -070052 GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" git commit -a -m "Second."'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010053
54test_expect_success \
Junio C Hamano92a903a2006-03-05 22:07:37 -080055 'Two lines blamed on A, two on B' \
56 'check_count A 2 B 2'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010057
58test_expect_success \
59 'merge-setup part 1' \
60 'git checkout -b branch1 master &&
61 echo "3A slow green fox jumps into the" >> file &&
62 echo "well." >> file &&
Kevin Ballard1b8cdce2010-10-15 23:57:51 -070063 GIT_AUTHOR_NAME="B1" GIT_AUTHOR_EMAIL="B1@test.git" git commit -a -m "Branch1-1"'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010064
65test_expect_success \
Junio C Hamano92a903a2006-03-05 22:07:37 -080066 'Two lines blamed on A, two on B, two on B1' \
67 'check_count A 2 B 2 B1 2'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010068
69test_expect_success \
70 'merge-setup part 2' \
71 'git checkout -b branch2 master &&
72 sed -e "s/2A quick brown/4A quick brown lazy dog/" < file > file.new &&
73 mv file.new file &&
Kevin Ballard1b8cdce2010-10-15 23:57:51 -070074 GIT_AUTHOR_NAME="B2" GIT_AUTHOR_EMAIL="B2@test.git" git commit -a -m "Branch2-1"'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010075
76test_expect_success \
Junio C Hamano92a903a2006-03-05 22:07:37 -080077 'Two lines blamed on A, one on B, one on B2' \
78 'check_count A 2 B 1 B2 1'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010079
80test_expect_success \
81 'merge-setup part 3' \
82 'git pull . branch1'
83
84test_expect_success \
Junio C Hamano92a903a2006-03-05 22:07:37 -080085 'Two lines blamed on A, one on B, two on B1, one on B2' \
86 'check_count A 2 B 1 B1 2 B2 1'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010087
88test_expect_success \
Junio C Hamano92a903a2006-03-05 22:07:37 -080089 'Annotating an old revision works' \
90 'check_count -h master A 2 B 2'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010091
92test_expect_success \
Junio C Hamano92a903a2006-03-05 22:07:37 -080093 'Annotating an old revision works' \
94 'check_count -h master^ A 2'
Fredrik Kuivinen8752d112006-03-05 12:13:34 +010095
Junio C Hamanoce5b6e72006-03-05 22:37:15 -080096test_expect_success \
97 'merge-setup part 4' \
98 'echo "evil merge." >>file &&
Eric Wong8ff99e72006-07-11 12:01:54 -070099 git commit -a --amend'
Junio C Hamanoce5b6e72006-03-05 22:37:15 -0800100
101test_expect_success \
102 'Two lines blamed on A, one on B, two on B1, one on B2, one on A U Thor' \
103 'check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1'
104
Junio C Hamano12426422006-03-06 00:41:17 -0800105test_expect_success \
106 'an incomplete line added' \
107 'echo "incomplete" | tr -d "\\012" >>file &&
Kevin Ballard1b8cdce2010-10-15 23:57:51 -0700108 GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" git commit -a -m "Incomplete"'
Junio C Hamano12426422006-03-06 00:41:17 -0800109
110test_expect_success \
111 'With incomplete lines.' \
112 'check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1'
113
114test_expect_success \
115 'some edit' \
Alex Riesen563b43e2007-02-05 14:04:09 +0100116 'mv file file.orig &&
Brandon Caseyd8b69ec2009-05-06 13:29:16 -0500117 {
118 cat file.orig &&
119 echo
120 } | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" > file &&
Johannes Schindelin58db64f2007-03-06 19:48:59 -0500121 echo "incomplete" | tr -d "\\012" >>file &&
Kevin Ballard1b8cdce2010-10-15 23:57:51 -0700122 GIT_AUTHOR_NAME="D" GIT_AUTHOR_EMAIL="D@test.git" git commit -a -m "edit"'
Junio C Hamano12426422006-03-06 00:41:17 -0800123
124test_expect_success \
125 'some edit' \
126 'check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1'
Josh Stone9b01f002011-04-21 15:07:36 -0700127
128test_expect_success \
129 'an obfuscated email added' \
Brian Gernhardtc01bd5a2011-05-05 00:43:37 -0400130 'echo "No robots allowed" > file.new &&
131 cat file >> file.new &&
Josh Stone9b01f002011-04-21 15:07:36 -0700132 mv file.new file &&
133 GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" git commit -a -m "norobots"'
134
135test_expect_success \
136 'obfuscated email parsed' \
137 'check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1'