t / t1000-read-tree-m-3way.shon commit git-read-tree: make one-way merge also honor the "update" flag (b5b4250)
   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# Try merging and showing the various diffs
  79
  80# The tree is dirty at this point.
  81test_expect_failure \
  82    '3-way merge with git-read-tree -m' \
  83    "git-read-tree -m $tree_O $tree_A $tree_B"
  84
  85# This is done on an empty work directory, which is the normal
  86# merge person behaviour.
  87test_expect_success \
  88    '3-way merge with git-read-tree -m' \
  89    "rm -fr [NDMALTS][NDMALTSF] Z &&
  90     rm .git/index &&
  91     git-read-tree -m $tree_O $tree_A $tree_B"
  92
  93# This starts out with the first head, which is the normal
  94# patch submitter behaviour.
  95test_expect_success \
  96    '3-way merge with git-read-tree -m' \
  97    "git-read-tree $tree_A &&
  98     git-checkout-cache -f -u -a &&
  99     git-read-tree -m $tree_O $tree_A $tree_B"
 100
 101_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
 102_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
 103test_expect_success \
 104    'git-ls-files --stage of the merge result' \
 105    'git-ls-files --stage >current- &&
 106     sed -e "s/ $_x40 / X /" <current- >current'
 107
 108cat >expected <<\EOF
 109100644 X 2      AA
 110100644 X 3      AA
 111100644 X 2      AN
 112100644 X 1      DD
 113100644 X 3      DF
 114100644 X 2      DF/DF
 115100644 X 1      DM
 116100644 X 3      DM
 117100644 X 1      DN
 118100644 X 3      DN
 119100644 X 2      LL
 120100644 X 3      LL
 121100644 X 1      MD
 122100644 X 2      MD
 123100644 X 1      MM
 124100644 X 2      MM
 125100644 X 3      MM
 126100644 X 0      MN
 127100644 X 3      NA
 128100644 X 1      ND
 129100644 X 2      ND
 130100644 X 0      NM
 131100644 X 0      NN
 132100644 X 0      SS
 133100644 X 1      TT
 134100644 X 2      TT
 135100644 X 3      TT
 136100644 X 2      Z/AA
 137100644 X 3      Z/AA
 138100644 X 2      Z/AN
 139100644 X 1      Z/DD
 140100644 X 1      Z/DM
 141100644 X 3      Z/DM
 142100644 X 1      Z/DN
 143100644 X 3      Z/DN
 144100644 X 1      Z/MD
 145100644 X 2      Z/MD
 146100644 X 1      Z/MM
 147100644 X 2      Z/MM
 148100644 X 3      Z/MM
 149100644 X 0      Z/MN
 150100644 X 3      Z/NA
 151100644 X 1      Z/ND
 152100644 X 2      Z/ND
 153100644 X 0      Z/NM
 154100644 X 0      Z/NN
 155EOF
 156
 157test_expect_success \
 158    'validate merge result' \
 159    'diff current expected'
 160
 161test_done