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 . ../lib-read-tree-m-3way.sh
77 ################################################################
78 # Trivial "majority when 3 stages exist" merge plus #2ALT, #3ALT
79 # and #5ALT trivial merges.
129 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
130 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
133 git-ls-files --stage | sed -e 's/ '"$_x40"' / X /' >current &&
134 diff -u expected current
137 # This is done on an empty work directory, which is the normal
138 # merge person behaviour.
139 test_expect_success \
140 '3-way merge with git-read-tree -m, empty cache' \
141 "rm -fr [NDMALTS][NDMALTSF] Z &&
143 git-read-tree -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 \
149 '3-way merge with git-read-tree -m, match H' \
150 "rm -fr [NDMALTS][NDMALTSF] Z &&
152 git-read-tree $tree_A &&
153 git-checkout-index -f -u -a &&
154 git-read-tree -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
161 checked. The table also lists alternative semantics which is not
162 currently implemented.
164 "git-diff-tree -m O A B"
166 O A B result index requirements
167 -------------------------------------------------------------------
168 1 missing missing missing - must not exist.
169 ------------------------------------------------------------------
170 2 missing missing exists no merge must not exist.
171 ------------------------------------
172 (ALT) take B* must match B, if exists.
173 ------------------------------------------------------------------
174 3 missing exists missing no merge must match A and be
175 up-to-date, if exists.
176 ------------------------------------
177 (ALT) take A* must match A, if exists.
178 ------------------------------------------------------------------
179 4 missing exists A!=B no merge must match A and be
180 up-to-date, if exists.
181 ------------------------------------------------------------------
182 5 missing exists A==B no merge must match A and be
183 up-to-date, if exists.
184 ------------------------------------
185 (ALT) take A must match A, if exists.
186 ------------------------------------------------------------------
187 6 exists missing missing no merge must not exist.
188 ------------------------------------
189 (ALT) remove must not exist.
190 ------------------------------------------------------------------
191 7 exists missing O!=B no merge must not exist.
192 ------------------------------------------------------------------
193 8 exists missing O==B no merge must not exist.
194 ------------------------------------
195 (ALT) remove must not exist.
196 ------------------------------------------------------------------
197 9 exists O!=A missing no merge must match A and be
198 up-to-date, if exists.
199 ------------------------------------------------------------------
200 10 exists O==A missing no merge must match A and be
201 up-to-date, if exists.
202 ------------------------------------
204 ------------------------------------------------------------------
205 11 exists O!=A O!=B no merge must match A and be
206 A!=B up-to-date, if exists.
207 ------------------------------------------------------------------
208 12 exists O!=A O!=B take A must match A, if exists.
210 ------------------------------------------------------------------
211 13 exists O!=A O==B take A must match A, if exists.
212 ------------------------------------------------------------------
213 14 exists O==A O!=B take B must match A and be
214 be up-to-date, if exists.
215 ------------------------------------
216 (ALT) take B if exists, must either (1)
217 match A and be up-to-date,
219 ------------------------------------------------------------------
220 15 exists O==A O==B take B must match A if exists.
221 ------------------------------------------------------------------
222 16 exists O==A O==B barf must match A if exists.
223 *multi* in one in another
224 -------------------------------------------------------------------
226 Note: if we want to implement 2ALT and 3ALT we need to be careful.
227 The tree A may contain DF (file) when tree B require DF to be a
228 directory by having DF/DF (file).
232 test_expect_failure \
233 '1 - must not have an entry not in A.' \
234 "rm -f .git/index XX &&
236 git-update-index --add XX &&
237 git-read-tree -m $tree_O $tree_A $tree_B"
239 test_expect_success \
240 '2 - must match B in !O && !A && B case.' \
241 "rm -f .git/index NA &&
243 git-update-index --add NA &&
244 git-read-tree -m $tree_O $tree_A $tree_B"
246 test_expect_success \
247 '2 - matching B alone is OK in !O && !A && B case.' \
248 "rm -f .git/index NA &&
250 git-update-index --add NA &&
252 git-read-tree -m $tree_O $tree_A $tree_B"
254 test_expect_success \
255 '3 - must match A in !O && A && !B case.' \
256 "rm -f .git/index AN &&
258 git-update-index --add AN &&
259 git-read-tree -m $tree_O $tree_A $tree_B &&
262 test_expect_success \
263 '3 - matching A alone is OK in !O && A && !B case.' \
264 "rm -f .git/index AN &&
266 git-update-index --add AN &&
268 git-read-tree -m $tree_O $tree_A $tree_B"
270 test_expect_failure \
271 '3 (fail) - must match A in !O && A && !B case.' \
272 "rm -f .git/index AN &&
275 git-update-index --add AN &&
276 git-read-tree -m $tree_O $tree_A $tree_B"
278 test_expect_success \
279 '4 - must match and be up-to-date in !O && A && B && A!=B case.' \
280 "rm -f .git/index AA &&
282 git-update-index --add AA &&
283 git-read-tree -m $tree_O $tree_A $tree_B &&
286 test_expect_failure \
287 '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' \
288 "rm -f .git/index AA &&
290 git-update-index --add AA &&
292 git-read-tree -m $tree_O $tree_A $tree_B"
294 test_expect_failure \
295 '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' \
296 "rm -f .git/index AA &&
299 git-update-index --add AA &&
300 git-read-tree -m $tree_O $tree_A $tree_B"
302 test_expect_success \
303 '5 - must match in !O && A && B && A==B case.' \
304 "rm -f .git/index LL &&
306 git-update-index --add LL &&
307 git-read-tree -m $tree_O $tree_A $tree_B &&
310 test_expect_success \
311 '5 - must match in !O && A && B && A==B case.' \
312 "rm -f .git/index LL &&
314 git-update-index --add LL &&
316 git-read-tree -m $tree_O $tree_A $tree_B &&
319 test_expect_failure \
320 '5 (fail) - must match A in !O && A && B && A==B case.' \
321 "rm -f .git/index LL &&
324 git-update-index --add LL &&
325 git-read-tree -m $tree_O $tree_A $tree_B"
327 test_expect_failure \
328 '6 - must not exist in O && !A && !B case' \
329 "rm -f .git/index DD &&
331 git-update-index --add DD &&
332 git-read-tree -m $tree_O $tree_A $tree_B"
334 test_expect_failure \
335 '7 - must not exist in O && !A && B && O!=B case' \
336 "rm -f .git/index DM &&
338 git-update-index --add DM &&
339 git-read-tree -m $tree_O $tree_A $tree_B"
341 test_expect_failure \
342 '8 - must not exist in O && !A && B && O==B case' \
343 "rm -f .git/index DN &&
345 git-update-index --add DN &&
346 git-read-tree -m $tree_O $tree_A $tree_B"
348 test_expect_success \
349 '9 - must match and be up-to-date in O && A && !B && O!=A case' \
350 "rm -f .git/index MD &&
352 git-update-index --add MD &&
353 git-read-tree -m $tree_O $tree_A $tree_B &&
356 test_expect_failure \
357 '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' \
358 "rm -f .git/index MD &&
360 git-update-index --add MD &&
362 git-read-tree -m $tree_O $tree_A $tree_B"
364 test_expect_failure \
365 '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' \
366 "rm -f .git/index MD &&
369 git-update-index --add MD &&
370 git-read-tree -m $tree_O $tree_A $tree_B"
372 test_expect_success \
373 '10 - must match and be up-to-date in O && A && !B && O==A case' \
374 "rm -f .git/index ND &&
376 git-update-index --add ND &&
377 git-read-tree -m $tree_O $tree_A $tree_B &&
380 test_expect_failure \
381 '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' \
382 "rm -f .git/index ND &&
384 git-update-index --add ND &&
386 git-read-tree -m $tree_O $tree_A $tree_B"
388 test_expect_failure \
389 '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' \
390 "rm -f .git/index ND &&
393 git-update-index --add ND &&
394 git-read-tree -m $tree_O $tree_A $tree_B"
396 test_expect_success \
397 '11 - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' \
398 "rm -f .git/index MM &&
400 git-update-index --add MM &&
401 git-read-tree -m $tree_O $tree_A $tree_B &&
404 test_expect_failure \
405 '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' \
406 "rm -f .git/index MM &&
408 git-update-index --add MM &&
410 git-read-tree -m $tree_O $tree_A $tree_B"
412 test_expect_failure \
413 '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' \
414 "rm -f .git/index MM &&
417 git-update-index --add MM &&
418 git-read-tree -m $tree_O $tree_A $tree_B"
420 test_expect_success \
421 '12 - must match A in O && A && B && O!=A && A==B case' \
422 "rm -f .git/index SS &&
424 git-update-index --add SS &&
425 git-read-tree -m $tree_O $tree_A $tree_B &&
428 test_expect_success \
429 '12 - must match A in O && A && B && O!=A && A==B case' \
430 "rm -f .git/index SS &&
432 git-update-index --add SS &&
434 git-read-tree -m $tree_O $tree_A $tree_B &&
437 test_expect_failure \
438 '12 (fail) - must match A in O && A && B && O!=A && A==B case' \
439 "rm -f .git/index SS &&
442 git-update-index --add SS &&
443 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 &&
450 git-read-tree -m $tree_O $tree_A $tree_B &&
453 test_expect_success \
454 '13 - must match A in O && A && B && O!=A && O==B case' \
455 "rm -f .git/index MN &&
457 git-update-index --add MN &&
459 git-read-tree -m $tree_O $tree_A $tree_B &&
462 test_expect_success \
463 '14 - must match and be up-to-date in O && A && B && O==A && O!=B case' \
464 "rm -f .git/index NM &&
466 git-update-index --add NM &&
467 git-read-tree -m $tree_O $tree_A $tree_B &&
470 test_expect_success \
471 '14 - may match B in O && A && B && O==A && O!=B case' \
472 "rm -f .git/index NM &&
474 git-update-index --add NM &&
476 git-read-tree -m $tree_O $tree_A $tree_B &&
479 test_expect_failure \
480 '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' \
481 "rm -f .git/index NM &&
483 git-update-index --add NM &&
485 git-read-tree -m $tree_O $tree_A $tree_B"
487 test_expect_failure \
488 '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' \
489 "rm -f .git/index NM &&
492 git-update-index --add NM &&
493 git-read-tree -m $tree_O $tree_A $tree_B"
495 test_expect_success \
496 '15 - must match A in O && A && B && O==A && O==B case' \
497 "rm -f .git/index NN &&
499 git-update-index --add NN &&
500 git-read-tree -m $tree_O $tree_A $tree_B &&
503 test_expect_success \
504 '15 - must match A in O && A && B && O==A && O==B case' \
505 "rm -f .git/index NN &&
507 git-update-index --add NN &&
509 git-read-tree -m $tree_O $tree_A $tree_B &&
512 test_expect_failure \
513 '15 (fail) - must match A in O && A && B && O==A && O==B case' \
514 "rm -f .git/index NN &&
517 git-update-index --add NN &&
518 git-read-tree -m $tree_O $tree_A $tree_B"
521 test_expect_success \
522 '16 - A matches in one and B matches in another.' \
523 'rm -f .git/index F16 &&
525 git-update-index --add F16 &&
526 tree0=`git-write-tree` &&
528 git-update-index F16 &&
529 tree1=`git-write-tree` &&
530 git-read-tree -m $tree0 $tree1 $tree1 $tree0 &&
531 git-ls-files --stage'