]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4104-apply-boundary.sh
Merge branch 'wb/fsmonitor-bitmap-fix'
[thirdparty/git.git] / t / t4104-apply-boundary.sh
CommitLineData
4be60962
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
5be60078 6test_description='git apply boundary tests
4be60962
JH
7
8'
9. ./test-lib.sh
10
11L="c d e f g h i j k l m n o p q r s t u v w x"
12
13test_expect_success setup '
14 for i in b '"$L"' y
15 do
16 echo $i
17 done >victim &&
18 cat victim >original &&
19 git update-index --add victim &&
20
53350a35 21 # add to the head
4be60962
JH
22 for i in a b '"$L"' y
23 do
24 echo $i
25 done >victim &&
26 cat victim >add-a-expect &&
27 git diff victim >add-a-patch.with &&
28 git diff --unified=0 >add-a-patch.without &&
29
53350a35 30 # insert at line two
ed0f47a8
JH
31 for i in b a '"$L"' y
32 do
33 echo $i
34 done >victim &&
35 cat victim >insert-a-expect &&
36 git diff victim >insert-a-patch.with &&
37 git diff --unified=0 >insert-a-patch.without &&
38
53350a35 39 # modify at the head
4be60962
JH
40 for i in a '"$L"' y
41 do
42 echo $i
43 done >victim &&
44 cat victim >mod-a-expect &&
45 git diff victim >mod-a-patch.with &&
46 git diff --unified=0 >mod-a-patch.without &&
47
53350a35 48 # remove from the head
4be60962
JH
49 for i in '"$L"' y
50 do
51 echo $i
52 done >victim &&
53 cat victim >del-a-expect &&
53350a35 54 git diff victim >del-a-patch.with &&
4be60962
JH
55 git diff --unified=0 >del-a-patch.without &&
56
53350a35 57 # add to the tail
4be60962
JH
58 for i in b '"$L"' y z
59 do
60 echo $i
61 done >victim &&
62 cat victim >add-z-expect &&
63 git diff victim >add-z-patch.with &&
64 git diff --unified=0 >add-z-patch.without &&
65
53350a35 66 # modify at the tail
ed0f47a8 67 for i in b '"$L"' z
4be60962
JH
68 do
69 echo $i
70 done >victim &&
71 cat victim >mod-z-expect &&
72 git diff victim >mod-z-patch.with &&
73 git diff --unified=0 >mod-z-patch.without &&
74
53350a35 75 # remove from the tail
4be60962
JH
76 for i in b '"$L"'
77 do
78 echo $i
79 done >victim &&
80 cat victim >del-z-expect &&
8fb26872
JK
81 git diff victim >del-z-patch.with &&
82 git diff --unified=0 >del-z-patch.without
4be60962 83
53350a35 84 # done
4be60962
JH
85'
86
87for with in with without
88do
89 case "$with" in
90 with) u= ;;
91 without) u='--unidiff-zero ' ;;
92 esac
ed0f47a8 93 for kind in add-a add-z insert-a mod-a mod-z del-a del-z
4be60962
JH
94 do
95 test_expect_success "apply $kind-patch $with context" '
96 cat original >victim &&
97 git update-index victim &&
8bafd20f 98 git apply --index '"$u$kind-patch.$with"' &&
3af82863 99 test_cmp '"$kind"'-expect victim
4be60962
JH
100 '
101 done
102done
103
ed0f47a8 104for kind in add-a add-z insert-a mod-a mod-z del-a del-z
4be60962
JH
105do
106 rm -f $kind-ng.without
107 sed -e "s/^diff --git /diff /" \
108 -e '/^index /d' \
109 <$kind-patch.without >$kind-ng.without
110 test_expect_success "apply non-git $kind-patch without context" '
111 cat original >victim &&
112 git update-index victim &&
8bafd20f 113 git apply --unidiff-zero --index '"$kind-ng.without"' &&
3af82863 114 test_cmp '"$kind"'-expect victim
4be60962
JH
115 '
116done
117
ee5a317e
JH
118test_expect_success 'two lines' '
119
120 >file &&
121 git add file &&
122 echo aaa >file &&
123 git diff >patch &&
124 git add file &&
125 echo bbb >file &&
126 git add file &&
127 test_must_fail git apply --check patch
128
129'
130
24ff4d56
BG
131test_expect_success 'apply patch with 3 context lines matching at end' '
132 { echo a; echo b; echo c; echo d; } >file &&
133 git add file &&
134 echo e >>file &&
135 git diff >patch &&
136 >file &&
137 test_must_fail git apply patch
138'
139
4be60962 140test_done