]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4103-apply-binary.sh
shortlog: match commit trailers with --group
[thirdparty/git.git] / t / t4103-apply-binary.sh
CommitLineData
27dedf0c
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
5be60078 6test_description='git apply handling binary patches
27dedf0c
JH
7
8'
9. ./test-lib.sh
10
6a2abdc1
JH
11test_expect_success 'setup' '
12 cat >file1 <<-\EOF &&
13 A quick brown fox jumps over the lazy dog.
14 A tiny little penguin runs around in circles.
15 There is a flag with Linux written on it.
16 A slow black-and-white panda just sits there,
17 munching on his bamboo.
18 EOF
19 cat file1 >file2 &&
20 cat file1 >file4 &&
21
4a45f7dd 22 git update-index --add --remove file1 file2 file4 &&
6a2abdc1 23 git commit -m "Initial Version" 2>/dev/null &&
4a45f7dd
BG
24
25 git checkout -b binary &&
94221d22 26 perl -pe "y/x/\000/" <file1 >file3 &&
4a45f7dd
BG
27 cat file3 >file4 &&
28 git add file2 &&
94221d22 29 perl -pe "y/\000/v/" <file3 >file1 &&
4a45f7dd
BG
30 rm -f file2 &&
31 git update-index --add --remove file1 file2 file3 file4 &&
6a2abdc1 32 git commit -m "Second Version" &&
4a45f7dd
BG
33
34 git diff-tree -p master binary >B.diff &&
35 git diff-tree -p -C master binary >C.diff &&
36
37 git diff-tree -p --binary master binary >BF.diff &&
24305cd7
JK
38 git diff-tree -p --binary -C master binary >CF.diff &&
39
40 git diff-tree -p --full-index master binary >B-index.diff &&
41 git diff-tree -p -C --full-index master binary >C-index.diff &&
42
6a2abdc1
JH
43 git diff-tree -p --binary --no-prefix master binary -- file3 >B0.diff &&
44
24305cd7 45 git init other-repo &&
6a2abdc1
JH
46 (
47 cd other-repo &&
48 git fetch .. master &&
49 git reset --hard FETCH_HEAD
24305cd7 50 )
6a2abdc1 51'
27dedf0c
JH
52
53test_expect_success 'stat binary diff -- should not fail.' \
a48fcd83 54 'git checkout master &&
5be60078 55 git apply --stat --summary B.diff'
27dedf0c 56
6a2abdc1
JH
57test_expect_success 'stat binary -p0 diff -- should not fail.' '
58 git checkout master &&
59 git apply --stat -p0 B0.diff
60'
61
27dedf0c 62test_expect_success 'stat binary diff (copy) -- should not fail.' \
a48fcd83 63 'git checkout master &&
5be60078 64 git apply --stat --summary C.diff'
27dedf0c 65
41ac414e 66test_expect_success 'check binary diff -- should fail.' \
3604e7c5 67 'git checkout master &&
d492b31c 68 test_must_fail git apply --check B.diff'
41ac414e
JH
69
70test_expect_success 'check binary diff (copy) -- should fail.' \
3604e7c5 71 'git checkout master &&
d492b31c 72 test_must_fail git apply --check C.diff'
41ac414e
JH
73
74test_expect_success \
75 'check incomplete binary diff with replacement -- should fail.' '
3604e7c5 76 git checkout master &&
d492b31c 77 test_must_fail git apply --check --allow-binary-replacement B.diff
41ac414e 78'
27dedf0c 79
41ac414e
JH
80test_expect_success \
81 'check incomplete binary diff with replacement (copy) -- should fail.' '
3604e7c5 82 git checkout master &&
d492b31c 83 test_must_fail git apply --check --allow-binary-replacement C.diff
41ac414e 84'
27dedf0c
JH
85
86test_expect_success 'check binary diff with replacement.' \
a48fcd83 87 'git checkout master &&
5be60078 88 git apply --check --allow-binary-replacement BF.diff'
27dedf0c
JH
89
90test_expect_success 'check binary diff with replacement (copy).' \
a48fcd83 91 'git checkout master &&
5be60078 92 git apply --check --allow-binary-replacement CF.diff'
27dedf0c
JH
93
94# Now we start applying them.
95
96do_reset () {
41ac414e 97 rm -f file? &&
3604e7c5
NS
98 git reset --hard &&
99 git checkout -f master
27dedf0c
JH
100}
101
41ac414e
JH
102test_expect_success 'apply binary diff -- should fail.' \
103 'do_reset &&
d492b31c 104 test_must_fail git apply B.diff'
27dedf0c 105
41ac414e
JH
106test_expect_success 'apply binary diff -- should fail.' \
107 'do_reset &&
d492b31c 108 test_must_fail git apply --index B.diff'
27dedf0c 109
41ac414e
JH
110test_expect_success 'apply binary diff (copy) -- should fail.' \
111 'do_reset &&
d492b31c 112 test_must_fail git apply C.diff'
27dedf0c 113
41ac414e
JH
114test_expect_success 'apply binary diff (copy) -- should fail.' \
115 'do_reset &&
d492b31c 116 test_must_fail git apply --index C.diff'
27dedf0c 117
24305cd7
JK
118test_expect_success 'apply binary diff with full-index' '
119 do_reset &&
120 git apply B-index.diff
121'
122
123test_expect_success 'apply binary diff with full-index (copy)' '
124 do_reset &&
125 git apply C-index.diff
126'
127
128test_expect_success 'apply full-index binary diff in new repo' '
129 (cd other-repo &&
130 do_reset &&
131 test_must_fail git apply ../B-index.diff)
132'
133
2b6eef94 134test_expect_success 'apply binary diff without replacement.' \
41ac414e 135 'do_reset &&
5be60078 136 git apply BF.diff'
27dedf0c 137
2b6eef94 138test_expect_success 'apply binary diff without replacement (copy).' \
41ac414e 139 'do_reset &&
5be60078 140 git apply CF.diff'
27dedf0c
JH
141
142test_expect_success 'apply binary diff.' \
41ac414e 143 'do_reset &&
5be60078
JH
144 git apply --allow-binary-replacement --index BF.diff &&
145 test -z "$(git diff --name-status binary)"'
27dedf0c
JH
146
147test_expect_success 'apply binary diff (copy).' \
41ac414e 148 'do_reset &&
5be60078
JH
149 git apply --allow-binary-replacement --index CF.diff &&
150 test -z "$(git diff --name-status binary)"'
27dedf0c 151
6a2abdc1
JH
152test_expect_success 'apply binary -p0 diff' '
153 do_reset &&
154 git apply -p0 --index B0.diff &&
155 test -z "$(git diff --name-status binary -- file3)"
156'
157
27dedf0c 158test_done