3 # Copyright (c) 2006 Junio C Hamano
6 test_description
='Binary diff and apply
11 cat >expect.binary-numstat
<<\EOF
18 test_expect_success
'prepare repository' \
19 'echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d &&
20 git update-index --add a b c d &&
22 cat "$TEST_DIRECTORY"/test-binary-1.png >b &&
31 4 files changed
, 2 insertions
(+), 2 deletions
(-)
33 test_expect_success
'"apply --stat" output for binary file change' '
35 git apply --stat --summary <diff >current &&
36 test_i18ncmp expected current
39 test_expect_success
'diff --shortstat output for binary file change' '
40 echo " 4 files changed, 2 insertions(+), 2 deletions(-)" >expected &&
41 git diff --shortstat >current &&
42 test_i18ncmp expected current
45 test_expect_success
'diff --shortstat output for binary file change only' '
46 echo " 1 file changed, 0 insertions(+), 0 deletions(-)" >expected &&
47 git diff --shortstat -- b >current &&
48 test_i18ncmp expected current
51 test_expect_success
'apply --numstat notices binary file change' '
53 git apply --numstat <diff >current &&
54 test_cmp expect.binary-numstat current
57 test_expect_success
'apply --numstat understands diff --binary format' '
58 git diff --binary >diff &&
59 git apply --numstat <diff >current &&
60 test_cmp expect.binary-numstat current
63 # apply needs to be able to skip the binary material correctly
64 # in order to report the line number of a corrupt patch.
65 test_expect_success
'apply detecting corrupt patch correctly' \
66 'git diff | sed -e 's
/-CIT/xCIT
/' >broken &&
67 if git apply --stat --summary broken 2>detected
69 echo unhappy - should have detected an error
74 detected=`cat detected` &&
75 detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&
76 detected=`sed -ne "${detected}p" broken` &&
77 test "$detected" = xCIT'
79 test_expect_success
'apply detecting corrupt patch correctly' \
80 'git diff --binary | sed -e 's
/-CIT/xCIT
/' >broken &&
81 if git apply --stat --summary broken 2>detected
83 echo unhappy - should have detected an error
88 detected=`cat detected` &&
89 detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&
90 detected=`sed -ne "${detected}p" broken` &&
91 test "$detected" = xCIT'
93 test_expect_success
'initial commit' 'git commit -a -m initial'
95 # Try removal (b), modification (d), and creation (e).
96 test_expect_success
'diff-index with --binary' \
97 'echo AIT >a && mv b e && echo CIT >c && cat e >d &&
98 git update-index --add --remove a b c d e &&
99 tree0=`git write-tree` &&
100 git diff --cached --binary >current &&
101 git apply --stat --summary current'
103 test_expect_success
'apply binary patch' \
105 git apply --binary --index <current &&
106 tree1=`git write-tree` &&
107 test "$tree1" = "$tree0"'
109 test_expect_success
'diff --no-index with binary creation' '
110 echo Q | q_to_nul >binary &&
111 (: hide error code from diff, which just indicates differences
112 git diff --binary --no-index /dev/null binary >current ||
116 git apply --binary <current &&
118 nul_to_q <binary >actual &&
119 test_cmp expected actual
123 binfile | Bin 0 -> 1026 bytes
124 textfile | 10000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
127 test_expect_success
'diff --stat with binary files and big change count' '
128 echo X | dd of=binfile bs=1k seek=1 &&
131 while test $i -lt 10000; do
136 git diff --cached --stat binfile textfile >output &&
137 grep " | " output >actual &&
138 test_cmp expect actual