| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test textconv caching' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | cat >helper <<'EOF' |
| 8 | #!/bin/sh |
| 9 | sed 's/^/converted: /' "$@" >helper.out |
| 10 | cat helper.out |
| 11 | EOF |
| 12 | chmod +x helper |
| 13 | |
| 14 | test_expect_success 'setup' ' |
| 15 | echo foo content 1 >foo.bin && |
| 16 | echo bar content 1 >bar.bin && |
| 17 | git add . && |
| 18 | git commit -m one && |
| 19 | foo1=$(git rev-parse --short HEAD:foo.bin) && |
| 20 | bar1=$(git rev-parse --short HEAD:bar.bin) && |
| 21 | echo foo content 2 >foo.bin && |
| 22 | echo bar content 2 >bar.bin && |
| 23 | git commit -a -m two && |
| 24 | foo2=$(git rev-parse --short HEAD:foo.bin) && |
| 25 | bar2=$(git rev-parse --short HEAD:bar.bin) && |
| 26 | echo "*.bin diff=magic" >.gitattributes && |
| 27 | git config diff.magic.textconv ./helper && |
| 28 | git config diff.magic.cachetextconv true |
| 29 | ' |
| 30 | |
| 31 | cat >expect <<EOF |
| 32 | diff --git a/bar.bin b/bar.bin |
| 33 | index $bar1..$bar2 100644 |
| 34 | --- a/bar.bin |
| 35 | +++ b/bar.bin |
| 36 | @@ -1 +1 @@ |
| 37 | -converted: bar content 1 |
| 38 | +converted: bar content 2 |
| 39 | diff --git a/foo.bin b/foo.bin |
| 40 | index $foo1..$foo2 100644 |
| 41 | --- a/foo.bin |
| 42 | +++ b/foo.bin |
| 43 | @@ -1 +1 @@ |
| 44 | -converted: foo content 1 |
| 45 | +converted: foo content 2 |
| 46 | EOF |
| 47 | |
| 48 | test_expect_success 'first textconv works' ' |
| 49 | git diff HEAD^ HEAD >actual && |
| 50 | test_cmp expect actual |
| 51 | ' |
| 52 | |
| 53 | test_expect_success 'cached textconv produces same output' ' |
| 54 | git diff HEAD^ HEAD >actual && |
| 55 | test_cmp expect actual |
| 56 | ' |
| 57 | |
| 58 | test_expect_success 'cached textconv does not run helper' ' |
| 59 | rm -f helper.out && |
| 60 | git diff HEAD^ HEAD >actual && |
| 61 | test_cmp expect actual && |
| 62 | ! test -r helper.out |
| 63 | ' |
| 64 | |
| 65 | cat >expect <<EOF |
| 66 | diff --git a/bar.bin b/bar.bin |
| 67 | index $bar1..$bar2 100644 |
| 68 | --- a/bar.bin |
| 69 | +++ b/bar.bin |
| 70 | @@ -1,2 +1,2 @@ |
| 71 | converted: other |
| 72 | -converted: bar content 1 |
| 73 | +converted: bar content 2 |
| 74 | diff --git a/foo.bin b/foo.bin |
| 75 | index $foo1..$foo2 100644 |
| 76 | --- a/foo.bin |
| 77 | +++ b/foo.bin |
| 78 | @@ -1,2 +1,2 @@ |
| 79 | converted: other |
| 80 | -converted: foo content 1 |
| 81 | +converted: foo content 2 |
| 82 | EOF |
| 83 | test_expect_success 'changing textconv invalidates cache' ' |
| 84 | echo other >other && |
| 85 | git config diff.magic.textconv "./helper other" && |
| 86 | git diff HEAD^ HEAD >actual && |
| 87 | test_cmp expect actual |
| 88 | ' |
| 89 | |
| 90 | cat >expect <<EOF |
| 91 | diff --git a/bar.bin b/bar.bin |
| 92 | index $bar1..$bar2 100644 |
| 93 | --- a/bar.bin |
| 94 | +++ b/bar.bin |
| 95 | @@ -1,2 +1,2 @@ |
| 96 | converted: other |
| 97 | -converted: bar content 1 |
| 98 | +converted: bar content 2 |
| 99 | diff --git a/foo.bin b/foo.bin |
| 100 | index $foo1..$foo2 100644 |
| 101 | --- a/foo.bin |
| 102 | +++ b/foo.bin |
| 103 | @@ -1 +1 @@ |
| 104 | -converted: foo content 1 |
| 105 | +converted: foo content 2 |
| 106 | EOF |
| 107 | test_expect_success 'switching diff driver produces correct results' ' |
| 108 | git config diff.moremagic.textconv ./helper && |
| 109 | echo foo.bin diff=moremagic >>.gitattributes && |
| 110 | git diff HEAD^ HEAD >actual && |
| 111 | test_cmp expect actual |
| 112 | ' |
| 113 | |
| 114 | # The point here is to test that we can log the notes cache and still use it to |
| 115 | # produce a diff later (older versions of git would segfault on this). It's |
| 116 | # much more likely to come up in the real world with "log --all -p", but using |
| 117 | # --no-walk lets us reliably reproduce the order of traversal. |
| 118 | test_expect_success 'log notes cache and still use cache for -p' ' |
| 119 | git log --no-walk -p refs/notes/textconv/magic HEAD |
| 120 | ' |
| 121 | |
| 122 | test_expect_success 'caching is silently ignored outside repo' ' |
| 123 | test_oid_cache <<-\EOM && |
| 124 | oid1 sha1:5626abf |
| 125 | oid1 sha256:a4ed1f3 |
| 126 | oid2 sha1:f719efd |
| 127 | oid2 sha256:aa9e7dc |
| 128 | EOM |
| 129 | oid1=$(test_oid --hash=builtin oid1) && |
| 130 | oid2=$(test_oid --hash=builtin oid2) && |
| 131 | mkdir -p non-repo && |
| 132 | echo one >non-repo/one && |
| 133 | echo two >non-repo/two && |
| 134 | echo "* diff=test" >attr && |
| 135 | test_expect_code 1 \ |
| 136 | nongit git -c core.attributesFile="$PWD/attr" \ |
| 137 | -c diff.test.textconv="tr a-z A-Z <" \ |
| 138 | -c diff.test.cachetextconv=true \ |
| 139 | diff --no-index one two >actual && |
| 140 | cat >expect <<-EOF && |
| 141 | diff --git a/one b/two |
| 142 | index $oid1..$oid2 100644 |
| 143 | --- a/one |
| 144 | +++ b/two |
| 145 | @@ -1 +1 @@ |
| 146 | -ONE |
| 147 | +TWO |
| 148 | EOF |
| 149 | test_cmp expect actual |
| 150 | ' |
| 151 | |
| 152 | test_done |