git/t/t4030-diff-textconv.sh
Jeff King c7534ef4a1 userdiff: require explicitly allowing textconv
Diffs that have been produced with textconv almost certainly
cannot be applied, so we want to be careful not to generate
them in things like format-patch.

This introduces a new diff options, ALLOW_TEXTCONV, which
controls this behavior. It is off by default, but is
explicitly turned on for the "log" family of commands, as
well as the "diff" porcelain (but not diff-* plumbing).

Because both text conversion and external diffing are
controlled by these diff options, we can get rid of the
"plumbing versus porcelain" distinction when reading the
config. This was an attempt to control the same thing, but
suffered from being too coarse-grained.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-10-26 14:09:48 -07:00

119 lines
2.5 KiB
Bash
Executable file

#!/bin/sh
test_description='diff.*.textconv tests'
. ./test-lib.sh
find_diff() {
sed '1,/^index /d' | sed '/^-- $/,$d'
}
cat >expect.binary <<'EOF'
Binary files a/file and b/file differ
EOF
cat >expect.text <<'EOF'
--- a/file
+++ b/file
@@ -1 +1,2 @@
0
+1
EOF
cat >hexdump <<'EOF'
#!/bin/sh
perl -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' "$1"
EOF
chmod +x hexdump
test_expect_success 'setup binary file with history' '
printf "\\0\\n" >file &&
git add file &&
git commit -m one &&
printf "\\1\\n" >>file &&
git add file &&
git commit -m two
'
test_expect_success 'file is considered binary by porcelain' '
git diff HEAD^ HEAD >diff &&
find_diff <diff >actual &&
test_cmp expect.binary actual
'
test_expect_success 'file is considered binary by plumbing' '
git diff-tree -p HEAD^ HEAD >diff &&
find_diff <diff >actual &&
test_cmp expect.binary actual
'
test_expect_success 'setup textconv filters' '
echo file diff=foo >.gitattributes &&
git config diff.foo.textconv "$PWD"/hexdump &&
git config diff.fail.textconv false
'
test_expect_success 'diff produces text' '
git diff HEAD^ HEAD >diff &&
find_diff <diff >actual &&
test_cmp expect.text actual
'
test_expect_success 'diff-tree produces binary' '
git diff-tree -p HEAD^ HEAD >diff &&
find_diff <diff >actual &&
test_cmp expect.binary actual
'
test_expect_success 'log produces text' '
git log -1 -p >log &&
find_diff <log >actual &&
test_cmp expect.text actual
'
test_expect_success 'format-patch produces binary' '
git format-patch --no-binary --stdout HEAD^ >patch &&
find_diff <patch >actual &&
test_cmp expect.binary actual
'
cat >expect.stat <<'EOF'
file | Bin 2 -> 4 bytes
1 files changed, 0 insertions(+), 0 deletions(-)
EOF
test_expect_success 'diffstat does not run textconv' '
echo file diff=fail >.gitattributes &&
git diff --stat HEAD^ HEAD >actual &&
test_cmp expect.stat actual
'
# restore working setup
echo file diff=foo >.gitattributes
cat >expect.typechange <<'EOF'
--- a/file
+++ /dev/null
@@ -1,2 +0,0 @@
-0
-1
diff --git a/file b/file
new file mode 120000
index ad8b3d2..67be421
--- /dev/null
+++ b/file
@@ -0,0 +1 @@
+frotz
\ No newline at end of file
EOF
# make a symlink the hard way that works on symlink-challenged file systems
test_expect_failure 'textconv does not act on symlinks' '
echo -n frotz > file &&
git add file &&
git ls-files -s | sed -e s/100644/120000/ |
git update-index --index-info &&
git commit -m typechange &&
git show >diff &&
find_diff <diff >actual &&
test_cmp expect.typechange actual
'
test_done