3 test_description
='test textconv caching'
5 TEST_PASSES_SANITIZE_LEAK
=true
10 sed 's/^/converted: /' "$@" >helper.out
15 test_expect_success
'setup' '
16 echo foo content 1 >foo.bin &&
17 echo bar content 1 >bar.bin &&
20 foo1=$(git rev-parse --short HEAD:foo.bin) &&
21 bar1=$(git rev-parse --short HEAD:bar.bin) &&
22 echo foo content 2 >foo.bin &&
23 echo bar content 2 >bar.bin &&
24 git commit -a -m two &&
25 foo2=$(git rev-parse --short HEAD:foo.bin) &&
26 bar2=$(git rev-parse --short HEAD:bar.bin) &&
27 echo "*.bin diff=magic" >.gitattributes &&
28 git config diff.magic.textconv ./helper &&
29 git config diff.magic.cachetextconv true
33 diff --git a/bar.bin b/bar.bin
34 index $bar1..$bar2 100644
38 -converted: bar content 1
39 +converted: bar content 2
40 diff --git a/foo.bin b/foo.bin
41 index $foo1..$foo2 100644
45 -converted: foo content 1
46 +converted: foo content 2
49 test_expect_success
'first textconv works' '
50 git diff HEAD^ HEAD >actual &&
51 test_cmp expect actual
54 test_expect_success
'cached textconv produces same output' '
55 git diff HEAD^ HEAD >actual &&
56 test_cmp expect actual
59 test_expect_success
'cached textconv does not run helper' '
61 git diff HEAD^ HEAD >actual &&
62 test_cmp expect actual &&
67 diff --git a/bar.bin b/bar.bin
68 index $bar1..$bar2 100644
73 -converted: bar content 1
74 +converted: bar content 2
75 diff --git a/foo.bin b/foo.bin
76 index $foo1..$foo2 100644
81 -converted: foo content 1
82 +converted: foo content 2
84 test_expect_success
'changing textconv invalidates cache' '
86 git config diff.magic.textconv "./helper other" &&
87 git diff HEAD^ HEAD >actual &&
88 test_cmp expect actual
92 diff --git a/bar.bin b/bar.bin
93 index $bar1..$bar2 100644
98 -converted: bar content 1
99 +converted: bar content 2
100 diff --git a/foo.bin b/foo.bin
101 index $foo1..$foo2 100644
105 -converted: foo content 1
106 +converted: foo content 2
108 test_expect_success
'switching diff driver produces correct results' '
109 git config diff.moremagic.textconv ./helper &&
110 echo foo.bin diff=moremagic >>.gitattributes &&
111 git diff HEAD^ HEAD >actual &&
112 test_cmp expect actual
115 # The point here is to test that we can log the notes cache and still use it to
116 # produce a diff later (older versions of git would segfault on this). It's
117 # much more likely to come up in the real world with "log --all -p", but using
118 # --no-walk lets us reliably reproduce the order of traversal.
119 test_expect_success
'log notes cache and still use cache for -p' '
120 git log --no-walk -p refs/notes/textconv/magic HEAD
123 test_expect_success
'caching is silently ignored outside repo' '
125 echo one >non-repo/one &&
126 echo two >non-repo/two &&
127 echo "* diff=test" >attr &&
129 nongit git -c core.attributesFile="$PWD/attr" \
130 -c diff.test.textconv="tr a-z A-Z <" \
131 -c diff.test.cachetextconv=true \
132 diff --no-index one two >actual &&
133 cat >expect <<-\EOF &&
134 diff --git a/one b/two
135 index 5626abf..f719efd 100644
142 test_cmp expect actual