t / t8006-blame-textconv.shon commit completion: fix multiple command removals (057ab54)
   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; }
  13"$PERL_PATH" -p -e 's/^bin: /converted: /' "$1"
  14EOF
  15chmod +x helper
  16
  17test_expect_success 'setup ' '
  18        echo "bin: test number 0" >zero.bin &&
  19        echo "bin: test 1" >one.bin &&
  20        echo "bin: test number 2" >two.bin &&
  21        test_ln_s_add one.bin symlink.bin &&
  22        git add . &&
  23        GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
  24        echo "bin: test 1 version 2" >one.bin &&
  25        echo "bin: test number 2 version 2" >>two.bin &&
  26        rm -f symlink.bin &&
  27        test_ln_s_add two.bin symlink.bin &&
  28        GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
  29'
  30
  31cat >expected <<EOF
  32(Number2 2010-01-01 20:00:00 +0000 1) bin: test 1 version 2
  33EOF
  34
  35test_expect_success 'no filter specified' '
  36        git blame one.bin >blame &&
  37        find_blame Number2 <blame >result &&
  38        test_cmp expected result
  39'
  40
  41test_expect_success 'setup textconv filters' '
  42        echo "*.bin diff=test" >.gitattributes &&
  43        echo "zero.bin eol=crlf" >>.gitattributes &&
  44        git config diff.test.textconv ./helper &&
  45        git config diff.test.cachetextconv false
  46'
  47
  48test_expect_success 'blame with --no-textconv' '
  49        git blame --no-textconv one.bin >blame &&
  50        find_blame <blame> result &&
  51        test_cmp expected result
  52'
  53
  54cat >expected <<EOF
  55(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
  56EOF
  57
  58test_expect_success 'basic blame on last commit' '
  59        git blame one.bin >blame &&
  60        find_blame  <blame >result &&
  61        test_cmp expected result
  62'
  63
  64cat >expected <<EOF
  65(Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
  66(Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
  67EOF
  68
  69test_expect_success 'blame --textconv going through revisions' '
  70        git blame --textconv two.bin >blame &&
  71        find_blame <blame >result &&
  72        test_cmp expected result
  73'
  74
  75test_expect_success 'blame --textconv with local changes' '
  76        test_when_finished "git checkout zero.bin" &&
  77        printf "bin: updated number 0\015" >zero.bin &&
  78        git blame --textconv zero.bin >blame &&
  79        expect="(Not Committed Yet ....-..-.. ..:..:.. +0000 1)" &&
  80        expect="$expect converted: updated number 0" &&
  81        expr "$(find_blame <blame)" : "^$expect"
  82'
  83
  84test_expect_success 'setup +cachetextconv' '
  85        git config diff.test.cachetextconv true
  86'
  87
  88cat >expected_one <<EOF
  89(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
  90EOF
  91
  92test_expect_success 'blame --textconv works with textconvcache' '
  93        git blame --textconv two.bin >blame &&
  94        find_blame <blame >result &&
  95        test_cmp expected result &&
  96        git blame --textconv one.bin >blame &&
  97        find_blame  <blame >result &&
  98        test_cmp expected_one result
  99'
 100
 101test_expect_success 'setup -cachetextconv' '
 102        git config diff.test.cachetextconv false
 103'
 104
 105test_expect_success 'make a new commit' '
 106        echo "bin: test number 2 version 3" >>two.bin &&
 107        GIT_AUTHOR_NAME=Number3 git commit -a -m Third --date="2010-01-01 22:00:00"
 108'
 109
 110test_expect_success 'blame from previous revision' '
 111        git blame HEAD^ two.bin >blame &&
 112        find_blame <blame >result &&
 113        test_cmp expected result
 114'
 115
 116cat >expected <<EOF
 117(Number2 2010-01-01 20:00:00 +0000 1) two.bin
 118EOF
 119
 120test_expect_success SYMLINKS 'blame with --no-textconv (on symlink)' '
 121        git blame --no-textconv symlink.bin >blame &&
 122        find_blame <blame >result &&
 123        test_cmp expected result
 124'
 125
 126test_expect_success SYMLINKS 'blame --textconv (on symlink)' '
 127        git blame --textconv symlink.bin >blame &&
 128        find_blame <blame >result &&
 129        test_cmp expected result
 130'
 131
 132# cp two.bin three.bin  and make small tweak
 133# (this will direct blame -C -C three.bin to consider two.bin and symlink.bin)
 134test_expect_success 'make another new commit' '
 135        cat >three.bin <<\EOF &&
 136bin: test number 2
 137bin: test number 2 version 2
 138bin: test number 2 version 3
 139bin: test number 3
 140EOF
 141        git add three.bin &&
 142        GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00"
 143'
 144
 145test_expect_success 'blame on last commit (-C -C, symlink)' '
 146        git blame -C -C three.bin >blame &&
 147        find_blame <blame >result &&
 148        cat >expected <<\EOF &&
 149(Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
 150(Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
 151(Number3 2010-01-01 22:00:00 +0000 3) converted: test number 2 version 3
 152(Number4 2010-01-01 23:00:00 +0000 4) converted: test number 3
 153EOF
 154        test_cmp expected result
 155'
 156
 157test_done