Merge branch 'jc/maint-diff-patch-header' into maint
[alt-git.git] / t / t8006-blame-textconv.sh
blobc3c22f7764adc1542579dfddf1b47a687a93607a
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 -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 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 rm symlink.bin &&
30 ln -s two.bin symlink.bin
31 fi &&
32 GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
35 cat >expected <<EOF
36 (Number2 2010-01-01 20:00:00 +0000 1) bin: test 1 version 2
37 EOF
39 test_expect_success 'no filter specified' '
40 git blame one.bin >blame &&
41 find_blame Number2 <blame >result &&
42 test_cmp expected result
45 test_expect_success 'setup textconv filters' '
46 echo "*.bin diff=test" >.gitattributes &&
47 echo "zero.bin eol=crlf" >>.gitattributes &&
48 git config diff.test.textconv ./helper &&
49 git config diff.test.cachetextconv false
52 test_expect_success 'blame with --no-textconv' '
53 git blame --no-textconv one.bin >blame &&
54 find_blame <blame> result &&
55 test_cmp expected result
58 cat >expected <<EOF
59 (Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
60 EOF
62 test_expect_success 'basic blame on last commit' '
63 git blame one.bin >blame &&
64 find_blame <blame >result &&
65 test_cmp expected result
68 cat >expected <<EOF
69 (Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
70 (Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
71 EOF
73 test_expect_success 'blame --textconv going through revisions' '
74 git blame --textconv two.bin >blame &&
75 find_blame <blame >result &&
76 test_cmp expected result
79 test_expect_success 'blame --textconv with local changes' '
80 test_when_finished "git checkout zero.bin" &&
81 printf "bin: updated number 0\015" >zero.bin &&
82 git blame --textconv zero.bin >blame &&
83 expect="(Not Committed Yet ....-..-.. ..:..:.. +0000 1)" &&
84 expect="$expect converted: updated number 0" &&
85 expr "$(find_blame <blame)" : "^$expect"
88 test_expect_success 'setup +cachetextconv' '
89 git config diff.test.cachetextconv true
92 cat >expected_one <<EOF
93 (Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
94 EOF
96 test_expect_success 'blame --textconv works with textconvcache' '
97 git blame --textconv two.bin >blame &&
98 find_blame <blame >result &&
99 test_cmp expected result &&
100 git blame --textconv one.bin >blame &&
101 find_blame <blame >result &&
102 test_cmp expected_one result
105 test_expect_success 'setup -cachetextconv' '
106 git config diff.test.cachetextconv false
109 test_expect_success 'make a new commit' '
110 echo "bin: test number 2 version 3" >>two.bin &&
111 GIT_AUTHOR_NAME=Number3 git commit -a -m Third --date="2010-01-01 22:00:00"
114 test_expect_success 'blame from previous revision' '
115 git blame HEAD^ two.bin >blame &&
116 find_blame <blame >result &&
117 test_cmp expected result
120 cat >expected <<EOF
121 (Number2 2010-01-01 20:00:00 +0000 1) two.bin
124 test_expect_success SYMLINKS 'blame with --no-textconv (on symlink)' '
125 git blame --no-textconv symlink.bin >blame &&
126 find_blame <blame >result &&
127 test_cmp expected result
130 test_expect_success SYMLINKS 'blame --textconv (on symlink)' '
131 git blame --textconv symlink.bin >blame &&
132 find_blame <blame >result &&
133 test_cmp expected result
136 # cp two.bin three.bin and make small tweak
137 # (this will direct blame -C -C three.bin to consider two.bin and symlink.bin)
138 test_expect_success SYMLINKS 'make another new commit' '
139 cat >three.bin <<\EOF &&
140 bin: test number 2
141 bin: test number 2 version 2
142 bin: test number 2 version 3
143 bin: test number 3
145 git add three.bin &&
146 GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00"
149 test_expect_success SYMLINKS 'blame on last commit (-C -C, symlink)' '
150 git blame -C -C three.bin >blame &&
151 find_blame <blame >result &&
152 cat >expected <<\EOF &&
153 (Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
154 (Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
155 (Number3 2010-01-01 22:00:00 +0000 3) converted: test number 2 version 3
156 (Number4 2010-01-01 23:00:00 +0000 4) converted: test number 3
158 test_cmp expected result
161 test_done