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