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_DIRECTORY"/lib-read-tree-m-3way.sh
77 ################################################################
78 # Trivial "majority when 3 stages exist" merge plus #2ALT, #3ALT
79 # and #5ALT trivial merges.
130 git ls-files
--stage |
sed -e 's/ '"$_x40"' / X /' >current
&&
131 test_cmp expected current
134 # This is done on an empty work directory, which is the normal
135 # merge person behaviour.
136 test_expect_success \
137 '3-way merge with git read-tree -m, empty cache' \
138 "rm -fr [NDMALTS][NDMALTSF] Z &&
140 git read-tree -m $tree_O $tree_A $tree_B &&
143 # This starts out with the first head, which is the normal
144 # patch submitter behaviour.
145 test_expect_success \
146 '3-way merge with git read-tree -m, match H' \
147 "rm -fr [NDMALTS][NDMALTSF] Z &&
149 git read-tree $tree_A &&
150 git checkout-index -f -u -a &&
151 git read-tree -m $tree_O $tree_A $tree_B &&
154 : <<\END_OF_CASE_TABLE
156 We have so far tested only empty index and clean-and-matching-A index
157 case which are trivial. Make sure index requirements are also
160 "git read-tree -m O A B"
162 O A B result index requirements
163 -------------------------------------------------------------------
164 1 missing missing missing
- must not exist.
165 ------------------------------------------------------------------
166 2 missing missing exists take B
* must match B
, if exists.
167 ------------------------------------------------------------------
168 3 missing exists missing take A
* must match A
, if exists.
169 ------------------------------------------------------------------
170 4 missing exists A
!=B no merge must match A and be
171 up-to-date
, if exists.
172 ------------------------------------------------------------------
173 5 missing exists A
==B take A must match A
, if exists.
174 ------------------------------------------------------------------
175 6 exists missing missing remove must not exist.
176 ------------------------------------------------------------------
177 7 exists missing O
!=B no merge must not exist.
178 ------------------------------------------------------------------
179 8 exists missing O
==B remove must not exist.
180 ------------------------------------------------------------------
181 9 exists O
!=A missing no merge must match A and be
182 up-to-date
, if exists.
183 ------------------------------------------------------------------
184 10 exists O
==A missing no merge must match A
185 ------------------------------------------------------------------
186 11 exists O
!=A O
!=B no merge must match A and be
187 A
!=B up-to-date
, if exists.
188 ------------------------------------------------------------------
189 12 exists O
!=A O
!=B take A must match A
, if exists.
191 ------------------------------------------------------------------
192 13 exists O
!=A O
==B take A must match A
, if exists.
193 ------------------------------------------------------------------
194 14 exists O
==A O
!=B take B
if exists
, must either
(1)
195 match A and be up-to-date
,
197 ------------------------------------------------------------------
198 15 exists O
==A O
==B take B must match A
if exists.
199 ------------------------------------------------------------------
200 16 exists O
==A O
==B barf must match A
if exists.
201 *multi
* in one
in another
202 -------------------------------------------------------------------
204 Note
: we need to be careful
in case 2 and
3. The tree A may contain
205 DF
(file) when tree B require DF to be a directory by having DF
/DF
210 test_expect_success
'1 - must not have an entry not in A.' "
211 rm -f .git/index XX &&
213 git update-index --add XX &&
214 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
217 test_expect_success \
218 '2 - must match B in !O && !A && B case.' \
219 "rm -f .git/index NA &&
221 git update-index --add NA &&
222 git read-tree -m $tree_O $tree_A $tree_B"
224 test_expect_success \
225 '2 - matching B alone is OK in !O && !A && B case.' \
226 "rm -f .git/index NA &&
228 git update-index --add NA &&
230 git read-tree -m $tree_O $tree_A $tree_B"
232 test_expect_success \
233 '3 - must match A in !O && A && !B case.' \
234 "rm -f .git/index AN &&
236 git update-index --add AN &&
237 git read-tree -m $tree_O $tree_A $tree_B &&
240 test_expect_success \
241 '3 - matching A alone is OK in !O && A && !B case.' \
242 "rm -f .git/index AN &&
244 git update-index --add AN &&
246 git read-tree -m $tree_O $tree_A $tree_B"
248 test_expect_success \
249 '3 (fail) - must match A in !O && A && !B case.' "
250 rm -f .git/index AN &&
253 git update-index --add AN &&
254 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
257 test_expect_success \
258 '4 - must match and be up-to-date in !O && A && B && A!=B case.' \
259 "rm -f .git/index AA &&
261 git update-index --add AA &&
262 git read-tree -m $tree_O $tree_A $tree_B &&
265 test_expect_success \
266 '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' "
267 rm -f .git/index AA &&
269 git update-index --add AA &&
271 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
274 test_expect_success \
275 '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 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
283 test_expect_success \
284 '5 - must match in !O && A && B && A==B case.' \
285 "rm -f .git/index LL &&
287 git update-index --add LL &&
288 git read-tree -m $tree_O $tree_A $tree_B &&
291 test_expect_success \
292 '5 - must match in !O && A && B && A==B case.' \
293 "rm -f .git/index LL &&
295 git update-index --add LL &&
297 git read-tree -m $tree_O $tree_A $tree_B &&
300 test_expect_success \
301 '5 (fail) - must match A in !O && A && B && A==B case.' "
302 rm -f .git/index LL &&
305 git update-index --add LL &&
306 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
309 test_expect_success \
310 '6 - must not exist in O && !A && !B case' "
311 rm -f .git/index DD &&
313 git update-index --add DD &&
314 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
317 test_expect_success \
318 '7 - must not exist in O && !A && B && O!=B case' "
319 rm -f .git/index DM &&
321 git update-index --add DM &&
322 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
325 test_expect_success \
326 '8 - must not exist in O && !A && B && O==B case' "
327 rm -f .git/index DN &&
329 git update-index --add DN &&
330 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
333 test_expect_success \
334 '9 - must match and be up-to-date in O && A && !B && O!=A case' \
335 "rm -f .git/index MD &&
337 git update-index --add MD &&
338 git read-tree -m $tree_O $tree_A $tree_B &&
341 test_expect_success \
342 '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' "
343 rm -f .git/index MD &&
345 git update-index --add MD &&
347 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
350 test_expect_success \
351 '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' "
352 rm -f .git/index MD &&
355 git update-index --add MD &&
356 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
359 test_expect_success \
360 '10 - must match and be up-to-date in O && A && !B && O==A case' \
361 "rm -f .git/index ND &&
363 git update-index --add ND &&
364 git read-tree -m $tree_O $tree_A $tree_B &&
367 test_expect_success \
368 '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' "
369 rm -f .git/index ND &&
371 git update-index --add ND &&
373 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
376 test_expect_success \
377 '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' "
378 rm -f .git/index ND &&
381 git update-index --add ND &&
382 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
385 test_expect_success \
386 '11 - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' \
387 "rm -f .git/index MM &&
389 git update-index --add MM &&
390 git read-tree -m $tree_O $tree_A $tree_B &&
393 test_expect_success \
394 '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' "
395 rm -f .git/index MM &&
397 git update-index --add MM &&
399 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
402 test_expect_success \
403 '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' "
404 rm -f .git/index MM &&
407 git update-index --add MM &&
408 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
411 test_expect_success \
412 '12 - must match A in O && A && B && O!=A && A==B case' \
413 "rm -f .git/index SS &&
415 git update-index --add SS &&
416 git read-tree -m $tree_O $tree_A $tree_B &&
419 test_expect_success \
420 '12 - must match A in O && A && B && O!=A && A==B case' \
421 "rm -f .git/index SS &&
423 git update-index --add SS &&
425 git read-tree -m $tree_O $tree_A $tree_B &&
428 test_expect_success \
429 '12 (fail) - must match A in O && A && B && O!=A && A==B case' "
430 rm -f .git/index SS &&
433 git update-index --add SS &&
434 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
437 test_expect_success \
438 '13 - must match A in O && A && B && O!=A && O==B case' \
439 "rm -f .git/index MN &&
441 git update-index --add MN &&
442 git read-tree -m $tree_O $tree_A $tree_B &&
445 test_expect_success \
446 '13 - must match A in O && A && B && O!=A && O==B case' \
447 "rm -f .git/index MN &&
449 git update-index --add MN &&
451 git read-tree -m $tree_O $tree_A $tree_B &&
454 test_expect_success \
455 '14 - must match and be up-to-date in O && A && B && O==A && O!=B case' \
456 "rm -f .git/index NM &&
458 git update-index --add NM &&
459 git read-tree -m $tree_O $tree_A $tree_B &&
462 test_expect_success \
463 '14 - may match B in O && A && B && O==A && O!=B case' \
464 "rm -f .git/index NM &&
466 git update-index --add NM &&
468 git read-tree -m $tree_O $tree_A $tree_B &&
471 test_expect_success \
472 '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' "
473 rm -f .git/index NM &&
475 git update-index --add NM &&
477 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
480 test_expect_success \
481 '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' "
482 rm -f .git/index NM &&
485 git update-index --add NM &&
486 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
489 test_expect_success \
490 '15 - must match A in O && A && B && O==A && O==B case' \
491 "rm -f .git/index NN &&
493 git update-index --add NN &&
494 git read-tree -m $tree_O $tree_A $tree_B &&
497 test_expect_success \
498 '15 - must match A in O && A && B && O==A && O==B case' \
499 "rm -f .git/index NN &&
501 git update-index --add NN &&
503 git read-tree -m $tree_O $tree_A $tree_B &&
506 test_expect_success \
507 '15 (fail) - must match A in O && A && B && O==A && O==B case' "
508 rm -f .git/index NN &&
511 git update-index --add NN &&
512 test_must_fail git read-tree -m $tree_O $tree_A $tree_B
516 test_expect_success \
517 '16 - A matches in one and B matches in another.' \
518 'rm -f .git/index F16 &&
520 git update-index --add F16 &&
521 tree0=`git write-tree` &&
523 git update-index F16 &&
524 tree1=`git write-tree` &&
525 git read-tree -m $tree0 $tree1 $tree1 $tree0 &&
526 git ls-files --stage'