Merge branch 'jc/exclusion-doc'
[alt-git.git] / t / t8006-blame-textconv.sh
blob7683515155497d9303f319b31c3a49fb6610706f
1 #!/bin/sh
3 test_description='git blame textconv support'
4 . ./test-lib.sh
6 find_blame() {
7 sed -e 's/^[^(]*//'
10 cat >helper <<'EOF'
11 #!/bin/sh
12 grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
13 "$PERL_PATH" -p -e 's/^bin: /converted: /' "$1"
14 EOF
15 chmod +x helper
17 test_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"
31 cat >expected <<EOF
32 (Number2 2010-01-01 20:00:00 +0000 1) bin: test 1 version 2
33 EOF
35 test_expect_success 'no filter specified' '
36 git blame one.bin >blame &&
37 find_blame Number2 <blame >result &&
38 test_cmp expected result
41 test_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
48 test_expect_success 'blame with --no-textconv' '
49 git blame --no-textconv one.bin >blame &&
50 find_blame <blame> result &&
51 test_cmp expected result
54 cat >expected <<EOF
55 (Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
56 EOF
58 test_expect_success 'basic blame on last commit' '
59 git blame one.bin >blame &&
60 find_blame <blame >result &&
61 test_cmp expected result
64 cat >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
67 EOF
69 test_expect_success 'blame --textconv going through revisions' '
70 git blame --textconv two.bin >blame &&
71 find_blame <blame >result &&
72 test_cmp expected result
75 test_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"
84 test_expect_success 'setup +cachetextconv' '
85 git config diff.test.cachetextconv true
88 cat >expected_one <<EOF
89 (Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
90 EOF
92 test_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
101 test_expect_success 'setup -cachetextconv' '
102 git config diff.test.cachetextconv false
105 test_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"
110 test_expect_success 'blame from previous revision' '
111 git blame HEAD^ two.bin >blame &&
112 find_blame <blame >result &&
113 test_cmp expected result
116 cat >expected <<EOF
117 (Number2 2010-01-01 20:00:00 +0000 1) two.bin
120 test_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
126 test_expect_success SYMLINKS 'blame --textconv (on symlink)' '
127 git blame --textconv symlink.bin >blame &&
128 find_blame <blame >result &&
129 test_cmp expected result
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)
134 test_expect_success 'make another new commit' '
135 cat >three.bin <<\EOF &&
136 bin: test number 2
137 bin: test number 2 version 2
138 bin: test number 2 version 3
139 bin: test number 3
141 git add three.bin &&
142 GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00"
145 test_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
154 test_cmp expected result
157 test_done