t / t8006-blame-textconv.shon commit i18n: git-branch "Deleted branch [...]" message (8af42b0)
   1#!/bin/sh
   2
   3test_description='git blame textconv support'
   4. ./test-lib.sh
   5
   6find_blame() {
   7        sed -e 's/^[^(]*//'
   8}
   9
  10cat >helper <<'EOF'
  11#!/bin/sh
  12grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
  13sed 's/^bin: /converted: /' "$1"
  14EOF
  15chmod +x helper
  16
  17test_expect_success 'setup ' '
  18        echo "bin: test 1" >one.bin &&
  19        echo "bin: test number 2" >two.bin &&
  20        if test_have_prereq SYMLINKS; then
  21                ln -s one.bin symlink.bin
  22        fi &&
  23        git add . &&
  24        GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
  25        echo "bin: test 1 version 2" >one.bin &&
  26        echo "bin: test number 2 version 2" >>two.bin &&
  27        if test_have_prereq SYMLINKS; then
  28                ln -sf two.bin symlink.bin
  29        fi &&
  30        GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
  31'
  32
  33cat >expected <<EOF
  34(Number2 2010-01-01 20:00:00 +0000 1) bin: test 1 version 2
  35EOF
  36
  37test_expect_success 'no filter specified' '
  38        git blame one.bin >blame &&
  39        find_blame Number2 <blame >result &&
  40        test_cmp expected result
  41'
  42
  43test_expect_success 'setup textconv filters' '
  44        echo "*.bin diff=test" >.gitattributes &&
  45        git config diff.test.textconv ./helper &&
  46        git config diff.test.cachetextconv false
  47'
  48
  49test_expect_success 'blame with --no-textconv' '
  50        git blame --no-textconv one.bin >blame &&
  51        find_blame <blame> result &&
  52        test_cmp expected result
  53'
  54
  55cat >expected <<EOF
  56(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
  57EOF
  58
  59test_expect_success 'basic blame on last commit' '
  60        git blame one.bin >blame &&
  61        find_blame  <blame >result &&
  62        test_cmp expected result
  63'
  64
  65cat >expected <<EOF
  66(Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
  67(Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
  68EOF
  69
  70test_expect_success 'blame --textconv going through revisions' '
  71        git blame --textconv two.bin >blame &&
  72        find_blame <blame >result &&
  73        test_cmp expected result
  74'
  75
  76test_expect_success 'setup +cachetextconv' '
  77        git config diff.test.cachetextconv true
  78'
  79
  80cat >expected_one <<EOF
  81(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
  82EOF
  83
  84test_expect_success 'blame --textconv works with textconvcache' '
  85        git blame --textconv two.bin >blame &&
  86        find_blame <blame >result &&
  87        test_cmp expected result &&
  88        git blame --textconv one.bin >blame &&
  89        find_blame  <blame >result &&
  90        test_cmp expected_one result
  91'
  92
  93test_expect_success 'setup -cachetextconv' '
  94        git config diff.test.cachetextconv false
  95'
  96
  97test_expect_success 'make a new commit' '
  98        echo "bin: test number 2 version 3" >>two.bin &&
  99        GIT_AUTHOR_NAME=Number3 git commit -a -m Third --date="2010-01-01 22:00:00"
 100'
 101
 102test_expect_success 'blame from previous revision' '
 103        git blame HEAD^ two.bin >blame &&
 104        find_blame <blame >result &&
 105        test_cmp expected result
 106'
 107
 108cat >expected <<EOF
 109(Number2 2010-01-01 20:00:00 +0000 1) two.bin
 110EOF
 111
 112test_expect_success SYMLINKS 'blame with --no-textconv (on symlink)' '
 113        git blame --no-textconv symlink.bin >blame &&
 114        find_blame <blame >result &&
 115        test_cmp expected result
 116'
 117
 118test_expect_success SYMLINKS 'blame --textconv (on symlink)' '
 119        git blame --textconv symlink.bin >blame &&
 120        find_blame <blame >result &&
 121        test_cmp expected result
 122'
 123
 124# cp two.bin three.bin  and make small tweak
 125# (this will direct blame -C -C three.bin to consider two.bin and symlink.bin)
 126test_expect_success SYMLINKS 'make another new commit' '
 127        cat >three.bin <<\EOF &&
 128bin: test number 2
 129bin: test number 2 version 2
 130bin: test number 2 version 3
 131bin: test number 3
 132EOF
 133        git add three.bin &&
 134        GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00"
 135'
 136
 137test_expect_success SYMLINKS 'blame on last commit (-C -C, symlink)' '
 138        git blame -C -C three.bin >blame &&
 139        find_blame <blame >result &&
 140        cat >expected <<\EOF &&
 141(Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
 142(Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
 143(Number3 2010-01-01 22:00:00 +0000 3) converted: test number 2 version 3
 144(Number4 2010-01-01 23:00:00 +0000 4) converted: test number 3
 145EOF
 146        test_cmp expected result
 147'
 148
 149test_done