]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4012-diff-binary.sh
Git 1.7.11.2
[thirdparty/git.git] / t / t4012-diff-binary.sh
CommitLineData
42d0ee83
JH
1#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
5
6test_description='Binary diff and apply
7'
8
9. ./test-lib.sh
10
2983c0e2
JN
11cat >expect.binary-numstat <<\EOF
121 1 a
13- - b
141 1 c
15- - d
16EOF
17
42d0ee83
JH
18test_expect_success 'prepare repository' \
19 'echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d &&
5be60078 20 git update-index --add a b c d &&
42d0ee83 21 echo git >a &&
b5967f82 22 cat "$TEST_DIRECTORY"/test-binary-1.png >b &&
42d0ee83
JH
23 echo git >c &&
24 cat b b >d'
25
c7053aa8 26cat > expected <<\EOF
42d0ee83
JH
27 a | 2 +-
28 b | Bin
29 c | 2 +-
30 d | Bin
31 4 files changed, 2 insertions(+), 2 deletions(-)
c7053aa8 32EOF
2983c0e2
JN
33test_expect_success '"apply --stat" output for binary file change' '
34 git diff >diff &&
35 git apply --stat --summary <diff >current &&
36 test_i18ncmp expected current
37'
42d0ee83 38
de9658b5
AS
39test_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
43'
44
45test_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
49'
50
2983c0e2
JN
51test_expect_success 'apply --numstat notices binary file change' '
52 git diff >diff &&
53 git apply --numstat <diff >current &&
54 test_cmp expect.binary-numstat current
55'
56
57test_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
61'
42d0ee83
JH
62
63# apply needs to be able to skip the binary material correctly
64# in order to report the line number of a corrupt patch.
65test_expect_success 'apply detecting corrupt patch correctly' \
5be60078
JH
66 'git diff | sed -e 's/-CIT/xCIT/' >broken &&
67 if git apply --stat --summary broken 2>detected
42d0ee83
JH
68 then
69 echo unhappy - should have detected an error
70 (exit 1)
71 else
72 echo happy
73 fi &&
74 detected=`cat detected` &&
75 detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&
76 detected=`sed -ne "${detected}p" broken` &&
77 test "$detected" = xCIT'
78
79test_expect_success 'apply detecting corrupt patch correctly' \
5be60078
JH
80 'git diff --binary | sed -e 's/-CIT/xCIT/' >broken &&
81 if git apply --stat --summary broken 2>detected
42d0ee83
JH
82 then
83 echo unhappy - should have detected an error
84 (exit 1)
85 else
86 echo happy
87 fi &&
88 detected=`cat detected` &&
89 detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&
90 detected=`sed -ne "${detected}p" broken` &&
91 test "$detected" = xCIT'
92
3604e7c5 93test_expect_success 'initial commit' 'git commit -a -m initial'
42d0ee83
JH
94
95# Try removal (b), modification (d), and creation (e).
96test_expect_success 'diff-index with --binary' \
97 'echo AIT >a && mv b e && echo CIT >c && cat e >d &&
5be60078
JH
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'
42d0ee83
JH
102
103test_expect_success 'apply binary patch' \
3604e7c5 104 'git reset --hard &&
5be60078
JH
105 git apply --binary --index <current &&
106 tree1=`git write-tree` &&
42d0ee83
JH
107 test "$tree1" = "$tree0"'
108
71b989e7
LT
109test_expect_success 'diff --no-index with binary creation' '
110 echo Q | q_to_nul >binary &&
36adb4ab 111 (: hide error code from diff, which just indicates differences
71b989e7
LT
112 git diff --binary --no-index /dev/null binary >current ||
113 true
114 ) &&
115 rm binary &&
116 git apply --binary <current &&
117 echo Q >expected &&
118 nul_to_q <binary >actual &&
119 test_cmp expected actual
120'
121
dc801e71
ZJS
122cat >expect <<EOF
123 binfile | Bin 0 -> 1026 bytes
124 textfile | 10000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
125EOF
126
127test_expect_success 'diff --stat with binary files and big change count' '
128 echo X | dd of=binfile bs=1k seek=1 &&
129 git add binfile &&
130 i=0 &&
131 while test $i -lt 10000; do
132 echo $i &&
133 i=$(($i + 1))
134 done >textfile &&
135 git add textfile &&
136 git diff --cached --stat binfile textfile >output &&
137 grep " | " output >actual &&
138 test_cmp expect actual
139'
140
42d0ee83 141test_done