]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4030-diff-textconv.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t4030-diff-textconv.sh
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
24 "$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
25 EOF
26 chmod +x hexdump
27
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"
31 '
32
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
37 '
38
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
43 '
44
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
49 '
50
51 test_expect_success 'diff produces text' '
52 git diff HEAD^ HEAD >diff &&
53 find_diff <diff >actual &&
54 test_cmp expect.text actual
55 '
56
57 test_expect_success 'show commit produces text' '
58 git show HEAD >diff &&
59 find_diff <diff >actual &&
60 test_cmp expect.text actual
61 '
62
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
67 '
68
69 test_expect_success 'log produces text' '
70 git log -1 -p >log &&
71 find_diff <log >actual &&
72 test_cmp expect.text actual
73 '
74
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
79 '
80
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}
87 '
88
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
93 '
94
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
99 '
100
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
105 '
106
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
111 '
112
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
117 '
118
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
123 '
124
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
129 '
130
131 cat >expect.stat <<'EOF'
132 file | Bin 2 -> 4 bytes
133 1 file changed, 0 insertions(+), 0 deletions(-)
134 EOF
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 &&
139
140 head -n1 <expect.stat >expect.line1 &&
141 head -n1 <actual >actual.line1 &&
142 test_cmp expect.line1 actual.line1
143 '
144 # restore working setup
145 echo file diff=foo >.gitattributes
146
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 @@
152 -0
153 -1
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
162 EOF
163
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
171 '
172
173 test_done