Jeff King | 0c01857 | 2008-12-09 03:12:28 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='rewrite diff on binary file' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | # We must be large enough to meet the MINIMUM_BREAK_SIZE |
| 8 | # requirement. |
| 9 | make_file() { |
Jeff King | 3aa1f7c | 2008-12-09 03:13:21 -0500 | [diff] [blame] | 10 | # common first line to help identify rewrite versus regular diff |
| 11 | printf "=\n" >file |
Jeff King | 0c01857 | 2008-12-09 03:12:28 -0500 | [diff] [blame] | 12 | for i in 1 2 3 4 5 6 7 8 9 10 |
| 13 | do |
| 14 | for j in 1 2 3 4 5 6 7 8 9 |
| 15 | do |
| 16 | for k in 1 2 3 4 5 |
| 17 | do |
| 18 | printf "$1\n" |
| 19 | done |
| 20 | done |
Jeff King | 3aa1f7c | 2008-12-09 03:13:21 -0500 | [diff] [blame] | 21 | done >>file |
Jeff King | 0c01857 | 2008-12-09 03:12:28 -0500 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | test_expect_success 'create binary file with changes' ' |
| 25 | make_file "\\0" && |
| 26 | git add file && |
| 27 | make_file "\\01" |
| 28 | ' |
| 29 | |
| 30 | test_expect_success 'vanilla diff is binary' ' |
| 31 | git diff >diff && |
| 32 | grep "Binary files a/file and b/file differ" diff |
| 33 | ' |
| 34 | |
| 35 | test_expect_success 'rewrite diff is binary' ' |
| 36 | git diff -B >diff && |
| 37 | grep "dissimilarity index" diff && |
| 38 | grep "Binary files a/file and b/file differ" diff |
| 39 | ' |
| 40 | |
| 41 | test_expect_success 'rewrite diff can show binary patch' ' |
| 42 | git diff -B --binary >diff && |
| 43 | grep "dissimilarity index" diff && |
| 44 | grep "GIT binary patch" diff |
| 45 | ' |
| 46 | |
Jonathan Nieder | 6dd8883 | 2012-03-13 00:05:54 -0500 | [diff] [blame] | 47 | test_expect_success 'rewrite diff --numstat shows binary changes' ' |
| 48 | git diff -B --numstat --summary >diff && |
| 49 | grep -e "- - " diff && |
| 50 | grep " rewrite file" diff |
| 51 | ' |
| 52 | |
| 53 | test_expect_success 'diff --stat counts binary rewrite as 0 lines' ' |
Jeff King | ded0abc | 2011-02-19 03:04:56 -0500 | [diff] [blame] | 54 | git diff -B --stat --summary >diff && |
| 55 | grep "Bin" diff && |
Jonathan Nieder | 6dd8883 | 2012-03-13 00:05:54 -0500 | [diff] [blame] | 56 | test_i18ngrep "0 insertions.*0 deletions" diff && |
Jeff King | ded0abc | 2011-02-19 03:04:56 -0500 | [diff] [blame] | 57 | grep " rewrite file" diff |
| 58 | ' |
| 59 | |
Jeff King | 3aa1f7c | 2008-12-09 03:13:21 -0500 | [diff] [blame] | 60 | { |
| 61 | echo "#!$SHELL_PATH" |
Junio C Hamano | de749a9 | 2008-12-10 11:39:07 -0800 | [diff] [blame] | 62 | cat <<'EOF' |
Junio C Hamano | 7096b64 | 2012-06-12 09:49:59 -0700 | [diff] [blame] | 63 | "$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1" |
Jeff King | 3aa1f7c | 2008-12-09 03:13:21 -0500 | [diff] [blame] | 64 | EOF |
| 65 | } >dump |
| 66 | chmod +x dump |
| 67 | |
| 68 | test_expect_success 'setup textconv' ' |
| 69 | echo file diff=foo >.gitattributes && |
Johannes Sixt | 6396258 | 2010-01-01 23:15:18 +0100 | [diff] [blame] | 70 | git config diff.foo.textconv "\"$(pwd)\""/dump |
Jeff King | 3aa1f7c | 2008-12-09 03:13:21 -0500 | [diff] [blame] | 71 | ' |
| 72 | |
| 73 | test_expect_success 'rewrite diff respects textconv' ' |
| 74 | git diff -B >diff && |
| 75 | grep "dissimilarity index" diff && |
| 76 | grep "^-61" diff && |
| 77 | grep "^-0" diff |
| 78 | ' |
| 79 | |
Jeff King | 0c01857 | 2008-12-09 03:12:28 -0500 | [diff] [blame] | 80 | test_done |