]>
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 | |
3b91c30b | 24 | perl -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' ' | |
29 | printf "\\0\\n" >file && | |
30 | git add file && | |
31 | git commit -m one && | |
deb13872 | 32 | printf "\\01\\n" >>file && |
df5e91fc JK |
33 | git add file && |
34 | git commit -m two | |
35 | ' | |
36 | ||
37 | test_expect_success 'file is considered binary by porcelain' ' | |
38 | git diff HEAD^ HEAD >diff && | |
39 | find_diff <diff >actual && | |
40 | test_cmp expect.binary actual | |
41 | ' | |
42 | ||
43 | test_expect_success 'file is considered binary by plumbing' ' | |
44 | git diff-tree -p HEAD^ HEAD >diff && | |
45 | find_diff <diff >actual && | |
46 | test_cmp expect.binary actual | |
47 | ' | |
48 | ||
49 | test_expect_success 'setup textconv filters' ' | |
50 | echo file diff=foo >.gitattributes && | |
63962583 | 51 | git config diff.foo.textconv "\"$(pwd)\""/hexdump && |
df5e91fc JK |
52 | git config diff.fail.textconv false |
53 | ' | |
54 | ||
04427ac8 | 55 | test_expect_success 'diff produces text' ' |
df5e91fc JK |
56 | git diff HEAD^ HEAD >diff && |
57 | find_diff <diff >actual && | |
58 | test_cmp expect.text actual | |
59 | ' | |
60 | ||
61 | test_expect_success 'diff-tree produces binary' ' | |
62 | git diff-tree -p HEAD^ HEAD >diff && | |
63 | find_diff <diff >actual && | |
64 | test_cmp expect.binary actual | |
65 | ' | |
66 | ||
04427ac8 | 67 | test_expect_success 'log produces text' ' |
df5e91fc JK |
68 | git log -1 -p >log && |
69 | find_diff <log >actual && | |
70 | test_cmp expect.text actual | |
71 | ' | |
72 | ||
c7534ef4 | 73 | test_expect_success 'format-patch produces binary' ' |
df5e91fc JK |
74 | git format-patch --no-binary --stdout HEAD^ >patch && |
75 | find_diff <patch >actual && | |
76 | test_cmp expect.binary actual | |
77 | ' | |
78 | ||
a79b8b66 JK |
79 | test_expect_success 'status -v produces text' ' |
80 | git reset --soft HEAD^ && | |
81 | git status -v >diff && | |
82 | find_diff <diff >actual && | |
83 | test_cmp expect.text actual && | |
84 | git reset --soft HEAD@{1} | |
85 | ' | |
86 | ||
df5e91fc | 87 | cat >expect.stat <<'EOF' |
dc801e71 | 88 | file | Bin 2 -> 4 bytes |
7f814632 | 89 | 1 file changed, 0 insertions(+), 0 deletions(-) |
df5e91fc | 90 | EOF |
04427ac8 | 91 | test_expect_success 'diffstat does not run textconv' ' |
df5e91fc JK |
92 | echo file diff=fail >.gitattributes && |
93 | git diff --stat HEAD^ HEAD >actual && | |
6dd88832 JN |
94 | test_i18ncmp expect.stat actual && |
95 | ||
96 | head -n1 <expect.stat >expect.line1 && | |
97 | head -n1 <actual >actual.line1 && | |
98 | test_cmp expect.line1 actual.line1 | |
df5e91fc JK |
99 | ' |
100 | # restore working setup | |
101 | echo file diff=foo >.gitattributes | |
102 | ||
103 | cat >expect.typechange <<'EOF' | |
104 | --- a/file | |
105 | +++ /dev/null | |
106 | @@ -1,2 +0,0 @@ | |
107 | -0 | |
108 | -1 | |
109 | diff --git a/file b/file | |
110 | new file mode 120000 | |
90b23e5f | 111 | index 0000000..67be421 |
df5e91fc JK |
112 | --- /dev/null |
113 | +++ b/file | |
114 | @@ -0,0 +1 @@ | |
115 | +frotz | |
116 | \ No newline at end of file | |
117 | EOF | |
118 | # make a symlink the hard way that works on symlink-challenged file systems | |
2675773a | 119 | test_expect_success 'textconv does not act on symlinks' ' |
6ecfd91d | 120 | printf frotz > file && |
df5e91fc JK |
121 | git add file && |
122 | git ls-files -s | sed -e s/100644/120000/ | | |
123 | git update-index --index-info && | |
124 | git commit -m typechange && | |
125 | git show >diff && | |
126 | find_diff <diff >actual && | |
127 | test_cmp expect.typechange actual | |
128 | ' | |
129 | ||
130 | test_done |