blob: 7d7470f21b66a937e7414f4fe5419f8830fd8e86 [file] [log] [blame]
Jeff King0c018572008-12-09 03:12:28 -05001#!/bin/sh
2
3test_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.
9make_file() {
Jeff King3aa1f7c2008-12-09 03:13:21 -050010 # common first line to help identify rewrite versus regular diff
11 printf "=\n" >file
Jeff King0c018572008-12-09 03:12:28 -050012 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 King3aa1f7c2008-12-09 03:13:21 -050021 done >>file
Jeff King0c018572008-12-09 03:12:28 -050022}
23
24test_expect_success 'create binary file with changes' '
25 make_file "\\0" &&
26 git add file &&
27 make_file "\\01"
28'
29
30test_expect_success 'vanilla diff is binary' '
31 git diff >diff &&
32 grep "Binary files a/file and b/file differ" diff
33'
34
35test_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
41test_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
Jeff Kingded0abc2011-02-19 03:04:56 -050047test_expect_success 'rewrite diff --stat shows binary changes' '
48 git diff -B --stat --summary >diff &&
49 grep "Bin" diff &&
50 grep "0 insertions.*0 deletions" diff &&
51 grep " rewrite file" diff
52'
53
Jeff King3aa1f7c2008-12-09 03:13:21 -050054{
55 echo "#!$SHELL_PATH"
Junio C Hamanode749a92008-12-10 11:39:07 -080056 cat <<'EOF'
Jeff King3aa1f7c2008-12-09 03:13:21 -050057perl -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
58EOF
59} >dump
60chmod +x dump
61
62test_expect_success 'setup textconv' '
63 echo file diff=foo >.gitattributes &&
Johannes Sixt63962582010-01-01 23:15:18 +010064 git config diff.foo.textconv "\"$(pwd)\""/dump
Jeff King3aa1f7c2008-12-09 03:13:21 -050065'
66
67test_expect_success 'rewrite diff respects textconv' '
68 git diff -B >diff &&
69 grep "dissimilarity index" diff &&
70 grep "^-61" diff &&
71 grep "^-0" diff
72'
73
Jeff King0c018572008-12-09 03:12:28 -050074test_done