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
test_expect_success 'setup' '
12cat >file1 <<-\EOF &&
13A quick brown fox jumps over the lazy dog.
14A tiny little penguin runs around in circles.
15There is a flag with Linux written on it.
16A slow black-and-white panda just sits there,
17munching on his bamboo.
18EOF
19cat file1 >file2 &&
20cat file1 >file4 &&
2122
git update-index --add --remove file1 file2 file4 &&
23git commit -m "Initial Version" 2>/dev/null &&
2425
git checkout -b binary &&
26perl -pe "y/x/\000/" <file1 >file3 &&
27cat file3 >file4 &&
28git add file2 &&
29perl -pe "y/\000/v/" <file3 >file1 &&
30rm -f file2 &&
31git update-index --add --remove file1 file2 file3 file4 &&
32git commit -m "Second Version" &&
3334
git diff-tree -p master binary >B.diff &&
35git diff-tree -p -C master binary >C.diff &&
3637
git diff-tree -p --binary master binary >BF.diff &&
38git diff-tree -p --binary -C master binary >CF.diff &&
3940
git diff-tree -p --full-index master binary >B-index.diff &&
41git diff-tree -p -C --full-index master binary >C-index.diff &&
4243
git diff-tree -p --binary --no-prefix master binary -- file3 >B0.diff &&
4445
git init other-repo &&
46(
47cd other-repo &&
48git fetch .. master &&
49git reset --hard FETCH_HEAD
50)
51'
5253
test_expect_success 'stat binary diff -- should not fail.' \
54'git checkout master &&
55git apply --stat --summary B.diff'
5657
test_expect_success 'stat binary -p0 diff -- should not fail.' '
58git checkout master &&
59git apply --stat -p0 B0.diff
60'
6162
test_expect_success 'stat binary diff (copy) -- should not fail.' \
63'git checkout master &&
64git apply --stat --summary C.diff'
6566
test_expect_success 'check binary diff -- should fail.' \
67'git checkout master &&
68test_must_fail git apply --check B.diff'
6970
test_expect_success 'check binary diff (copy) -- should fail.' \
71'git checkout master &&
72test_must_fail git apply --check C.diff'
7374
test_expect_success \
75'check incomplete binary diff with replacement -- should fail.' '
76git checkout master &&
77test_must_fail git apply --check --allow-binary-replacement B.diff
78'
7980
test_expect_success \
81'check incomplete binary diff with replacement (copy) -- should fail.' '
82git checkout master &&
83test_must_fail git apply --check --allow-binary-replacement C.diff
84'
8586
test_expect_success 'check binary diff with replacement.' \
87'git checkout master &&
88git apply --check --allow-binary-replacement BF.diff'
8990
test_expect_success 'check binary diff with replacement (copy).' \
91'git checkout master &&
92git apply --check --allow-binary-replacement CF.diff'
9394
# Now we start applying them.
9596
do_reset () {
97rm -f file? &&
98git reset --hard &&
99git checkout -f master
100}
101102
test_expect_success 'apply binary diff -- should fail.' \
103'do_reset &&
104test_must_fail git apply B.diff'
105106
test_expect_success 'apply binary diff -- should fail.' \
107'do_reset &&
108test_must_fail git apply --index B.diff'
109110
test_expect_success 'apply binary diff (copy) -- should fail.' \
111'do_reset &&
112test_must_fail git apply C.diff'
113114
test_expect_success 'apply binary diff (copy) -- should fail.' \
115'do_reset &&
116test_must_fail git apply --index C.diff'
117118
test_expect_success 'apply binary diff with full-index' '
119do_reset &&
120git apply B-index.diff
121'
122123
test_expect_success 'apply binary diff with full-index (copy)' '
124do_reset &&
125git apply C-index.diff
126'
127128
test_expect_success 'apply full-index binary diff in new repo' '
129(cd other-repo &&
130do_reset &&
131test_must_fail git apply ../B-index.diff)
132'
133134
test_expect_success 'apply binary diff without replacement.' \
135'do_reset &&
136git apply BF.diff'
137138
test_expect_success 'apply binary diff without replacement (copy).' \
139'do_reset &&
140git apply CF.diff'
141142
test_expect_success 'apply binary diff.' \
143'do_reset &&
144git apply --allow-binary-replacement --index BF.diff &&
145test -z "$(git diff --name-status binary)"'
146147
test_expect_success 'apply binary diff (copy).' \
148'do_reset &&
149git apply --allow-binary-replacement --index CF.diff &&
150test -z "$(git diff --name-status binary)"'
151152
test_expect_success 'apply binary -p0 diff' '
153do_reset &&
154git apply -p0 --index B0.diff &&
155test -z "$(git diff --name-status binary -- file3)"
156'
157158
test_done