interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t4030-diff-textconv.sh

171 lines · 3984 bytes Raw Blame History
1#!/bin/sh
2
3test_description='diff.*.textconv tests'
4
5. ./test-lib.sh
6
7find_diff() {
8 sed '1,/^index /d' | sed '/^-- $/,$d'
9}
10
11cat >expect.binary <<'EOF'
12Binary files a/file and b/file differ
13EOF
14
15cat >expect.text <<'EOF'
16--- a/file
17+++ b/file
18@@ -1 +1,2 @@
19 0
20+1
21EOF
22
23test_expect_success 'setup binary file with history' '
24 write_script hexdump <<-\EOF &&
25 tr "\000\001" "01" <"$1"
26 EOF
27 test_commit --printf one file "\\0\\n" &&
28 test_commit --printf --append two file "\\01\\n"
29'
30
31test_expect_success 'file is considered binary by porcelain' '
32 git diff HEAD^ HEAD >diff &&
33 find_diff <diff >actual &&
34 test_cmp expect.binary actual
35'
36
37test_expect_success 'file is considered binary by plumbing' '
38 git diff-tree -p HEAD^ HEAD >diff &&
39 find_diff <diff >actual &&
40 test_cmp expect.binary actual
41'
42
43test_expect_success 'setup textconv filters' '
44 echo file diff=foo >.gitattributes &&
45 git config diff.foo.textconv "\"$(pwd)\""/hexdump &&
46 git config diff.fail.textconv false
47'
48
49test_expect_success 'diff produces text' '
50 git diff HEAD^ HEAD >diff &&
51 find_diff <diff >actual &&
52 test_cmp expect.text actual
53'
54
55test_expect_success 'show commit produces text' '
56 git show 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
67test_expect_success 'log produces text' '
68 git log -1 -p >log &&
69 find_diff <log >actual &&
70 test_cmp expect.text actual
71'
72
73test_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'
78
79test_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
87test_expect_success 'show blob produces binary' '
88 git show HEAD:file >actual &&
89 printf "\\0\\n\\01\\n" >expect &&
90 test_cmp expect actual
91'
92
93test_expect_success 'show --textconv blob produces text' '
94 git show --textconv HEAD:file >actual &&
95 printf "0\\n1\\n" >expect &&
96 test_cmp expect actual
97'
98
99test_expect_success 'show --no-textconv blob produces binary' '
100 git show --no-textconv HEAD:file >actual &&
101 printf "\\0\\n\\01\\n" >expect &&
102 test_cmp expect actual
103'
104
105test_expect_success 'grep-diff (-G) operates on textconv data (add)' '
106 echo one >expect &&
107 git log --root --format=%s -G0 >actual &&
108 test_cmp expect actual
109'
110
111test_expect_success 'grep-diff (-G) operates on textconv data (modification)' '
112 echo two >expect &&
113 git log --root --format=%s -G1 >actual &&
114 test_cmp expect actual
115'
116
117test_expect_success 'pickaxe (-S) operates on textconv data (add)' '
118 echo one >expect &&
119 git log --root --format=%s -S0 >actual &&
120 test_cmp expect actual
121'
122
123test_expect_success 'pickaxe (-S) operates on textconv data (modification)' '
124 echo two >expect &&
125 git log --root --format=%s -S1 >actual &&
126 test_cmp expect actual
127'
128
129cat >expect.stat <<'EOF'
130 file | Bin 2 -> 4 bytes
131 1 file changed, 0 insertions(+), 0 deletions(-)
132EOF
133test_expect_success 'diffstat does not run textconv' '
134 echo file diff=fail >.gitattributes &&
135 git diff --stat HEAD^ HEAD >actual &&
136 test_cmp expect.stat actual &&
137
138 head -n1 <expect.stat >expect.line1 &&
139 head -n1 <actual >actual.line1 &&
140 test_cmp expect.line1 actual.line1
141'
142# restore working setup
143echo file diff=foo >.gitattributes
144
145symlink=$(git rev-parse --short $(printf frotz | git hash-object --stdin))
146cat >expect.typechange <<EOF
147--- a/file
148+++ /dev/null
149@@ -1,2 +0,0 @@
150-0
151-1
152diff --git a/file b/file
153new file mode 120000
154index 0000000..$symlink
155--- /dev/null
156+++ b/file
157@@ -0,0 +1 @@
158+frotz
159\ No newline at end of file
160EOF
161
162test_expect_success 'textconv does not act on symlinks' '
163 rm -f file &&
164 test_ln_s_add frotz file &&
165 git commit -m typechange &&
166 git show >diff &&
167 find_diff <diff >actual &&
168 test_cmp expect.typechange actual
169'
170
171test_done