t/README: add missing value for GIT_TEST_DEFAULT_REF_FORMAT
[git/gitster.git] / t / t1000-read-tree-m-3way.sh
blob0e8c0dfbbee643c80d2164b6dc8e80fe6522f2e0
1 #!/bin/sh
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.
14 merge A O B
16 Decisions are made by comparing contents of O, A and B pathname
17 by pathname. The result is determined by the following guiding
18 principle:
20 - If only A does something to it and B does not touch it, take
21 whatever A does.
23 - If only B does something to it and A does not touch it, take
24 whatever B does.
26 - If both A and B does something but in the same way, take
27 whatever they do.
29 - If A and B does something but different things, we need a
30 3-way merge:
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 |------------+------------+------------+------------+------------|
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 .----------------------------------------------------------------.
66 In addition:
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_PASSES_SANITIZE_LEAK=true
76 . ./test-lib.sh
77 . "$TEST_DIRECTORY"/lib-read-tree.sh
78 . "$TEST_DIRECTORY"/lib-read-tree-m-3way.sh
80 ################################################################
81 # Trivial "majority when 3 stages exist" merge plus #2ALT, #3ALT
82 # and #5ALT trivial merges.
84 cat >expected <<\EOF
85 100644 X 2 AA
86 100644 X 3 AA
87 100644 X 0 AN
88 100644 X 1 DD
89 100644 X 3 DF
90 100644 X 2 DF/DF
91 100644 X 1 DM
92 100644 X 3 DM
93 100644 X 1 DN
94 100644 X 3 DN
95 100644 X 0 LL
96 100644 X 1 MD
97 100644 X 2 MD
98 100644 X 1 MM
99 100644 X 2 MM
100 100644 X 3 MM
101 100644 X 0 MN
102 100644 X 0 NA
103 100644 X 1 ND
104 100644 X 2 ND
105 100644 X 0 NM
106 100644 X 0 NN
107 100644 X 0 SS
108 100644 X 1 TT
109 100644 X 2 TT
110 100644 X 3 TT
111 100644 X 2 Z/AA
112 100644 X 3 Z/AA
113 100644 X 0 Z/AN
114 100644 X 1 Z/DD
115 100644 X 1 Z/DM
116 100644 X 3 Z/DM
117 100644 X 1 Z/DN
118 100644 X 3 Z/DN
119 100644 X 1 Z/MD
120 100644 X 2 Z/MD
121 100644 X 1 Z/MM
122 100644 X 2 Z/MM
123 100644 X 3 Z/MM
124 100644 X 0 Z/MN
125 100644 X 0 Z/NA
126 100644 X 1 Z/ND
127 100644 X 2 Z/ND
128 100644 X 0 Z/NM
129 100644 X 0 Z/NN
132 check_result () {
133 git ls-files --stage | sed -e 's/ '"$OID_REGEX"' / X /' >current &&
134 test_cmp expected current
137 # This is done on an empty work directory, which is the normal
138 # merge person behaviour.
139 test_expect_success '3-way merge with git read-tree -m, empty cache' '
140 rm -fr [NDMALTS][NDMALTSF] Z &&
141 rm .git/index &&
142 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
143 check_result
146 # This starts out with the first head, which is the normal
147 # patch submitter behaviour.
148 test_expect_success '3-way merge with git read-tree -m, match H' '
149 rm -fr [NDMALTS][NDMALTSF] Z &&
150 rm .git/index &&
151 read_tree_must_succeed $tree_A &&
152 git checkout-index -f -u -a &&
153 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
154 check_result
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.
163 "git read-tree -m O A B"
165 O A B result index requirements
166 -------------------------------------------------------------------
167 1 missing missing missing - must not exist.
168 ------------------------------------------------------------------
169 2 missing missing exists take B* must match B, if exists.
170 ------------------------------------------------------------------
171 3 missing exists missing take A* must match A, if exists.
172 ------------------------------------------------------------------
173 4 missing exists A!=B no merge must match A and be
174 up-to-date, if exists.
175 ------------------------------------------------------------------
176 5 missing exists A==B take A must match A, if exists.
177 ------------------------------------------------------------------
178 6 exists missing missing remove must not exist.
179 ------------------------------------------------------------------
180 7 exists missing O!=B no merge must not exist.
181 ------------------------------------------------------------------
182 8 exists missing O==B remove must not exist.
183 ------------------------------------------------------------------
184 9 exists O!=A missing no merge must match A and be
185 up-to-date, if exists.
186 ------------------------------------------------------------------
187 10 exists O==A missing no merge must match A
188 ------------------------------------------------------------------
189 11 exists O!=A O!=B no merge must match A and be
190 A!=B up-to-date, if exists.
191 ------------------------------------------------------------------
192 12 exists O!=A O!=B take A must match A, if exists.
193 A==B
194 ------------------------------------------------------------------
195 13 exists O!=A O==B take A must match A, if exists.
196 ------------------------------------------------------------------
197 14 exists O==A O!=B take B if exists, must either (1)
198 match A and be up-to-date,
199 or (2) match B.
200 ------------------------------------------------------------------
201 15 exists O==A O==B take B must match A if exists.
202 ------------------------------------------------------------------
203 16 exists O==A O==B barf must match A if exists.
204 *multi* in one in another
205 -------------------------------------------------------------------
207 Note: we need to be careful in case 2 and 3. The tree A may contain
208 DF (file) when tree B require DF to be a directory by having DF/DF
209 (file).
211 END_OF_CASE_TABLE
213 test_expect_success '1 - must not have an entry not in A.' '
214 rm -f .git/index XX &&
215 echo XX >XX &&
216 git update-index --add XX &&
217 read_tree_must_fail -m $tree_O $tree_A $tree_B
220 test_expect_success '2 - must match B in !O && !A && B case.' '
221 rm -f .git/index NA &&
222 cp .orig-B/NA NA &&
223 git update-index --add NA &&
224 read_tree_must_succeed -m $tree_O $tree_A $tree_B
227 test_expect_success '2 - matching B alone is OK in !O && !A && B case.' '
228 rm -f .git/index NA &&
229 cp .orig-B/NA NA &&
230 git update-index --add NA &&
231 echo extra >>NA &&
232 read_tree_must_succeed -m $tree_O $tree_A $tree_B
235 test_expect_success '3 - must match A in !O && A && !B case.' '
236 rm -f .git/index AN &&
237 cp .orig-A/AN AN &&
238 git update-index --add AN &&
239 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
240 check_result
243 test_expect_success '3 - matching A alone is OK in !O && A && !B case.' '
244 rm -f .git/index AN &&
245 cp .orig-A/AN AN &&
246 git update-index --add AN &&
247 echo extra >>AN &&
248 read_tree_must_succeed -m $tree_O $tree_A $tree_B
251 test_expect_success '3 (fail) - must match A in !O && A && !B case.' '
252 rm -f .git/index AN &&
253 cp .orig-A/AN AN &&
254 echo extra >>AN &&
255 git update-index --add AN &&
256 read_tree_must_fail -m $tree_O $tree_A $tree_B
259 test_expect_success '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 &&
262 git update-index --add AA &&
263 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
264 check_result
267 test_expect_success '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' '
268 rm -f .git/index AA &&
269 cp .orig-A/AA AA &&
270 git update-index --add AA &&
271 echo extra >>AA &&
272 read_tree_must_fail -m $tree_O $tree_A $tree_B
275 test_expect_success '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' '
276 rm -f .git/index AA &&
277 cp .orig-A/AA AA &&
278 echo extra >>AA &&
279 git update-index --add AA &&
280 read_tree_must_fail -m $tree_O $tree_A $tree_B
283 test_expect_success '5 - must match in !O && A && B && A==B case.' '
284 rm -f .git/index LL &&
285 cp .orig-A/LL LL &&
286 git update-index --add LL &&
287 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
288 check_result
291 test_expect_success '5 - must match in !O && A && B && A==B case.' '
292 rm -f .git/index LL &&
293 cp .orig-A/LL LL &&
294 git update-index --add LL &&
295 echo extra >>LL &&
296 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
297 check_result
300 test_expect_success '5 (fail) - must match A in !O && A && B && A==B case.' '
301 rm -f .git/index LL &&
302 cp .orig-A/LL LL &&
303 echo extra >>LL &&
304 git update-index --add LL &&
305 read_tree_must_fail -m $tree_O $tree_A $tree_B
308 test_expect_success '6 - must not exist in O && !A && !B case' '
309 rm -f .git/index DD &&
310 echo DD >DD &&
311 git update-index --add DD &&
312 read_tree_must_fail -m $tree_O $tree_A $tree_B
315 test_expect_success '7 - must not exist in O && !A && B && O!=B case' '
316 rm -f .git/index DM &&
317 cp .orig-B/DM DM &&
318 git update-index --add DM &&
319 read_tree_must_fail -m $tree_O $tree_A $tree_B
322 test_expect_success '8 - must not exist in O && !A && B && O==B case' '
323 rm -f .git/index DN &&
324 cp .orig-B/DN DN &&
325 git update-index --add DN &&
326 read_tree_must_fail -m $tree_O $tree_A $tree_B
329 test_expect_success '9 - must match and be up-to-date in O && A && !B && O!=A case' '
330 rm -f .git/index MD &&
331 cp .orig-A/MD MD &&
332 git update-index --add MD &&
333 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
334 check_result
337 test_expect_success '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' '
338 rm -f .git/index MD &&
339 cp .orig-A/MD MD &&
340 git update-index --add MD &&
341 echo extra >>MD &&
342 read_tree_must_fail -m $tree_O $tree_A $tree_B
345 test_expect_success '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' '
346 rm -f .git/index MD &&
347 cp .orig-A/MD MD &&
348 echo extra >>MD &&
349 git update-index --add MD &&
350 read_tree_must_fail -m $tree_O $tree_A $tree_B
353 test_expect_success '10 - must match and be up-to-date in O && A && !B && O==A case' '
354 rm -f .git/index ND &&
355 cp .orig-A/ND ND &&
356 git update-index --add ND &&
357 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
358 check_result
361 test_expect_success '10 (fail) - 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 &&
364 git update-index --add ND &&
365 echo extra >>ND &&
366 read_tree_must_fail -m $tree_O $tree_A $tree_B
369 test_expect_success '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' '
370 rm -f .git/index ND &&
371 cp .orig-A/ND ND &&
372 echo extra >>ND &&
373 git update-index --add ND &&
374 read_tree_must_fail -m $tree_O $tree_A $tree_B
377 test_expect_success '11 - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' '
378 rm -f .git/index MM &&
379 cp .orig-A/MM MM &&
380 git update-index --add MM &&
381 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
382 check_result
385 test_expect_success '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' '
386 rm -f .git/index MM &&
387 cp .orig-A/MM MM &&
388 git update-index --add MM &&
389 echo extra >>MM &&
390 read_tree_must_fail -m $tree_O $tree_A $tree_B
393 test_expect_success '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' '
394 rm -f .git/index MM &&
395 cp .orig-A/MM MM &&
396 echo extra >>MM &&
397 git update-index --add MM &&
398 read_tree_must_fail -m $tree_O $tree_A $tree_B
401 test_expect_success '12 - must match A in O && A && B && O!=A && A==B case' '
402 rm -f .git/index SS &&
403 cp .orig-A/SS SS &&
404 git update-index --add SS &&
405 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
406 check_result
409 test_expect_success '12 - must match A in O && A && B && O!=A && A==B case' '
410 rm -f .git/index SS &&
411 cp .orig-A/SS SS &&
412 git update-index --add SS &&
413 echo extra >>SS &&
414 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
415 check_result
418 test_expect_success '12 (fail) - must match A in O && A && B && O!=A && A==B case' '
419 rm -f .git/index SS &&
420 cp .orig-A/SS SS &&
421 echo extra >>SS &&
422 git update-index --add SS &&
423 read_tree_must_fail -m $tree_O $tree_A $tree_B
426 test_expect_success '13 - must match A in O && A && B && O!=A && O==B case' '
427 rm -f .git/index MN &&
428 cp .orig-A/MN MN &&
429 git update-index --add MN &&
430 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
431 check_result
434 test_expect_success '13 - must match A in O && A && B && O!=A && O==B case' '
435 rm -f .git/index MN &&
436 cp .orig-A/MN MN &&
437 git update-index --add MN &&
438 echo extra >>MN &&
439 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
440 check_result
443 test_expect_success '14 - must match and be up-to-date in O && A && B && O==A && O!=B case' '
444 rm -f .git/index NM &&
445 cp .orig-A/NM NM &&
446 git update-index --add NM &&
447 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
448 check_result
451 test_expect_success '14 - may match B in O && A && B && O==A && O!=B case' '
452 rm -f .git/index NM &&
453 cp .orig-B/NM NM &&
454 git update-index --add NM &&
455 echo extra >>NM &&
456 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
457 check_result
460 test_expect_success '14 (fail) - 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 &&
463 git update-index --add NM &&
464 echo extra >>NM &&
465 read_tree_must_fail -m $tree_O $tree_A $tree_B
468 test_expect_success '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' '
469 rm -f .git/index NM &&
470 cp .orig-A/NM NM &&
471 echo extra >>NM &&
472 git update-index --add NM &&
473 read_tree_must_fail -m $tree_O $tree_A $tree_B
476 test_expect_success '15 - must match A in O && A && B && O==A && O==B case' '
477 rm -f .git/index NN &&
478 cp .orig-A/NN NN &&
479 git update-index --add NN &&
480 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
481 check_result
484 test_expect_success '15 - must match A in O && A && B && O==A && O==B case' '
485 rm -f .git/index NN &&
486 cp .orig-A/NN NN &&
487 git update-index --add NN &&
488 echo extra >>NN &&
489 read_tree_must_succeed -m $tree_O $tree_A $tree_B &&
490 check_result
493 test_expect_success '15 (fail) - must match A in O && A && B && O==A && O==B case' '
494 rm -f .git/index NN &&
495 cp .orig-A/NN NN &&
496 echo extra >>NN &&
497 git update-index --add NN &&
498 read_tree_must_fail -m $tree_O $tree_A $tree_B
501 test_expect_success '16 - A matches in one and B matches in another.' '
502 rm -f .git/index F16 &&
503 echo F16 >F16 &&
504 git update-index --add F16 &&
505 tree0=$(git write-tree) &&
506 echo E16 >F16 &&
507 git update-index F16 &&
508 tree1=$(git write-tree) &&
509 read_tree_must_succeed -m $tree0 $tree1 $tree1 $tree0 &&
510 git ls-files --stage
513 test_done