blob: 2f27a0ba9ec002b1a6e4d3bd0ed1dc7484d4d14e [file] [log] [blame]
Jeff Kingdf5e91f2008-10-26 00:42:25 -04001#!/bin/sh
2
3test_description='diff.*.textconv tests'
4. ./test-lib.sh
5
6find_diff() {
7 sed '1,/^index /d' | sed '/^-- $/,$d'
8}
9
10cat >expect.binary <<'EOF'
11Binary files a/file and b/file differ
12EOF
13
14cat >expect.text <<'EOF'
15--- a/file
16+++ b/file
17@@ -1 +1,2 @@
18 0
19+1
20EOF
21
22cat >hexdump <<'EOF'
23#!/bin/sh
Alex Riesen3b91c302008-11-19 12:14:50 +010024perl -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
Jeff Kingdf5e91f2008-10-26 00:42:25 -040025EOF
26chmod +x hexdump
27
28test_expect_success 'setup binary file with history' '
29 printf "\\0\\n" >file &&
30 git add file &&
31 git commit -m one &&
Johannes Sixtdeb13872008-12-02 09:31:01 +010032 printf "\\01\\n" >>file &&
Jeff Kingdf5e91f2008-10-26 00:42:25 -040033 git add file &&
34 git commit -m two
35'
36
37test_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
43test_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
49test_expect_success 'setup textconv filters' '
50 echo file diff=foo >.gitattributes &&
51 git config diff.foo.textconv "$PWD"/hexdump &&
52 git config diff.fail.textconv false
53'
54
Jeff King04427ac2008-10-26 00:44:53 -040055test_expect_success 'diff produces text' '
Jeff Kingdf5e91f2008-10-26 00:42:25 -040056 git diff HEAD^ HEAD >diff &&
57 find_diff <diff >actual &&
58 test_cmp expect.text actual
59'
60
61test_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
Jeff King04427ac2008-10-26 00:44:53 -040067test_expect_success 'log produces text' '
Jeff Kingdf5e91f2008-10-26 00:42:25 -040068 git log -1 -p >log &&
69 find_diff <log >actual &&
70 test_cmp expect.text actual
71'
72
Jeff Kingc7534ef2008-10-26 00:45:55 -040073test_expect_success 'format-patch produces binary' '
Jeff Kingdf5e91f2008-10-26 00:42:25 -040074 git format-patch --no-binary --stdout HEAD^ >patch &&
75 find_diff <patch >actual &&
76 test_cmp expect.binary actual
77'
78
Jeff Kinga79b8b62008-10-26 00:50:02 -040079test_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
Jeff Kingdf5e91f2008-10-26 00:42:25 -040087cat >expect.stat <<'EOF'
88 file | Bin 2 -> 4 bytes
89 1 files changed, 0 insertions(+), 0 deletions(-)
90EOF
Jeff King04427ac2008-10-26 00:44:53 -040091test_expect_success 'diffstat does not run textconv' '
Jeff Kingdf5e91f2008-10-26 00:42:25 -040092 echo file diff=fail >.gitattributes &&
93 git diff --stat HEAD^ HEAD >actual &&
94 test_cmp expect.stat actual
95'
96# restore working setup
97echo file diff=foo >.gitattributes
98
99cat >expect.typechange <<'EOF'
100--- a/file
101+++ /dev/null
102@@ -1,2 +0,0 @@
103-0
104-1
105diff --git a/file b/file
106new file mode 120000
107index ad8b3d2..67be421
108--- /dev/null
109+++ b/file
110@@ -0,0 +1 @@
111+frotz
112\ No newline at end of file
113EOF
114# make a symlink the hard way that works on symlink-challenged file systems
Jeff King26757732008-10-26 00:46:21 -0400115test_expect_success 'textconv does not act on symlinks' '
Brian Gernhardt6ecfd912008-10-31 01:09:13 -0400116 printf frotz > file &&
Jeff Kingdf5e91f2008-10-26 00:42:25 -0400117 git add file &&
118 git ls-files -s | sed -e s/100644/120000/ |
119 git update-index --index-info &&
120 git commit -m typechange &&
121 git show >diff &&
122 find_diff <diff >actual &&
123 test_cmp expect.typechange actual
124'
125
126test_done