]>
Commit | Line | Data |
---|---|---|
f32e9852 WP |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2010 Will Palmer | |
4 | # | |
5 | ||
6 | test_description='git merge-tree' | |
7ff24785 ÆAB |
7 | |
8 | TEST_PASSES_SANITIZE_LEAK=true | |
f32e9852 WP |
9 | . ./test-lib.sh |
10 | ||
11 | test_expect_success setup ' | |
12 | test_commit "initial" "initial-file" "initial" | |
13 | ' | |
14 | ||
15 | test_expect_success 'file add A, !B' ' | |
525a7f17 | 16 | git reset --hard initial && |
17 | test_commit "add-a-not-b" "ONE" "AAA" && | |
18 | git merge-tree initial initial add-a-not-b >actual && | |
19 | cat >expected <<EXPECTED && | |
f32e9852 | 20 | added in remote |
525a7f17 | 21 | their 100644 $(git rev-parse HEAD:ONE) ONE |
f32e9852 WP |
22 | @@ -0,0 +1 @@ |
23 | +AAA | |
24 | EXPECTED | |
25 | ||
f32e9852 WP |
26 | test_cmp expected actual |
27 | ' | |
28 | ||
21baa6e0 | 29 | test_expect_success 'file add !A, B' ' |
f32e9852 WP |
30 | git reset --hard initial && |
31 | test_commit "add-not-a-b" "ONE" "AAA" && | |
32 | git merge-tree initial add-not-a-b initial >actual && | |
1c5e94f4 | 33 | test_must_be_empty actual |
f32e9852 WP |
34 | ' |
35 | ||
36 | test_expect_success 'file add A, B (same)' ' | |
f32e9852 WP |
37 | git reset --hard initial && |
38 | test_commit "add-a-b-same-A" "ONE" "AAA" && | |
39 | git reset --hard initial && | |
40 | test_commit "add-a-b-same-B" "ONE" "AAA" && | |
41 | git merge-tree initial add-a-b-same-A add-a-b-same-B >actual && | |
1c5e94f4 | 42 | test_must_be_empty actual |
f32e9852 WP |
43 | ' |
44 | ||
45 | test_expect_success 'file add A, B (different)' ' | |
525a7f17 | 46 | git reset --hard initial && |
47 | test_commit "add-a-b-diff-A" "ONE" "AAA" && | |
48 | git reset --hard initial && | |
49 | test_commit "add-a-b-diff-B" "ONE" "BBB" && | |
50 | git merge-tree initial add-a-b-diff-A add-a-b-diff-B >actual && | |
51 | cat >expected <<EXPECTED && | |
f32e9852 | 52 | added in both |
525a7f17 | 53 | our 100644 $(git rev-parse add-a-b-diff-A:ONE) ONE |
54 | their 100644 $(git rev-parse add-a-b-diff-B:ONE) ONE | |
f32e9852 WP |
55 | @@ -1 +1,5 @@ |
56 | +<<<<<<< .our | |
57 | AAA | |
58 | +======= | |
59 | +BBB | |
60 | +>>>>>>> .their | |
61 | EXPECTED | |
62 | ||
f32e9852 WP |
63 | test_cmp expected actual |
64 | ' | |
65 | ||
66 | test_expect_success 'file change A, !B' ' | |
f32e9852 WP |
67 | git reset --hard initial && |
68 | test_commit "change-a-not-b" "initial-file" "BBB" && | |
69 | git merge-tree initial change-a-not-b initial >actual && | |
1c5e94f4 | 70 | test_must_be_empty actual |
f32e9852 WP |
71 | ' |
72 | ||
73 | test_expect_success 'file change !A, B' ' | |
525a7f17 | 74 | git reset --hard initial && |
75 | test_commit "change-not-a-b" "initial-file" "BBB" && | |
76 | git merge-tree initial initial change-not-a-b >actual && | |
77 | cat >expected <<EXPECTED && | |
f32e9852 | 78 | merged |
525a7f17 | 79 | result 100644 $(git rev-parse change-a-not-b:initial-file) initial-file |
80 | our 100644 $(git rev-parse initial:initial-file ) initial-file | |
f32e9852 WP |
81 | @@ -1 +1 @@ |
82 | -initial | |
83 | +BBB | |
84 | EXPECTED | |
85 | ||
f32e9852 WP |
86 | test_cmp expected actual |
87 | ' | |
88 | ||
89 | test_expect_success 'file change A, B (same)' ' | |
f32e9852 WP |
90 | git reset --hard initial && |
91 | test_commit "change-a-b-same-A" "initial-file" "AAA" && | |
92 | git reset --hard initial && | |
93 | test_commit "change-a-b-same-B" "initial-file" "AAA" && | |
94 | git merge-tree initial change-a-b-same-A change-a-b-same-B >actual && | |
1c5e94f4 | 95 | test_must_be_empty actual |
f32e9852 WP |
96 | ' |
97 | ||
98 | test_expect_success 'file change A, B (different)' ' | |
525a7f17 | 99 | git reset --hard initial && |
100 | test_commit "change-a-b-diff-A" "initial-file" "AAA" && | |
101 | git reset --hard initial && | |
102 | test_commit "change-a-b-diff-B" "initial-file" "BBB" && | |
103 | git merge-tree initial change-a-b-diff-A change-a-b-diff-B >actual && | |
104 | cat >expected <<EXPECTED && | |
f32e9852 | 105 | changed in both |
525a7f17 | 106 | base 100644 $(git rev-parse initial:initial-file ) initial-file |
107 | our 100644 $(git rev-parse change-a-b-diff-A:initial-file) initial-file | |
108 | their 100644 $(git rev-parse change-a-b-diff-B:initial-file) initial-file | |
f32e9852 WP |
109 | @@ -1 +1,5 @@ |
110 | +<<<<<<< .our | |
111 | AAA | |
112 | +======= | |
113 | +BBB | |
114 | +>>>>>>> .their | |
115 | EXPECTED | |
116 | ||
f32e9852 WP |
117 | test_cmp expected actual |
118 | ' | |
119 | ||
120 | test_expect_success 'file change A, B (mixed)' ' | |
f32e9852 WP |
121 | git reset --hard initial && |
122 | test_commit "change-a-b-mix-base" "ONE" " | |
123 | AAA | |
124 | AAA | |
125 | AAA | |
126 | AAA | |
127 | AAA | |
128 | AAA | |
129 | AAA | |
130 | AAA | |
131 | AAA | |
132 | AAA | |
133 | AAA | |
134 | AAA | |
135 | AAA | |
136 | AAA | |
137 | AAA" && | |
138 | test_commit "change-a-b-mix-A" "ONE" \ | |
139 | "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/BBB/;}" <ONE)" && | |
140 | git reset --hard change-a-b-mix-base && | |
141 | test_commit "change-a-b-mix-B" "ONE" \ | |
142 | "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/CCC/;}" <ONE)" && | |
143 | git merge-tree change-a-b-mix-base change-a-b-mix-A change-a-b-mix-B \ | |
144 | >actual && | |
525a7f17 | 145 | |
146 | cat >expected <<EXPECTED && | |
147 | changed in both | |
148 | base 100644 $(git rev-parse change-a-b-mix-base:ONE) ONE | |
149 | our 100644 $(git rev-parse change-a-b-mix-A:ONE ) ONE | |
150 | their 100644 $(git rev-parse change-a-b-mix-B:ONE ) ONE | |
151 | @@ -7,7 +7,11 @@ | |
152 | AAA | |
153 | AAA | |
154 | AAA | |
155 | +<<<<<<< .our | |
156 | BBB | |
157 | +======= | |
158 | +CCC | |
159 | +>>>>>>> .their | |
160 | AAA | |
161 | AAA | |
162 | AAA | |
163 | EXPECTED | |
164 | ||
f32e9852 WP |
165 | test_cmp expected actual |
166 | ' | |
167 | ||
168 | test_expect_success 'file remove A, !B' ' | |
f32e9852 WP |
169 | git reset --hard initial && |
170 | test_commit "rm-a-not-b-base" "ONE" "AAA" && | |
171 | git rm ONE && | |
172 | git commit -m "rm-a-not-b" && | |
173 | git tag "rm-a-not-b" && | |
174 | git merge-tree rm-a-not-b-base rm-a-not-b rm-a-not-b-base >actual && | |
1c5e94f4 | 175 | test_must_be_empty actual |
f32e9852 WP |
176 | ' |
177 | ||
21baa6e0 | 178 | test_expect_success 'file remove !A, B' ' |
f32e9852 WP |
179 | git reset --hard initial && |
180 | test_commit "rm-not-a-b-base" "ONE" "AAA" && | |
181 | git rm ONE && | |
182 | git commit -m "rm-not-a-b" && | |
183 | git tag "rm-not-a-b" && | |
184 | git merge-tree rm-a-not-b-base rm-a-not-b-base rm-a-not-b >actual && | |
525a7f17 | 185 | cat >expected <<EXPECTED && |
186 | removed in remote | |
187 | base 100644 $(git rev-parse rm-a-not-b-base:ONE) ONE | |
188 | our 100644 $(git rev-parse rm-a-not-b-base:ONE) ONE | |
189 | @@ -1 +0,0 @@ | |
190 | -AAA | |
191 | EXPECTED | |
192 | ||
f32e9852 WP |
193 | test_cmp expected actual |
194 | ' | |
195 | ||
ab5f4242 | 196 | test_expect_success 'file remove A, B (same)' ' |
ab5f4242 JK |
197 | git reset --hard initial && |
198 | test_commit "rm-a-b-base" "ONE" "AAA" && | |
199 | git rm ONE && | |
200 | git commit -m "rm-a-b" && | |
201 | git tag "rm-a-b" && | |
202 | git merge-tree rm-a-b-base rm-a-b rm-a-b >actual && | |
1c5e94f4 | 203 | test_must_be_empty actual |
ab5f4242 JK |
204 | ' |
205 | ||
21baa6e0 | 206 | test_expect_success 'file change A, remove B' ' |
f32e9852 WP |
207 | git reset --hard initial && |
208 | test_commit "change-a-rm-b-base" "ONE" "AAA" && | |
209 | test_commit "change-a-rm-b-A" "ONE" "BBB" && | |
210 | git reset --hard change-a-rm-b-base && | |
211 | git rm ONE && | |
212 | git commit -m "change-a-rm-b-B" && | |
213 | git tag "change-a-rm-b-B" && | |
214 | git merge-tree change-a-rm-b-base change-a-rm-b-A change-a-rm-b-B \ | |
215 | >actual && | |
525a7f17 | 216 | cat >expected <<EXPECTED && |
217 | removed in remote | |
218 | base 100644 $(git rev-parse change-a-rm-b-base:ONE) ONE | |
219 | our 100644 $(git rev-parse change-a-rm-b-A:ONE ) ONE | |
220 | @@ -1 +0,0 @@ | |
221 | -BBB | |
222 | EXPECTED | |
223 | ||
f32e9852 WP |
224 | test_cmp expected actual |
225 | ' | |
226 | ||
227 | test_expect_success 'file remove A, change B' ' | |
f32e9852 WP |
228 | git reset --hard initial && |
229 | test_commit "rm-a-change-b-base" "ONE" "AAA" && | |
230 | ||
231 | git rm ONE && | |
232 | git commit -m "rm-a-change-b-A" && | |
233 | git tag "rm-a-change-b-A" && | |
234 | git reset --hard rm-a-change-b-base && | |
235 | test_commit "rm-a-change-b-B" "ONE" "BBB" && | |
236 | git merge-tree rm-a-change-b-base rm-a-change-b-A rm-a-change-b-B \ | |
237 | >actual && | |
525a7f17 | 238 | cat >expected <<EXPECTED && |
239 | removed in local | |
240 | base 100644 $(git rev-parse rm-a-change-b-base:ONE) ONE | |
241 | their 100644 $(git rev-parse rm-a-change-b-B:ONE ) ONE | |
242 | EXPECTED | |
f32e9852 WP |
243 | test_cmp expected actual |
244 | ' | |
245 | ||
94883b43 | 246 | test_expect_success 'tree add A, B (same)' ' |
94883b43 JK |
247 | git reset --hard initial && |
248 | mkdir sub && | |
249 | test_commit "add sub/file" "sub/file" "file" add-tree-A && | |
250 | git merge-tree initial add-tree-A add-tree-A >actual && | |
1c5e94f4 | 251 | test_must_be_empty actual |
94883b43 JK |
252 | ' |
253 | ||
254 | test_expect_success 'tree add A, B (different)' ' | |
525a7f17 | 255 | git reset --hard initial && |
256 | mkdir sub && | |
257 | test_commit "add sub/file" "sub/file" "AAA" add-tree-a-b-A && | |
258 | git reset --hard initial && | |
259 | mkdir sub && | |
260 | test_commit "add sub/file" "sub/file" "BBB" add-tree-a-b-B && | |
261 | git merge-tree initial add-tree-a-b-A add-tree-a-b-B >actual && | |
262 | cat >expect <<-EOF && | |
94883b43 | 263 | added in both |
525a7f17 | 264 | our 100644 $(git rev-parse add-tree-a-b-A:sub/file) sub/file |
265 | their 100644 $(git rev-parse add-tree-a-b-B:sub/file) sub/file | |
94883b43 JK |
266 | @@ -1 +1,5 @@ |
267 | +<<<<<<< .our | |
268 | AAA | |
269 | +======= | |
270 | +BBB | |
271 | +>>>>>>> .their | |
272 | EOF | |
94883b43 JK |
273 | test_cmp expect actual |
274 | ' | |
275 | ||
276 | test_expect_success 'tree unchanged A, removed B' ' | |
94883b43 JK |
277 | git reset --hard initial && |
278 | mkdir sub && | |
279 | test_commit "add sub/file" "sub/file" "AAA" tree-remove-b-initial && | |
280 | git rm sub/file && | |
281 | test_tick && | |
282 | git commit -m "remove sub/file" && | |
283 | git tag tree-remove-b-B && | |
284 | git merge-tree tree-remove-b-initial tree-remove-b-initial tree-remove-b-B >actual && | |
525a7f17 | 285 | cat >expect <<-EOF && |
286 | removed in remote | |
287 | base 100644 $(git rev-parse tree-remove-b-initial:sub/file) sub/file | |
288 | our 100644 $(git rev-parse tree-remove-b-initial:sub/file) sub/file | |
289 | @@ -1 +0,0 @@ | |
290 | -AAA | |
291 | EOF | |
94883b43 JK |
292 | test_cmp expect actual |
293 | ' | |
294 | ||
35ffe758 | 295 | test_expect_success 'turn file to tree' ' |
8dd15c6a JH |
296 | git reset --hard initial && |
297 | rm initial-file && | |
298 | mkdir initial-file && | |
299 | test_commit "turn-file-to-tree" "initial-file/ONE" "CCC" && | |
300 | git merge-tree initial initial turn-file-to-tree >actual && | |
525a7f17 | 301 | cat >expect <<-EOF && |
8dd15c6a | 302 | added in remote |
525a7f17 | 303 | their 100644 $(git rev-parse turn-file-to-tree:initial-file/ONE) initial-file/ONE |
8dd15c6a JH |
304 | @@ -0,0 +1 @@ |
305 | +CCC | |
306 | removed in remote | |
525a7f17 | 307 | base 100644 $(git rev-parse initial:initial-file) initial-file |
308 | our 100644 $(git rev-parse initial:initial-file) initial-file | |
8dd15c6a JH |
309 | @@ -1 +0,0 @@ |
310 | -initial | |
311 | EOF | |
312 | test_cmp expect actual | |
313 | ' | |
314 | ||
35ffe758 | 315 | test_expect_success 'turn tree to file' ' |
8dd15c6a JH |
316 | git reset --hard initial && |
317 | mkdir dir && | |
318 | test_commit "add-tree" "dir/path" "AAA" && | |
319 | test_commit "add-another-tree" "dir/another" "BBB" && | |
320 | rm -fr dir && | |
321 | test_commit "make-file" "dir" "CCC" && | |
322 | git merge-tree add-tree add-another-tree make-file >actual && | |
525a7f17 | 323 | cat >expect <<-EOF && |
8dd15c6a | 324 | removed in remote |
525a7f17 | 325 | base 100644 $(git rev-parse add-tree:dir/path) dir/path |
326 | our 100644 $(git rev-parse add-tree:dir/path) dir/path | |
8dd15c6a JH |
327 | @@ -1 +0,0 @@ |
328 | -AAA | |
329 | added in remote | |
525a7f17 | 330 | their 100644 $(git rev-parse make-file:dir) dir |
8dd15c6a JH |
331 | @@ -0,0 +1 @@ |
332 | +CCC | |
333 | EOF | |
334 | test_cmp expect actual | |
335 | ' | |
336 | ||
b6551fea DS |
337 | test_expect_success 'merge-tree respects core.useReplaceRefs=false' ' |
338 | test_commit merge-to && | |
339 | test_commit valid base && | |
340 | git reset --hard HEAD^ && | |
341 | test_commit malicious base && | |
342 | ||
343 | test_when_finished "git replace -d $(git rev-parse valid^0)" && | |
344 | git replace valid^0 malicious^0 && | |
345 | ||
346 | tree=$(git -c core.useReplaceRefs=true merge-tree --write-tree merge-to valid) && | |
347 | merged=$(git cat-file -p $tree:base) && | |
348 | test malicious = $merged && | |
349 | ||
350 | tree=$(git -c core.useReplaceRefs=false merge-tree --write-tree merge-to valid) && | |
351 | merged=$(git cat-file -p $tree:base) && | |
352 | test valid = $merged | |
353 | ' | |
354 | ||
f32e9852 | 355 | test_done |