]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1000-read-tree-m-3way.sh
test-lib: refactor $GIT_SKIP_TESTS matching
[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
ea5070c9 75. "$TEST_DIRECTORY"/lib-read-tree.sh
bfdbee98 76. "$TEST_DIRECTORY"/lib-read-tree-m-3way.sh
2ecd9050
JH
77
78################################################################
32192e66
JH
79# Trivial "majority when 3 stages exist" merge plus #2ALT, #3ALT
80# and #5ALT trivial merges.
2ecd9050 81
2ecd9050 82cat >expected <<\EOF
2eab945e
JH
83100644 X 2 AA
84100644 X 3 AA
32192e66 85100644 X 0 AN
2eab945e
JH
86100644 X 1 DD
87100644 X 3 DF
88100644 X 2 DF/DF
89100644 X 1 DM
90100644 X 3 DM
91100644 X 1 DN
92100644 X 3 DN
e7f9bc41 93100644 X 0 LL
2eab945e
JH
94100644 X 1 MD
95100644 X 2 MD
96100644 X 1 MM
97100644 X 2 MM
98100644 X 3 MM
99100644 X 0 MN
32192e66 100100644 X 0 NA
2eab945e
JH
101100644 X 1 ND
102100644 X 2 ND
103100644 X 0 NM
104100644 X 0 NN
105100644 X 0 SS
106100644 X 1 TT
107100644 X 2 TT
108100644 X 3 TT
109100644 X 2 Z/AA
110100644 X 3 Z/AA
32192e66 111100644 X 0 Z/AN
2eab945e
JH
112100644 X 1 Z/DD
113100644 X 1 Z/DM
114100644 X 3 Z/DM
115100644 X 1 Z/DN
116100644 X 3 Z/DN
117100644 X 1 Z/MD
118100644 X 2 Z/MD
119100644 X 1 Z/MM
120100644 X 2 Z/MM
121100644 X 3 Z/MM
122100644 X 0 Z/MN
32192e66 123100644 X 0 Z/NA
2eab945e
JH
124100644 X 1 Z/ND
125100644 X 2 Z/ND
126100644 X 0 Z/NM
127100644 X 0 Z/NN
2ecd9050
JH
128EOF
129
f225b218 130check_result () {
5be60078 131 git ls-files --stage | sed -e 's/ '"$_x40"' / X /' >current &&
3af82863 132 test_cmp expected current
f225b218 133}
7d95ee93
JH
134
135# This is done on an empty work directory, which is the normal
136# merge person behaviour.
137test_expect_success \
5be60078 138 '3-way merge with git read-tree -m, empty cache' \
7d95ee93
JH
139 "rm -fr [NDMALTS][NDMALTSF] Z &&
140 rm .git/index &&
ea5070c9 141 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218 142 check_result"
7d95ee93
JH
143
144# This starts out with the first head, which is the normal
145# patch submitter behaviour.
2ecd9050 146test_expect_success \
5be60078 147 '3-way merge with git read-tree -m, match H' \
f225b218
JH
148 "rm -fr [NDMALTS][NDMALTSF] Z &&
149 rm .git/index &&
ea5070c9 150 read_tree_must_succeed $tree_A &&
5be60078 151 git checkout-index -f -u -a &&
ea5070c9 152 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218
JH
153 check_result"
154
155: <<\END_OF_CASE_TABLE
156
157We have so far tested only empty index and clean-and-matching-A index
158case which are trivial. Make sure index requirements are also
3e03aaf5 159checked.
f225b218 160
5be60078 161"git read-tree -m O A B"
f225b218
JH
162
163 O A B result index requirements
164-------------------------------------------------------------------
165 1 missing missing missing - must not exist.
166 ------------------------------------------------------------------
3e03aaf5 167 2 missing missing exists take B* must match B, if exists.
f225b218 168 ------------------------------------------------------------------
3e03aaf5 169 3 missing exists missing take A* must match A, if exists.
f225b218
JH
170 ------------------------------------------------------------------
171 4 missing exists A!=B no merge must match A and be
172 up-to-date, if exists.
173 ------------------------------------------------------------------
3e03aaf5 174 5 missing exists A==B take A must match A, if exists.
f225b218 175 ------------------------------------------------------------------
3e03aaf5 176 6 exists missing missing remove must not exist.
f225b218
JH
177 ------------------------------------------------------------------
178 7 exists missing O!=B no merge must not exist.
179 ------------------------------------------------------------------
3e03aaf5 180 8 exists missing O==B remove must not exist.
f225b218
JH
181 ------------------------------------------------------------------
182 9 exists O!=A missing no merge must match A and be
183 up-to-date, if exists.
184 ------------------------------------------------------------------
ea4b52a8 185 10 exists O==A missing no merge must match A
f225b218
JH
186 ------------------------------------------------------------------
187 11 exists O!=A O!=B no merge must match A and be
188 A!=B up-to-date, if exists.
189 ------------------------------------------------------------------
190 12 exists O!=A O!=B take A must match A, if exists.
191 A==B
192 ------------------------------------------------------------------
193 13 exists O!=A O==B take A must match A, if exists.
194 ------------------------------------------------------------------
3e03aaf5 195 14 exists O==A O!=B take B if exists, must either (1)
f225b218
JH
196 match A and be up-to-date,
197 or (2) match B.
198 ------------------------------------------------------------------
199 15 exists O==A O==B take B must match A if exists.
4d3fe0c5
JH
200 ------------------------------------------------------------------
201 16 exists O==A O==B barf must match A if exists.
202 *multi* in one in another
f225b218
JH
203-------------------------------------------------------------------
204
3e03aaf5
JH
205Note: we need to be careful in case 2 and 3. The tree A may contain
206DF (file) when tree B require DF to be a directory by having DF/DF
207(file).
f225b218
JH
208
209END_OF_CASE_TABLE
210
41ac414e
JH
211test_expect_success '1 - must not have an entry not in A.' "
212 rm -f .git/index XX &&
f225b218 213 echo XX >XX &&
5be60078 214 git update-index --add XX &&
ea5070c9 215 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 216"
f225b218 217
32192e66
JH
218test_expect_success \
219 '2 - must match B in !O && !A && B case.' \
220 "rm -f .git/index NA &&
221 cp .orig-B/NA NA &&
5be60078 222 git update-index --add NA &&
ea5070c9 223 read_tree_must_succeed -m $tree_O $tree_A $tree_B"
32192e66
JH
224
225test_expect_success \
226 '2 - matching B alone is OK in !O && !A && B case.' \
f225b218
JH
227 "rm -f .git/index NA &&
228 cp .orig-B/NA NA &&
5be60078 229 git update-index --add NA &&
32192e66 230 echo extra >>NA &&
ea5070c9 231 read_tree_must_succeed -m $tree_O $tree_A $tree_B"
f225b218
JH
232
233test_expect_success \
32192e66 234 '3 - must match A in !O && A && !B case.' \
f225b218
JH
235 "rm -f .git/index AN &&
236 cp .orig-A/AN AN &&
5be60078 237 git update-index --add AN &&
ea5070c9 238 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218
JH
239 check_result"
240
32192e66
JH
241test_expect_success \
242 '3 - matching A alone is OK in !O && A && !B case.' \
f225b218
JH
243 "rm -f .git/index AN &&
244 cp .orig-A/AN AN &&
5be60078 245 git update-index --add AN &&
f225b218 246 echo extra >>AN &&
ea5070c9 247 read_tree_must_succeed -m $tree_O $tree_A $tree_B"
f225b218 248
41ac414e
JH
249test_expect_success \
250 '3 (fail) - must match A in !O && A && !B case.' "
251 rm -f .git/index AN &&
f225b218
JH
252 cp .orig-A/AN AN &&
253 echo extra >>AN &&
5be60078 254 git update-index --add AN &&
ea5070c9 255 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 256"
f225b218
JH
257
258test_expect_success \
259 '4 - must match and be up-to-date in !O && A && B && A!=B case.' \
260 "rm -f .git/index AA &&
261 cp .orig-A/AA AA &&
5be60078 262 git update-index --add AA &&
ea5070c9 263 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218
JH
264 check_result"
265
41ac414e
JH
266test_expect_success \
267 '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' "
268 rm -f .git/index AA &&
f225b218 269 cp .orig-A/AA AA &&
5be60078 270 git update-index --add AA &&
f225b218 271 echo extra >>AA &&
ea5070c9 272 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 273"
f225b218 274
41ac414e
JH
275test_expect_success \
276 '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' "
277 rm -f .git/index AA &&
f225b218
JH
278 cp .orig-A/AA AA &&
279 echo extra >>AA &&
5be60078 280 git update-index --add AA &&
ea5070c9 281 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 282"
f225b218
JH
283
284test_expect_success \
e7f9bc41 285 '5 - must match in !O && A && B && A==B case.' \
f225b218
JH
286 "rm -f .git/index LL &&
287 cp .orig-A/LL LL &&
5be60078 288 git update-index --add LL &&
ea5070c9 289 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218
JH
290 check_result"
291
e7f9bc41
JH
292test_expect_success \
293 '5 - must match in !O && A && B && A==B case.' \
f225b218
JH
294 "rm -f .git/index LL &&
295 cp .orig-A/LL LL &&
5be60078 296 git update-index --add LL &&
f225b218 297 echo extra >>LL &&
ea5070c9 298 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
e7f9bc41 299 check_result"
f225b218 300
41ac414e
JH
301test_expect_success \
302 '5 (fail) - must match A in !O && A && B && A==B case.' "
303 rm -f .git/index LL &&
f225b218
JH
304 cp .orig-A/LL LL &&
305 echo extra >>LL &&
5be60078 306 git update-index --add LL &&
ea5070c9 307 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 308"
f225b218 309
41ac414e
JH
310test_expect_success \
311 '6 - must not exist in O && !A && !B case' "
312 rm -f .git/index DD &&
a48fcd83 313 echo DD >DD &&
5be60078 314 git update-index --add DD &&
ea5070c9 315 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 316"
f225b218 317
41ac414e
JH
318test_expect_success \
319 '7 - must not exist in O && !A && B && O!=B case' "
320 rm -f .git/index DM &&
f225b218 321 cp .orig-B/DM DM &&
5be60078 322 git update-index --add DM &&
ea5070c9 323 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 324"
f225b218 325
41ac414e
JH
326test_expect_success \
327 '8 - must not exist in O && !A && B && O==B case' "
328 rm -f .git/index DN &&
f225b218 329 cp .orig-B/DN DN &&
5be60078 330 git update-index --add DN &&
ea5070c9 331 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 332"
f225b218
JH
333
334test_expect_success \
335 '9 - must match and be up-to-date in O && A && !B && O!=A case' \
336 "rm -f .git/index MD &&
337 cp .orig-A/MD MD &&
5be60078 338 git update-index --add MD &&
ea5070c9 339 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218
JH
340 check_result"
341
41ac414e
JH
342test_expect_success \
343 '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' "
344 rm -f .git/index MD &&
f225b218 345 cp .orig-A/MD MD &&
5be60078 346 git update-index --add MD &&
f225b218 347 echo extra >>MD &&
ea5070c9 348 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 349"
f225b218 350
41ac414e
JH
351test_expect_success \
352 '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' "
353 rm -f .git/index MD &&
f225b218
JH
354 cp .orig-A/MD MD &&
355 echo extra >>MD &&
5be60078 356 git update-index --add MD &&
ea5070c9 357 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 358"
f225b218
JH
359
360test_expect_success \
361 '10 - must match and be up-to-date in O && A && !B && O==A case' \
362 "rm -f .git/index ND &&
363 cp .orig-A/ND ND &&
5be60078 364 git update-index --add ND &&
ea5070c9 365 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218
JH
366 check_result"
367
41ac414e
JH
368test_expect_success \
369 '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' "
370 rm -f .git/index ND &&
f225b218 371 cp .orig-A/ND ND &&
5be60078 372 git update-index --add ND &&
f225b218 373 echo extra >>ND &&
ea5070c9 374 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 375"
f225b218 376
41ac414e
JH
377test_expect_success \
378 '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' "
379 rm -f .git/index ND &&
f225b218
JH
380 cp .orig-A/ND ND &&
381 echo extra >>ND &&
5be60078 382 git update-index --add ND &&
ea5070c9 383 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 384"
f225b218
JH
385
386test_expect_success \
387 '11 - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' \
388 "rm -f .git/index MM &&
389 cp .orig-A/MM MM &&
5be60078 390 git update-index --add MM &&
ea5070c9 391 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218
JH
392 check_result"
393
41ac414e
JH
394test_expect_success \
395 '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' "
396 rm -f .git/index MM &&
f225b218 397 cp .orig-A/MM MM &&
5be60078 398 git update-index --add MM &&
f225b218 399 echo extra >>MM &&
ea5070c9 400 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 401"
f225b218 402
41ac414e
JH
403test_expect_success \
404 '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' "
405 rm -f .git/index MM &&
f225b218
JH
406 cp .orig-A/MM MM &&
407 echo extra >>MM &&
5be60078 408 git update-index --add MM &&
ea5070c9 409 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 410"
f225b218
JH
411
412test_expect_success \
413 '12 - must match A in O && A && B && O!=A && A==B case' \
414 "rm -f .git/index SS &&
415 cp .orig-A/SS SS &&
5be60078 416 git update-index --add SS &&
ea5070c9 417 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218
JH
418 check_result"
419
420test_expect_success \
421 '12 - must match A in O && A && B && O!=A && A==B case' \
422 "rm -f .git/index SS &&
423 cp .orig-A/SS SS &&
5be60078 424 git update-index --add SS &&
f225b218 425 echo extra >>SS &&
ea5070c9 426 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218
JH
427 check_result"
428
41ac414e
JH
429test_expect_success \
430 '12 (fail) - must match A in O && A && B && O!=A && A==B case' "
431 rm -f .git/index SS &&
f225b218
JH
432 cp .orig-A/SS SS &&
433 echo extra >>SS &&
5be60078 434 git update-index --add SS &&
ea5070c9 435 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 436"
f225b218
JH
437
438test_expect_success \
439 '13 - must match A in O && A && B && O!=A && O==B case' \
440 "rm -f .git/index MN &&
441 cp .orig-A/MN MN &&
5be60078 442 git update-index --add MN &&
ea5070c9 443 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218
JH
444 check_result"
445
446test_expect_success \
447 '13 - must match A in O && A && B && O!=A && O==B case' \
448 "rm -f .git/index MN &&
449 cp .orig-A/MN MN &&
5be60078 450 git update-index --add MN &&
f225b218 451 echo extra >>MN &&
ea5070c9 452 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218
JH
453 check_result"
454
455test_expect_success \
456 '14 - must match and be up-to-date in O && A && B && O==A && O!=B case' \
457 "rm -f .git/index NM &&
458 cp .orig-A/NM NM &&
5be60078 459 git update-index --add NM &&
ea5070c9 460 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218
JH
461 check_result"
462
036d51cc
JH
463test_expect_success \
464 '14 - may match B in O && A && B && O==A && O!=B case' \
465 "rm -f .git/index NM &&
466 cp .orig-B/NM NM &&
5be60078 467 git update-index --add NM &&
036d51cc 468 echo extra >>NM &&
ea5070c9 469 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
036d51cc
JH
470 check_result"
471
41ac414e
JH
472test_expect_success \
473 '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' "
474 rm -f .git/index NM &&
f225b218 475 cp .orig-A/NM NM &&
5be60078 476 git update-index --add NM &&
f225b218 477 echo extra >>NM &&
ea5070c9 478 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 479"
f225b218 480
41ac414e
JH
481test_expect_success \
482 '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' "
483 rm -f .git/index NM &&
f225b218
JH
484 cp .orig-A/NM NM &&
485 echo extra >>NM &&
5be60078 486 git update-index --add NM &&
ea5070c9 487 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 488"
f225b218
JH
489
490test_expect_success \
491 '15 - must match A in O && A && B && O==A && O==B case' \
492 "rm -f .git/index NN &&
493 cp .orig-A/NN NN &&
5be60078 494 git update-index --add NN &&
ea5070c9 495 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218
JH
496 check_result"
497
498test_expect_success \
499 '15 - must match A in O && A && B && O==A && O==B case' \
500 "rm -f .git/index NN &&
501 cp .orig-A/NN NN &&
5be60078 502 git update-index --add NN &&
f225b218 503 echo extra >>NN &&
ea5070c9 504 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
f225b218
JH
505 check_result"
506
41ac414e
JH
507test_expect_success \
508 '15 (fail) - must match A in O && A && B && O==A && O==B case' "
509 rm -f .git/index NN &&
f225b218
JH
510 cp .orig-A/NN NN &&
511 echo extra >>NN &&
5be60078 512 git update-index --add NN &&
ea5070c9 513 read_tree_must_fail -m $tree_O $tree_A $tree_B
41ac414e 514"
2ecd9050 515
4d3fe0c5
JH
516# #16
517test_expect_success \
518 '16 - A matches in one and B matches in another.' \
519 'rm -f .git/index F16 &&
520 echo F16 >F16 &&
5be60078
JH
521 git update-index --add F16 &&
522 tree0=`git write-tree` &&
4d3fe0c5 523 echo E16 >F16 &&
5be60078
JH
524 git update-index F16 &&
525 tree1=`git write-tree` &&
ea5070c9 526 read_tree_must_succeed -m $tree0 $tree1 $tree1 $tree0 &&
5be60078 527 git ls-files --stage'
4d3fe0c5 528
2ecd9050 529test_done