3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='Three way merge with read-tree -m
8 This test tries three-way merge with read-tree -m
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.
16 Decisions are made by comparing contents of O, A and B pathname
17 by pathname. The result is determined by the following guiding
20 - If only A does something to it and B does not touch it, take
23 - If only B does something to it and A does not touch it, take
26 - If both A and B does something but in the same way, take
29 - If A and B does something but different things, we need a
32 - We cannot do anything about the following cases:
34 * O does not have it. A and B both must be adding to the
35 same path independently.
37 * A deletes it. B must be modifying.
39 - Otherwise, A and B are modifying. Run 3-way merge.
41 First, the case matrix.
43 - Vertical axis is for A'\''s actions.
44 - Horizontal axis is for B'\''s actions.
46 .----------------------------------------------------------------.
47 | A B | No Action | Delete | Modify | Add |
48 |------------+------------+------------+------------+------------|
50 | | select O | delete | select B | select B |
52 |------------+------------+------------+------------+------------|
53 | Delete | | | ********** | can |
54 | | delete | delete | merge | not |
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 .----------------------------------------------------------------.
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.
75 TEST_PASSES_SANITIZE_LEAK
=true
77 .
"$TEST_DIRECTORY"/lib-read-tree.sh
78 .
"$TEST_DIRECTORY"/lib-read-tree-m-3way.sh
80 ################################################################
81 # Trivial "majority when 3 stages exist" merge plus #2ALT, #3ALT
82 # and #5ALT trivial merges.
133 git ls-files
--stage |
sed -e 's/ '"$OID_REGEX"' / X /' >current
&&
134 test_cmp expected current
137 # This is done on an empty work directory, which is the normal
138 # merge person behaviour.
139 test_expect_success
'3-way merge with git read-tree -m, empty cache' '
140 rm -fr [NDMALTS][NDMALTSF] Z &&
142 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
146 # This starts out with the first head, which is the normal
147 # patch submitter behaviour.
148 test_expect_success
'3-way merge with git read-tree -m, match H' '
149 rm -fr [NDMALTS][NDMALTSF] Z &&
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 &&
157 : <<\END_OF_CASE_TABLE
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
163 "git read-tree -m O A B"
165 O A B result index requirements
166 -------------------------------------------------------------------
167 1 missing missing missing
- must not exist.
168 ------------------------------------------------------------------
169 2 missing missing exists take B
* must match B
, if exists.
170 ------------------------------------------------------------------
171 3 missing exists missing take A
* must match A
, if exists.
172 ------------------------------------------------------------------
173 4 missing exists A
!=B no merge must match A and be
174 up-to-date
, if exists.
175 ------------------------------------------------------------------
176 5 missing exists A
==B take A must match A
, if exists.
177 ------------------------------------------------------------------
178 6 exists missing missing remove must not exist.
179 ------------------------------------------------------------------
180 7 exists missing O
!=B no merge must not exist.
181 ------------------------------------------------------------------
182 8 exists missing O
==B remove must not exist.
183 ------------------------------------------------------------------
184 9 exists O
!=A missing no merge must match A and be
185 up-to-date
, if exists.
186 ------------------------------------------------------------------
187 10 exists O
==A missing no merge must match A
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.
194 ------------------------------------------------------------------
195 13 exists O
!=A O
==B take A must match A
, if exists.
196 ------------------------------------------------------------------
197 14 exists O
==A O
!=B take B
if exists
, must either
(1)
198 match A and be up-to-date
,
200 ------------------------------------------------------------------
201 15 exists O
==A O
==B take B must match A
if exists.
202 ------------------------------------------------------------------
203 16 exists O
==A O
==B barf must match A
if exists.
204 *multi
* in one
in another
205 -------------------------------------------------------------------
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
213 test_expect_success
'1 - must not have an entry not in A.' '
214 rm -f .git/index XX &&
216 git update-index --add XX &&
217 read_tree_must_fail -m $tree_O $tree_A $tree_B
220 test_expect_success
'2 - must match B in !O && !A && B case.' '
221 rm -f .git/index NA &&
223 git update-index --add NA &&
224 read_tree_must_succeed -m $tree_O $tree_A $tree_B
227 test_expect_success
'2 - matching B alone is OK in !O && !A && B case.' '
228 rm -f .git/index NA &&
230 git update-index --add NA &&
232 read_tree_must_succeed -m $tree_O $tree_A $tree_B
235 test_expect_success
'3 - must match A in !O && A && !B case.' '
236 rm -f .git/index AN &&
238 git update-index --add AN &&
239 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
243 test_expect_success
'3 - matching A alone is OK in !O && A && !B case.' '
244 rm -f .git/index AN &&
246 git update-index --add AN &&
248 read_tree_must_succeed -m $tree_O $tree_A $tree_B
251 test_expect_success
'3 (fail) - must match A in !O && A && !B case.' '
252 rm -f .git/index AN &&
255 git update-index --add AN &&
256 read_tree_must_fail -m $tree_O $tree_A $tree_B
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 &&
262 git update-index --add AA &&
263 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
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 &&
270 git update-index --add AA &&
272 read_tree_must_fail -m $tree_O $tree_A $tree_B
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 &&
279 git update-index --add AA &&
280 read_tree_must_fail -m $tree_O $tree_A $tree_B
283 test_expect_success
'5 - must match in !O && A && B && A==B case.' '
284 rm -f .git/index LL &&
286 git update-index --add LL &&
287 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
291 test_expect_success
'5 - must match in !O && A && B && A==B case.' '
292 rm -f .git/index LL &&
294 git update-index --add LL &&
296 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
300 test_expect_success
'5 (fail) - must match A in !O && A && B && A==B case.' '
301 rm -f .git/index LL &&
304 git update-index --add LL &&
305 read_tree_must_fail -m $tree_O $tree_A $tree_B
308 test_expect_success
'6 - must not exist in O && !A && !B case' '
309 rm -f .git/index DD &&
311 git update-index --add DD &&
312 read_tree_must_fail -m $tree_O $tree_A $tree_B
315 test_expect_success
'7 - must not exist in O && !A && B && O!=B case' '
316 rm -f .git/index DM &&
318 git update-index --add DM &&
319 read_tree_must_fail -m $tree_O $tree_A $tree_B
322 test_expect_success
'8 - must not exist in O && !A && B && O==B case' '
323 rm -f .git/index DN &&
325 git update-index --add DN &&
326 read_tree_must_fail -m $tree_O $tree_A $tree_B
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 &&
332 git update-index --add MD &&
333 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
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 &&
340 git update-index --add MD &&
342 read_tree_must_fail -m $tree_O $tree_A $tree_B
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 &&
349 git update-index --add MD &&
350 read_tree_must_fail -m $tree_O $tree_A $tree_B
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 &&
356 git update-index --add ND &&
357 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
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 &&
364 git update-index --add ND &&
366 read_tree_must_fail -m $tree_O $tree_A $tree_B
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 &&
373 git update-index --add ND &&
374 read_tree_must_fail -m $tree_O $tree_A $tree_B
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 &&
380 git update-index --add MM &&
381 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
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 &&
388 git update-index --add MM &&
390 read_tree_must_fail -m $tree_O $tree_A $tree_B
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 &&
397 git update-index --add MM &&
398 read_tree_must_fail -m $tree_O $tree_A $tree_B
401 test_expect_success
'12 - must match A in O && A && B && O!=A && A==B case' '
402 rm -f .git/index SS &&
404 git update-index --add SS &&
405 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
409 test_expect_success
'12 - must match A in O && A && B && O!=A && A==B case' '
410 rm -f .git/index SS &&
412 git update-index --add SS &&
414 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
418 test_expect_success
'12 (fail) - must match A in O && A && B && O!=A && A==B case' '
419 rm -f .git/index SS &&
422 git update-index --add SS &&
423 read_tree_must_fail -m $tree_O $tree_A $tree_B
426 test_expect_success
'13 - must match A in O && A && B && O!=A && O==B case' '
427 rm -f .git/index MN &&
429 git update-index --add MN &&
430 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
434 test_expect_success
'13 - must match A in O && A && B && O!=A && O==B case' '
435 rm -f .git/index MN &&
437 git update-index --add MN &&
439 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
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 &&
446 git update-index --add NM &&
447 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
451 test_expect_success
'14 - may match B in O && A && B && O==A && O!=B case' '
452 rm -f .git/index NM &&
454 git update-index --add NM &&
456 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
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 &&
463 git update-index --add NM &&
465 read_tree_must_fail -m $tree_O $tree_A $tree_B
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 &&
472 git update-index --add NM &&
473 read_tree_must_fail -m $tree_O $tree_A $tree_B
476 test_expect_success
'15 - must match A in O && A && B && O==A && O==B case' '
477 rm -f .git/index NN &&
479 git update-index --add NN &&
480 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
484 test_expect_success
'15 - must match A in O && A && B && O==A && O==B case' '
485 rm -f .git/index NN &&
487 git update-index --add NN &&
489 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
493 test_expect_success
'15 (fail) - must match A in O && A && B && O==A && O==B case' '
494 rm -f .git/index NN &&
497 git update-index --add NN &&
498 read_tree_must_fail -m $tree_O $tree_A $tree_B
501 test_expect_success
'16 - A matches in one and B matches in another.' '
502 rm -f .git/index F16 &&
504 git update-index --add F16 &&
505 tree0=$(git write-tree) &&
507 git update-index F16 &&
508 tree1=$(git write-tree) &&
509 read_tree_must_succeed -m $tree0 $tree1 $tree1 $tree0 &&