Merge branch 'tb/commit-graph-genv2-upgrade-fix' into maint
[git/debian.git] / t / t4104-apply-boundary.sh
blob71ef4132d153b7be4b4f3d4ebfb1a85ee4bfa9ab
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git apply boundary tests'
8 . ./test-lib.sh
10 L="c d e f g h i j k l m n o p q r s t u v w x"
12 test_expect_success setup '
13 test_write_lines b $L y >victim &&
14 cat victim >original &&
15 git update-index --add victim &&
17 # add to the head
18 test_write_lines a b $L y >victim &&
19 cat victim >add-a-expect &&
20 git diff victim >add-a-patch.with &&
21 git diff --unified=0 >add-a-patch.without &&
23 # insert at line two
24 test_write_lines b a $L y >victim &&
25 cat victim >insert-a-expect &&
26 git diff victim >insert-a-patch.with &&
27 git diff --unified=0 >insert-a-patch.without &&
29 # modify at the head
30 test_write_lines a $L y >victim &&
31 cat victim >mod-a-expect &&
32 git diff victim >mod-a-patch.with &&
33 git diff --unified=0 >mod-a-patch.without &&
35 # remove from the head
36 test_write_lines $L y >victim &&
37 cat victim >del-a-expect &&
38 git diff victim >del-a-patch.with &&
39 git diff --unified=0 >del-a-patch.without &&
41 # add to the tail
42 test_write_lines b $L y z >victim &&
43 cat victim >add-z-expect &&
44 git diff victim >add-z-patch.with &&
45 git diff --unified=0 >add-z-patch.without &&
47 # modify at the tail
48 test_write_lines b $L z >victim &&
49 cat victim >mod-z-expect &&
50 git diff victim >mod-z-patch.with &&
51 git diff --unified=0 >mod-z-patch.without &&
53 # remove from the tail
54 test_write_lines b $L >victim &&
55 cat victim >del-z-expect &&
56 git diff victim >del-z-patch.with &&
57 git diff --unified=0 >del-z-patch.without
59 # done
62 for with in with without
64 case "$with" in
65 with) u= ;;
66 without) u=--unidiff-zero ;;
67 esac
68 for kind in add-a add-z insert-a mod-a mod-z del-a del-z
70 test_expect_success "apply $kind-patch $with context" '
71 cat original >victim &&
72 git update-index victim &&
73 git apply --index $u "$kind-patch.$with" &&
74 test_cmp "$kind-expect" victim
76 done
77 done
79 for kind in add-a add-z insert-a mod-a mod-z del-a del-z
81 rm -f $kind-ng.without
82 sed -e "s/^diff --git /diff /" \
83 -e '/^index /d' \
84 <$kind-patch.without >$kind-ng.without
85 test_expect_success "apply non-git $kind-patch without context" '
86 cat original >victim &&
87 git update-index victim &&
88 git apply --unidiff-zero --index "$kind-ng.without" &&
89 test_cmp "$kind-expect" victim
91 done
93 test_expect_success 'two lines' '
94 >file &&
95 git add file &&
96 echo aaa >file &&
97 git diff >patch &&
98 git add file &&
99 echo bbb >file &&
100 git add file &&
101 test_must_fail git apply --check patch
104 test_expect_success 'apply patch with 3 context lines matching at end' '
105 test_write_lines a b c d >file &&
106 git add file &&
107 echo e >>file &&
108 git diff >patch &&
109 >file &&
110 test_must_fail git apply patch
113 test_done