]>
Commit | Line | Data |
---|---|---|
2ecd9050 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Three way merge with read-tree -m | |
7 | ||
8 | This test tries three-way merge with read-tree -m | |
9 | ||
10 | There is one ancestor (called O for Original) and two branches A | |
11 | and B derived from it. We want to do a 3-way merge between A and | |
12 | B, using O as the common ancestor. | |
13 | ||
14 | merge A O B | |
15 | ||
16 | Decisions are made by comparing contents of O, A and B pathname | |
17 | by pathname. The result is determined by the following guiding | |
18 | principle: | |
19 | ||
20 | - If only A does something to it and B does not touch it, take | |
21 | whatever A does. | |
22 | ||
23 | - If only B does something to it and A does not touch it, take | |
24 | whatever B does. | |
25 | ||
26 | - If both A and B does something but in the same way, take | |
27 | whatever they do. | |
28 | ||
29 | - If A and B does something but different things, we need a | |
30 | 3-way merge: | |
31 | ||
32 | - We cannot do anything about the following cases: | |
33 | ||
34 | * O does not have it. A and B both must be adding to the | |
35 | same path independently. | |
36 | ||
37 | * A deletes it. B must be modifying. | |
38 | ||
39 | - Otherwise, A and B are modifying. Run 3-way merge. | |
40 | ||
41 | First, the case matrix. | |
42 | ||
43 | - Vertical axis is for A'\''s actions. | |
44 | - Horizontal axis is for B'\''s actions. | |
45 | ||
46 | .----------------------------------------------------------------. | |
47 | | A B | No Action | Delete | Modify | Add | | |
48 | |------------+------------+------------+------------+------------| | |
49 | | No Action | | | | | | |
50 | | | select O | delete | select B | select B | | |
51 | | | | | | | | |
52 | |------------+------------+------------+------------+------------| | |
53 | | Delete | | | ********** | can | | |
54 | | | delete | delete | merge | not | | |
55 | | | | | | happen | | |
56 | |------------+------------+------------+------------+------------| | |
57 | | Modify | | ********** | ?????????? | can | | |
58 | | | select A | merge | select A=B | not | | |
59 | | | | | merge | happen | | |
60 | |------------+------------+------------+------------+------------| | |
61 | | Add | | can | can | ?????????? | | |
62 | | | select A | not | not | select A=B | | |
63 | | | | happen | happen | merge | | |
64 | .----------------------------------------------------------------. | |
65 | ||
66 | In addition: | |
67 | ||
68 | SS: a special case of MM, where A and B makes the same modification. | |
69 | LL: a special case of AA, where A and B creates the same file. | |
70 | TT: a special case of MM, where A and B makes mergeable changes. | |
71 | DF: a special case, where A makes a directory and B makes a file. | |
72 | ||
73 | ' | |
98300c81 ÆAB |
74 | |
75 | TEST_PASSES_SANITIZE_LEAK=true | |
2ecd9050 | 76 | . ./test-lib.sh |
ea5070c9 | 77 | . "$TEST_DIRECTORY"/lib-read-tree.sh |
bfdbee98 | 78 | . "$TEST_DIRECTORY"/lib-read-tree-m-3way.sh |
2ecd9050 JH |
79 | |
80 | ################################################################ | |
32192e66 JH |
81 | # Trivial "majority when 3 stages exist" merge plus #2ALT, #3ALT |
82 | # and #5ALT trivial merges. | |
2ecd9050 | 83 | |
2ecd9050 | 84 | cat >expected <<\EOF |
2eab945e JH |
85 | 100644 X 2 AA |
86 | 100644 X 3 AA | |
32192e66 | 87 | 100644 X 0 AN |
2eab945e JH |
88 | 100644 X 1 DD |
89 | 100644 X 3 DF | |
90 | 100644 X 2 DF/DF | |
91 | 100644 X 1 DM | |
92 | 100644 X 3 DM | |
93 | 100644 X 1 DN | |
94 | 100644 X 3 DN | |
e7f9bc41 | 95 | 100644 X 0 LL |
2eab945e JH |
96 | 100644 X 1 MD |
97 | 100644 X 2 MD | |
98 | 100644 X 1 MM | |
99 | 100644 X 2 MM | |
100 | 100644 X 3 MM | |
101 | 100644 X 0 MN | |
32192e66 | 102 | 100644 X 0 NA |
2eab945e JH |
103 | 100644 X 1 ND |
104 | 100644 X 2 ND | |
105 | 100644 X 0 NM | |
106 | 100644 X 0 NN | |
107 | 100644 X 0 SS | |
108 | 100644 X 1 TT | |
109 | 100644 X 2 TT | |
110 | 100644 X 3 TT | |
111 | 100644 X 2 Z/AA | |
112 | 100644 X 3 Z/AA | |
32192e66 | 113 | 100644 X 0 Z/AN |
2eab945e JH |
114 | 100644 X 1 Z/DD |
115 | 100644 X 1 Z/DM | |
116 | 100644 X 3 Z/DM | |
117 | 100644 X 1 Z/DN | |
118 | 100644 X 3 Z/DN | |
119 | 100644 X 1 Z/MD | |
120 | 100644 X 2 Z/MD | |
121 | 100644 X 1 Z/MM | |
122 | 100644 X 2 Z/MM | |
123 | 100644 X 3 Z/MM | |
124 | 100644 X 0 Z/MN | |
32192e66 | 125 | 100644 X 0 Z/NA |
2eab945e JH |
126 | 100644 X 1 Z/ND |
127 | 100644 X 2 Z/ND | |
128 | 100644 X 0 Z/NM | |
129 | 100644 X 0 Z/NN | |
2ecd9050 JH |
130 | EOF |
131 | ||
f225b218 | 132 | check_result () { |
2ece6ad2 | 133 | git ls-files --stage | sed -e 's/ '"$OID_REGEX"' / X /' >current && |
0b8b25f6 | 134 | test_cmp expected current |
f225b218 | 135 | } |
7d95ee93 JH |
136 | |
137 | # This is done on an empty work directory, which is the normal | |
138 | # merge person behaviour. | |
0b8b25f6 SB |
139 | test_expect_success '3-way merge with git read-tree -m, empty cache' ' |
140 | rm -fr [NDMALTS][NDMALTSF] Z && | |
141 | rm .git/index && | |
142 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
143 | check_result | |
144 | ' | |
7d95ee93 JH |
145 | |
146 | # This starts out with the first head, which is the normal | |
147 | # patch submitter behaviour. | |
0b8b25f6 SB |
148 | test_expect_success '3-way merge with git read-tree -m, match H' ' |
149 | rm -fr [NDMALTS][NDMALTSF] Z && | |
150 | rm .git/index && | |
151 | read_tree_must_succeed $tree_A && | |
152 | git checkout-index -f -u -a && | |
153 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
154 | check_result | |
155 | ' | |
f225b218 JH |
156 | |
157 | : <<\END_OF_CASE_TABLE | |
158 | ||
159 | We have so far tested only empty index and clean-and-matching-A index | |
160 | case which are trivial. Make sure index requirements are also | |
3e03aaf5 | 161 | checked. |
f225b218 | 162 | |
5be60078 | 163 | "git read-tree -m O A B" |
f225b218 JH |
164 | |
165 | O A B result index requirements | |
166 | ------------------------------------------------------------------- | |
167 | 1 missing missing missing - must not exist. | |
168 | ------------------------------------------------------------------ | |
3e03aaf5 | 169 | 2 missing missing exists take B* must match B, if exists. |
f225b218 | 170 | ------------------------------------------------------------------ |
3e03aaf5 | 171 | 3 missing exists missing take A* must match A, if exists. |
f225b218 JH |
172 | ------------------------------------------------------------------ |
173 | 4 missing exists A!=B no merge must match A and be | |
174 | up-to-date, if exists. | |
175 | ------------------------------------------------------------------ | |
3e03aaf5 | 176 | 5 missing exists A==B take A must match A, if exists. |
f225b218 | 177 | ------------------------------------------------------------------ |
3e03aaf5 | 178 | 6 exists missing missing remove must not exist. |
f225b218 JH |
179 | ------------------------------------------------------------------ |
180 | 7 exists missing O!=B no merge must not exist. | |
181 | ------------------------------------------------------------------ | |
3e03aaf5 | 182 | 8 exists missing O==B remove must not exist. |
f225b218 JH |
183 | ------------------------------------------------------------------ |
184 | 9 exists O!=A missing no merge must match A and be | |
185 | up-to-date, if exists. | |
186 | ------------------------------------------------------------------ | |
ea4b52a8 | 187 | 10 exists O==A missing no merge must match A |
f225b218 JH |
188 | ------------------------------------------------------------------ |
189 | 11 exists O!=A O!=B no merge must match A and be | |
190 | A!=B up-to-date, if exists. | |
191 | ------------------------------------------------------------------ | |
192 | 12 exists O!=A O!=B take A must match A, if exists. | |
193 | A==B | |
194 | ------------------------------------------------------------------ | |
195 | 13 exists O!=A O==B take A must match A, if exists. | |
196 | ------------------------------------------------------------------ | |
3e03aaf5 | 197 | 14 exists O==A O!=B take B if exists, must either (1) |
f225b218 JH |
198 | match A and be up-to-date, |
199 | or (2) match B. | |
200 | ------------------------------------------------------------------ | |
201 | 15 exists O==A O==B take B must match A if exists. | |
4d3fe0c5 JH |
202 | ------------------------------------------------------------------ |
203 | 16 exists O==A O==B barf must match A if exists. | |
204 | *multi* in one in another | |
f225b218 JH |
205 | ------------------------------------------------------------------- |
206 | ||
3e03aaf5 JH |
207 | Note: we need to be careful in case 2 and 3. The tree A may contain |
208 | DF (file) when tree B require DF to be a directory by having DF/DF | |
209 | (file). | |
f225b218 JH |
210 | |
211 | END_OF_CASE_TABLE | |
212 | ||
0b8b25f6 SB |
213 | test_expect_success '1 - must not have an entry not in A.' ' |
214 | rm -f .git/index XX && | |
215 | echo XX >XX && | |
216 | git update-index --add XX && | |
217 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
218 | ' | |
219 | ||
220 | test_expect_success '2 - must match B in !O && !A && B case.' ' | |
221 | rm -f .git/index NA && | |
222 | cp .orig-B/NA NA && | |
223 | git update-index --add NA && | |
224 | read_tree_must_succeed -m $tree_O $tree_A $tree_B | |
225 | ' | |
226 | ||
227 | test_expect_success '2 - matching B alone is OK in !O && !A && B case.' ' | |
228 | rm -f .git/index NA && | |
229 | cp .orig-B/NA NA && | |
230 | git update-index --add NA && | |
231 | echo extra >>NA && | |
232 | read_tree_must_succeed -m $tree_O $tree_A $tree_B | |
233 | ' | |
234 | ||
235 | test_expect_success '3 - must match A in !O && A && !B case.' ' | |
236 | rm -f .git/index AN && | |
237 | cp .orig-A/AN AN && | |
238 | git update-index --add AN && | |
239 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
240 | check_result | |
241 | ' | |
242 | ||
243 | test_expect_success '3 - matching A alone is OK in !O && A && !B case.' ' | |
244 | rm -f .git/index AN && | |
245 | cp .orig-A/AN AN && | |
246 | git update-index --add AN && | |
247 | echo extra >>AN && | |
248 | read_tree_must_succeed -m $tree_O $tree_A $tree_B | |
249 | ' | |
250 | ||
251 | test_expect_success '3 (fail) - must match A in !O && A && !B case.' ' | |
252 | rm -f .git/index AN && | |
253 | cp .orig-A/AN AN && | |
254 | echo extra >>AN && | |
255 | git update-index --add AN && | |
256 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
257 | ' | |
258 | ||
259 | test_expect_success '4 - must match and be up-to-date in !O && A && B && A!=B case.' ' | |
260 | rm -f .git/index AA && | |
261 | cp .orig-A/AA AA && | |
262 | git update-index --add AA && | |
263 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
264 | check_result | |
265 | ' | |
266 | ||
267 | test_expect_success '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' ' | |
268 | rm -f .git/index AA && | |
269 | cp .orig-A/AA AA && | |
270 | git update-index --add AA && | |
271 | echo extra >>AA && | |
272 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
273 | ' | |
274 | ||
275 | test_expect_success '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' ' | |
276 | rm -f .git/index AA && | |
277 | cp .orig-A/AA AA && | |
278 | echo extra >>AA && | |
279 | git update-index --add AA && | |
280 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
281 | ' | |
282 | ||
283 | test_expect_success '5 - must match in !O && A && B && A==B case.' ' | |
284 | rm -f .git/index LL && | |
285 | cp .orig-A/LL LL && | |
286 | git update-index --add LL && | |
287 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
288 | check_result | |
289 | ' | |
290 | ||
291 | test_expect_success '5 - must match in !O && A && B && A==B case.' ' | |
292 | rm -f .git/index LL && | |
293 | cp .orig-A/LL LL && | |
294 | git update-index --add LL && | |
295 | echo extra >>LL && | |
296 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
297 | check_result | |
298 | ' | |
299 | ||
300 | test_expect_success '5 (fail) - must match A in !O && A && B && A==B case.' ' | |
301 | rm -f .git/index LL && | |
302 | cp .orig-A/LL LL && | |
303 | echo extra >>LL && | |
304 | git update-index --add LL && | |
305 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
306 | ' | |
307 | ||
308 | test_expect_success '6 - must not exist in O && !A && !B case' ' | |
309 | rm -f .git/index DD && | |
310 | echo DD >DD && | |
311 | git update-index --add DD && | |
312 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
313 | ' | |
314 | ||
315 | test_expect_success '7 - must not exist in O && !A && B && O!=B case' ' | |
316 | rm -f .git/index DM && | |
317 | cp .orig-B/DM DM && | |
318 | git update-index --add DM && | |
319 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
320 | ' | |
321 | ||
322 | test_expect_success '8 - must not exist in O && !A && B && O==B case' ' | |
323 | rm -f .git/index DN && | |
324 | cp .orig-B/DN DN && | |
325 | git update-index --add DN && | |
326 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
327 | ' | |
328 | ||
329 | test_expect_success '9 - must match and be up-to-date in O && A && !B && O!=A case' ' | |
330 | rm -f .git/index MD && | |
331 | cp .orig-A/MD MD && | |
332 | git update-index --add MD && | |
333 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
334 | check_result | |
335 | ' | |
336 | ||
337 | test_expect_success '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' ' | |
338 | rm -f .git/index MD && | |
339 | cp .orig-A/MD MD && | |
340 | git update-index --add MD && | |
341 | echo extra >>MD && | |
342 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
343 | ' | |
344 | ||
345 | test_expect_success '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' ' | |
346 | rm -f .git/index MD && | |
347 | cp .orig-A/MD MD && | |
348 | echo extra >>MD && | |
349 | git update-index --add MD && | |
350 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
351 | ' | |
352 | ||
353 | test_expect_success '10 - must match and be up-to-date in O && A && !B && O==A case' ' | |
354 | rm -f .git/index ND && | |
355 | cp .orig-A/ND ND && | |
356 | git update-index --add ND && | |
357 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
358 | check_result | |
359 | ' | |
360 | ||
361 | test_expect_success '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' ' | |
362 | rm -f .git/index ND && | |
363 | cp .orig-A/ND ND && | |
364 | git update-index --add ND && | |
365 | echo extra >>ND && | |
366 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
367 | ' | |
368 | ||
369 | test_expect_success '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' ' | |
370 | rm -f .git/index ND && | |
371 | cp .orig-A/ND ND && | |
372 | echo extra >>ND && | |
373 | git update-index --add ND && | |
374 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
375 | ' | |
376 | ||
377 | test_expect_success '11 - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' ' | |
378 | rm -f .git/index MM && | |
379 | cp .orig-A/MM MM && | |
380 | git update-index --add MM && | |
381 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
382 | check_result | |
383 | ' | |
384 | ||
385 | test_expect_success '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' ' | |
386 | rm -f .git/index MM && | |
387 | cp .orig-A/MM MM && | |
388 | git update-index --add MM && | |
389 | echo extra >>MM && | |
390 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
391 | ' | |
392 | ||
393 | test_expect_success '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' ' | |
394 | rm -f .git/index MM && | |
395 | cp .orig-A/MM MM && | |
396 | echo extra >>MM && | |
397 | git update-index --add MM && | |
398 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
399 | ' | |
400 | ||
401 | test_expect_success '12 - must match A in O && A && B && O!=A && A==B case' ' | |
402 | rm -f .git/index SS && | |
403 | cp .orig-A/SS SS && | |
404 | git update-index --add SS && | |
405 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
406 | check_result | |
407 | ' | |
408 | ||
409 | test_expect_success '12 - must match A in O && A && B && O!=A && A==B case' ' | |
410 | rm -f .git/index SS && | |
411 | cp .orig-A/SS SS && | |
412 | git update-index --add SS && | |
413 | echo extra >>SS && | |
414 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
415 | check_result | |
416 | ' | |
417 | ||
418 | test_expect_success '12 (fail) - must match A in O && A && B && O!=A && A==B case' ' | |
419 | rm -f .git/index SS && | |
420 | cp .orig-A/SS SS && | |
421 | echo extra >>SS && | |
422 | git update-index --add SS && | |
423 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
424 | ' | |
425 | ||
426 | test_expect_success '13 - must match A in O && A && B && O!=A && O==B case' ' | |
427 | rm -f .git/index MN && | |
428 | cp .orig-A/MN MN && | |
429 | git update-index --add MN && | |
430 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
431 | check_result | |
432 | ' | |
433 | ||
434 | test_expect_success '13 - must match A in O && A && B && O!=A && O==B case' ' | |
435 | rm -f .git/index MN && | |
436 | cp .orig-A/MN MN && | |
437 | git update-index --add MN && | |
438 | echo extra >>MN && | |
439 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
440 | check_result | |
441 | ' | |
442 | ||
443 | test_expect_success '14 - must match and be up-to-date in O && A && B && O==A && O!=B case' ' | |
444 | rm -f .git/index NM && | |
445 | cp .orig-A/NM NM && | |
446 | git update-index --add NM && | |
447 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
448 | check_result | |
449 | ' | |
450 | ||
451 | test_expect_success '14 - may match B in O && A && B && O==A && O!=B case' ' | |
452 | rm -f .git/index NM && | |
453 | cp .orig-B/NM NM && | |
454 | git update-index --add NM && | |
455 | echo extra >>NM && | |
456 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
457 | check_result | |
458 | ' | |
459 | ||
460 | test_expect_success '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' ' | |
461 | rm -f .git/index NM && | |
462 | cp .orig-A/NM NM && | |
463 | git update-index --add NM && | |
464 | echo extra >>NM && | |
465 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
466 | ' | |
467 | ||
468 | test_expect_success '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' ' | |
469 | rm -f .git/index NM && | |
470 | cp .orig-A/NM NM && | |
471 | echo extra >>NM && | |
472 | git update-index --add NM && | |
473 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
474 | ' | |
475 | ||
476 | test_expect_success '15 - must match A in O && A && B && O==A && O==B case' ' | |
477 | rm -f .git/index NN && | |
478 | cp .orig-A/NN NN && | |
479 | git update-index --add NN && | |
480 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
481 | check_result | |
482 | ' | |
483 | ||
484 | test_expect_success '15 - must match A in O && A && B && O==A && O==B case' ' | |
485 | rm -f .git/index NN && | |
486 | cp .orig-A/NN NN && | |
487 | git update-index --add NN && | |
488 | echo extra >>NN && | |
489 | read_tree_must_succeed -m $tree_O $tree_A $tree_B && | |
490 | check_result | |
491 | ' | |
492 | ||
493 | test_expect_success '15 (fail) - must match A in O && A && B && O==A && O==B case' ' | |
494 | rm -f .git/index NN && | |
495 | cp .orig-A/NN NN && | |
496 | echo extra >>NN && | |
497 | git update-index --add NN && | |
498 | read_tree_must_fail -m $tree_O $tree_A $tree_B | |
499 | ' | |
500 | ||
501 | test_expect_success '16 - A matches in one and B matches in another.' ' | |
502 | rm -f .git/index F16 && | |
503 | echo F16 >F16 && | |
504 | git update-index --add F16 && | |
505 | tree0=$(git write-tree) && | |
506 | echo E16 >F16 && | |
507 | git update-index F16 && | |
508 | tree1=$(git write-tree) && | |
509 | read_tree_must_succeed -m $tree0 $tree1 $tree1 $tree0 && | |
510 | git ls-files --stage | |
511 | ' | |
4d3fe0c5 | 512 | |
2ecd9050 | 513 | test_done |