t / annotate-tests.shon commit Merge branch 'ts/daemon' (d5d0a0e)
   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 () {
   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}++;
  17                                }
  18                        }
  19                }
  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";
  26                        }
  27                        else {
  28                                $ok = "good";
  29                        }
  30                        print STDERR "Author $author (expected $expect{$author}, attributed $count) $ok\n";
  31                }
  32                exit($bad);
  33        ' "$@"
  34}
  35
  36test_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."'
  42
  43test_expect_success \
  44    'check all lines blamed on A' \
  45    'check_count A 2'
  46
  47test_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."'
  52
  53test_expect_success \
  54    'Two lines blamed on A, two on B' \
  55    'check_count A 2 B 2'
  56
  57test_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"'
  63
  64test_expect_success \
  65    'Two lines blamed on A, two on B, two on B1' \
  66    'check_count A 2 B 2 B1 2'
  67
  68test_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"'
  74
  75test_expect_success \
  76    'Two lines blamed on A, one on B, one on B2' \
  77    'check_count A 2 B 1 B2 1'
  78
  79test_expect_success \
  80    'merge-setup part 3' \
  81    'git pull . branch1'
  82
  83test_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'
  86
  87test_expect_success \
  88    'Annotating an old revision works' \
  89    'check_count -h master A 2 B 2'
  90
  91test_expect_success \
  92    'Annotating an old revision works' \
  93    'check_count -h master^ A 2'
  94
  95test_expect_success \
  96    'merge-setup part 4' \
  97    'echo "evil merge." >>file &&
  98     git commit -a --amend'
  99
 100test_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'
 103
 104test_expect_success \
 105    'an incomplete line added' \
 106    'echo "incomplete" | tr -d "\\012" >>file &&
 107    GIT_AUTHOR_NAME="C" git commit -a -m "Incomplete"'
 108
 109test_expect_success \
 110    'With incomplete lines.' \
 111    'check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 C 1'
 112
 113test_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"'
 117
 118test_expect_success \
 119    'some edit' \
 120    'check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1'