interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t1000-read-tree-m-3way.sh

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