Git fork
at reftables-rust 158 lines 4.4 kB view raw
1#!/bin/sh 2 3test_description='git blame textconv support' 4 5. ./test-lib.sh 6 7find_blame() { 8 sed -e 's/^[^(]*//' 9} 10 11cat >helper <<'EOF' 12#!/bin/sh 13grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; } 14sed 's/^bin: /converted: /' "$1" 15EOF 16chmod +x helper 17 18test_expect_success 'setup ' ' 19 echo "bin: test number 0" >zero.bin && 20 echo "bin: test 1" >one.bin && 21 echo "bin: test number 2" >two.bin && 22 test_ln_s_add one.bin symlink.bin && 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 rm -f symlink.bin && 28 test_ln_s_add two.bin symlink.bin && 29 GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00" 30' 31 32cat >expected <<EOF 33(Number2 2010-01-01 20:00:00 +0000 1) bin: test 1 version 2 34EOF 35 36test_expect_success 'no filter specified' ' 37 git blame one.bin >blame && 38 find_blame Number2 <blame >result && 39 test_cmp expected result 40' 41 42test_expect_success 'setup textconv filters' ' 43 echo "*.bin diff=test" >.gitattributes && 44 echo "zero.bin eol=crlf" >>.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 'blame --textconv with local changes' ' 77 test_when_finished "git checkout zero.bin" && 78 printf "bin: updated number 0\015" >zero.bin && 79 git blame --textconv zero.bin >blame && 80 expect="(Not Committed Yet ....-..-.. ..:..:.. +0000 1)" && 81 expect="$expect converted: updated number 0" && 82 expr "$(find_blame <blame)" : "^$expect" 83' 84 85test_expect_success 'setup +cachetextconv' ' 86 git config diff.test.cachetextconv true 87' 88 89cat >expected_one <<EOF 90(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2 91EOF 92 93test_expect_success 'blame --textconv works with textconvcache' ' 94 git blame --textconv two.bin >blame && 95 find_blame <blame >result && 96 test_cmp expected result && 97 git blame --textconv one.bin >blame && 98 find_blame <blame >result && 99 test_cmp expected_one result 100' 101 102test_expect_success 'setup -cachetextconv' ' 103 git config diff.test.cachetextconv false 104' 105 106test_expect_success 'make a new commit' ' 107 echo "bin: test number 2 version 3" >>two.bin && 108 GIT_AUTHOR_NAME=Number3 git commit -a -m Third --date="2010-01-01 22:00:00" 109' 110 111test_expect_success 'blame from previous revision' ' 112 git blame HEAD^ two.bin >blame && 113 find_blame <blame >result && 114 test_cmp expected result 115' 116 117cat >expected <<EOF 118(Number2 2010-01-01 20:00:00 +0000 1) two.bin 119EOF 120 121test_expect_success SYMLINKS 'blame with --no-textconv (on symlink)' ' 122 git blame --no-textconv symlink.bin >blame && 123 find_blame <blame >result && 124 test_cmp expected result 125' 126 127test_expect_success SYMLINKS 'blame --textconv (on symlink)' ' 128 git blame --textconv symlink.bin >blame && 129 find_blame <blame >result && 130 test_cmp expected result 131' 132 133# cp two.bin three.bin and make small tweak 134# (this will direct blame -C -C three.bin to consider two.bin and symlink.bin) 135test_expect_success 'make another new commit' ' 136 cat >three.bin <<\EOF && 137bin: test number 2 138bin: test number 2 version 2 139bin: test number 2 version 3 140bin: test number 3 141EOF 142 git add three.bin && 143 GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00" 144' 145 146test_expect_success 'blame on last commit (-C -C, symlink)' ' 147 git blame -C -C three.bin >blame && 148 find_blame <blame >result && 149 cat >expected <<\EOF && 150(Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2 151(Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2 152(Number3 2010-01-01 22:00:00 +0000 3) converted: test number 2 version 3 153(Number4 2010-01-01 23:00:00 +0000 4) converted: test number 3 154EOF 155 test_cmp expected result 156' 157 158test_done