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 -------------------------------------------------------------------
223 Note
: if we want to implement
2ALT and
3ALT we need to be careful.
224 The tree A may contain DF
(file) when tree B require DF to be a
225 directory by having DF
/DF
(file).
229 test_expect_failure \
230 '1 - must not have an entry not in A.' \
231 "rm -f .git/index XX &&
233 git-update-index --add XX &&
234 git-read-tree -m $tree_O $tree_A $tree_B"
236 test_expect_success \
237 '2 - must match B in !O && !A && B case.' \
238 "rm -f .git/index NA &&
240 git-update-index --add NA &&
241 git-read-tree -m $tree_O $tree_A $tree_B"
243 test_expect_success \
244 '2 - matching B alone is OK in !O && !A && B case.' \
245 "rm -f .git/index NA &&
247 git-update-index --add NA &&
249 git-read-tree -m $tree_O $tree_A $tree_B"
251 test_expect_success \
252 '3 - must match A in !O && A && !B case.' \
253 "rm -f .git/index AN &&
255 git-update-index --add AN &&
256 git-read-tree -m $tree_O $tree_A $tree_B &&
259 test_expect_success \
260 '3 - matching A alone is OK in !O && A && !B case.' \
261 "rm -f .git/index AN &&
263 git-update-index --add AN &&
265 git-read-tree -m $tree_O $tree_A $tree_B"
267 test_expect_failure \
268 '3 (fail) - must match A in !O && A && !B case.' \
269 "rm -f .git/index AN &&
272 git-update-index --add AN &&
273 git-read-tree -m $tree_O $tree_A $tree_B"
275 test_expect_success \
276 '4 - must match and be up-to-date in !O && A && B && A!=B case.' \
277 "rm -f .git/index AA &&
279 git-update-index --add AA &&
280 git-read-tree -m $tree_O $tree_A $tree_B &&
283 test_expect_failure \
284 '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' \
285 "rm -f .git/index AA &&
287 git-update-index --add AA &&
289 git-read-tree -m $tree_O $tree_A $tree_B"
291 test_expect_failure \
292 '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' \
293 "rm -f .git/index AA &&
296 git-update-index --add AA &&
297 git-read-tree -m $tree_O $tree_A $tree_B"
299 test_expect_success \
300 '5 - must match in !O && A && B && A==B case.' \
301 "rm -f .git/index LL &&
303 git-update-index --add LL &&
304 git-read-tree -m $tree_O $tree_A $tree_B &&
307 test_expect_success \
308 '5 - must match in !O && A && B && A==B case.' \
309 "rm -f .git/index LL &&
311 git-update-index --add LL &&
313 git-read-tree -m $tree_O $tree_A $tree_B &&
316 test_expect_failure \
317 '5 (fail) - must match A in !O && A && B && A==B case.' \
318 "rm -f .git/index LL &&
321 git-update-index --add LL &&
322 git-read-tree -m $tree_O $tree_A $tree_B"
324 test_expect_failure \
325 '6 - must not exist in O && !A && !B case' \
326 "rm -f .git/index DD &&
328 git-update-index --add DD &&
329 git-read-tree -m $tree_O $tree_A $tree_B"
331 test_expect_failure \
332 '7 - must not exist in O && !A && B && O!=B case' \
333 "rm -f .git/index DM &&
335 git-update-index --add DM &&
336 git-read-tree -m $tree_O $tree_A $tree_B"
338 test_expect_failure \
339 '8 - must not exist in O && !A && B && O==B case' \
340 "rm -f .git/index DN &&
342 git-update-index --add DN &&
343 git-read-tree -m $tree_O $tree_A $tree_B"
345 test_expect_success \
346 '9 - must match and be up-to-date in O && A && !B && O!=A case' \
347 "rm -f .git/index MD &&
349 git-update-index --add MD &&
350 git-read-tree -m $tree_O $tree_A $tree_B &&
353 test_expect_failure \
354 '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' \
355 "rm -f .git/index MD &&
357 git-update-index --add MD &&
359 git-read-tree -m $tree_O $tree_A $tree_B"
361 test_expect_failure \
362 '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' \
363 "rm -f .git/index MD &&
366 git-update-index --add MD &&
367 git-read-tree -m $tree_O $tree_A $tree_B"
369 test_expect_success \
370 '10 - must match and be up-to-date in O && A && !B && O==A case' \
371 "rm -f .git/index ND &&
373 git-update-index --add ND &&
374 git-read-tree -m $tree_O $tree_A $tree_B &&
377 test_expect_failure \
378 '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' \
379 "rm -f .git/index ND &&
381 git-update-index --add ND &&
383 git-read-tree -m $tree_O $tree_A $tree_B"
385 test_expect_failure \
386 '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' \
387 "rm -f .git/index ND &&
390 git-update-index --add ND &&
391 git-read-tree -m $tree_O $tree_A $tree_B"
393 test_expect_success \
394 '11 - 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 &&
398 git-read-tree -m $tree_O $tree_A $tree_B &&
401 test_expect_failure \
402 '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' \
403 "rm -f .git/index MM &&
405 git-update-index --add MM &&
407 git-read-tree -m $tree_O $tree_A $tree_B"
409 test_expect_failure \
410 '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' \
411 "rm -f .git/index MM &&
414 git-update-index --add MM &&
415 git-read-tree -m $tree_O $tree_A $tree_B"
417 test_expect_success \
418 '12 - must match A in O && A && B && O!=A && A==B case' \
419 "rm -f .git/index SS &&
421 git-update-index --add SS &&
422 git-read-tree -m $tree_O $tree_A $tree_B &&
425 test_expect_success \
426 '12 - must match A in O && A && B && O!=A && A==B case' \
427 "rm -f .git/index SS &&
429 git-update-index --add SS &&
431 git-read-tree -m $tree_O $tree_A $tree_B &&
434 test_expect_failure \
435 '12 (fail) - must match A in O && A && B && O!=A && A==B case' \
436 "rm -f .git/index SS &&
439 git-update-index --add SS &&
440 git-read-tree -m $tree_O $tree_A $tree_B"
442 test_expect_success \
443 '13 - must match A in O && A && B && O!=A && O==B case' \
444 "rm -f .git/index MN &&
446 git-update-index --add MN &&
447 git-read-tree -m $tree_O $tree_A $tree_B &&
450 test_expect_success \
451 '13 - must match A in O && A && B && O!=A && O==B case' \
452 "rm -f .git/index MN &&
454 git-update-index --add MN &&
456 git-read-tree -m $tree_O $tree_A $tree_B &&
459 test_expect_success \
460 '14 - 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 &&
464 git-read-tree -m $tree_O $tree_A $tree_B &&
467 test_expect_success \
468 '14 - may match B in O && A && B && O==A && O!=B case' \
469 "rm -f .git/index NM &&
471 git-update-index --add NM &&
473 git-read-tree -m $tree_O $tree_A $tree_B &&
476 test_expect_failure \
477 '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' \
478 "rm -f .git/index NM &&
480 git-update-index --add NM &&
482 git-read-tree -m $tree_O $tree_A $tree_B"
484 test_expect_failure \
485 '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' \
486 "rm -f .git/index NM &&
489 git-update-index --add NM &&
490 git-read-tree -m $tree_O $tree_A $tree_B"
492 test_expect_success \
493 '15 - must match A in O && A && B && O==A && O==B case' \
494 "rm -f .git/index NN &&
496 git-update-index --add NN &&
497 git-read-tree -m $tree_O $tree_A $tree_B &&
500 test_expect_success \
501 '15 - must match A in O && A && B && O==A && O==B case' \
502 "rm -f .git/index NN &&
504 git-update-index --add NN &&
506 git-read-tree -m $tree_O $tree_A $tree_B &&
509 test_expect_failure \
510 '15 (fail) - must match A in O && A && B && O==A && O==B case' \
511 "rm -f .git/index NN &&
514 git-update-index --add NN &&
515 git-read-tree -m $tree_O $tree_A $tree_B"