Jeff King | df5e91f | 2008-10-26 00:42:25 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='diff.*.textconv tests' |
| 4 | . ./test-lib.sh |
| 5 | |
| 6 | find_diff() { |
| 7 | sed '1,/^index /d' | sed '/^-- $/,$d' |
| 8 | } |
| 9 | |
| 10 | cat >expect.binary <<'EOF' |
| 11 | Binary files a/file and b/file differ |
| 12 | EOF |
| 13 | |
| 14 | cat >expect.text <<'EOF' |
| 15 | --- a/file |
| 16 | +++ b/file |
| 17 | @@ -1 +1,2 @@ |
| 18 | 0 |
| 19 | +1 |
| 20 | EOF |
| 21 | |
| 22 | cat >hexdump <<'EOF' |
| 23 | #!/bin/sh |
Junio C Hamano | 7096b64 | 2012-06-12 09:49:59 -0700 | [diff] [blame] | 24 | "$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1" |
Jeff King | df5e91f | 2008-10-26 00:42:25 -0400 | [diff] [blame] | 25 | EOF |
| 26 | chmod +x hexdump |
| 27 | |
| 28 | test_expect_success 'setup binary file with history' ' |
| 29 | printf "\\0\\n" >file && |
| 30 | git add file && |
| 31 | git commit -m one && |
Johannes Sixt | deb1387 | 2008-12-02 09:31:01 +0100 | [diff] [blame] | 32 | printf "\\01\\n" >>file && |
Jeff King | df5e91f | 2008-10-26 00:42:25 -0400 | [diff] [blame] | 33 | git add file && |
| 34 | git commit -m two |
| 35 | ' |
| 36 | |
| 37 | test_expect_success 'file is considered binary by porcelain' ' |
| 38 | git diff HEAD^ HEAD >diff && |
| 39 | find_diff <diff >actual && |
| 40 | test_cmp expect.binary actual |
| 41 | ' |
| 42 | |
| 43 | test_expect_success 'file is considered binary by plumbing' ' |
| 44 | git diff-tree -p HEAD^ HEAD >diff && |
| 45 | find_diff <diff >actual && |
| 46 | test_cmp expect.binary actual |
| 47 | ' |
| 48 | |
| 49 | test_expect_success 'setup textconv filters' ' |
| 50 | echo file diff=foo >.gitattributes && |
Johannes Sixt | 6396258 | 2010-01-01 23:15:18 +0100 | [diff] [blame] | 51 | git config diff.foo.textconv "\"$(pwd)\""/hexdump && |
Jeff King | df5e91f | 2008-10-26 00:42:25 -0400 | [diff] [blame] | 52 | git config diff.fail.textconv false |
| 53 | ' |
| 54 | |
Jeff King | 04427ac | 2008-10-26 00:44:53 -0400 | [diff] [blame] | 55 | test_expect_success 'diff produces text' ' |
Jeff King | df5e91f | 2008-10-26 00:42:25 -0400 | [diff] [blame] | 56 | git diff HEAD^ HEAD >diff && |
| 57 | find_diff <diff >actual && |
| 58 | test_cmp expect.text actual |
| 59 | ' |
| 60 | |
Michael J Gruber | 4bd52d0 | 2013-05-10 17:10:10 +0200 | [diff] [blame] | 61 | test_expect_success 'show commit produces text' ' |
| 62 | git show HEAD >diff && |
| 63 | find_diff <diff >actual && |
| 64 | test_cmp expect.text actual |
| 65 | ' |
| 66 | |
Jeff King | df5e91f | 2008-10-26 00:42:25 -0400 | [diff] [blame] | 67 | test_expect_success 'diff-tree produces binary' ' |
| 68 | git diff-tree -p HEAD^ HEAD >diff && |
| 69 | find_diff <diff >actual && |
| 70 | test_cmp expect.binary actual |
| 71 | ' |
| 72 | |
Jeff King | 04427ac | 2008-10-26 00:44:53 -0400 | [diff] [blame] | 73 | test_expect_success 'log produces text' ' |
Jeff King | df5e91f | 2008-10-26 00:42:25 -0400 | [diff] [blame] | 74 | git log -1 -p >log && |
| 75 | find_diff <log >actual && |
| 76 | test_cmp expect.text actual |
| 77 | ' |
| 78 | |
Jeff King | c7534ef | 2008-10-26 00:45:55 -0400 | [diff] [blame] | 79 | test_expect_success 'format-patch produces binary' ' |
Jeff King | df5e91f | 2008-10-26 00:42:25 -0400 | [diff] [blame] | 80 | git format-patch --no-binary --stdout HEAD^ >patch && |
| 81 | find_diff <patch >actual && |
| 82 | test_cmp expect.binary actual |
| 83 | ' |
| 84 | |
Jeff King | a79b8b6 | 2008-10-26 00:50:02 -0400 | [diff] [blame] | 85 | test_expect_success 'status -v produces text' ' |
| 86 | git reset --soft HEAD^ && |
| 87 | git status -v >diff && |
| 88 | find_diff <diff >actual && |
| 89 | test_cmp expect.text actual && |
| 90 | git reset --soft HEAD@{1} |
| 91 | ' |
| 92 | |
Michael J Gruber | 4bd52d0 | 2013-05-10 17:10:10 +0200 | [diff] [blame] | 93 | test_expect_success 'show blob produces binary' ' |
| 94 | git show HEAD:file >actual && |
| 95 | printf "\\0\\n\\01\\n" >expect && |
| 96 | test_cmp expect actual |
| 97 | ' |
| 98 | |
Michael J Gruber | 083b993 | 2013-05-10 17:10:12 +0200 | [diff] [blame] | 99 | test_expect_success 'show --textconv blob produces text' ' |
Michael J Gruber | 4bd52d0 | 2013-05-10 17:10:10 +0200 | [diff] [blame] | 100 | git show --textconv HEAD:file >actual && |
| 101 | printf "0\\n1\\n" >expect && |
| 102 | test_cmp expect actual |
| 103 | ' |
| 104 | |
Michael J Gruber | 083b993 | 2013-05-10 17:10:12 +0200 | [diff] [blame] | 105 | test_expect_success 'show --no-textconv blob produces binary' ' |
| 106 | git show --no-textconv HEAD:file >actual && |
Michael J Gruber | 4bd52d0 | 2013-05-10 17:10:10 +0200 | [diff] [blame] | 107 | printf "\\0\\n\\01\\n" >expect && |
| 108 | test_cmp expect actual |
| 109 | ' |
| 110 | |
Jeff King | b1c2f57 | 2012-10-28 07:40:00 -0400 | [diff] [blame] | 111 | test_expect_success 'grep-diff (-G) operates on textconv data (add)' ' |
| 112 | echo one >expect && |
| 113 | git log --root --format=%s -G0 >actual && |
| 114 | test_cmp expect actual |
| 115 | ' |
| 116 | |
| 117 | test_expect_success 'grep-diff (-G) operates on textconv data (modification)' ' |
| 118 | echo two >expect && |
| 119 | git log --root --format=%s -G1 >actual && |
| 120 | test_cmp expect actual |
| 121 | ' |
| 122 | |
Jeff King | ef90ab6 | 2012-10-28 08:27:12 -0400 | [diff] [blame] | 123 | test_expect_success 'pickaxe (-S) operates on textconv data (add)' ' |
| 124 | echo one >expect && |
| 125 | git log --root --format=%s -S0 >actual && |
| 126 | test_cmp expect actual |
| 127 | ' |
| 128 | |
| 129 | test_expect_success 'pickaxe (-S) operates on textconv data (modification)' ' |
| 130 | echo two >expect && |
| 131 | git log --root --format=%s -S1 >actual && |
| 132 | test_cmp expect actual |
| 133 | ' |
| 134 | |
Jeff King | df5e91f | 2008-10-26 00:42:25 -0400 | [diff] [blame] | 135 | cat >expect.stat <<'EOF' |
Zbigniew Jędrzejewski-Szmek | dc801e7 | 2012-04-30 22:38:58 +0200 | [diff] [blame] | 136 | file | Bin 2 -> 4 bytes |
Nguyễn Thái Ngọc Duy | 7f81463 | 2012-02-01 19:55:07 +0700 | [diff] [blame] | 137 | 1 file changed, 0 insertions(+), 0 deletions(-) |
Jeff King | df5e91f | 2008-10-26 00:42:25 -0400 | [diff] [blame] | 138 | EOF |
Jeff King | 04427ac | 2008-10-26 00:44:53 -0400 | [diff] [blame] | 139 | test_expect_success 'diffstat does not run textconv' ' |
Jeff King | df5e91f | 2008-10-26 00:42:25 -0400 | [diff] [blame] | 140 | echo file diff=fail >.gitattributes && |
| 141 | git diff --stat HEAD^ HEAD >actual && |
Jonathan Nieder | 6dd8883 | 2012-03-13 00:05:54 -0500 | [diff] [blame] | 142 | test_i18ncmp expect.stat actual && |
| 143 | |
| 144 | head -n1 <expect.stat >expect.line1 && |
| 145 | head -n1 <actual >actual.line1 && |
| 146 | test_cmp expect.line1 actual.line1 |
Jeff King | df5e91f | 2008-10-26 00:42:25 -0400 | [diff] [blame] | 147 | ' |
| 148 | # restore working setup |
| 149 | echo file diff=foo >.gitattributes |
| 150 | |
| 151 | cat >expect.typechange <<'EOF' |
| 152 | --- a/file |
| 153 | +++ /dev/null |
| 154 | @@ -1,2 +0,0 @@ |
| 155 | -0 |
| 156 | -1 |
| 157 | diff --git a/file b/file |
| 158 | new file mode 120000 |
Junio C Hamano | 90b23e5 | 2009-01-27 01:08:02 -0800 | [diff] [blame] | 159 | index 0000000..67be421 |
Jeff King | df5e91f | 2008-10-26 00:42:25 -0400 | [diff] [blame] | 160 | --- /dev/null |
| 161 | +++ b/file |
| 162 | @@ -0,0 +1 @@ |
| 163 | +frotz |
| 164 | \ No newline at end of file |
| 165 | EOF |
Johannes Sixt | 889c6f0 | 2013-06-07 22:53:28 +0200 | [diff] [blame] | 166 | |
Jeff King | 2675773 | 2008-10-26 00:46:21 -0400 | [diff] [blame] | 167 | test_expect_success 'textconv does not act on symlinks' ' |
Johannes Sixt | 889c6f0 | 2013-06-07 22:53:28 +0200 | [diff] [blame] | 168 | rm -f file && |
| 169 | test_ln_s_add frotz file && |
Jeff King | df5e91f | 2008-10-26 00:42:25 -0400 | [diff] [blame] | 170 | git commit -m typechange && |
| 171 | git show >diff && |
| 172 | find_diff <diff >actual && |
| 173 | test_cmp expect.typechange actual |
| 174 | ' |
| 175 | |
| 176 | test_done |