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 4check_count () { 5head= 6case"$1"in-h)head="$2";shift;shift;;esac 7$PROGfile$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 35test_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 42test_expect_success \ 43'check all lines blamed on A' \ 44'check_count A 2' 45 46test_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 52test_expect_success \ 53'Two lines blamed on A, two on B' \ 54'check_count A 2 B 2' 55 56test_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 63test_expect_success \ 64'Two lines blamed on A, two on B, two on B1' \ 65'check_count A 2 B 2 B1 2' 66 67test_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 74test_expect_success \ 75'Two lines blamed on A, one on B, one on B2' \ 76'check_count A 2 B 1 B2 1' 77 78test_expect_success \ 79'merge-setup part 3' \ 80'git pull . branch1' 81 82test_expect_success \ 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' 85 86test_expect_success \ 87'Annotating an old revision works' \ 88'check_count -h master A 2 B 2' 89 90test_expect_success \ 91'Annotating an old revision works' \ 92'check_count -h master^ A 2' 93 94test_expect_success \ 95'merge-setup part 4' \ 96'echo "evil merge." >>file && 97 git commit -a --amend' 98 99test_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 103test_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 108test_expect_success \ 109'With incomplete lines.' \ 110'check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1' 111 112test_expect_success \ 113'some edit' \ 114'perl -p -i.orig -e "s/^1A.*\n$//; s/^3A/99/" file && 115 GIT_AUTHOR_NAME="D" git commit -a -m "edit"' 116 117test_expect_success \ 118'some edit' \ 119'check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1'