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
test_expect_success 'diff without --binary' \
20'git-diff | git-apply --stat --summary >current &&
21cmp current - <<\EOF
22a | 2 +-
23b | Bin
24c | 2 +-
25d | Bin
264 files changed, 2 insertions(+), 2 deletions(-)
27EOF'
2829
test_expect_success 'diff with --binary' \
30'git-diff --binary | git-apply --stat --summary >current &&
31cmp current - <<\EOF
32a | 2 +-
33b | Bin
34c | 2 +-
35d | Bin
364 files changed, 2 insertions(+), 2 deletions(-)
37EOF'
3839
# apply needs to be able to skip the binary material correctly
40# in order to report the line number of a corrupt patch.
41test_expect_success 'apply detecting corrupt patch correctly' \
42'git-diff | sed -e 's/-CIT/xCIT/' >broken &&
43if git-apply --stat --summary broken 2>detected
44then
45echo unhappy - should have detected an error
46(exit 1)
47else
48echo happy
49fi &&
50detected=`cat detected` &&
51detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&
52detected=`sed -ne "${detected}p" broken` &&
53test "$detected" = xCIT'
5455
test_expect_success 'apply detecting corrupt patch correctly' \
56'git-diff --binary | sed -e 's/-CIT/xCIT/' >broken &&
57if git-apply --stat --summary broken 2>detected
58then
59echo unhappy - should have detected an error
60(exit 1)
61else
62echo happy
63fi &&
64detected=`cat detected` &&
65detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&
66detected=`sed -ne "${detected}p" broken` &&
67test "$detected" = xCIT'
6869
test_expect_success 'initial commit' 'git-commit -a -m initial'
7071
# Try removal (b), modification (d), and creation (e).
72test_expect_success 'diff-index with --binary' \
73'echo AIT >a && mv b e && echo CIT >c && cat e >d &&
74git-update-index --add --remove a b c d e &&
75tree0=`git-write-tree` &&
76git-diff --cached --binary >current &&
77git-apply --stat --summary current'
7879
test_expect_success 'apply binary patch' \
80'git-reset --hard &&
81git-apply --binary --index <current &&
82tree1=`git-write-tree` &&
83test "$tree1" = "$tree0"'
8485
test_done