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.with &&55git 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.with &&82git diff --unified=0 >del-z-patch.without8384# 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"' &&99test_cmp '"$kind"'-expect victim100'101done102done103104for kind in add-a add-z insert-a mod-a mod-z del-a del-z105do106rm -f $kind-ng.without107sed -e "s/^diff --git /diff /" \108-e '/^index /d' \109<$kind-patch.without >$kind-ng.without110test_expect_success "apply non-git $kind-patch without context" '111cat original >victim &&112git update-index victim &&113git apply --unidiff-zero --index '"$kind-ng.without"' &&114test_cmp '"$kind"'-expect victim115'116done117118test_expect_success 'two lines' '119120>file &&121git add file &&122echo aaa >file &&123git diff >patch &&124git add file &&125echo bbb >file &&126git add file &&127test_must_fail git apply --check patch128129'130131test_expect_success 'apply patch with 3 context lines matching at end' '132{ echo a; echo b; echo c; echo d; } >file &&133git add file &&134echo e >>file &&135git diff >patch &&136>file &&137test_must_fail git apply patch138'139140test_done