1#!/bin/sh
   2test_description="merges with unrelated index changes"
   4. ./test-lib.sh
   6# Testcase for some simple merges
   8#   A
   9#   o-----o B
  10#    \
  11#     \---o C
  12#      \
  13#       \-o D
  14#        \
  15#         o E
  16#   Commit A: some file a
  17#   Commit B: adds file b, modifies end of a
  18#   Commit C: adds file c
  19#   Commit D: adds file d, modifies beginning of a
  20#   Commit E: renames a->subdir/a, adds subdir/e
  21test_expect_success 'setup trivial merges' '
  23        test_seq 1 10 >a &&
  24        git add a &&
  25        test_tick && git commit -m A &&
  26        git branch A &&
  28        git branch B &&
  29        git branch C &&
  30        git branch D &&
  31        git branch E &&
  32        git checkout B &&
  34        echo b >b &&
  35        echo 11 >>a &&
  36        git add a b &&
  37        test_tick && git commit -m B &&
  38        git checkout C &&
  40        echo c >c &&
  41        git add c &&
  42        test_tick && git commit -m C &&
  43        git checkout D &&
  45        test_seq 2 10 >a &&
  46        echo d >d &&
  47        git add a d &&
  48        test_tick && git commit -m D &&
  49        git checkout E &&
  51        mkdir subdir &&
  52        git mv a subdir/a &&
  53        echo e >subdir/e &&
  54        git add subdir &&
  55        test_tick && git commit -m E
  56'
  57test_expect_success 'ff update' '
  59        git reset --hard &&
  60        git checkout A^0 &&
  61        touch random_file && git add random_file &&
  63        git merge E^0 &&
  65        test_must_fail git rev-parse HEAD:random_file &&
  67        test "$(git diff --name-only --cached E)" = "random_file"
  68'
  69test_expect_success 'ff update, important file modified' '
  71        git reset --hard &&
  72        git checkout A^0 &&
  73        mkdir subdir &&
  75        touch subdir/e &&
  76        git add subdir/e &&
  77        test_must_fail git merge E^0
  79'
  80test_expect_success 'resolve, trivial' '
  82        git reset --hard &&
  83        git checkout B^0 &&
  84        touch random_file && git add random_file &&
  86        test_must_fail git merge -s resolve C^0
  88'
  89test_expect_success 'resolve, non-trivial' '
  91        git reset --hard &&
  92        git checkout B^0 &&
  93        touch random_file && git add random_file &&
  95        test_must_fail git merge -s resolve D^0
  97'
  98test_expect_success 'recursive' '
 100        git reset --hard &&
 101        git checkout B^0 &&
 102        touch random_file && git add random_file &&
 104        test_must_fail git merge -s recursive C^0
 106'
 107test_expect_success 'octopus, unrelated file touched' '
 109        git reset --hard &&
 110        git checkout B^0 &&
 111        touch random_file && git add random_file &&
 113        test_must_fail git merge C^0 D^0
 115'
 116test_expect_success 'octopus, related file removed' '
 118        git reset --hard &&
 119        git checkout B^0 &&
 120        git rm b &&
 122        test_must_fail git merge C^0 D^0
 124'
 125test_expect_success 'octopus, related file modified' '
 127        git reset --hard &&
 128        git checkout B^0 &&
 129        echo 12 >>a && git add a &&
 131        test_must_fail git merge C^0 D^0
 133'
 134test_expect_success 'ours' '
 136        git reset --hard &&
 137        git checkout B^0 &&
 138        touch random_file && git add random_file &&
 140        test_must_fail git merge -s ours C^0
 142'
 143test_expect_success 'subtree' '
 145        git reset --hard &&
 146        git checkout B^0 &&
 147        touch random_file && git add random_file &&
 149        test_must_fail git merge -s subtree E^0
 151'
 152test_done