1#!/bin/sh2#3# Copyright (c) 2006 Junio C Hamano4#56test_description='Binary diff and apply7'89. ./test-lib.sh1011test_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'1819test_expect_success 'diff without --binary' \20'git-diff | git-apply --stat --summary >current &&21cmp current - <<\EOF22a | 2 +-23b | Bin24c | 2 +-25d | Bin264 files changed, 2 insertions(+), 2 deletions(-)27EOF'2829test_expect_success 'diff with --binary' \30'git-diff --binary | git-apply --stat --summary >current &&31cmp current - <<\EOF32a | 2 +-33b | Bin34c | 2 +-35d | Bin364 files changed, 2 insertions(+), 2 deletions(-)37EOF'3839# apply needs to be able to skip the binary material correctly40# 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>detected44then45echo unhappy - should have detected an error46(exit 1)47else48echo happy49fi &&50detected=`cat detected` &&51detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&52detected=`sed -ne "${detected}p" broken` &&53test "$detected" = xCIT'5455test_expect_success 'apply detecting corrupt patch correctly' \56'git-diff --binary | sed -e 's/-CIT/xCIT/' >broken &&57if git-apply --stat --summary broken 2>detected58then59echo unhappy - should have detected an error60(exit 1)61else62echo happy63fi &&64detected=`cat detected` &&65detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&66detected=`sed -ne "${detected}p" broken` &&67test "$detected" = xCIT'6869test_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'7879test_expect_success 'apply binary patch' \80'git-reset --hard &&81git-apply --binary --index <current &&82tree1=`git-write-tree` &&83test "$tree1" = "$tree0"'8485test_done