Commit | Line | Data |
---|---|---|
d9bae1a1 JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='test textconv caching' | |
4 | . ./test-lib.sh | |
5 | ||
6 | cat >helper <<'EOF' | |
7 | #!/bin/sh | |
8 | sed 's/^/converted: /' "$@" >helper.out | |
9 | cat helper.out | |
10 | EOF | |
11 | chmod +x helper | |
12 | ||
13 | test_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 | ||
26 | cat >expect <<EOF | |
27 | diff --git a/bar.bin b/bar.bin | |
28 | index fcf9166..28283d5 100644 | |
29 | --- a/bar.bin | |
30 | +++ b/bar.bin | |
31 | @@ -1 +1 @@ | |
32 | -converted: bar content 1 | |
33 | +converted: bar content 2 | |
34 | diff --git a/foo.bin b/foo.bin | |
35 | index d5b9fe3..1345db2 100644 | |
36 | --- a/foo.bin | |
37 | +++ b/foo.bin | |
38 | @@ -1 +1 @@ | |
39 | -converted: foo content 1 | |
40 | +converted: foo content 2 | |
41 | EOF | |
42 | ||
43 | test_expect_success 'first textconv works' ' | |
44 | git diff HEAD^ HEAD >actual && | |
45 | test_cmp expect actual | |
46 | ' | |
47 | ||
48 | test_expect_success 'cached textconv produces same output' ' | |
49 | git diff HEAD^ HEAD >actual && | |
50 | test_cmp expect actual | |
51 | ' | |
52 | ||
53 | test_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 | ||
60 | cat >expect <<EOF | |
61 | diff --git a/bar.bin b/bar.bin | |
62 | index 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 | |
69 | diff --git a/foo.bin b/foo.bin | |
70 | index 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 | |
77 | EOF | |
78 | test_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 | ||
85 | cat >expect <<EOF | |
86 | diff --git a/bar.bin b/bar.bin | |
87 | index 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 | |
94 | diff --git a/foo.bin b/foo.bin | |
95 | index d5b9fe3..1345db2 100644 | |
96 | --- a/foo.bin | |
97 | +++ b/foo.bin | |
98 | @@ -1 +1 @@ | |
99 | -converted: foo content 1 | |
100 | +converted: foo content 2 | |
101 | EOF | |
102 | test_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 | ||
be5c9fb9 JK |
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. | |
113 | test_expect_success 'log notes cache and still use cache for -p' ' | |
114 | git log --no-walk -p refs/notes/textconv/magic HEAD | |
115 | ' | |
116 | ||
d9bae1a1 | 117 | test_done |