t: add test functions to translate hash-related values
[git/raj.git] / t / t4103-apply-binary.sh
blob1b420e3b5fc2a7130d2b10bcd5660670b9d780c8
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git apply handling binary patches
9 . ./test-lib.sh
11 test_expect_success 'setup' '
12 cat >file1 <<-\EOF &&
13 A quick brown fox jumps over the lazy dog.
14 A tiny little penguin runs around in circles.
15 There is a flag with Linux written on it.
16 A slow black-and-white panda just sits there,
17 munching on his bamboo.
18 EOF
19 cat file1 >file2 &&
20 cat file1 >file4 &&
22 git update-index --add --remove file1 file2 file4 &&
23 git commit -m "Initial Version" 2>/dev/null &&
25 git checkout -b binary &&
26 perl -pe "y/x/\000/" <file1 >file3 &&
27 cat file3 >file4 &&
28 git add file2 &&
29 perl -pe "y/\000/v/" <file3 >file1 &&
30 rm -f file2 &&
31 git update-index --add --remove file1 file2 file3 file4 &&
32 git commit -m "Second Version" &&
34 git diff-tree -p master binary >B.diff &&
35 git diff-tree -p -C master binary >C.diff &&
37 git diff-tree -p --binary master binary >BF.diff &&
38 git diff-tree -p --binary -C master binary >CF.diff &&
40 git diff-tree -p --full-index master binary >B-index.diff &&
41 git diff-tree -p -C --full-index master binary >C-index.diff &&
43 git diff-tree -p --binary --no-prefix master binary -- file3 >B0.diff &&
45 git init other-repo &&
47 cd other-repo &&
48 git fetch .. master &&
49 git reset --hard FETCH_HEAD
53 test_expect_success 'stat binary diff -- should not fail.' \
54 'git checkout master &&
55 git apply --stat --summary B.diff'
57 test_expect_success 'stat binary -p0 diff -- should not fail.' '
58 git checkout master &&
59 git apply --stat -p0 B0.diff
62 test_expect_success 'stat binary diff (copy) -- should not fail.' \
63 'git checkout master &&
64 git apply --stat --summary C.diff'
66 test_expect_success 'check binary diff -- should fail.' \
67 'git checkout master &&
68 test_must_fail git apply --check B.diff'
70 test_expect_success 'check binary diff (copy) -- should fail.' \
71 'git checkout master &&
72 test_must_fail git apply --check C.diff'
74 test_expect_success \
75 'check incomplete binary diff with replacement -- should fail.' '
76 git checkout master &&
77 test_must_fail git apply --check --allow-binary-replacement B.diff
80 test_expect_success \
81 'check incomplete binary diff with replacement (copy) -- should fail.' '
82 git checkout master &&
83 test_must_fail git apply --check --allow-binary-replacement C.diff
86 test_expect_success 'check binary diff with replacement.' \
87 'git checkout master &&
88 git apply --check --allow-binary-replacement BF.diff'
90 test_expect_success 'check binary diff with replacement (copy).' \
91 'git checkout master &&
92 git apply --check --allow-binary-replacement CF.diff'
94 # Now we start applying them.
96 do_reset () {
97 rm -f file? &&
98 git reset --hard &&
99 git checkout -f master
102 test_expect_success 'apply binary diff -- should fail.' \
103 'do_reset &&
104 test_must_fail git apply B.diff'
106 test_expect_success 'apply binary diff -- should fail.' \
107 'do_reset &&
108 test_must_fail git apply --index B.diff'
110 test_expect_success 'apply binary diff (copy) -- should fail.' \
111 'do_reset &&
112 test_must_fail git apply C.diff'
114 test_expect_success 'apply binary diff (copy) -- should fail.' \
115 'do_reset &&
116 test_must_fail git apply --index C.diff'
118 test_expect_success 'apply binary diff with full-index' '
119 do_reset &&
120 git apply B-index.diff
123 test_expect_success 'apply binary diff with full-index (copy)' '
124 do_reset &&
125 git apply C-index.diff
128 test_expect_success 'apply full-index binary diff in new repo' '
129 (cd other-repo &&
130 do_reset &&
131 test_must_fail git apply ../B-index.diff)
134 test_expect_success 'apply binary diff without replacement.' \
135 'do_reset &&
136 git apply BF.diff'
138 test_expect_success 'apply binary diff without replacement (copy).' \
139 'do_reset &&
140 git apply CF.diff'
142 test_expect_success 'apply binary diff.' \
143 'do_reset &&
144 git apply --allow-binary-replacement --index BF.diff &&
145 test -z "$(git diff --name-status binary)"'
147 test_expect_success 'apply binary diff (copy).' \
148 'do_reset &&
149 git apply --allow-binary-replacement --index CF.diff &&
150 test -z "$(git diff --name-status binary)"'
152 test_expect_success 'apply binary -p0 diff' '
153 do_reset &&
154 git apply -p0 --index B0.diff &&
155 test -z "$(git diff --name-status binary -- file3)"
158 test_done