completion: add 'symbolic-ref'
[alt-git.git] / t / t4103-apply-binary.sh
blobd370ecfe0d9eea752d81d02f50f5739bfc923b04
1 #!/bin/sh
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
12 . ./test-lib.sh
14 test_expect_success 'setup' '
15 cat >file1 <<-\EOF &&
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.
21 EOF
22 cat file1 >file2 &&
23 cat file1 >file4 &&
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 &&
30 cat file3 >file4 &&
31 git add file2 &&
32 perl -pe "y/\000/v/" <file3 >file1 &&
33 rm -f file2 &&
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 &&
50 cd other-repo &&
51 git fetch .. main &&
52 git reset --hard FETCH_HEAD
56 test_expect_success 'stat binary diff -- should not fail.' \
57 'git checkout main &&
58 git apply --stat --summary B.diff'
60 test_expect_success 'stat binary -p0 diff -- should not fail.' '
61 git checkout main &&
62 git apply --stat -p0 B0.diff
65 test_expect_success 'stat binary diff (copy) -- should not fail.' \
66 'git checkout main &&
67 git apply --stat --summary C.diff'
69 test_expect_success 'check binary diff -- should fail.' \
70 'git checkout main &&
71 test_must_fail git apply --check B.diff'
73 test_expect_success 'check binary diff (copy) -- should fail.' \
74 'git checkout main &&
75 test_must_fail git apply --check C.diff'
77 test_expect_success \
78 'check incomplete binary diff with replacement -- should fail.' '
79 git checkout main &&
80 test_must_fail git apply --check --allow-binary-replacement B.diff
83 test_expect_success \
84 'check incomplete binary diff with replacement (copy) -- should fail.' '
85 git checkout main &&
86 test_must_fail git apply --check --allow-binary-replacement C.diff
89 test_expect_success 'check binary diff with replacement.' \
90 'git checkout main &&
91 git apply --check --allow-binary-replacement BF.diff'
93 test_expect_success 'check binary diff with replacement (copy).' \
94 'git checkout main &&
95 git apply --check --allow-binary-replacement CF.diff'
97 # Now we start applying them.
99 do_reset () {
100 rm -f file? &&
101 git reset --hard &&
102 git checkout -f main
105 test_expect_success 'apply binary diff -- should fail.' \
106 'do_reset &&
107 test_must_fail git apply B.diff'
109 test_expect_success 'apply binary diff -- should fail.' \
110 'do_reset &&
111 test_must_fail git apply --index B.diff'
113 test_expect_success 'apply binary diff (copy) -- should fail.' \
114 'do_reset &&
115 test_must_fail git apply C.diff'
117 test_expect_success 'apply binary diff (copy) -- should fail.' \
118 'do_reset &&
119 test_must_fail git apply --index C.diff'
121 test_expect_success 'apply binary diff with full-index' '
122 do_reset &&
123 git apply B-index.diff
126 test_expect_success 'apply binary diff with full-index (copy)' '
127 do_reset &&
128 git apply C-index.diff
131 test_expect_success 'apply full-index binary diff in new repo' '
132 (cd other-repo &&
133 do_reset &&
134 test_must_fail git apply ../B-index.diff)
137 test_expect_success 'apply binary diff without replacement.' \
138 'do_reset &&
139 git apply BF.diff'
141 test_expect_success 'apply binary diff without replacement (copy).' \
142 'do_reset &&
143 git apply CF.diff'
145 test_expect_success 'apply binary diff.' \
146 'do_reset &&
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).' \
151 'do_reset &&
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' '
156 do_reset &&
157 git apply -p0 --index B0.diff &&
158 test -z "$(git diff --name-status binary -- file3)"
161 test_expect_success 'reject truncated binary diff' '
162 do_reset &&
164 # this length is calculated to get us very close to
165 # the 8192-byte strbuf we will use to read in the patch.
166 test-tool genrandom foo 6205 >file1 &&
167 git diff --binary >patch &&
169 # truncate the patch at the second "literal" line,
170 # but exclude the trailing newline. We must use perl
171 # for this, since tools like "sed" cannot reliably
172 # produce output without the trailing newline.
173 perl -pe "
174 if (/^literal/ && \$count++ >= 1) {
175 chomp;
176 print;
177 exit 0;
179 " <patch >patch.trunc &&
181 do_reset &&
182 test_must_fail git apply patch.trunc
184 test_done