t7004: Add tests for the git tag -n option.
[git/jnareb-git.git] / t / t1000-read-tree-m-3way.sh
blob37add1b50472e23ccb6b938ac6cdadba0c097fb8
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.
74 . ./test-lib.sh
75 . ../lib-read-tree-m-3way.sh
77 ################################################################
78 # Trivial "majority when 3 stages exist" merge plus #2ALT, #3ALT
79 # and #5ALT trivial merges.
81 cat >expected <<\EOF
82 100644 X 2 AA
83 100644 X 3 AA
84 100644 X 0 AN
85 100644 X 1 DD
86 100644 X 3 DF
87 100644 X 2 DF/DF
88 100644 X 1 DM
89 100644 X 3 DM
90 100644 X 1 DN
91 100644 X 3 DN
92 100644 X 0 LL
93 100644 X 1 MD
94 100644 X 2 MD
95 100644 X 1 MM
96 100644 X 2 MM
97 100644 X 3 MM
98 100644 X 0 MN
99 100644 X 0 NA
100 100644 X 1 ND
101 100644 X 2 ND
102 100644 X 0 NM
103 100644 X 0 NN
104 100644 X 0 SS
105 100644 X 1 TT
106 100644 X 2 TT
107 100644 X 3 TT
108 100644 X 2 Z/AA
109 100644 X 3 Z/AA
110 100644 X 0 Z/AN
111 100644 X 1 Z/DD
112 100644 X 1 Z/DM
113 100644 X 3 Z/DM
114 100644 X 1 Z/DN
115 100644 X 3 Z/DN
116 100644 X 1 Z/MD
117 100644 X 2 Z/MD
118 100644 X 1 Z/MM
119 100644 X 2 Z/MM
120 100644 X 3 Z/MM
121 100644 X 0 Z/MN
122 100644 X 0 Z/NA
123 100644 X 1 Z/ND
124 100644 X 2 Z/ND
125 100644 X 0 Z/NM
126 100644 X 0 Z/NN
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"
132 check_result () {
133 git ls-files --stage | sed -e 's/ '"$_x40"' / X /' >current &&
134 git diff 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 &&
142 rm .git/index &&
143 git read-tree -m $tree_O $tree_A $tree_B &&
144 check_result"
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 &&
151 rm .git/index &&
152 git read-tree $tree_A &&
153 git checkout-index -f -u -a &&
154 git read-tree -m $tree_O $tree_A $tree_B &&
155 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_failure \
214 '1 - must not have an entry not in A.' \
215 "rm -f .git/index XX &&
216 echo XX >XX &&
217 git update-index --add XX &&
218 git read-tree -m $tree_O $tree_A $tree_B"
220 test_expect_success \
221 '2 - must match B in !O && !A && B case.' \
222 "rm -f .git/index NA &&
223 cp .orig-B/NA NA &&
224 git update-index --add NA &&
225 git read-tree -m $tree_O $tree_A $tree_B"
227 test_expect_success \
228 '2 - matching B alone is OK in !O && !A && B case.' \
229 "rm -f .git/index NA &&
230 cp .orig-B/NA NA &&
231 git update-index --add NA &&
232 echo extra >>NA &&
233 git read-tree -m $tree_O $tree_A $tree_B"
235 test_expect_success \
236 '3 - must match A in !O && A && !B case.' \
237 "rm -f .git/index AN &&
238 cp .orig-A/AN AN &&
239 git update-index --add AN &&
240 git read-tree -m $tree_O $tree_A $tree_B &&
241 check_result"
243 test_expect_success \
244 '3 - matching A alone is OK in !O && A && !B case.' \
245 "rm -f .git/index AN &&
246 cp .orig-A/AN AN &&
247 git update-index --add AN &&
248 echo extra >>AN &&
249 git read-tree -m $tree_O $tree_A $tree_B"
251 test_expect_failure \
252 '3 (fail) - must match A in !O && A && !B case.' \
253 "rm -f .git/index AN &&
254 cp .orig-A/AN AN &&
255 echo extra >>AN &&
256 git update-index --add AN &&
257 git read-tree -m $tree_O $tree_A $tree_B"
259 test_expect_success \
260 '4 - must match and be up-to-date in !O && A && B && A!=B case.' \
261 "rm -f .git/index AA &&
262 cp .orig-A/AA AA &&
263 git update-index --add AA &&
264 git read-tree -m $tree_O $tree_A $tree_B &&
265 check_result"
267 test_expect_failure \
268 '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' \
269 "rm -f .git/index AA &&
270 cp .orig-A/AA AA &&
271 git update-index --add AA &&
272 echo extra >>AA &&
273 git read-tree -m $tree_O $tree_A $tree_B"
275 test_expect_failure \
276 '4 (fail) - 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 &&
279 echo extra >>AA &&
280 git update-index --add AA &&
281 git read-tree -m $tree_O $tree_A $tree_B"
283 test_expect_success \
284 '5 - must match in !O && A && B && A==B case.' \
285 "rm -f .git/index LL &&
286 cp .orig-A/LL LL &&
287 git update-index --add LL &&
288 git read-tree -m $tree_O $tree_A $tree_B &&
289 check_result"
291 test_expect_success \
292 '5 - must match in !O && A && B && A==B case.' \
293 "rm -f .git/index LL &&
294 cp .orig-A/LL LL &&
295 git update-index --add LL &&
296 echo extra >>LL &&
297 git read-tree -m $tree_O $tree_A $tree_B &&
298 check_result"
300 test_expect_failure \
301 '5 (fail) - must match A in !O && A && B && A==B case.' \
302 "rm -f .git/index LL &&
303 cp .orig-A/LL LL &&
304 echo extra >>LL &&
305 git update-index --add LL &&
306 git read-tree -m $tree_O $tree_A $tree_B"
308 test_expect_failure \
309 '6 - must not exist in O && !A && !B case' \
310 "rm -f .git/index DD &&
311 echo DD >DD
312 git update-index --add DD &&
313 git read-tree -m $tree_O $tree_A $tree_B"
315 test_expect_failure \
316 '7 - must not exist in O && !A && B && O!=B case' \
317 "rm -f .git/index DM &&
318 cp .orig-B/DM DM &&
319 git update-index --add DM &&
320 git read-tree -m $tree_O $tree_A $tree_B"
322 test_expect_failure \
323 '8 - must not exist in O && !A && B && O==B case' \
324 "rm -f .git/index DN &&
325 cp .orig-B/DN DN &&
326 git update-index --add DN &&
327 git read-tree -m $tree_O $tree_A $tree_B"
329 test_expect_success \
330 '9 - must match and be up-to-date in O && A && !B && O!=A case' \
331 "rm -f .git/index MD &&
332 cp .orig-A/MD MD &&
333 git update-index --add MD &&
334 git read-tree -m $tree_O $tree_A $tree_B &&
335 check_result"
337 test_expect_failure \
338 '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' \
339 "rm -f .git/index MD &&
340 cp .orig-A/MD MD &&
341 git update-index --add MD &&
342 echo extra >>MD &&
343 git read-tree -m $tree_O $tree_A $tree_B"
345 test_expect_failure \
346 '9 (fail) - 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 &&
349 echo extra >>MD &&
350 git update-index --add MD &&
351 git read-tree -m $tree_O $tree_A $tree_B"
353 test_expect_success \
354 '10 - must match and be up-to-date in O && A && !B && O==A case' \
355 "rm -f .git/index ND &&
356 cp .orig-A/ND ND &&
357 git update-index --add ND &&
358 git read-tree -m $tree_O $tree_A $tree_B &&
359 check_result"
361 test_expect_failure \
362 '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' \
363 "rm -f .git/index ND &&
364 cp .orig-A/ND ND &&
365 git update-index --add ND &&
366 echo extra >>ND &&
367 git read-tree -m $tree_O $tree_A $tree_B"
369 test_expect_failure \
370 '10 (fail) - 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 &&
373 echo extra >>ND &&
374 git update-index --add ND &&
375 git read-tree -m $tree_O $tree_A $tree_B"
377 test_expect_success \
378 '11 - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' \
379 "rm -f .git/index MM &&
380 cp .orig-A/MM MM &&
381 git update-index --add MM &&
382 git read-tree -m $tree_O $tree_A $tree_B &&
383 check_result"
385 test_expect_failure \
386 '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' \
387 "rm -f .git/index MM &&
388 cp .orig-A/MM MM &&
389 git update-index --add MM &&
390 echo extra >>MM &&
391 git read-tree -m $tree_O $tree_A $tree_B"
393 test_expect_failure \
394 '11 (fail) - 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 &&
397 echo extra >>MM &&
398 git update-index --add MM &&
399 git read-tree -m $tree_O $tree_A $tree_B"
401 test_expect_success \
402 '12 - must match A in O && A && B && O!=A && A==B case' \
403 "rm -f .git/index SS &&
404 cp .orig-A/SS SS &&
405 git update-index --add SS &&
406 git read-tree -m $tree_O $tree_A $tree_B &&
407 check_result"
409 test_expect_success \
410 '12 - must match A in O && A && B && O!=A && A==B case' \
411 "rm -f .git/index SS &&
412 cp .orig-A/SS SS &&
413 git update-index --add SS &&
414 echo extra >>SS &&
415 git read-tree -m $tree_O $tree_A $tree_B &&
416 check_result"
418 test_expect_failure \
419 '12 (fail) - must match A in O && A && B && O!=A && A==B case' \
420 "rm -f .git/index SS &&
421 cp .orig-A/SS SS &&
422 echo extra >>SS &&
423 git update-index --add SS &&
424 git read-tree -m $tree_O $tree_A $tree_B"
426 test_expect_success \
427 '13 - must match A in O && A && B && O!=A && O==B case' \
428 "rm -f .git/index MN &&
429 cp .orig-A/MN MN &&
430 git update-index --add MN &&
431 git read-tree -m $tree_O $tree_A $tree_B &&
432 check_result"
434 test_expect_success \
435 '13 - must match A in O && A && B && O!=A && O==B case' \
436 "rm -f .git/index MN &&
437 cp .orig-A/MN MN &&
438 git update-index --add MN &&
439 echo extra >>MN &&
440 git read-tree -m $tree_O $tree_A $tree_B &&
441 check_result"
443 test_expect_success \
444 '14 - must match and be up-to-date in O && A && B && O==A && O!=B case' \
445 "rm -f .git/index NM &&
446 cp .orig-A/NM NM &&
447 git update-index --add NM &&
448 git read-tree -m $tree_O $tree_A $tree_B &&
449 check_result"
451 test_expect_success \
452 '14 - may match B in O && A && B && O==A && O!=B case' \
453 "rm -f .git/index NM &&
454 cp .orig-B/NM NM &&
455 git update-index --add NM &&
456 echo extra >>NM &&
457 git read-tree -m $tree_O $tree_A $tree_B &&
458 check_result"
460 test_expect_failure \
461 '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' \
462 "rm -f .git/index NM &&
463 cp .orig-A/NM NM &&
464 git update-index --add NM &&
465 echo extra >>NM &&
466 git read-tree -m $tree_O $tree_A $tree_B"
468 test_expect_failure \
469 '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' \
470 "rm -f .git/index NM &&
471 cp .orig-A/NM NM &&
472 echo extra >>NM &&
473 git update-index --add NM &&
474 git read-tree -m $tree_O $tree_A $tree_B"
476 test_expect_success \
477 '15 - must match A in O && A && B && O==A && O==B case' \
478 "rm -f .git/index NN &&
479 cp .orig-A/NN NN &&
480 git update-index --add NN &&
481 git read-tree -m $tree_O $tree_A $tree_B &&
482 check_result"
484 test_expect_success \
485 '15 - must match A in O && A && B && O==A && O==B case' \
486 "rm -f .git/index NN &&
487 cp .orig-A/NN NN &&
488 git update-index --add NN &&
489 echo extra >>NN &&
490 git read-tree -m $tree_O $tree_A $tree_B &&
491 check_result"
493 test_expect_failure \
494 '15 (fail) - must match A in O && A && B && O==A && O==B case' \
495 "rm -f .git/index NN &&
496 cp .orig-A/NN NN &&
497 echo extra >>NN &&
498 git update-index --add NN &&
499 git read-tree -m $tree_O $tree_A $tree_B"
501 # #16
502 test_expect_success \
503 '16 - A matches in one and B matches in another.' \
504 'rm -f .git/index F16 &&
505 echo F16 >F16 &&
506 git update-index --add F16 &&
507 tree0=`git write-tree` &&
508 echo E16 >F16 &&
509 git update-index F16 &&
510 tree1=`git write-tree` &&
511 git read-tree -m $tree0 $tree1 $tree1 $tree0 &&
512 git ls-files --stage'
514 test_done