]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1000-read-tree-m-3way.sh
[PATCH] Disable debugging from read-tree.
[thirdparty/git.git] / t / t1000-read-tree-m-3way.sh
CommitLineData
2ecd9050
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Three way merge with read-tree -m
7
8This test tries three-way merge with read-tree -m
9
10There is one ancestor (called O for Original) and two branches A
11and B derived from it. We want to do a 3-way merge between A and
12B, using O as the common ancestor.
13
14 merge A O B
15
16Decisions are made by comparing contents of O, A and B pathname
17by pathname. The result is determined by the following guiding
18principle:
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
41First, 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
66In 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'
2ecd9050 74. ./test-lib.sh
63713028 75. ../lib-read-tree-m-3way.sh
2ecd9050
JH
76
77################################################################
32192e66
JH
78# Trivial "majority when 3 stages exist" merge plus #2ALT, #3ALT
79# and #5ALT trivial merges.
2ecd9050 80
2ecd9050 81cat >expected <<\EOF
2eab945e
JH
82100644 X 2 AA
83100644 X 3 AA
32192e66 84100644 X 0 AN
2eab945e
JH
85100644 X 1 DD
86100644 X 3 DF
87100644 X 2 DF/DF
88100644 X 1 DM
89100644 X 3 DM
90100644 X 1 DN
91100644 X 3 DN
e7f9bc41 92100644 X 0 LL
2eab945e
JH
93100644 X 1 MD
94100644 X 2 MD
95100644 X 1 MM
96100644 X 2 MM
97100644 X 3 MM
98100644 X 0 MN
32192e66 99100644 X 0 NA
2eab945e
JH
100100644 X 1 ND
101100644 X 2 ND
102100644 X 0 NM
103100644 X 0 NN
104100644 X 0 SS
105100644 X 1 TT
106100644 X 2 TT
107100644 X 3 TT
108100644 X 2 Z/AA
109100644 X 3 Z/AA
32192e66 110100644 X 0 Z/AN
2eab945e
JH
111100644 X 1 Z/DD
112100644 X 1 Z/DM
113100644 X 3 Z/DM
114100644 X 1 Z/DN
115100644 X 3 Z/DN
116100644 X 1 Z/MD
117100644 X 2 Z/MD
118100644 X 1 Z/MM
119100644 X 2 Z/MM
120100644 X 3 Z/MM
121100644 X 0 Z/MN
32192e66 122100644 X 0 Z/NA
2eab945e
JH
123100644 X 1 Z/ND
124100644 X 2 Z/ND
125100644 X 0 Z/NM
126100644 X 0 Z/NN
2ecd9050
JH
127EOF
128
7d95ee93
JH
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"
131
f225b218
JH
132check_result () {
133 git-ls-files --stage | sed -e 's/ '"$_x40"' / X /' >current &&
134 diff -u expected current
135}
7d95ee93
JH
136
137# This is done on an empty work directory, which is the normal
138# merge person behaviour.
139test_expect_success \
140 '3-way merge with git-read-tree -m, empty cache' \
141 "rm -fr [NDMALTS][NDMALTSF] Z &&
142 rm .git/index &&
143 git-read-tree -m $tree_O $tree_A $tree_B &&
f225b218 144 check_result"
7d95ee93
JH
145
146# This starts out with the first head, which is the normal
147# patch submitter behaviour.
2ecd9050 148test_expect_success \
7d95ee93 149 '3-way merge with git-read-tree -m, match H' \
f225b218
JH
150 "rm -fr [NDMALTS][NDMALTSF] Z &&
151 rm .git/index &&
152 git-read-tree $tree_A &&
215a7ad1 153 git-checkout-index -f -u -a &&
7d95ee93 154 git-read-tree -m $tree_O $tree_A $tree_B &&
f225b218
JH
155 check_result"
156
157: <<\END_OF_CASE_TABLE
158
159We have so far tested only empty index and clean-and-matching-A index
160case which are trivial. Make sure index requirements are also
161checked. The table also lists alternative semantics which is not
162currently implemented.
163
164"git-diff-tree -m O A B"
165
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 ------------------------------------
203 (ALT) remove ditto
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.
209 A==B
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,
218 or (2) match B.
219 ------------------------------------------------------------------
220 15 exists O==A O==B take B must match A if exists.
221-------------------------------------------------------------------
222
223Note: if we want to implement 2ALT and 3ALT we need to be careful.
224The tree A may contain DF (file) when tree B require DF to be a
225directory by having DF/DF (file).
226
227END_OF_CASE_TABLE
228
229test_expect_failure \
230 '1 - must not have an entry not in A.' \
231 "rm -f .git/index XX &&
232 echo XX >XX &&
215a7ad1 233 git-update-index --add XX &&
f225b218
JH
234 git-read-tree -m $tree_O $tree_A $tree_B"
235
32192e66
JH
236test_expect_success \
237 '2 - must match B in !O && !A && B case.' \
238 "rm -f .git/index NA &&
239 cp .orig-B/NA NA &&
215a7ad1 240 git-update-index --add NA &&
32192e66
JH
241 git-read-tree -m $tree_O $tree_A $tree_B"
242
243test_expect_success \
244 '2 - matching B alone is OK in !O && !A && B case.' \
f225b218
JH
245 "rm -f .git/index NA &&
246 cp .orig-B/NA NA &&
215a7ad1 247 git-update-index --add NA &&
32192e66 248 echo extra >>NA &&
f225b218
JH
249 git-read-tree -m $tree_O $tree_A $tree_B"
250
251test_expect_success \
32192e66 252 '3 - must match A in !O && A && !B case.' \
f225b218
JH
253 "rm -f .git/index AN &&
254 cp .orig-A/AN AN &&
215a7ad1 255 git-update-index --add AN &&
f225b218
JH
256 git-read-tree -m $tree_O $tree_A $tree_B &&
257 check_result"
258
32192e66
JH
259test_expect_success \
260 '3 - matching A alone is OK in !O && A && !B case.' \
f225b218
JH
261 "rm -f .git/index AN &&
262 cp .orig-A/AN AN &&
215a7ad1 263 git-update-index --add AN &&
f225b218
JH
264 echo extra >>AN &&
265 git-read-tree -m $tree_O $tree_A $tree_B"
266
267test_expect_failure \
32192e66 268 '3 (fail) - must match A in !O && A && !B case.' \
f225b218
JH
269 "rm -f .git/index AN &&
270 cp .orig-A/AN AN &&
271 echo extra >>AN &&
215a7ad1 272 git-update-index --add AN &&
f225b218
JH
273 git-read-tree -m $tree_O $tree_A $tree_B"
274
275test_expect_success \
276 '4 - must match and be up-to-date in !O && A && B && A!=B case.' \
277 "rm -f .git/index AA &&
278 cp .orig-A/AA AA &&
215a7ad1 279 git-update-index --add AA &&
f225b218
JH
280 git-read-tree -m $tree_O $tree_A $tree_B &&
281 check_result"
282
283test_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 &&
286 cp .orig-A/AA AA &&
215a7ad1 287 git-update-index --add AA &&
f225b218
JH
288 echo extra >>AA &&
289 git-read-tree -m $tree_O $tree_A $tree_B"
290
291test_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 &&
294 cp .orig-A/AA AA &&
295 echo extra >>AA &&
215a7ad1 296 git-update-index --add AA &&
f225b218
JH
297 git-read-tree -m $tree_O $tree_A $tree_B"
298
299test_expect_success \
e7f9bc41 300 '5 - must match in !O && A && B && A==B case.' \
f225b218
JH
301 "rm -f .git/index LL &&
302 cp .orig-A/LL LL &&
215a7ad1 303 git-update-index --add LL &&
f225b218
JH
304 git-read-tree -m $tree_O $tree_A $tree_B &&
305 check_result"
306
e7f9bc41
JH
307test_expect_success \
308 '5 - must match in !O && A && B && A==B case.' \
f225b218
JH
309 "rm -f .git/index LL &&
310 cp .orig-A/LL LL &&
215a7ad1 311 git-update-index --add LL &&
f225b218 312 echo extra >>LL &&
e7f9bc41
JH
313 git-read-tree -m $tree_O $tree_A $tree_B &&
314 check_result"
f225b218
JH
315
316test_expect_failure \
e7f9bc41 317 '5 (fail) - must match A in !O && A && B && A==B case.' \
f225b218
JH
318 "rm -f .git/index LL &&
319 cp .orig-A/LL LL &&
320 echo extra >>LL &&
215a7ad1 321 git-update-index --add LL &&
f225b218
JH
322 git-read-tree -m $tree_O $tree_A $tree_B"
323
324test_expect_failure \
325 '6 - must not exist in O && !A && !B case' \
326 "rm -f .git/index DD &&
327 echo DD >DD
215a7ad1 328 git-update-index --add DD &&
f225b218
JH
329 git-read-tree -m $tree_O $tree_A $tree_B"
330
331test_expect_failure \
332 '7 - must not exist in O && !A && B && O!=B case' \
333 "rm -f .git/index DM &&
334 cp .orig-B/DM DM &&
215a7ad1 335 git-update-index --add DM &&
f225b218
JH
336 git-read-tree -m $tree_O $tree_A $tree_B"
337
338test_expect_failure \
339 '8 - must not exist in O && !A && B && O==B case' \
340 "rm -f .git/index DN &&
341 cp .orig-B/DN DN &&
215a7ad1 342 git-update-index --add DN &&
f225b218
JH
343 git-read-tree -m $tree_O $tree_A $tree_B"
344
345test_expect_success \
346 '9 - must match and be up-to-date in O && A && !B && O!=A case' \
347 "rm -f .git/index MD &&
348 cp .orig-A/MD MD &&
215a7ad1 349 git-update-index --add MD &&
f225b218
JH
350 git-read-tree -m $tree_O $tree_A $tree_B &&
351 check_result"
352
353test_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 &&
356 cp .orig-A/MD MD &&
215a7ad1 357 git-update-index --add MD &&
f225b218
JH
358 echo extra >>MD &&
359 git-read-tree -m $tree_O $tree_A $tree_B"
360
361test_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 &&
364 cp .orig-A/MD MD &&
365 echo extra >>MD &&
215a7ad1 366 git-update-index --add MD &&
f225b218
JH
367 git-read-tree -m $tree_O $tree_A $tree_B"
368
369test_expect_success \
370 '10 - must match and be up-to-date in O && A && !B && O==A case' \
371 "rm -f .git/index ND &&
372 cp .orig-A/ND ND &&
215a7ad1 373 git-update-index --add ND &&
f225b218
JH
374 git-read-tree -m $tree_O $tree_A $tree_B &&
375 check_result"
376
377test_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 &&
380 cp .orig-A/ND ND &&
215a7ad1 381 git-update-index --add ND &&
f225b218
JH
382 echo extra >>ND &&
383 git-read-tree -m $tree_O $tree_A $tree_B"
384
385test_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 &&
388 cp .orig-A/ND ND &&
389 echo extra >>ND &&
215a7ad1 390 git-update-index --add ND &&
f225b218
JH
391 git-read-tree -m $tree_O $tree_A $tree_B"
392
393test_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 &&
396 cp .orig-A/MM MM &&
215a7ad1 397 git-update-index --add MM &&
f225b218
JH
398 git-read-tree -m $tree_O $tree_A $tree_B &&
399 check_result"
400
401test_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 &&
404 cp .orig-A/MM MM &&
215a7ad1 405 git-update-index --add MM &&
f225b218
JH
406 echo extra >>MM &&
407 git-read-tree -m $tree_O $tree_A $tree_B"
408
409test_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 &&
412 cp .orig-A/MM MM &&
413 echo extra >>MM &&
215a7ad1 414 git-update-index --add MM &&
f225b218
JH
415 git-read-tree -m $tree_O $tree_A $tree_B"
416
417test_expect_success \
418 '12 - must match A in O && A && B && O!=A && A==B case' \
419 "rm -f .git/index SS &&
420 cp .orig-A/SS SS &&
215a7ad1 421 git-update-index --add SS &&
f225b218
JH
422 git-read-tree -m $tree_O $tree_A $tree_B &&
423 check_result"
424
425test_expect_success \
426 '12 - must match A in O && A && B && O!=A && A==B case' \
427 "rm -f .git/index SS &&
428 cp .orig-A/SS SS &&
215a7ad1 429 git-update-index --add SS &&
f225b218
JH
430 echo extra >>SS &&
431 git-read-tree -m $tree_O $tree_A $tree_B &&
432 check_result"
433
434test_expect_failure \
435 '12 (fail) - must match A in O && A && B && O!=A && A==B case' \
436 "rm -f .git/index SS &&
437 cp .orig-A/SS SS &&
438 echo extra >>SS &&
215a7ad1 439 git-update-index --add SS &&
f225b218
JH
440 git-read-tree -m $tree_O $tree_A $tree_B"
441
442test_expect_success \
443 '13 - must match A in O && A && B && O!=A && O==B case' \
444 "rm -f .git/index MN &&
445 cp .orig-A/MN MN &&
215a7ad1 446 git-update-index --add MN &&
f225b218
JH
447 git-read-tree -m $tree_O $tree_A $tree_B &&
448 check_result"
449
450test_expect_success \
451 '13 - must match A in O && A && B && O!=A && O==B case' \
452 "rm -f .git/index MN &&
453 cp .orig-A/MN MN &&
215a7ad1 454 git-update-index --add MN &&
f225b218
JH
455 echo extra >>MN &&
456 git-read-tree -m $tree_O $tree_A $tree_B &&
457 check_result"
458
459test_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 &&
462 cp .orig-A/NM NM &&
215a7ad1 463 git-update-index --add NM &&
f225b218
JH
464 git-read-tree -m $tree_O $tree_A $tree_B &&
465 check_result"
466
036d51cc
JH
467test_expect_success \
468 '14 - may match B in O && A && B && O==A && O!=B case' \
469 "rm -f .git/index NM &&
470 cp .orig-B/NM NM &&
215a7ad1 471 git-update-index --add NM &&
036d51cc
JH
472 echo extra >>NM &&
473 git-read-tree -m $tree_O $tree_A $tree_B &&
474 check_result"
475
f225b218
JH
476test_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 &&
479 cp .orig-A/NM NM &&
215a7ad1 480 git-update-index --add NM &&
f225b218
JH
481 echo extra >>NM &&
482 git-read-tree -m $tree_O $tree_A $tree_B"
483
484test_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 &&
487 cp .orig-A/NM NM &&
488 echo extra >>NM &&
215a7ad1 489 git-update-index --add NM &&
f225b218
JH
490 git-read-tree -m $tree_O $tree_A $tree_B"
491
492test_expect_success \
493 '15 - must match A in O && A && B && O==A && O==B case' \
494 "rm -f .git/index NN &&
495 cp .orig-A/NN NN &&
215a7ad1 496 git-update-index --add NN &&
f225b218
JH
497 git-read-tree -m $tree_O $tree_A $tree_B &&
498 check_result"
499
500test_expect_success \
501 '15 - must match A in O && A && B && O==A && O==B case' \
502 "rm -f .git/index NN &&
503 cp .orig-A/NN NN &&
215a7ad1 504 git-update-index --add NN &&
f225b218
JH
505 echo extra >>NN &&
506 git-read-tree -m $tree_O $tree_A $tree_B &&
507 check_result"
508
509test_expect_failure \
510 '15 (fail) - must match A in O && A && B && O==A && O==B case' \
511 "rm -f .git/index NN &&
512 cp .orig-A/NN NN &&
513 echo extra >>NN &&
215a7ad1 514 git-update-index --add NN &&
f225b218 515 git-read-tree -m $tree_O $tree_A $tree_B"
2ecd9050
JH
516
517test_done