revision: fix leaking parents when simplifying commits
[git/gitster.git] / t / t4042-diff-textconv-caching.sh
bloba179205394d8a33b4ab7be0d7e700739448a5597
1 #!/bin/sh
3 test_description='test textconv caching'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 cat >helper <<'EOF'
9 #!/bin/sh
10 sed 's/^/converted: /' "$@" >helper.out
11 cat helper.out
12 EOF
13 chmod +x helper
15 test_expect_success 'setup' '
16 echo foo content 1 >foo.bin &&
17 echo bar content 1 >bar.bin &&
18 git add . &&
19 git commit -m one &&
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
32 cat >expect <<EOF
33 diff --git a/bar.bin b/bar.bin
34 index $bar1..$bar2 100644
35 --- a/bar.bin
36 +++ b/bar.bin
37 @@ -1 +1 @@
38 -converted: bar content 1
39 +converted: bar content 2
40 diff --git a/foo.bin b/foo.bin
41 index $foo1..$foo2 100644
42 --- a/foo.bin
43 +++ b/foo.bin
44 @@ -1 +1 @@
45 -converted: foo content 1
46 +converted: foo content 2
47 EOF
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' '
60 rm -f helper.out &&
61 git diff HEAD^ HEAD >actual &&
62 test_cmp expect actual &&
63 ! test -r helper.out
66 cat >expect <<EOF
67 diff --git a/bar.bin b/bar.bin
68 index $bar1..$bar2 100644
69 --- a/bar.bin
70 +++ b/bar.bin
71 @@ -1,2 +1,2 @@
72 converted: other
73 -converted: bar content 1
74 +converted: bar content 2
75 diff --git a/foo.bin b/foo.bin
76 index $foo1..$foo2 100644
77 --- a/foo.bin
78 +++ b/foo.bin
79 @@ -1,2 +1,2 @@
80 converted: other
81 -converted: foo content 1
82 +converted: foo content 2
83 EOF
84 test_expect_success 'changing textconv invalidates cache' '
85 echo other >other &&
86 git config diff.magic.textconv "./helper other" &&
87 git diff HEAD^ HEAD >actual &&
88 test_cmp expect actual
91 cat >expect <<EOF
92 diff --git a/bar.bin b/bar.bin
93 index $bar1..$bar2 100644
94 --- a/bar.bin
95 +++ b/bar.bin
96 @@ -1,2 +1,2 @@
97 converted: other
98 -converted: bar content 1
99 +converted: bar content 2
100 diff --git a/foo.bin b/foo.bin
101 index $foo1..$foo2 100644
102 --- a/foo.bin
103 +++ b/foo.bin
104 @@ -1 +1 @@
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' '
124 mkdir -p non-repo &&
125 echo one >non-repo/one &&
126 echo two >non-repo/two &&
127 echo "* diff=test" >attr &&
128 test_expect_code 1 \
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
136 --- a/one
137 +++ b/two
138 @@ -1 +1 @@
139 -ONE
140 +TWO
142 test_cmp expect actual
145 test_done