1#!/bin/sh2#3# Copyright (c) 2005 Junio C Hamano4#56test_description='git apply boundary tests78'9. ./test-lib.sh1011L="c d e f g h i j k l m n o p q r s t u v w x"1213test_expect_success setup '14for i in b '"$L"' y15do16echo $i17done >victim &&18cat victim >original &&19git update-index --add victim &&2021: add to the head22for i in a b '"$L"' y23do24echo $i25done >victim &&26cat victim >add-a-expect &&27git diff victim >add-a-patch.with &&28git diff --unified=0 >add-a-patch.without &&2930: insert at line two31for i in b a '"$L"' y32do33echo $i34done >victim &&35cat victim >insert-a-expect &&36git diff victim >insert-a-patch.with &&37git diff --unified=0 >insert-a-patch.without &&3839: modify at the head40for i in a '"$L"' y41do42echo $i43done >victim &&44cat victim >mod-a-expect &&45git diff victim >mod-a-patch.with &&46git diff --unified=0 >mod-a-patch.without &&4748: remove from the head49for i in '"$L"' y50do51echo $i52done >victim &&53cat victim >del-a-expect &&54git diff victim >del-a-patch.with55git diff --unified=0 >del-a-patch.without &&5657: add to the tail58for i in b '"$L"' y z59do60echo $i61done >victim &&62cat victim >add-z-expect &&63git diff victim >add-z-patch.with &&64git diff --unified=0 >add-z-patch.without &&6566: modify at the tail67for i in b '"$L"' z68do69echo $i70done >victim &&71cat victim >mod-z-expect &&72git diff victim >mod-z-patch.with &&73git diff --unified=0 >mod-z-patch.without &&7475: remove from the tail76for i in b '"$L"'77do78echo $i79done >victim &&80cat victim >del-z-expect &&81git diff victim >del-z-patch.with82git diff --unified=0 >del-z-patch.without &&8384: done85'8687for with in with without88do89case "$with" in90with) u= ;;91without) u='--unidiff-zero ' ;;92esac93for kind in add-a add-z insert-a mod-a mod-z del-a del-z94do95test_expect_success "apply $kind-patch $with context" '96cat original >victim &&97git update-index victim &&98git apply --index '"$u$kind-patch.$with"' || {99cat '"$kind-patch.$with"'100(exit 1)101} &&102test_cmp '"$kind"'-expect victim103'104done105done106107for kind in add-a add-z insert-a mod-a mod-z del-a del-z108do109rm -f $kind-ng.without110sed -e "s/^diff --git /diff /" \111-e '/^index /d' \112<$kind-patch.without >$kind-ng.without113test_expect_success "apply non-git $kind-patch without context" '114cat original >victim &&115git update-index victim &&116git apply --unidiff-zero --index '"$kind-ng.without"' || {117cat '"$kind-ng.without"'118(exit 1)119} &&120test_cmp '"$kind"'-expect victim121'122done123124test_expect_success 'two lines' '125126>file &&127git add file &&128echo aaa >file &&129git diff >patch &&130git add file &&131echo bbb >file &&132git add file &&133test_must_fail git apply --check patch134135'136137test_expect_success 'apply patch with 3 context lines matching at end' '138{ echo a; echo b; echo c; echo d; } >file &&139git add file &&140echo e >>file &&141git diff >patch &&142>file &&143test_must_fail git apply patch144'145146test_done