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. ./test-lib.sh 75. ../lib-read-tree-m-3way.sh 76 77################################################################ 78# Trivial "majority when 3 stages exist" merge plus #5ALT trivial 79# merge. 80 81cat>expected <<\EOF 82100644 X 2 AA 83100644 X 3 AA 84100644 X 2 AN 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 92100644 X 0 LL 93100644 X 1 MD 94100644 X 2 MD 95100644 X 1 MM 96100644 X 2 MM 97100644 X 3 MM 98100644 X 0 MN 99100644 X 3 NA 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 110100644 X 2 Z/AN 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 122100644 X 3 Z/NA 123100644 X 1 Z/ND 124100644 X 2 Z/ND 125100644 X 0 Z/NM 126100644 X 0 Z/NN 127EOF 128 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 132check_result () { 133 git-ls-files --stage|sed-e's/ '"$_x40"' / X /'>current && 134diff-u expected current 135} 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&& 144 check_result" 145 146# This starts out with the first head, which is the normal 147# patch submitter behaviour. 148test_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-cache -f -u -a && 154 git-read-tree -m$tree_O$tree_A$tree_B&& 155 check_result" 156 157: <<\END_OF_CASE_TABLE 158 159We have so far tested only empty index and clean-and-matching-A index 160casewhich 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------------------------------------------------------------------- 1681 missing missing missing - must not exist. 169------------------------------------------------------------------ 1702 missing missing exists no merge must not exist. 171------------------------------------ 172(ALT) take B* must match B,if exists. 173------------------------------------------------------------------ 1743 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------------------------------------------------------------------ 1794 missing exists A!=B no merge must match A and be 180 up-to-date,if exists. 181------------------------------------------------------------------ 1825 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------------------------------------------------------------------ 1876 exists missing missing no merge must not exist. 188------------------------------------ 189(ALT) remove must not exist. 190------------------------------------------------------------------ 1917 exists missing O!=B no merge must not exist. 192------------------------------------------------------------------ 1938 exists missing O==B no merge must not exist. 194------------------------------------ 195(ALT) remove must not exist. 196------------------------------------------------------------------ 1979 exists O!=A missing no merge must match A and be 198 up-to-date,if exists. 199------------------------------------------------------------------ 20010 exists O==A missing no merge must match A and be 201 up-to-date,if exists. 202------------------------------------ 203(ALT) remove ditto 204------------------------------------------------------------------ 20511 exists O!=A O!=B no merge must match A and be 206 A!=B up-to-date,if exists. 207------------------------------------------------------------------ 20812 exists O!=A O!=B take A must match A,if exists. 209 A==B 210------------------------------------------------------------------ 21113 exists O!=A O==B take A must match A,if exists. 212------------------------------------------------------------------ 21314 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------------------------------------------------------------------ 22015 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 && 233 git-update-cache --add XX && 234 git-read-tree -m$tree_O$tree_A$tree_B" 235 236test_expect_failure \ 237'2 - must not have an entry not in A.' \ 238"rm -f .git/index NA && 239 cp .orig-B/NA NA && 240 git-update-cache --add NA && 241 git-read-tree -m$tree_O$tree_A$tree_B" 242 243test_expect_success \ 244'3 - must match and be up-to-date in !O && A && !B case.' \ 245"rm -f .git/index AN && 246 cp .orig-A/AN AN && 247 git-update-cache --add AN && 248 git-read-tree -m$tree_O$tree_A$tree_B&& 249 check_result" 250 251test_expect_failure \ 252'3 (fail) - must match and be up-to-date in !O && A && !B case.' \ 253"rm -f .git/index AN && 254 cp .orig-A/AN AN && 255 git-update-cache --add AN && 256 echo extra >>AN && 257 git-read-tree -m$tree_O$tree_A$tree_B" 258 259test_expect_failure \ 260'3 (fail) - must match and be up-to-date in !O && A && !B case.' \ 261"rm -f .git/index AN && 262 cp .orig-A/AN AN && 263 echo extra >>AN && 264 git-update-cache --add AN && 265 git-read-tree -m$tree_O$tree_A$tree_B" 266 267test_expect_success \ 268'4 - 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-cache --add AA && 272 git-read-tree -m$tree_O$tree_A$tree_B&& 273 check_result" 274 275test_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 git-update-cache --add AA && 280 echo extra >>AA && 281 git-read-tree -m$tree_O$tree_A$tree_B" 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 && 287 echo extra >>AA && 288 git-update-cache --add AA && 289 git-read-tree -m$tree_O$tree_A$tree_B" 290 291test_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-cache --add LL && 296 git-read-tree -m$tree_O$tree_A$tree_B&& 297 check_result" 298 299test_expect_success \ 300'5 - must match in !O && A && B && A==B case.' \ 301"rm -f .git/index LL && 302 cp .orig-A/LL LL && 303 git-update-cache --add LL && 304 echo extra >>LL && 305 git-read-tree -m$tree_O$tree_A$tree_B&& 306 check_result" 307 308test_expect_failure \ 309'5 (fail) - must match A in !O && A && B && A==B case.' \ 310"rm -f .git/index LL && 311 cp .orig-A/LL LL && 312 echo extra >>LL && 313 git-update-cache --add LL && 314 git-read-tree -m$tree_O$tree_A$tree_B" 315 316test_expect_failure \ 317'6 - must not exist in O && !A && !B case' \ 318"rm -f .git/index DD && 319 echo DD >DD 320 git-update-cache --add DD && 321 git-read-tree -m$tree_O$tree_A$tree_B" 322 323test_expect_failure \ 324'7 - must not exist in O && !A && B && O!=B case' \ 325"rm -f .git/index DM && 326 cp .orig-B/DM DM && 327 git-update-cache --add DM && 328 git-read-tree -m$tree_O$tree_A$tree_B" 329 330test_expect_failure \ 331'8 - must not exist in O && !A && B && O==B case' \ 332"rm -f .git/index DN && 333 cp .orig-B/DN DN && 334 git-update-cache --add DN && 335 git-read-tree -m$tree_O$tree_A$tree_B" 336 337test_expect_success \ 338'9 - 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-cache --add MD && 342 git-read-tree -m$tree_O$tree_A$tree_B&& 343 check_result" 344 345test_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 git-update-cache --add MD && 350 echo extra >>MD && 351 git-read-tree -m$tree_O$tree_A$tree_B" 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 && 357 echo extra >>MD && 358 git-update-cache --add MD && 359 git-read-tree -m$tree_O$tree_A$tree_B" 360 361test_expect_success \ 362'10 - 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-cache --add ND && 366 git-read-tree -m$tree_O$tree_A$tree_B&& 367 check_result" 368 369test_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 git-update-cache --add ND && 374 echo extra >>ND && 375 git-read-tree -m$tree_O$tree_A$tree_B" 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 && 381 echo extra >>ND && 382 git-update-cache --add ND && 383 git-read-tree -m$tree_O$tree_A$tree_B" 384 385test_expect_success \ 386'11 - 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-cache --add MM && 390 git-read-tree -m$tree_O$tree_A$tree_B&& 391 check_result" 392 393test_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 git-update-cache --add MM && 398 echo extra >>MM && 399 git-read-tree -m$tree_O$tree_A$tree_B" 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 && 405 echo extra >>MM && 406 git-update-cache --add MM && 407 git-read-tree -m$tree_O$tree_A$tree_B" 408 409test_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-cache --add SS && 414 git-read-tree -m$tree_O$tree_A$tree_B&& 415 check_result" 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 && 421 git-update-cache --add SS && 422 echo extra >>SS && 423 git-read-tree -m$tree_O$tree_A$tree_B&& 424 check_result" 425 426test_expect_failure \ 427'12 (fail) - must match A in O && A && B && O!=A && A==B case' \ 428"rm -f .git/index SS && 429 cp .orig-A/SS SS && 430 echo extra >>SS && 431 git-update-cache --add SS && 432 git-read-tree -m$tree_O$tree_A$tree_B" 433 434test_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-cache --add MN && 439 git-read-tree -m$tree_O$tree_A$tree_B&& 440 check_result" 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 && 446 git-update-cache --add MN && 447 echo extra >>MN && 448 git-read-tree -m$tree_O$tree_A$tree_B&& 449 check_result" 450 451test_expect_success \ 452'14 - must match and be up-to-date in O && A && B && O==A && O!=B case' \ 453"rm -f .git/index NM && 454 cp .orig-A/NM NM && 455 git-update-cache --add NM && 456 git-read-tree -m$tree_O$tree_A$tree_B&& 457 check_result" 458 459test_expect_failure \ 460'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-cache --add NM && 464 echo extra >>NM && 465 git-read-tree -m$tree_O$tree_A$tree_B" 466 467test_expect_failure \ 468'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-cache --add NM && 473 git-read-tree -m$tree_O$tree_A$tree_B" 474 475test_expect_success \ 476'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-cache --add NN && 480 git-read-tree -m$tree_O$tree_A$tree_B&& 481 check_result" 482 483test_expect_success \ 484'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-cache --add NN && 488 echo extra >>NN && 489 git-read-tree -m$tree_O$tree_A$tree_B&& 490 check_result" 491 492test_expect_failure \ 493'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-cache --add NN && 498 git-read-tree -m$tree_O$tree_A$tree_B" 499 500test_done