]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4012-diff-binary.sh
hashmap: use *_entry APIs for iteration
[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
1358bb49 18test_expect_success 'prepare repository' '
3e9cdf7f
AS
19 echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d &&
20 git update-index --add a b c d &&
21 echo git >a &&
22 cat "$TEST_DIRECTORY"/test-binary-1.png >b &&
23 echo git >c &&
24 cat b b >d
1358bb49 25'
42d0ee83 26
c7053aa8 27cat > 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 33EOF
bb84e67c 34test_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 40test_expect_success 'diff --shortstat output for binary file change' '
216f25f6 41 tail -n 1 expected >expect &&
de9658b5 42 git diff --shortstat >current &&
216f25f6 43 test_i18ncmp expect current
de9658b5
AS
44'
45
46test_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
52test_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
58test_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.
76638d90 66test_expect_success C_LOCALE_OUTPUT 'apply detecting corrupt patch correctly' '
3e9cdf7f
AS
67 git diff >output &&
68 sed -e "s/-CIT/xCIT/" <output >broken &&
c7c0a250 69 test_must_fail git apply --stat --summary broken 2>detected &&
e6ce6f4c 70 detected=$(cat detected) &&
dae197f7 71 detected=$(expr "$detected" : "error.*at line \\([0-9]*\\)\$") &&
e6ce6f4c 72 detected=$(sed -ne "${detected}p" broken) &&
3e9cdf7f 73 test "$detected" = xCIT
1358bb49 74'
42d0ee83 75
76638d90 76test_expect_success C_LOCALE_OUTPUT 'apply detecting corrupt patch correctly' '
3e9cdf7f 77 git diff --binary | sed -e "s/-CIT/xCIT/" >broken &&
c7c0a250 78 test_must_fail git apply --stat --summary broken 2>detected &&
e6ce6f4c 79 detected=$(cat detected) &&
dae197f7 80 detected=$(expr "$detected" : "error.*at line \\([0-9]*\\)\$") &&
e6ce6f4c 81 detected=$(sed -ne "${detected}p" broken) &&
3e9cdf7f 82 test "$detected" = xCIT
1358bb49 83'
42d0ee83 84
3604e7c5 85test_expect_success 'initial commit' 'git commit -a -m initial'
42d0ee83
JH
86
87# Try removal (b), modification (d), and creation (e).
1358bb49 88test_expect_success 'diff-index with --binary' '
3e9cdf7f
AS
89 echo AIT >a && mv b e && echo CIT >c && cat e >d &&
90 git update-index --add --remove a b c d e &&
e6ce6f4c 91 tree0=$(git write-tree) &&
3e9cdf7f
AS
92 git diff --cached --binary >current &&
93 git apply --stat --summary current
1358bb49 94'
42d0ee83 95
1358bb49 96test_expect_success 'apply binary patch' '
3e9cdf7f
AS
97 git reset --hard &&
98 git apply --binary --index <current &&
e6ce6f4c 99 tree1=$(git write-tree) &&
3e9cdf7f 100 test "$tree1" = "$tree0"
1358bb49 101'
42d0ee83 102
71b989e7
LT
103test_expect_success 'diff --no-index with binary creation' '
104 echo Q | q_to_nul >binary &&
83279748
ES
105 # hide error code from diff, which just indicates differences
106 test_might_fail git diff --binary --no-index /dev/null binary >current &&
71b989e7
LT
107 rm binary &&
108 git apply --binary <current &&
109 echo Q >expected &&
110 nul_to_q <binary >actual &&
111 test_cmp expected actual
112'
113
dc801e71
ZJS
114cat >expect <<EOF
115 binfile | Bin 0 -> 1026 bytes
116 textfile | 10000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
117EOF
118
119test_expect_success 'diff --stat with binary files and big change count' '
66fd93ee 120 printf "\01\00%1024d" 1 >binfile &&
dc801e71
ZJS
121 git add binfile &&
122 i=0 &&
123 while test $i -lt 10000; do
124 echo $i &&
125 i=$(($i + 1))
126 done >textfile &&
127 git add textfile &&
128 git diff --cached --stat binfile textfile >output &&
129 grep " | " output >actual &&
130 test_cmp expect actual
131'
132
42d0ee83 133test_done