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