Merge branch 'rs/diff-parseopts-cleanup'
[git/gitster.git] / t / t4030-diff-textconv.sh
bloba39a626664d4a529be3d7978fad831e35e224e8c
1 #!/bin/sh
3 test_description='diff.*.textconv tests'
4 . ./test-lib.sh
6 find_diff() {
7 sed '1,/^index /d' | sed '/^-- $/,$d'
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 @@
20 EOF
22 cat >hexdump <<'EOF'
23 #!/bin/sh
24 "$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
25 EOF
26 chmod +x hexdump
28 test_expect_success 'setup binary file with history' '
29 test_commit --printf one file "\\0\\n" &&
30 test_commit --printf --append two file "\\01\\n"
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
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
45 test_expect_success 'setup textconv filters' '
46 echo file diff=foo >.gitattributes &&
47 git config diff.foo.textconv "\"$(pwd)\""/hexdump &&
48 git config diff.fail.textconv false
51 test_expect_success 'diff produces text' '
52 git diff HEAD^ HEAD >diff &&
53 find_diff <diff >actual &&
54 test_cmp expect.text actual
57 test_expect_success 'show commit produces text' '
58 git show HEAD >diff &&
59 find_diff <diff >actual &&
60 test_cmp expect.text actual
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
69 test_expect_success 'log produces text' '
70 git log -1 -p >log &&
71 find_diff <log >actual &&
72 test_cmp expect.text actual
75 test_expect_success 'format-patch produces binary' '
76 git format-patch --no-binary --stdout HEAD^ >patch &&
77 find_diff <patch >actual &&
78 test_cmp expect.binary actual
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}
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
95 test_expect_success 'show --textconv blob produces text' '
96 git show --textconv HEAD:file >actual &&
97 printf "0\\n1\\n" >expect &&
98 test_cmp expect actual
101 test_expect_success 'show --no-textconv blob produces binary' '
102 git show --no-textconv HEAD:file >actual &&
103 printf "\\0\\n\\01\\n" >expect &&
104 test_cmp expect actual
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
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
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
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
131 cat >expect.stat <<'EOF'
132 file | Bin 2 -> 4 bytes
133 1 file changed, 0 insertions(+), 0 deletions(-)
135 test_expect_success 'diffstat does not run textconv' '
136 echo file diff=fail >.gitattributes &&
137 git diff --stat HEAD^ HEAD >actual &&
138 test_cmp expect.stat actual &&
140 head -n1 <expect.stat >expect.line1 &&
141 head -n1 <actual >actual.line1 &&
142 test_cmp expect.line1 actual.line1
144 # restore working setup
145 echo file diff=foo >.gitattributes
147 symlink=$(git rev-parse --short $(printf frotz | git hash-object --stdin))
148 cat >expect.typechange <<EOF
149 --- a/file
150 +++ /dev/null
151 @@ -1,2 +0,0 @@
154 diff --git a/file b/file
155 new file mode 120000
156 index 0000000..$symlink
157 --- /dev/null
158 +++ b/file
159 @@ -0,0 +1 @@
160 +frotz
161 \ No newline at end of file
164 test_expect_success 'textconv does not act on symlinks' '
165 rm -f file &&
166 test_ln_s_add frotz file &&
167 git commit -m typechange &&
168 git show >diff &&
169 find_diff <diff >actual &&
170 test_cmp expect.typechange actual
173 test_done