Merge branch 'jc/ci-upload-artifact-and-linux32'
[git/gitster.git] / t / t8006-blame-textconv.sh
blob42f8be25a3fdf98c0e1fc221fe8a43b8c103b69c
1 #!/bin/sh
3 test_description='git blame textconv support'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 find_blame() {
9 sed -e 's/^[^(]*//'
12 cat >helper <<'EOF'
13 #!/bin/sh
14 grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
15 "$PERL_PATH" -p -e 's/^bin: /converted: /' "$1"
16 EOF
17 chmod +x helper
19 test_expect_success 'setup ' '
20 echo "bin: test number 0" >zero.bin &&
21 echo "bin: test 1" >one.bin &&
22 echo "bin: test number 2" >two.bin &&
23 test_ln_s_add one.bin symlink.bin &&
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 rm -f symlink.bin &&
29 test_ln_s_add two.bin symlink.bin &&
30 GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
33 cat >expected <<EOF
34 (Number2 2010-01-01 20:00:00 +0000 1) bin: test 1 version 2
35 EOF
37 test_expect_success 'no filter specified' '
38 git blame one.bin >blame &&
39 find_blame Number2 <blame >result &&
40 test_cmp expected result
43 test_expect_success 'setup textconv filters' '
44 echo "*.bin diff=test" >.gitattributes &&
45 echo "zero.bin eol=crlf" >>.gitattributes &&
46 git config diff.test.textconv ./helper &&
47 git config diff.test.cachetextconv false
50 test_expect_success 'blame with --no-textconv' '
51 git blame --no-textconv one.bin >blame &&
52 find_blame <blame> result &&
53 test_cmp expected result
56 cat >expected <<EOF
57 (Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
58 EOF
60 test_expect_success 'basic blame on last commit' '
61 git blame one.bin >blame &&
62 find_blame <blame >result &&
63 test_cmp expected result
66 cat >expected <<EOF
67 (Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
68 (Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
69 EOF
71 test_expect_success 'blame --textconv going through revisions' '
72 git blame --textconv two.bin >blame &&
73 find_blame <blame >result &&
74 test_cmp expected result
77 test_expect_success 'blame --textconv with local changes' '
78 test_when_finished "git checkout zero.bin" &&
79 printf "bin: updated number 0\015" >zero.bin &&
80 git blame --textconv zero.bin >blame &&
81 expect="(Not Committed Yet ....-..-.. ..:..:.. +0000 1)" &&
82 expect="$expect converted: updated number 0" &&
83 expr "$(find_blame <blame)" : "^$expect"
86 test_expect_success 'setup +cachetextconv' '
87 git config diff.test.cachetextconv true
90 cat >expected_one <<EOF
91 (Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
92 EOF
94 test_expect_success 'blame --textconv works with textconvcache' '
95 git blame --textconv two.bin >blame &&
96 find_blame <blame >result &&
97 test_cmp expected result &&
98 git blame --textconv one.bin >blame &&
99 find_blame <blame >result &&
100 test_cmp expected_one result
103 test_expect_success 'setup -cachetextconv' '
104 git config diff.test.cachetextconv false
107 test_expect_success 'make a new commit' '
108 echo "bin: test number 2 version 3" >>two.bin &&
109 GIT_AUTHOR_NAME=Number3 git commit -a -m Third --date="2010-01-01 22:00:00"
112 test_expect_success 'blame from previous revision' '
113 git blame HEAD^ two.bin >blame &&
114 find_blame <blame >result &&
115 test_cmp expected result
118 cat >expected <<EOF
119 (Number2 2010-01-01 20:00:00 +0000 1) two.bin
122 test_expect_success SYMLINKS 'blame with --no-textconv (on symlink)' '
123 git blame --no-textconv symlink.bin >blame &&
124 find_blame <blame >result &&
125 test_cmp expected result
128 test_expect_success SYMLINKS 'blame --textconv (on symlink)' '
129 git blame --textconv symlink.bin >blame &&
130 find_blame <blame >result &&
131 test_cmp expected result
134 # cp two.bin three.bin and make small tweak
135 # (this will direct blame -C -C three.bin to consider two.bin and symlink.bin)
136 test_expect_success 'make another new commit' '
137 cat >three.bin <<\EOF &&
138 bin: test number 2
139 bin: test number 2 version 2
140 bin: test number 2 version 3
141 bin: test number 3
143 git add three.bin &&
144 GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00"
147 test_expect_success 'blame on last commit (-C -C, symlink)' '
148 git blame -C -C three.bin >blame &&
149 find_blame <blame >result &&
150 cat >expected <<\EOF &&
151 (Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
152 (Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
153 (Number3 2010-01-01 22:00:00 +0000 3) converted: test number 2 version 3
154 (Number4 2010-01-01 23:00:00 +0000 4) converted: test number 3
156 test_cmp expected result
159 test_done