t / t8006-blame-textconv.shon commit Merge branch 'jc/want-commit' (c672f01)
   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                rm symlink.bin &&
  29                ln -s two.bin symlink.bin
  30        fi &&
  31        GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
  32'
  33
  34cat >expected <<EOF
  35(Number2 2010-01-01 20:00:00 +0000 1) bin: test 1 version 2
  36EOF
  37
  38test_expect_success 'no filter specified' '
  39        git blame one.bin >blame &&
  40        find_blame Number2 <blame >result &&
  41        test_cmp expected result
  42'
  43
  44test_expect_success 'setup textconv filters' '
  45        echo "*.bin diff=test" >.gitattributes &&
  46        git config diff.test.textconv ./helper &&
  47        git config diff.test.cachetextconv false
  48'
  49
  50test_expect_success 'blame with --no-textconv' '
  51        git blame --no-textconv one.bin >blame &&
  52        find_blame <blame> result &&
  53        test_cmp expected result
  54'
  55
  56cat >expected <<EOF
  57(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
  58EOF
  59
  60test_expect_success 'basic blame on last commit' '
  61        git blame one.bin >blame &&
  62        find_blame  <blame >result &&
  63        test_cmp expected result
  64'
  65
  66cat >expected <<EOF
  67(Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
  68(Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
  69EOF
  70
  71test_expect_success 'blame --textconv going through revisions' '
  72        git blame --textconv two.bin >blame &&
  73        find_blame <blame >result &&
  74        test_cmp expected result
  75'
  76
  77test_expect_success 'setup +cachetextconv' '
  78        git config diff.test.cachetextconv true
  79'
  80
  81cat >expected_one <<EOF
  82(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
  83EOF
  84
  85test_expect_success 'blame --textconv works with textconvcache' '
  86        git blame --textconv two.bin >blame &&
  87        find_blame <blame >result &&
  88        test_cmp expected result &&
  89        git blame --textconv one.bin >blame &&
  90        find_blame  <blame >result &&
  91        test_cmp expected_one result
  92'
  93
  94test_expect_success 'setup -cachetextconv' '
  95        git config diff.test.cachetextconv false
  96'
  97
  98test_expect_success 'make a new commit' '
  99        echo "bin: test number 2 version 3" >>two.bin &&
 100        GIT_AUTHOR_NAME=Number3 git commit -a -m Third --date="2010-01-01 22:00:00"
 101'
 102
 103test_expect_success 'blame from previous revision' '
 104        git blame HEAD^ two.bin >blame &&
 105        find_blame <blame >result &&
 106        test_cmp expected result
 107'
 108
 109cat >expected <<EOF
 110(Number2 2010-01-01 20:00:00 +0000 1) two.bin
 111EOF
 112
 113test_expect_success SYMLINKS 'blame with --no-textconv (on symlink)' '
 114        git blame --no-textconv symlink.bin >blame &&
 115        find_blame <blame >result &&
 116        test_cmp expected result
 117'
 118
 119test_expect_success SYMLINKS 'blame --textconv (on symlink)' '
 120        git blame --textconv symlink.bin >blame &&
 121        find_blame <blame >result &&
 122        test_cmp expected result
 123'
 124
 125# cp two.bin three.bin  and make small tweak
 126# (this will direct blame -C -C three.bin to consider two.bin and symlink.bin)
 127test_expect_success SYMLINKS 'make another new commit' '
 128        cat >three.bin <<\EOF &&
 129bin: test number 2
 130bin: test number 2 version 2
 131bin: test number 2 version 3
 132bin: test number 3
 133EOF
 134        git add three.bin &&
 135        GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00"
 136'
 137
 138test_expect_success SYMLINKS 'blame on last commit (-C -C, symlink)' '
 139        git blame -C -C three.bin >blame &&
 140        find_blame <blame >result &&
 141        cat >expected <<\EOF &&
 142(Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
 143(Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
 144(Number3 2010-01-01 22:00:00 +0000 3) converted: test number 2 version 3
 145(Number4 2010-01-01 23:00:00 +0000 4) converted: test number 3
 146EOF
 147        test_cmp expected result
 148'
 149
 150test_done