blame.c: Properly initialize strbuf after calling textconv_object(), again
[git/dscho.git] / t / t8006-blame-textconv.sh
blob53905a222738d9fef0cdc79108a241ec3ee5a042
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 sed '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 if test_have_prereq SYMLINKS; then
22 ln -s one.bin symlink.bin
23 fi &&
24 git add . &&
25 GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
26 echo "bin: test 1 version 2" >one.bin &&
27 echo "bin: test number 2 version 2" >>two.bin &&
28 if test_have_prereq SYMLINKS; then
29 ln -sf two.bin symlink.bin
30 fi &&
31 GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
34 cat >expected <<EOF
35 (Number2 2010-01-01 20:00:00 +0000 1) bin: test 1 version 2
36 EOF
38 test_expect_success 'no filter specified' '
39 git blame one.bin >blame &&
40 find_blame Number2 <blame >result &&
41 test_cmp expected result
44 test_expect_success 'setup textconv filters' '
45 echo "*.bin diff=test" >.gitattributes &&
46 echo "zero.bin eol=crlf" >>.gitattributes &&
47 git config diff.test.textconv ./helper &&
48 git config diff.test.cachetextconv false
51 test_expect_success 'blame with --no-textconv' '
52 git blame --no-textconv one.bin >blame &&
53 find_blame <blame> result &&
54 test_cmp expected result
57 cat >expected <<EOF
58 (Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
59 EOF
61 test_expect_success 'basic blame on last commit' '
62 git blame one.bin >blame &&
63 find_blame <blame >result &&
64 test_cmp expected result
67 cat >expected <<EOF
68 (Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
69 (Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
70 EOF
72 test_expect_success 'blame --textconv going through revisions' '
73 git blame --textconv two.bin >blame &&
74 find_blame <blame >result &&
75 test_cmp expected result
78 test_expect_success 'blame --textconv with local changes' '
79 test_when_finished "git checkout zero.bin" &&
80 printf "bin: updated number 0\015" >zero.bin &&
81 git blame --textconv zero.bin >blame &&
82 expect="(Not Committed Yet ....-..-.. ..:..:.. +0000 1)" &&
83 expect="$expect converted: updated number 0" &&
84 expr "$(find_blame <blame)" : "^$expect"
87 test_expect_success 'make a new commit' '
88 echo "bin: test number 2 version 3" >>two.bin &&
89 GIT_AUTHOR_NAME=Number3 git commit -a -m Third --date="2010-01-01 22:00:00"
92 test_expect_success 'blame from previous revision' '
93 git blame HEAD^ two.bin >blame &&
94 find_blame <blame >result &&
95 test_cmp expected result
98 cat >expected <<EOF
99 (Number2 2010-01-01 20:00:00 +0000 1) two.bin
102 test_expect_success SYMLINKS 'blame with --no-textconv (on symlink)' '
103 git blame --no-textconv symlink.bin >blame &&
104 find_blame <blame >result &&
105 test_cmp expected result
108 test_expect_success SYMLINKS 'blame --textconv (on symlink)' '
109 git blame --textconv symlink.bin >blame &&
110 find_blame <blame >result &&
111 test_cmp expected result
114 # cp two.bin three.bin and make small tweak
115 # (this will direct blame -C -C three.bin to consider two.bin and symlink.bin)
116 test_expect_success SYMLINKS 'make another new commit' '
117 cat >three.bin <<\EOF &&
118 bin: test number 2
119 bin: test number 2 version 2
120 bin: test number 2 version 3
121 bin: test number 3
123 git add three.bin &&
124 GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00"
127 test_expect_success SYMLINKS 'blame on last commit (-C -C, symlink)' '
128 git blame -C -C three.bin >blame &&
129 find_blame <blame >result &&
130 cat >expected <<\EOF &&
131 (Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
132 (Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
133 (Number3 2010-01-01 22:00:00 +0000 3) converted: test number 2 version 3
134 (Number4 2010-01-01 23:00:00 +0000 4) converted: test number 3
136 test_cmp expected result
139 test_done