]>
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 | ||
16d4bd4f | 9 | TEST_PASSES_SANITIZE_LEAK=true |
42d0ee83 JH |
10 | . ./test-lib.sh |
11 | ||
2983c0e2 JN |
12 | cat >expect.binary-numstat <<\EOF |
13 | 1 1 a | |
14 | - - b | |
15 | 1 1 c | |
16 | - - d | |
17 | EOF | |
18 | ||
1358bb49 | 19 | test_expect_success 'prepare repository' ' |
3e9cdf7f AS |
20 | echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d && |
21 | git update-index --add a b c d && | |
22 | echo git >a && | |
23 | cat "$TEST_DIRECTORY"/test-binary-1.png >b && | |
24 | echo git >c && | |
25 | cat b b >d | |
1358bb49 | 26 | ' |
42d0ee83 | 27 | |
c7053aa8 | 28 | cat > expected <<\EOF |
42d0ee83 JH |
29 | a | 2 +- |
30 | b | Bin | |
31 | c | 2 +- | |
32 | d | Bin | |
33 | 4 files changed, 2 insertions(+), 2 deletions(-) | |
c7053aa8 | 34 | EOF |
bb84e67c | 35 | test_expect_success 'apply --stat output for binary file change' ' |
2983c0e2 JN |
36 | git diff >diff && |
37 | git apply --stat --summary <diff >current && | |
1108cea7 | 38 | test_cmp expected current |
2983c0e2 | 39 | ' |
42d0ee83 | 40 | |
de9658b5 | 41 | test_expect_success 'diff --shortstat output for binary file change' ' |
216f25f6 | 42 | tail -n 1 expected >expect && |
de9658b5 | 43 | git diff --shortstat >current && |
1108cea7 | 44 | test_cmp expect current |
de9658b5 AS |
45 | ' |
46 | ||
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 && | |
1108cea7 | 50 | test_cmp expected current |
de9658b5 AS |
51 | ' |
52 | ||
2983c0e2 JN |
53 | test_expect_success 'apply --numstat notices binary file change' ' |
54 | git diff >diff && | |
55 | git apply --numstat <diff >current && | |
56 | test_cmp expect.binary-numstat current | |
57 | ' | |
58 | ||
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 | |
63 | ' | |
42d0ee83 JH |
64 | |
65 | # apply needs to be able to skip the binary material correctly | |
66 | # in order to report the line number of a corrupt patch. | |
a926c4b9 | 67 | test_expect_success 'apply detecting corrupt patch correctly' ' |
3e9cdf7f AS |
68 | git diff >output && |
69 | sed -e "s/-CIT/xCIT/" <output >broken && | |
c7c0a250 | 70 | test_must_fail git apply --stat --summary broken 2>detected && |
e6ce6f4c | 71 | detected=$(cat detected) && |
dae197f7 | 72 | detected=$(expr "$detected" : "error.*at line \\([0-9]*\\)\$") && |
e6ce6f4c | 73 | detected=$(sed -ne "${detected}p" broken) && |
3e9cdf7f | 74 | test "$detected" = xCIT |
1358bb49 | 75 | ' |
42d0ee83 | 76 | |
a926c4b9 | 77 | test_expect_success 'apply detecting corrupt patch correctly' ' |
3e9cdf7f | 78 | git diff --binary | sed -e "s/-CIT/xCIT/" >broken && |
c7c0a250 | 79 | test_must_fail git apply --stat --summary broken 2>detected && |
e6ce6f4c | 80 | detected=$(cat detected) && |
dae197f7 | 81 | detected=$(expr "$detected" : "error.*at line \\([0-9]*\\)\$") && |
e6ce6f4c | 82 | detected=$(sed -ne "${detected}p" broken) && |
3e9cdf7f | 83 | test "$detected" = xCIT |
1358bb49 | 84 | ' |
42d0ee83 | 85 | |
3604e7c5 | 86 | test_expect_success 'initial commit' 'git commit -a -m initial' |
42d0ee83 JH |
87 | |
88 | # Try removal (b), modification (d), and creation (e). | |
1358bb49 | 89 | test_expect_success 'diff-index with --binary' ' |
3e9cdf7f AS |
90 | echo AIT >a && mv b e && echo CIT >c && cat e >d && |
91 | git update-index --add --remove a b c d e && | |
e6ce6f4c | 92 | tree0=$(git write-tree) && |
3e9cdf7f AS |
93 | git diff --cached --binary >current && |
94 | git apply --stat --summary current | |
1358bb49 | 95 | ' |
42d0ee83 | 96 | |
1358bb49 | 97 | test_expect_success 'apply binary patch' ' |
3e9cdf7f AS |
98 | git reset --hard && |
99 | git apply --binary --index <current && | |
e6ce6f4c | 100 | tree1=$(git write-tree) && |
3e9cdf7f | 101 | test "$tree1" = "$tree0" |
1358bb49 | 102 | ' |
42d0ee83 | 103 | |
71b989e7 LT |
104 | test_expect_success 'diff --no-index with binary creation' ' |
105 | echo Q | q_to_nul >binary && | |
83279748 ES |
106 | # hide error code from diff, which just indicates differences |
107 | test_might_fail git diff --binary --no-index /dev/null binary >current && | |
71b989e7 LT |
108 | rm binary && |
109 | git apply --binary <current && | |
110 | echo Q >expected && | |
111 | nul_to_q <binary >actual && | |
112 | test_cmp expected actual | |
113 | ' | |
114 | ||
dc801e71 | 115 | cat >expect <<EOF |
12fc4ad8 TB |
116 | binfilë | Bin 0 -> 1026 bytes |
117 | tëxtfilë | 10000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
dc801e71 ZJS |
118 | EOF |
119 | ||
120 | test_expect_success 'diff --stat with binary files and big change count' ' | |
12fc4ad8 TB |
121 | printf "\01\00%1024d" 1 >binfilë && |
122 | git add binfilë && | |
dc801e71 ZJS |
123 | i=0 && |
124 | while test $i -lt 10000; do | |
125 | echo $i && | |
cbe1d9d6 | 126 | i=$(($i + 1)) || return 1 |
12fc4ad8 TB |
127 | done >tëxtfilë && |
128 | git add tëxtfilë && | |
129 | git -c core.quotepath=false diff --cached --stat binfilë tëxtfilë >output && | |
dc801e71 ZJS |
130 | grep " | " output >actual && |
131 | test_cmp expect actual | |
132 | ' | |
133 | ||
42d0ee83 | 134 | test_done |