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