Git 2.45
[git/gitster.git] / t / t4104-apply-boundary.sh
blobdc501aac387b26aa344564dfb38f179f4601546c
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git apply boundary tests'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 L="c d e f g h i j k l m n o p q r s t u v w x"
13 test_expect_success setup '
14 test_write_lines b $L y >victim &&
15 cat victim >original &&
16 git update-index --add victim &&
18 # add to the head
19 test_write_lines a b $L y >victim &&
20 cat victim >add-a-expect &&
21 git diff victim >add-a-patch.with &&
22 git diff --unified=0 >add-a-patch.without &&
24 # insert at line two
25 test_write_lines b a $L y >victim &&
26 cat victim >insert-a-expect &&
27 git diff victim >insert-a-patch.with &&
28 git diff --unified=0 >insert-a-patch.without &&
30 # modify at the head
31 test_write_lines a $L y >victim &&
32 cat victim >mod-a-expect &&
33 git diff victim >mod-a-patch.with &&
34 git diff --unified=0 >mod-a-patch.without &&
36 # remove from the head
37 test_write_lines $L y >victim &&
38 cat victim >del-a-expect &&
39 git diff victim >del-a-patch.with &&
40 git diff --unified=0 >del-a-patch.without &&
42 # add to the tail
43 test_write_lines b $L y z >victim &&
44 cat victim >add-z-expect &&
45 git diff victim >add-z-patch.with &&
46 git diff --unified=0 >add-z-patch.without &&
48 # modify at the tail
49 test_write_lines b $L z >victim &&
50 cat victim >mod-z-expect &&
51 git diff victim >mod-z-patch.with &&
52 git diff --unified=0 >mod-z-patch.without &&
54 # remove from the tail
55 test_write_lines b $L >victim &&
56 cat victim >del-z-expect &&
57 git diff victim >del-z-patch.with &&
58 git diff --unified=0 >del-z-patch.without
60 # done
63 for with in with without
65 case "$with" in
66 with) u= ;;
67 without) u=--unidiff-zero ;;
68 esac
69 for kind in add-a add-z insert-a mod-a mod-z del-a del-z
71 test_expect_success "apply $kind-patch $with context" '
72 cat original >victim &&
73 git update-index victim &&
74 git apply --index $u "$kind-patch.$with" &&
75 test_cmp "$kind-expect" victim
77 done
78 done
80 for kind in add-a add-z insert-a mod-a mod-z del-a del-z
82 rm -f $kind-ng.without
83 sed -e "s/^diff --git /diff /" \
84 -e '/^index /d' \
85 <$kind-patch.without >$kind-ng.without
86 test_expect_success "apply non-git $kind-patch without context" '
87 cat original >victim &&
88 git update-index victim &&
89 git apply --unidiff-zero --index "$kind-ng.without" &&
90 test_cmp "$kind-expect" victim
92 done
94 test_expect_success 'two lines' '
95 >file &&
96 git add file &&
97 echo aaa >file &&
98 git diff >patch &&
99 git add file &&
100 echo bbb >file &&
101 git add file &&
102 test_must_fail git apply --check patch
105 test_expect_success 'apply patch with 3 context lines matching at end' '
106 test_write_lines a b c d >file &&
107 git add file &&
108 echo e >>file &&
109 git diff >patch &&
110 >file &&
111 test_must_fail git apply patch
114 test_done