Code

3945731e9a92eccffa6fcea4164da3bcbf991b3d
[git.git] / t / t4030-diff-textconv.sh
1 #!/bin/sh
3 test_description='diff.*.textconv tests'
4 . ./test-lib.sh
6 find_diff() {
7         sed '1,/^index /d' | sed '/^-- $/,$d'
8 }
10 cat >expect.binary <<'EOF'
11 Binary files a/file and b/file differ
12 EOF
14 cat >expect.text <<'EOF'
15 --- a/file
16 +++ b/file
17 @@ -1 +1,2 @@
18  0
19 +1
20 EOF
22 cat >hexdump <<'EOF'
23 #!/bin/sh
24 perl -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' "$1"
25 EOF
26 chmod +x hexdump
28 test_expect_success 'setup binary file with history' '
29         printf "\\0\\n" >file &&
30         git add file &&
31         git commit -m one &&
32         printf "\\1\\n" >>file &&
33         git add file &&
34         git commit -m two
35 '
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 '
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 '
49 test_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 '
55 test_expect_success 'diff produces text' '
56         git diff HEAD^ HEAD >diff &&
57         find_diff <diff >actual &&
58         test_cmp expect.text actual
59 '
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 '
67 test_expect_success 'log produces text' '
68         git log -1 -p >log &&
69         find_diff <log >actual &&
70         test_cmp expect.text actual
71 '
73 test_expect_success 'format-patch produces binary' '
74         git format-patch --no-binary --stdout HEAD^ >patch &&
75         find_diff <patch >actual &&
76         test_cmp expect.binary actual
77 '
79 cat >expect.stat <<'EOF'
80  file |  Bin 2 -> 4 bytes
81  1 files changed, 0 insertions(+), 0 deletions(-)
82 EOF
83 test_expect_success 'diffstat does not run textconv' '
84         echo file diff=fail >.gitattributes &&
85         git diff --stat HEAD^ HEAD >actual &&
86         test_cmp expect.stat actual
87 '
88 # restore working setup
89 echo file diff=foo >.gitattributes
91 cat >expect.typechange <<'EOF'
92 --- a/file
93 +++ /dev/null
94 @@ -1,2 +0,0 @@
95 -0
96 -1
97 diff --git a/file b/file
98 new file mode 120000
99 index ad8b3d2..67be421
100 --- /dev/null
101 +++ b/file
102 @@ -0,0 +1 @@
103 +frotz
104 \ No newline at end of file
105 EOF
106 # make a symlink the hard way that works on symlink-challenged file systems
107 test_expect_success 'textconv does not act on symlinks' '
108         echo -n frotz > file &&
109         git add file &&
110         git ls-files -s | sed -e s/100644/120000/ |
111                 git update-index --index-info &&
112         git commit -m typechange &&
113         git show >diff &&
114         find_diff <diff >actual &&
115         test_cmp expect.typechange actual
118 test_done