1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
56
test_description='git apply handling binary patches
78
'
9. ./test-lib.sh
1011
# setup
1213
cat >file1 <<EOF
14A quick brown fox jumps over the lazy dog.
15A tiny little penguin runs around in circles.
16There is a flag with Linux written on it.
17A slow black-and-white panda just sits there,
18munching on his bamboo.
19EOF
20cat file1 >file2
21cat file1 >file4
2223
test_expect_success 'setup' "
24git update-index --add --remove file1 file2 file4 &&
25git commit -m 'Initial Version' 2>/dev/null &&
2627
git checkout -b binary &&
28perl -pe 'y/x/\000/' <file1 >file3 &&
29cat file3 >file4 &&
30git add file2 &&
31perl -pe 'y/\000/v/' <file3 >file1 &&
32rm -f file2 &&
33git update-index --add --remove file1 file2 file3 file4 &&
34git commit -m 'Second Version' &&
3536
git diff-tree -p master binary >B.diff &&
37git diff-tree -p -C master binary >C.diff &&
3839
git diff-tree -p --binary master binary >BF.diff &&
40git diff-tree -p --binary -C master binary >CF.diff
41"
4243
test_expect_success 'stat binary diff -- should not fail.' \
44'git checkout master
45git apply --stat --summary B.diff'
4647
test_expect_success 'stat binary diff (copy) -- should not fail.' \
48'git checkout master
49git apply --stat --summary C.diff'
5051
test_expect_success 'check binary diff -- should fail.' \
52'git checkout master &&
53test_must_fail git apply --check B.diff'
5455
test_expect_success 'check binary diff (copy) -- should fail.' \
56'git checkout master &&
57test_must_fail git apply --check C.diff'
5859
test_expect_success \
60'check incomplete binary diff with replacement -- should fail.' '
61git checkout master &&
62test_must_fail git apply --check --allow-binary-replacement B.diff
63'
6465
test_expect_success \
66'check incomplete binary diff with replacement (copy) -- should fail.' '
67git checkout master &&
68test_must_fail git apply --check --allow-binary-replacement C.diff
69'
7071
test_expect_success 'check binary diff with replacement.' \
72'git checkout master
73git apply --check --allow-binary-replacement BF.diff'
7475
test_expect_success 'check binary diff with replacement (copy).' \
76'git checkout master
77git apply --check --allow-binary-replacement CF.diff'
7879
# Now we start applying them.
8081
do_reset () {
82rm -f file? &&
83git reset --hard &&
84git checkout -f master
85}
8687
test_expect_success 'apply binary diff -- should fail.' \
88'do_reset &&
89test_must_fail git apply B.diff'
9091
test_expect_success 'apply binary diff -- should fail.' \
92'do_reset &&
93test_must_fail git apply --index B.diff'
9495
test_expect_success 'apply binary diff (copy) -- should fail.' \
96'do_reset &&
97test_must_fail git apply C.diff'
9899
test_expect_success 'apply binary diff (copy) -- should fail.' \
100'do_reset &&
101test_must_fail git apply --index C.diff'
102103
test_expect_success 'apply binary diff without replacement.' \
104'do_reset &&
105git apply BF.diff'
106107
test_expect_success 'apply binary diff without replacement (copy).' \
108'do_reset &&
109git apply CF.diff'
110111
test_expect_success 'apply binary diff.' \
112'do_reset &&
113git apply --allow-binary-replacement --index BF.diff &&
114test -z "$(git diff --name-status binary)"'
115116
test_expect_success 'apply binary diff (copy).' \
117'do_reset &&
118git apply --allow-binary-replacement --index CF.diff &&
119test -z "$(git diff --name-status binary)"'
120121
test_done