]>
Commit | Line | Data |
---|---|---|
df5e91fc JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='diff.*.textconv tests' | |
4 | . ./test-lib.sh | |
5 | ||
6 | find_diff() { | |
7 | sed '1,/^index /d' | sed '/^-- $/,$d' | |
8 | } | |
9 | ||
10 | cat >expect.binary <<'EOF' | |
11 | Binary files a/file and b/file differ | |
12 | EOF | |
13 | ||
14 | cat >expect.text <<'EOF' | |
15 | --- a/file | |
16 | +++ b/file | |
17 | @@ -1 +1,2 @@ | |
18 | 0 | |
19 | +1 | |
20 | EOF | |
21 | ||
22 | cat >hexdump <<'EOF' | |
23 | #!/bin/sh | |
7096b648 | 24 | "$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1" |
df5e91fc JK |
25 | EOF |
26 | chmod +x hexdump | |
27 | ||
28 | test_expect_success 'setup binary file with history' ' | |
47c88d16 ÆAB |
29 | test_commit --printf one file "\\0\\n" && |
30 | test_commit --printf --append two file "\\01\\n" | |
df5e91fc JK |
31 | ' |
32 | ||
33 | test_expect_success 'file is considered binary by porcelain' ' | |
34 | git diff HEAD^ HEAD >diff && | |
35 | find_diff <diff >actual && | |
36 | test_cmp expect.binary actual | |
37 | ' | |
38 | ||
39 | test_expect_success 'file is considered binary by plumbing' ' | |
40 | git diff-tree -p HEAD^ HEAD >diff && | |
41 | find_diff <diff >actual && | |
42 | test_cmp expect.binary actual | |
43 | ' | |
44 | ||
45 | test_expect_success 'setup textconv filters' ' | |
46 | echo file diff=foo >.gitattributes && | |
63962583 | 47 | git config diff.foo.textconv "\"$(pwd)\""/hexdump && |
df5e91fc JK |
48 | git config diff.fail.textconv false |
49 | ' | |
50 | ||
04427ac8 | 51 | test_expect_success 'diff produces text' ' |
df5e91fc JK |
52 | git diff HEAD^ HEAD >diff && |
53 | find_diff <diff >actual && | |
54 | test_cmp expect.text actual | |
55 | ' | |
56 | ||
4bd52d09 MG |
57 | test_expect_success 'show commit produces text' ' |
58 | git show HEAD >diff && | |
59 | find_diff <diff >actual && | |
60 | test_cmp expect.text actual | |
61 | ' | |
62 | ||
df5e91fc JK |
63 | test_expect_success 'diff-tree produces binary' ' |
64 | git diff-tree -p HEAD^ HEAD >diff && | |
65 | find_diff <diff >actual && | |
66 | test_cmp expect.binary actual | |
67 | ' | |
68 | ||
04427ac8 | 69 | test_expect_success 'log produces text' ' |
df5e91fc JK |
70 | git log -1 -p >log && |
71 | find_diff <log >actual && | |
72 | test_cmp expect.text actual | |
73 | ' | |
74 | ||
c7534ef4 | 75 | test_expect_success 'format-patch produces binary' ' |
df5e91fc JK |
76 | git format-patch --no-binary --stdout HEAD^ >patch && |
77 | find_diff <patch >actual && | |
78 | test_cmp expect.binary actual | |
79 | ' | |
80 | ||
a79b8b66 JK |
81 | test_expect_success 'status -v produces text' ' |
82 | git reset --soft HEAD^ && | |
83 | git status -v >diff && | |
84 | find_diff <diff >actual && | |
85 | test_cmp expect.text actual && | |
86 | git reset --soft HEAD@{1} | |
87 | ' | |
88 | ||
4bd52d09 MG |
89 | test_expect_success 'show blob produces binary' ' |
90 | git show HEAD:file >actual && | |
91 | printf "\\0\\n\\01\\n" >expect && | |
92 | test_cmp expect actual | |
93 | ' | |
94 | ||
083b9931 | 95 | test_expect_success 'show --textconv blob produces text' ' |
4bd52d09 MG |
96 | git show --textconv HEAD:file >actual && |
97 | printf "0\\n1\\n" >expect && | |
98 | test_cmp expect actual | |
99 | ' | |
100 | ||
083b9931 MG |
101 | test_expect_success 'show --no-textconv blob produces binary' ' |
102 | git show --no-textconv HEAD:file >actual && | |
4bd52d09 MG |
103 | printf "\\0\\n\\01\\n" >expect && |
104 | test_cmp expect actual | |
105 | ' | |
106 | ||
b1c2f57d JK |
107 | test_expect_success 'grep-diff (-G) operates on textconv data (add)' ' |
108 | echo one >expect && | |
109 | git log --root --format=%s -G0 >actual && | |
110 | test_cmp expect actual | |
111 | ' | |
112 | ||
113 | test_expect_success 'grep-diff (-G) operates on textconv data (modification)' ' | |
114 | echo two >expect && | |
115 | git log --root --format=%s -G1 >actual && | |
116 | test_cmp expect actual | |
117 | ' | |
118 | ||
ef90ab66 JK |
119 | test_expect_success 'pickaxe (-S) operates on textconv data (add)' ' |
120 | echo one >expect && | |
121 | git log --root --format=%s -S0 >actual && | |
122 | test_cmp expect actual | |
123 | ' | |
124 | ||
125 | test_expect_success 'pickaxe (-S) operates on textconv data (modification)' ' | |
126 | echo two >expect && | |
127 | git log --root --format=%s -S1 >actual && | |
128 | test_cmp expect actual | |
129 | ' | |
130 | ||
df5e91fc | 131 | cat >expect.stat <<'EOF' |
dc801e71 | 132 | file | Bin 2 -> 4 bytes |
7f814632 | 133 | 1 file changed, 0 insertions(+), 0 deletions(-) |
df5e91fc | 134 | EOF |
04427ac8 | 135 | test_expect_success 'diffstat does not run textconv' ' |
df5e91fc JK |
136 | echo file diff=fail >.gitattributes && |
137 | git diff --stat HEAD^ HEAD >actual && | |
1108cea7 | 138 | test_cmp expect.stat actual && |
6dd88832 JN |
139 | |
140 | head -n1 <expect.stat >expect.line1 && | |
141 | head -n1 <actual >actual.line1 && | |
142 | test_cmp expect.line1 actual.line1 | |
df5e91fc JK |
143 | ' |
144 | # restore working setup | |
145 | echo file diff=foo >.gitattributes | |
146 | ||
a6c57990 | 147 | symlink=$(git rev-parse --short $(printf frotz | git hash-object --stdin)) |
148 | cat >expect.typechange <<EOF | |
df5e91fc JK |
149 | --- a/file |
150 | +++ /dev/null | |
151 | @@ -1,2 +0,0 @@ | |
152 | -0 | |
153 | -1 | |
154 | diff --git a/file b/file | |
155 | new file mode 120000 | |
a6c57990 | 156 | index 0000000..$symlink |
df5e91fc JK |
157 | --- /dev/null |
158 | +++ b/file | |
159 | @@ -0,0 +1 @@ | |
160 | +frotz | |
161 | \ No newline at end of file | |
162 | EOF | |
889c6f0e | 163 | |
2675773a | 164 | test_expect_success 'textconv does not act on symlinks' ' |
889c6f0e JS |
165 | rm -f file && |
166 | test_ln_s_add frotz file && | |
df5e91fc JK |
167 | git commit -m typechange && |
168 | git show >diff && | |
169 | find_diff <diff >actual && | |
170 | test_cmp expect.typechange actual | |
171 | ' | |
172 | ||
173 | test_done |