]>
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 | ||
42d0ee83 JH |
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 JH |
23 | echo git >c && |
24 | cat b b >d' | |
25 | ||
c7053aa8 | 26 | cat > 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 | 32 | EOF |
2983c0e2 JN |
33 | test_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 | |
2983c0e2 JN |
39 | test_expect_success 'apply --numstat notices binary file change' ' |
40 | git diff >diff && | |
41 | git apply --numstat <diff >current && | |
42 | test_cmp expect.binary-numstat current | |
43 | ' | |
44 | ||
45 | test_expect_success 'apply --numstat understands diff --binary format' ' | |
46 | git diff --binary >diff && | |
47 | git apply --numstat <diff >current && | |
48 | test_cmp expect.binary-numstat current | |
49 | ' | |
42d0ee83 JH |
50 | |
51 | # apply needs to be able to skip the binary material correctly | |
52 | # in order to report the line number of a corrupt patch. | |
53 | test_expect_success 'apply detecting corrupt patch correctly' \ | |
5be60078 JH |
54 | 'git diff | sed -e 's/-CIT/xCIT/' >broken && |
55 | if git apply --stat --summary broken 2>detected | |
42d0ee83 JH |
56 | then |
57 | echo unhappy - should have detected an error | |
58 | (exit 1) | |
59 | else | |
60 | echo happy | |
61 | fi && | |
62 | detected=`cat detected` && | |
63 | detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` && | |
64 | detected=`sed -ne "${detected}p" broken` && | |
65 | test "$detected" = xCIT' | |
66 | ||
67 | test_expect_success 'apply detecting corrupt patch correctly' \ | |
5be60078 JH |
68 | 'git diff --binary | sed -e 's/-CIT/xCIT/' >broken && |
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` && | |
79 | test "$detected" = xCIT' | |
80 | ||
3604e7c5 | 81 | test_expect_success 'initial commit' 'git commit -a -m initial' |
42d0ee83 JH |
82 | |
83 | # Try removal (b), modification (d), and creation (e). | |
84 | test_expect_success 'diff-index with --binary' \ | |
85 | 'echo AIT >a && mv b e && echo CIT >c && cat e >d && | |
5be60078 JH |
86 | git update-index --add --remove a b c d e && |
87 | tree0=`git write-tree` && | |
88 | git diff --cached --binary >current && | |
89 | git apply --stat --summary current' | |
42d0ee83 JH |
90 | |
91 | test_expect_success 'apply binary patch' \ | |
3604e7c5 | 92 | 'git reset --hard && |
5be60078 JH |
93 | git apply --binary --index <current && |
94 | tree1=`git write-tree` && | |
42d0ee83 JH |
95 | test "$tree1" = "$tree0"' |
96 | ||
71b989e7 LT |
97 | test_expect_success 'diff --no-index with binary creation' ' |
98 | echo Q | q_to_nul >binary && | |
36adb4ab | 99 | (: hide error code from diff, which just indicates differences |
71b989e7 LT |
100 | git diff --binary --no-index /dev/null binary >current || |
101 | true | |
102 | ) && | |
103 | rm binary && | |
104 | git apply --binary <current && | |
105 | echo Q >expected && | |
106 | nul_to_q <binary >actual && | |
107 | test_cmp expected actual | |
108 | ' | |
109 | ||
dc801e71 ZJS |
110 | cat >expect <<EOF |
111 | binfile | Bin 0 -> 1026 bytes | |
112 | textfile | 10000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
113 | EOF | |
114 | ||
115 | test_expect_success 'diff --stat with binary files and big change count' ' | |
116 | echo X | dd of=binfile bs=1k seek=1 && | |
117 | git add binfile && | |
118 | i=0 && | |
119 | while test $i -lt 10000; do | |
120 | echo $i && | |
121 | i=$(($i + 1)) | |
122 | done >textfile && | |
123 | git add textfile && | |
124 | git diff --cached --stat binfile textfile >output && | |
125 | grep " | " output >actual && | |
126 | test_cmp expect actual | |
127 | ' | |
128 | ||
42d0ee83 | 129 | test_done |