git-fast-import.txt: improve documentation for quoted paths
[git/jrn.git] / t / t4030-diff-textconv.sh
blob461d27ac202cc51f1f09b7a18de8b747198700e4
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 printf "\\0\\n" >file &&
30 git add file &&
31 git commit -m one &&
32 printf "\\01\\n" >>file &&
33 git add file &&
34 git commit -m two
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
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
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
55 test_expect_success 'diff produces text' '
56 git diff HEAD^ HEAD >diff &&
57 find_diff <diff >actual &&
58 test_cmp expect.text actual
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
67 test_expect_success 'log produces text' '
68 git log -1 -p >log &&
69 find_diff <log >actual &&
70 test_cmp expect.text actual
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
79 test_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}
87 test_expect_success 'grep-diff (-G) operates on textconv data (add)' '
88 echo one >expect &&
89 git log --root --format=%s -G0 >actual &&
90 test_cmp expect actual
93 test_expect_success 'grep-diff (-G) operates on textconv data (modification)' '
94 echo two >expect &&
95 git log --root --format=%s -G1 >actual &&
96 test_cmp expect actual
99 cat >expect.stat <<'EOF'
100 file | Bin 2 -> 4 bytes
101 1 file changed, 0 insertions(+), 0 deletions(-)
103 test_expect_success 'diffstat does not run textconv' '
104 echo file diff=fail >.gitattributes &&
105 git diff --stat HEAD^ HEAD >actual &&
106 test_i18ncmp expect.stat actual &&
108 head -n1 <expect.stat >expect.line1 &&
109 head -n1 <actual >actual.line1 &&
110 test_cmp expect.line1 actual.line1
112 # restore working setup
113 echo file diff=foo >.gitattributes
115 cat >expect.typechange <<'EOF'
116 --- a/file
117 +++ /dev/null
118 @@ -1,2 +0,0 @@
121 diff --git a/file b/file
122 new file mode 120000
123 index 0000000..67be421
124 --- /dev/null
125 +++ b/file
126 @@ -0,0 +1 @@
127 +frotz
128 \ No newline at end of file
130 # make a symlink the hard way that works on symlink-challenged file systems
131 test_expect_success 'textconv does not act on symlinks' '
132 printf frotz > file &&
133 git add file &&
134 git ls-files -s | sed -e s/100644/120000/ |
135 git update-index --index-info &&
136 git commit -m typechange &&
137 git show >diff &&
138 find_diff <diff >actual &&
139 test_cmp expect.typechange actual
142 test_done