1#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
56
test_description='Binary diff and apply
7'
89
. ./test-lib.sh
1011
test_expect_success 'prepare repository' \
12'echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d &&
13git update-index --add a b c d &&
14echo git >a &&
15cat ../test4012.png >b &&
16echo git >c &&
17cat b b >d'
1819
cat > expected <<\EOF
20a | 2 +-
21b | Bin
22c | 2 +-
23d | Bin
244 files changed, 2 insertions(+), 2 deletions(-)
25EOF
26test_expect_success 'diff without --binary' \
27'git diff | git apply --stat --summary >current &&
28cmp current expected'
2930
test_expect_success 'diff with --binary' \
31'git diff --binary | git apply --stat --summary >current &&
32cmp current expected'
3334
# apply needs to be able to skip the binary material correctly
35# in order to report the line number of a corrupt patch.
36test_expect_success 'apply detecting corrupt patch correctly' \
37'git diff | sed -e 's/-CIT/xCIT/' >broken &&
38if git apply --stat --summary broken 2>detected
39then
40echo unhappy - should have detected an error
41(exit 1)
42else
43echo happy
44fi &&
45detected=`cat detected` &&
46detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&
47detected=`sed -ne "${detected}p" broken` &&
48test "$detected" = xCIT'
4950
test_expect_success 'apply detecting corrupt patch correctly' \
51'git diff --binary | sed -e 's/-CIT/xCIT/' >broken &&
52if git apply --stat --summary broken 2>detected
53then
54echo unhappy - should have detected an error
55(exit 1)
56else
57echo happy
58fi &&
59detected=`cat detected` &&
60detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&
61detected=`sed -ne "${detected}p" broken` &&
62test "$detected" = xCIT'
6364
test_expect_success 'initial commit' 'git-commit -a -m initial'
6566
# Try removal (b), modification (d), and creation (e).
67test_expect_success 'diff-index with --binary' \
68'echo AIT >a && mv b e && echo CIT >c && cat e >d &&
69git update-index --add --remove a b c d e &&
70tree0=`git write-tree` &&
71git diff --cached --binary >current &&
72git apply --stat --summary current'
7374
test_expect_success 'apply binary patch' \
75'git-reset --hard &&
76git apply --binary --index <current &&
77tree1=`git write-tree` &&
78test "$tree1" = "$tree0"'
7980
test_done