3 # Copyright (c) 2006 Junio C Hamano
6 test_description
='Binary diff and apply
9 TEST_PASSES_SANITIZE_LEAK
=true
12 cat >expect.binary-numstat
<<\EOF
19 test_expect_success
'prepare repository' '
20 echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d &&
21 git update-index --add a b c d &&
23 cat "$TEST_DIRECTORY"/test-binary-1.png >b &&
33 4 files changed
, 2 insertions
(+), 2 deletions
(-)
35 test_expect_success
'apply --stat output for binary file change' '
37 git apply --stat --summary <diff >current &&
38 test_cmp expected current
41 test_expect_success
'diff --shortstat output for binary file change' '
42 tail -n 1 expected >expect &&
43 git diff --shortstat >current &&
44 test_cmp expect current
47 test_expect_success
'diff --shortstat output for binary file change only' '
48 echo " 1 file changed, 0 insertions(+), 0 deletions(-)" >expected &&
49 git diff --shortstat -- b >current &&
50 test_cmp expected current
53 test_expect_success
'apply --numstat notices binary file change' '
55 git apply --numstat <diff >current &&
56 test_cmp expect.binary-numstat current
59 test_expect_success
'apply --numstat understands diff --binary format' '
60 git diff --binary >diff &&
61 git apply --numstat <diff >current &&
62 test_cmp expect.binary-numstat current
65 # apply needs to be able to skip the binary material correctly
66 # in order to report the line number of a corrupt patch.
67 test_expect_success
'apply detecting corrupt patch correctly' '
69 sed -e "s/-CIT/xCIT/" <output >broken &&
70 test_must_fail git apply --stat --summary broken 2>detected &&
71 detected=$(cat detected) &&
72 detected=$(expr "$detected" : "error.*at line \\([0-9]*\\)\$") &&
73 detected=$(sed -ne "${detected}p" broken) &&
74 test "$detected" = xCIT
77 test_expect_success
'apply detecting corrupt patch correctly' '
78 git diff --binary | sed -e "s/-CIT/xCIT/" >broken &&
79 test_must_fail git apply --stat --summary broken 2>detected &&
80 detected=$(cat detected) &&
81 detected=$(expr "$detected" : "error.*at line \\([0-9]*\\)\$") &&
82 detected=$(sed -ne "${detected}p" broken) &&
83 test "$detected" = xCIT
86 test_expect_success
'initial commit' 'git commit -a -m initial'
88 # Try removal (b), modification (d), and creation (e).
89 test_expect_success
'diff-index with --binary' '
90 echo AIT >a && mv b e && echo CIT >c && cat e >d &&
91 git update-index --add --remove a b c d e &&
92 tree0=$(git write-tree) &&
93 git diff --cached --binary >current &&
94 git apply --stat --summary current
97 test_expect_success
'apply binary patch' '
99 git apply --binary --index <current &&
100 tree1=$(git write-tree) &&
101 test "$tree1" = "$tree0"
104 test_expect_success
'diff --no-index with binary creation' '
105 echo Q | q_to_nul >binary &&
106 # hide error code from diff, which just indicates differences
107 test_might_fail git diff --binary --no-index /dev/null binary >current &&
109 git apply --binary <current &&
111 nul_to_q <binary >actual &&
112 test_cmp expected actual
116 binfile | Bin 0 -> 1026 bytes
117 textfile | 10000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
120 test_expect_success
'diff --stat with binary files and big change count' '
121 printf "\01\00%1024d" 1 >binfile &&
124 while test $i -lt 10000; do
126 i=$(($i + 1)) || return 1
129 git diff --cached --stat binfile textfile >output &&
130 grep " | " output >actual &&
131 test_cmp expect actual