3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git apply handling binary patches
9 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
10 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
14 test_expect_success 'setup' '
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.
25 git update-index --add --remove file1 file2 file4 &&
26 git commit -m "Initial Version" 2>/dev/null &&
28 git checkout -b binary &&
29 perl -pe "y/x/\000/" <file1 >file3 &&
32 perl -pe "y/\000/v/" <file3 >file1 &&
34 git update-index --add --remove file1 file2 file3 file4 &&
35 git commit -m "Second Version" &&
37 git diff-tree -p main binary >B.diff &&
38 git diff-tree -p -C main binary >C.diff &&
40 git diff-tree -p --binary main binary >BF.diff &&
41 git diff-tree -p --binary -C main binary >CF.diff &&
43 git diff-tree -p --full-index main binary >B-index.diff &&
44 git diff-tree -p -C --full-index main binary >C-index.diff &&
46 git diff-tree -p --binary --no-prefix main binary -- file3 >B0.diff &&
48 git init other-repo &&
52 git reset --hard FETCH_HEAD
56 test_expect_success 'stat binary diff -- should not fail.' \
58 git apply --stat --summary B.diff'
60 test_expect_success 'stat binary -p0 diff -- should not fail.' '
62 git apply --stat -p0 B0.diff
65 test_expect_success 'stat binary diff (copy) -- should not fail.' \
67 git apply --stat --summary C.diff'
69 test_expect_success 'check binary diff -- should fail.' \
71 test_must_fail git apply --check B.diff'
73 test_expect_success 'check binary diff (copy) -- should fail.' \
75 test_must_fail git apply --check C.diff'
78 'check incomplete binary diff with replacement -- should fail.' '
80 test_must_fail git apply --check --allow-binary-replacement B.diff
84 'check incomplete binary diff with replacement (copy) -- should fail.' '
86 test_must_fail git apply --check --allow-binary-replacement C.diff
89 test_expect_success 'check binary diff with replacement.' \
91 git apply --check --allow-binary-replacement BF.diff'
93 test_expect_success 'check binary diff with replacement (copy).' \
95 git apply --check --allow-binary-replacement CF.diff'
97 # Now we start applying them.
105 test_expect_success 'apply binary diff -- should fail.' \
107 test_must_fail git apply B.diff'
109 test_expect_success 'apply binary diff -- should fail.' \
111 test_must_fail git apply --index B.diff'
113 test_expect_success 'apply binary diff (copy) -- should fail.' \
115 test_must_fail git apply C.diff'
117 test_expect_success 'apply binary diff (copy) -- should fail.' \
119 test_must_fail git apply --index C.diff'
121 test_expect_success 'apply binary diff with full-index' '
123 git apply B-index.diff
126 test_expect_success 'apply binary diff with full-index (copy)' '
128 git apply C-index.diff
131 test_expect_success 'apply full-index binary diff in new repo' '
134 test_must_fail git apply ../B-index.diff)
137 test_expect_success 'apply binary diff without replacement.' \
141 test_expect_success 'apply binary diff without replacement (copy).' \
145 test_expect_success 'apply binary diff.' \
147 git apply --allow-binary-replacement --index BF.diff &&
148 test -z "$(git diff --name-status binary)"'
150 test_expect_success 'apply binary diff (copy).' \
152 git apply --allow-binary-replacement --index CF.diff &&
153 test -z "$(git diff --name-status binary)"'
155 test_expect_success 'apply binary -p0 diff' '
157 git apply -p0 --index B0.diff &&
158 test -z "$(git diff --name-status binary -- file3)"