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