1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
56
test_description='git apply boundary tests
78
'
9. ./test-lib.sh
1011
L="c d e f g h i j k l m n o p q r s t u v w x"
1213
test_expect_success setup '
14for i in b '"$L"' y
15do
16echo $i
17done >victim &&
18cat victim >original &&
19git update-index --add victim &&
2021
# add to the head
22for i in a b '"$L"' y
23do
24echo $i
25done >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 two
31for i in b a '"$L"' y
32do
33echo $i
34done >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 head
40for i in a '"$L"' y
41do
42echo $i
43done >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 head
49for i in '"$L"' y
50do
51echo $i
52done >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 tail
58for i in b '"$L"' y z
59do
60echo $i
61done >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 tail
67for i in b '"$L"' z
68do
69echo $i
70done >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 tail
76for i in b '"$L"'
77do
78echo $i
79done >victim &&
80cat victim >del-z-expect &&
81git diff victim >del-z-patch.with &&
82git diff --unified=0 >del-z-patch.without
8384
# done
85'
8687
for with in with without
88do
89case "$with" in
90with) u= ;;
91without) u='--unidiff-zero ' ;;
92esac
93for kind in add-a add-z insert-a mod-a mod-z del-a del-z
94do
95test_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 victim
100'
101done
102done
103104
for kind in add-a add-z insert-a mod-a mod-z del-a del-z
105do
106rm -f $kind-ng.without
107sed -e "s/^diff --git /diff /" \
108-e '/^index /d' \
109<$kind-patch.without >$kind-ng.without
110test_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 victim
115'
116done
117118
test_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 patch
128129
'
130131
test_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 patch
138'
139140
test_done