ci updates
[git.git] / t / t4030-diff-textconv.sh
blob29f6d610c2e61bc80a7b9fa64f8212d6f2a9384d
1 #!/bin/sh
3 test_description='diff.*.textconv tests'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 find_diff() {
9 sed '1,/^index /d' | sed '/^-- $/,$d'
12 cat >expect.binary <<'EOF'
13 Binary files a/file and b/file differ
14 EOF
16 cat >expect.text <<'EOF'
17 --- a/file
18 +++ b/file
19 @@ -1 +1,2 @@
22 EOF
24 cat >hexdump <<'EOF'
25 #!/bin/sh
26 "$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
27 EOF
28 chmod +x hexdump
30 test_expect_success 'setup binary file with history' '
31 test_commit --printf one file "\\0\\n" &&
32 test_commit --printf --append two file "\\01\\n"
35 test_expect_success 'file is considered binary by porcelain' '
36 git diff HEAD^ HEAD >diff &&
37 find_diff <diff >actual &&
38 test_cmp expect.binary actual
41 test_expect_success 'file is considered binary by plumbing' '
42 git diff-tree -p HEAD^ HEAD >diff &&
43 find_diff <diff >actual &&
44 test_cmp expect.binary actual
47 test_expect_success 'setup textconv filters' '
48 echo file diff=foo >.gitattributes &&
49 git config diff.foo.textconv "\"$(pwd)\""/hexdump &&
50 git config diff.fail.textconv false
53 test_expect_success 'diff produces text' '
54 git diff HEAD^ HEAD >diff &&
55 find_diff <diff >actual &&
56 test_cmp expect.text actual
59 test_expect_success 'show commit produces text' '
60 git show HEAD >diff &&
61 find_diff <diff >actual &&
62 test_cmp expect.text actual
65 test_expect_success 'diff-tree produces binary' '
66 git diff-tree -p HEAD^ HEAD >diff &&
67 find_diff <diff >actual &&
68 test_cmp expect.binary actual
71 test_expect_success 'log produces text' '
72 git log -1 -p >log &&
73 find_diff <log >actual &&
74 test_cmp expect.text actual
77 test_expect_success 'format-patch produces binary' '
78 git format-patch --no-binary --stdout HEAD^ >patch &&
79 find_diff <patch >actual &&
80 test_cmp expect.binary actual
83 test_expect_success 'status -v produces text' '
84 git reset --soft HEAD^ &&
85 git status -v >diff &&
86 find_diff <diff >actual &&
87 test_cmp expect.text actual &&
88 git reset --soft HEAD@{1}
91 test_expect_success 'show blob produces binary' '
92 git show HEAD:file >actual &&
93 printf "\\0\\n\\01\\n" >expect &&
94 test_cmp expect actual
97 test_expect_success 'show --textconv blob produces text' '
98 git show --textconv HEAD:file >actual &&
99 printf "0\\n1\\n" >expect &&
100 test_cmp expect actual
103 test_expect_success 'show --no-textconv blob produces binary' '
104 git show --no-textconv HEAD:file >actual &&
105 printf "\\0\\n\\01\\n" >expect &&
106 test_cmp expect actual
109 test_expect_success 'grep-diff (-G) operates on textconv data (add)' '
110 echo one >expect &&
111 git log --root --format=%s -G0 >actual &&
112 test_cmp expect actual
115 test_expect_success 'grep-diff (-G) operates on textconv data (modification)' '
116 echo two >expect &&
117 git log --root --format=%s -G1 >actual &&
118 test_cmp expect actual
121 test_expect_success 'pickaxe (-S) operates on textconv data (add)' '
122 echo one >expect &&
123 git log --root --format=%s -S0 >actual &&
124 test_cmp expect actual
127 test_expect_success 'pickaxe (-S) operates on textconv data (modification)' '
128 echo two >expect &&
129 git log --root --format=%s -S1 >actual &&
130 test_cmp expect actual
133 cat >expect.stat <<'EOF'
134 file | Bin 2 -> 4 bytes
135 1 file changed, 0 insertions(+), 0 deletions(-)
137 test_expect_success 'diffstat does not run textconv' '
138 echo file diff=fail >.gitattributes &&
139 git diff --stat HEAD^ HEAD >actual &&
140 test_cmp expect.stat actual &&
142 head -n1 <expect.stat >expect.line1 &&
143 head -n1 <actual >actual.line1 &&
144 test_cmp expect.line1 actual.line1
146 # restore working setup
147 echo file diff=foo >.gitattributes
149 symlink=$(git rev-parse --short $(printf frotz | git hash-object --stdin))
150 cat >expect.typechange <<EOF
151 --- a/file
152 +++ /dev/null
153 @@ -1,2 +0,0 @@
156 diff --git a/file b/file
157 new file mode 120000
158 index 0000000..$symlink
159 --- /dev/null
160 +++ b/file
161 @@ -0,0 +1 @@
162 +frotz
163 \ No newline at end of file
166 test_expect_success 'textconv does not act on symlinks' '
167 rm -f file &&
168 test_ln_s_add frotz file &&
169 git commit -m typechange &&
170 git show >diff &&
171 find_diff <diff >actual &&
172 test_cmp expect.typechange actual
175 test_done