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