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 |
Junio C Hamano | cee7f24 | 2006-10-19 16:00:04 -0700 | [diff] [blame] | 7 | echo "$PROG file $head" >&4 |
Ramsay Allan Jones | 1fd4da6 | 2006-07-29 17:20:41 +0100 | [diff] [blame] | 8 | $PROG file $head >.result || return 1 |
| 9 | cat .result | perl -e ' |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 10 | my %expect = (@ARGV); |
| 11 | my %count = (); |
| 12 | while (<STDIN>) { |
| 13 | if (/^[0-9a-f]+\t\(([^\t]+)\t/) { |
| 14 | my $author = $1; |
| 15 | for ($author) { s/^\s*//; s/\s*$//; } |
| 16 | if (exists $expect{$author}) { |
| 17 | $count{$author}++; |
| 18 | } |
| 19 | } |
| 20 | } |
| 21 | my $bad = 0; |
| 22 | while (my ($author, $count) = each %count) { |
| 23 | my $ok; |
| 24 | if ($expect{$author} != $count) { |
| 25 | $bad = 1; |
| 26 | $ok = "bad"; |
| 27 | } |
| 28 | else { |
| 29 | $ok = "good"; |
| 30 | } |
| 31 | print STDERR "Author $author (expected $expect{$author}, attributed $count) $ok\n"; |
| 32 | } |
| 33 | exit($bad); |
| 34 | ' "$@" |
| 35 | } |
| 36 | |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 37 | test_expect_success \ |
| 38 | 'prepare reference tree' \ |
| 39 | 'echo "1A quick brown fox jumps over the" >file && |
| 40 | echo "lazy dog" >>file && |
| 41 | git add file |
| 42 | GIT_AUTHOR_NAME="A" git commit -a -m "Initial."' |
| 43 | |
| 44 | test_expect_success \ |
| 45 | 'check all lines blamed on A' \ |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 46 | 'check_count A 2' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 47 | |
| 48 | test_expect_success \ |
| 49 | 'Setup new lines blamed on B' \ |
| 50 | 'echo "2A quick brown fox jumps over the" >>file && |
| 51 | echo "lazy dog" >> file && |
| 52 | GIT_AUTHOR_NAME="B" git commit -a -m "Second."' |
| 53 | |
| 54 | test_expect_success \ |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 55 | 'Two lines blamed on A, two on B' \ |
| 56 | 'check_count A 2 B 2' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 57 | |
| 58 | test_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 && |
| 63 | GIT_AUTHOR_NAME="B1" git commit -a -m "Branch1-1"' |
| 64 | |
| 65 | test_expect_success \ |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 66 | 'Two lines blamed on A, two on B, two on B1' \ |
| 67 | 'check_count A 2 B 2 B1 2' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 68 | |
| 69 | test_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 && |
| 74 | GIT_AUTHOR_NAME="B2" git commit -a -m "Branch2-1"' |
| 75 | |
| 76 | test_expect_success \ |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 77 | 'Two lines blamed on A, one on B, one on B2' \ |
| 78 | 'check_count A 2 B 1 B2 1' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 79 | |
| 80 | test_expect_success \ |
| 81 | 'merge-setup part 3' \ |
| 82 | 'git pull . branch1' |
| 83 | |
| 84 | test_expect_success \ |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 85 | '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 Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 87 | |
| 88 | test_expect_success \ |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 89 | 'Annotating an old revision works' \ |
| 90 | 'check_count -h master A 2 B 2' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 91 | |
| 92 | test_expect_success \ |
Junio C Hamano | 92a903a | 2006-03-05 22:07:37 -0800 | [diff] [blame] | 93 | 'Annotating an old revision works' \ |
| 94 | 'check_count -h master^ A 2' |
Fredrik Kuivinen | 8752d11 | 2006-03-05 12:13:34 +0100 | [diff] [blame] | 95 | |
Junio C Hamano | ce5b6e7 | 2006-03-05 22:37:15 -0800 | [diff] [blame] | 96 | test_expect_success \ |
| 97 | 'merge-setup part 4' \ |
| 98 | 'echo "evil merge." >>file && |
Eric Wong | 8ff99e7 | 2006-07-11 12:01:54 -0700 | [diff] [blame] | 99 | git commit -a --amend' |
Junio C Hamano | ce5b6e7 | 2006-03-05 22:37:15 -0800 | [diff] [blame] | 100 | |
| 101 | test_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 Hamano | 1242642 | 2006-03-06 00:41:17 -0800 | [diff] [blame] | 105 | test_expect_success \ |
| 106 | 'an incomplete line added' \ |
| 107 | 'echo "incomplete" | tr -d "\\012" >>file && |
| 108 | GIT_AUTHOR_NAME="C" git commit -a -m "Incomplete"' |
| 109 | |
| 110 | test_expect_success \ |
| 111 | 'With incomplete lines.' \ |
| 112 | 'check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1' |
| 113 | |
| 114 | test_expect_success \ |
| 115 | 'some edit' \ |
Alex Riesen | 563b43e | 2007-02-05 14:04:09 +0100 | [diff] [blame] | 116 | 'mv file file.orig && |
Brandon Casey | d8b69ec | 2009-05-06 13:29:16 -0500 | [diff] [blame] | 117 | { |
| 118 | cat file.orig && |
| 119 | echo |
| 120 | } | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" > file && |
Johannes Schindelin | 58db64f | 2007-03-06 19:48:59 -0500 | [diff] [blame] | 121 | echo "incomplete" | tr -d "\\012" >>file && |
Junio C Hamano | 1242642 | 2006-03-06 00:41:17 -0800 | [diff] [blame] | 122 | GIT_AUTHOR_NAME="D" git commit -a -m "edit"' |
| 123 | |
| 124 | test_expect_success \ |
| 125 | 'some edit' \ |
| 126 | 'check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1' |