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"' || {
99cat '"$kind-patch.$with"'
100(exit 1)
101} &&
102test_cmp '"$kind"'-expect victim
103'
104done
105done
106107
for kind in add-a add-z insert-a mod-a mod-z del-a del-z
108do
109rm -f $kind-ng.without
110sed -e "s/^diff --git /diff /" \
111-e '/^index /d' \
112<$kind-patch.without >$kind-ng.without
113test_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 victim
121'
122done
123124
test_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 patch
134135
'
136137
test_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 patch
144'
145146
test_done