t / t4042-diff-textconv-caching.shon commit Merge branch 'es/local-atomic-push-failure-with-http' into maint (1a27b78)
   1#!/bin/sh
   2
   3test_description='test textconv caching'
   4. ./test-lib.sh
   5
   6cat >helper <<'EOF'
   7#!/bin/sh
   8sed 's/^/converted: /' "$@" >helper.out
   9cat helper.out
  10EOF
  11chmod +x helper
  12
  13test_expect_success 'setup' '
  14        echo foo content 1 >foo.bin &&
  15        echo bar content 1 >bar.bin &&
  16        git add . &&
  17        git commit -m one &&
  18        foo1=$(git rev-parse --short HEAD:foo.bin) &&
  19        bar1=$(git rev-parse --short HEAD:bar.bin) &&
  20        echo foo content 2 >foo.bin &&
  21        echo bar content 2 >bar.bin &&
  22        git commit -a -m two &&
  23        foo2=$(git rev-parse --short HEAD:foo.bin) &&
  24        bar2=$(git rev-parse --short HEAD:bar.bin) &&
  25        echo "*.bin diff=magic" >.gitattributes &&
  26        git config diff.magic.textconv ./helper &&
  27        git config diff.magic.cachetextconv true
  28'
  29
  30cat >expect <<EOF
  31diff --git a/bar.bin b/bar.bin
  32index $bar1..$bar2 100644
  33--- a/bar.bin
  34+++ b/bar.bin
  35@@ -1 +1 @@
  36-converted: bar content 1
  37+converted: bar content 2
  38diff --git a/foo.bin b/foo.bin
  39index $foo1..$foo2 100644
  40--- a/foo.bin
  41+++ b/foo.bin
  42@@ -1 +1 @@
  43-converted: foo content 1
  44+converted: foo content 2
  45EOF
  46
  47test_expect_success 'first textconv works' '
  48        git diff HEAD^ HEAD >actual &&
  49        test_cmp expect actual
  50'
  51
  52test_expect_success 'cached textconv produces same output' '
  53        git diff HEAD^ HEAD >actual &&
  54        test_cmp expect actual
  55'
  56
  57test_expect_success 'cached textconv does not run helper' '
  58        rm -f helper.out &&
  59        git diff HEAD^ HEAD >actual &&
  60        test_cmp expect actual &&
  61        ! test -r helper.out
  62'
  63
  64cat >expect <<EOF
  65diff --git a/bar.bin b/bar.bin
  66index $bar1..$bar2 100644
  67--- a/bar.bin
  68+++ b/bar.bin
  69@@ -1,2 +1,2 @@
  70 converted: other
  71-converted: bar content 1
  72+converted: bar content 2
  73diff --git a/foo.bin b/foo.bin
  74index $foo1..$foo2 100644
  75--- a/foo.bin
  76+++ b/foo.bin
  77@@ -1,2 +1,2 @@
  78 converted: other
  79-converted: foo content 1
  80+converted: foo content 2
  81EOF
  82test_expect_success 'changing textconv invalidates cache' '
  83        echo other >other &&
  84        git config diff.magic.textconv "./helper other" &&
  85        git diff HEAD^ HEAD >actual &&
  86        test_cmp expect actual
  87'
  88
  89cat >expect <<EOF
  90diff --git a/bar.bin b/bar.bin
  91index $bar1..$bar2 100644
  92--- a/bar.bin
  93+++ b/bar.bin
  94@@ -1,2 +1,2 @@
  95 converted: other
  96-converted: bar content 1
  97+converted: bar content 2
  98diff --git a/foo.bin b/foo.bin
  99index $foo1..$foo2 100644
 100--- a/foo.bin
 101+++ b/foo.bin
 102@@ -1 +1 @@
 103-converted: foo content 1
 104+converted: foo content 2
 105EOF
 106test_expect_success 'switching diff driver produces correct results' '
 107        git config diff.moremagic.textconv ./helper &&
 108        echo foo.bin diff=moremagic >>.gitattributes &&
 109        git diff HEAD^ HEAD >actual &&
 110        test_cmp expect actual
 111'
 112
 113# The point here is to test that we can log the notes cache and still use it to
 114# produce a diff later (older versions of git would segfault on this). It's
 115# much more likely to come up in the real world with "log --all -p", but using
 116# --no-walk lets us reliably reproduce the order of traversal.
 117test_expect_success 'log notes cache and still use cache for -p' '
 118        git log --no-walk -p refs/notes/textconv/magic HEAD
 119'
 120
 121test_done