t / t4030-diff-textconv.shon commit test-lib: factor out $GIT_UNZIP setup (f838ce5)
   1#!/bin/sh
   2
   3test_description='diff.*.textconv tests'
   4. ./test-lib.sh
   5
   6find_diff() {
   7        sed '1,/^index /d' | sed '/^-- $/,$d'
   8}
   9
  10cat >expect.binary <<'EOF'
  11Binary files a/file and b/file differ
  12EOF
  13
  14cat >expect.text <<'EOF'
  15--- a/file
  16+++ b/file
  17@@ -1 +1,2 @@
  18 0
  19+1
  20EOF
  21
  22cat >hexdump <<'EOF'
  23#!/bin/sh
  24"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
  25EOF
  26chmod +x hexdump
  27
  28test_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
  35'
  36
  37test_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
  41'
  42
  43test_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
  47'
  48
  49test_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
  53'
  54
  55test_expect_success 'diff produces text' '
  56        git diff HEAD^ 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 '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
  91'
  92
  93test_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
  97'
  98
  99test_expect_success 'pickaxe (-S) operates on textconv data (add)' '
 100        echo one >expect &&
 101        git log --root --format=%s -S0 >actual &&
 102        test_cmp expect actual
 103'
 104
 105test_expect_success 'pickaxe (-S) operates on textconv data (modification)' '
 106        echo two >expect &&
 107        git log --root --format=%s -S1 >actual &&
 108        test_cmp expect actual
 109'
 110
 111cat >expect.stat <<'EOF'
 112 file | Bin 2 -> 4 bytes
 113 1 file changed, 0 insertions(+), 0 deletions(-)
 114EOF
 115test_expect_success 'diffstat does not run textconv' '
 116        echo file diff=fail >.gitattributes &&
 117        git diff --stat HEAD^ HEAD >actual &&
 118        test_i18ncmp expect.stat actual &&
 119
 120        head -n1 <expect.stat >expect.line1 &&
 121        head -n1 <actual >actual.line1 &&
 122        test_cmp expect.line1 actual.line1
 123'
 124# restore working setup
 125echo file diff=foo >.gitattributes
 126
 127cat >expect.typechange <<'EOF'
 128--- a/file
 129+++ /dev/null
 130@@ -1,2 +0,0 @@
 131-0
 132-1
 133diff --git a/file b/file
 134new file mode 120000
 135index 0000000..67be421
 136--- /dev/null
 137+++ b/file
 138@@ -0,0 +1 @@
 139+frotz
 140\ No newline at end of file
 141EOF
 142# make a symlink the hard way that works on symlink-challenged file systems
 143test_expect_success 'textconv does not act on symlinks' '
 144        printf frotz > file &&
 145        git add file &&
 146        git ls-files -s | sed -e s/100644/120000/ |
 147                git update-index --index-info &&
 148        git commit -m typechange &&
 149        git show >diff &&
 150        find_diff <diff >actual &&
 151        test_cmp expect.typechange actual
 152'
 153
 154test_done