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'1819cat > expected <<\EOF20a | 2 +-21b | Bin22c | 2 +-23d | Bin244 files changed, 2 insertions(+), 2 deletions(-)25EOF26test_expect_success 'diff without --binary' \27'git diff | git apply --stat --summary >current &&28cmp current expected'2930test_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 correctly35# 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>detected39then40echo unhappy - should have detected an error41(exit 1)42else43echo happy44fi &&45detected=`cat detected` &&46detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&47detected=`sed -ne "${detected}p" broken` &&48test "$detected" = xCIT'4950test_expect_success 'apply detecting corrupt patch correctly' \51'git diff --binary | sed -e 's/-CIT/xCIT/' >broken &&52if git apply --stat --summary broken 2>detected53then54echo unhappy - should have detected an error55(exit 1)56else57echo happy58fi &&59detected=`cat detected` &&60detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&61detected=`sed -ne "${detected}p" broken` &&62test "$detected" = xCIT'6364test_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'7374test_expect_success 'apply binary patch' \75'git-reset --hard &&76git apply --binary --index <current &&77tree1=`git write-tree` &&78test "$tree1" = "$tree0"'7980test_done