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