]>
Commit | Line | Data |
---|---|---|
37d29e10 AB |
1 | #!/bin/sh |
2 | ||
3 | test_description='git blame textconv support' | |
4 | . ./test-lib.sh | |
5 | ||
6 | find_blame() { | |
7 | sed -e 's/^[^(]*//' | |
8 | } | |
9 | ||
10 | cat >helper <<'EOF' | |
11 | #!/bin/sh | |
6517cf7d | 12 | grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; } |
7096b648 | 13 | "$PERL_PATH" -p -e 's/^bin: /converted: /' "$1" |
37d29e10 AB |
14 | EOF |
15 | chmod +x helper | |
16 | ||
17 | test_expect_success 'setup ' ' | |
55e7c0aa | 18 | echo "bin: test number 0" >zero.bin && |
6517cf7d KS |
19 | echo "bin: test 1" >one.bin && |
20 | echo "bin: test number 2" >two.bin && | |
889c6f0e | 21 | test_ln_s_add one.bin symlink.bin && |
37d29e10 AB |
22 | git add . && |
23 | GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" && | |
6517cf7d KS |
24 | echo "bin: test 1 version 2" >one.bin && |
25 | echo "bin: test number 2 version 2" >>two.bin && | |
889c6f0e JS |
26 | rm -f symlink.bin && |
27 | test_ln_s_add two.bin symlink.bin && | |
37d29e10 AB |
28 | GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00" |
29 | ' | |
30 | ||
31 | cat >expected <<EOF | |
6517cf7d | 32 | (Number2 2010-01-01 20:00:00 +0000 1) bin: test 1 version 2 |
37d29e10 AB |
33 | EOF |
34 | ||
35 | test_expect_success 'no filter specified' ' | |
36 | git blame one.bin >blame && | |
37 | find_blame Number2 <blame >result && | |
38 | test_cmp expected result | |
39 | ' | |
40 | ||
41 | test_expect_success 'setup textconv filters' ' | |
42 | echo "*.bin diff=test" >.gitattributes && | |
55e7c0aa | 43 | echo "zero.bin eol=crlf" >>.gitattributes && |
37d29e10 AB |
44 | git config diff.test.textconv ./helper && |
45 | git config diff.test.cachetextconv false | |
46 | ' | |
47 | ||
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 | |
52 | ' | |
53 | ||
54 | cat >expected <<EOF | |
55 | (Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2 | |
56 | EOF | |
57 | ||
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 | |
62 | ' | |
63 | ||
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 | |
68 | ||
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 | |
73 | ' | |
74 | ||
55e7c0aa JH |
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" | |
82 | ' | |
83 | ||
b1b14ec3 KS |
84 | test_expect_success 'setup +cachetextconv' ' |
85 | git config diff.test.cachetextconv true | |
86 | ' | |
87 | ||
88 | cat >expected_one <<EOF | |
89 | (Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2 | |
90 | EOF | |
91 | ||
9ec09b04 | 92 | test_expect_success 'blame --textconv works with textconvcache' ' |
b1b14ec3 KS |
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 | |
99 | ' | |
100 | ||
101 | test_expect_success 'setup -cachetextconv' ' | |
102 | git config diff.test.cachetextconv false | |
103 | ' | |
104 | ||
37d29e10 | 105 | test_expect_success 'make a new commit' ' |
6517cf7d | 106 | echo "bin: test number 2 version 3" >>two.bin && |
37d29e10 AB |
107 | GIT_AUTHOR_NAME=Number3 git commit -a -m Third --date="2010-01-01 22:00:00" |
108 | ' | |
109 | ||
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 | |
114 | ' | |
115 | ||
ab3b7b9a KS |
116 | cat >expected <<EOF |
117 | (Number2 2010-01-01 20:00:00 +0000 1) two.bin | |
118 | EOF | |
119 | ||
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 | |
124 | ' | |
125 | ||
90064710 | 126 | test_expect_success SYMLINKS 'blame --textconv (on symlink)' ' |
ab3b7b9a KS |
127 | git blame --textconv symlink.bin >blame && |
128 | find_blame <blame >result && | |
129 | test_cmp expected result | |
130 | ' | |
131 | ||
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) | |
889c6f0e | 134 | test_expect_success 'make another new commit' ' |
ab3b7b9a KS |
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 | |
140 | EOF | |
141 | git add three.bin && | |
142 | GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00" | |
143 | ' | |
144 | ||
889c6f0e | 145 | test_expect_success 'blame on last commit (-C -C, symlink)' ' |
ab3b7b9a KS |
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 | |
153 | EOF | |
154 | test_cmp expected result | |
155 | ' | |
156 | ||
37d29e10 | 157 | test_done |