t / t7601-merge-pull-config.shon commit t1500: avoid changing working directory outside of tests (1e043cf)
   1#!/bin/sh
   2
   3test_description='git merge
   4
   5Testing pull.* configuration parsing.'
   6
   7. ./test-lib.sh
   8
   9test_expect_success 'setup' '
  10        echo c0 >c0.c &&
  11        git add c0.c &&
  12        git commit -m c0 &&
  13        git tag c0 &&
  14        echo c1 >c1.c &&
  15        git add c1.c &&
  16        git commit -m c1 &&
  17        git tag c1 &&
  18        git reset --hard c0 &&
  19        echo c2 >c2.c &&
  20        git add c2.c &&
  21        git commit -m c2 &&
  22        git tag c2 &&
  23        git reset --hard c0 &&
  24        echo c3 >c3.c &&
  25        git add c3.c &&
  26        git commit -m c3 &&
  27        git tag c3
  28'
  29
  30test_expect_success 'merge c1 with c2' '
  31        git reset --hard c1 &&
  32        test -f c0.c &&
  33        test -f c1.c &&
  34        test ! -f c2.c &&
  35        test ! -f c3.c &&
  36        git merge c2 &&
  37        test -f c1.c &&
  38        test -f c2.c
  39'
  40
  41test_expect_success 'fast-forward pull succeeds with "true" in pull.ff' '
  42        git reset --hard c0 &&
  43        test_config pull.ff true &&
  44        git pull . c1 &&
  45        test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
  46'
  47
  48test_expect_success 'pull.ff=true overrides merge.ff=false' '
  49        git reset --hard c0 &&
  50        test_config merge.ff false &&
  51        test_config pull.ff true &&
  52        git pull . c1 &&
  53        test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
  54'
  55
  56test_expect_success 'fast-forward pull creates merge with "false" in pull.ff' '
  57        git reset --hard c0 &&
  58        test_config pull.ff false &&
  59        git pull . c1 &&
  60        test "$(git rev-parse HEAD^1)" = "$(git rev-parse c0)" &&
  61        test "$(git rev-parse HEAD^2)" = "$(git rev-parse c1)"
  62'
  63
  64test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' '
  65        git reset --hard c1 &&
  66        test_config pull.ff only &&
  67        test_must_fail git pull . c3
  68'
  69
  70test_expect_success 'merge c1 with c2 (ours in pull.twohead)' '
  71        git reset --hard c1 &&
  72        git config pull.twohead ours &&
  73        git merge c2 &&
  74        test -f c1.c &&
  75        ! test -f c2.c
  76'
  77
  78test_expect_success 'merge c1 with c2 and c3 (recursive in pull.octopus)' '
  79        git reset --hard c1 &&
  80        git config pull.octopus "recursive" &&
  81        test_must_fail git merge c2 c3 &&
  82        test "$(git rev-parse c1)" = "$(git rev-parse HEAD)"
  83'
  84
  85test_expect_success 'merge c1 with c2 and c3 (recursive and octopus in pull.octopus)' '
  86        git reset --hard c1 &&
  87        git config pull.octopus "recursive octopus" &&
  88        git merge c2 c3 &&
  89        test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&
  90        test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" &&
  91        test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" &&
  92        test "$(git rev-parse c3)" = "$(git rev-parse HEAD^3)" &&
  93        git diff --exit-code &&
  94        test -f c0.c &&
  95        test -f c1.c &&
  96        test -f c2.c &&
  97        test -f c3.c
  98'
  99
 100conflict_count()
 101{
 102        {
 103                git diff-files --name-only
 104                git ls-files --unmerged
 105        } | wc -l
 106}
 107
 108# c4 - c5
 109#    \ c6
 110#
 111# There are two conflicts here:
 112#
 113# 1) Because foo.c is renamed to bar.c, recursive will handle this,
 114# resolve won't.
 115#
 116# 2) One in conflict.c and that will always fail.
 117
 118test_expect_success 'setup conflicted merge' '
 119        git reset --hard c0 &&
 120        echo A >conflict.c &&
 121        git add conflict.c &&
 122        echo contents >foo.c &&
 123        git add foo.c &&
 124        git commit -m c4 &&
 125        git tag c4 &&
 126        echo B >conflict.c &&
 127        git add conflict.c &&
 128        git mv foo.c bar.c &&
 129        git commit -m c5 &&
 130        git tag c5 &&
 131        git reset --hard c4 &&
 132        echo C >conflict.c &&
 133        git add conflict.c &&
 134        echo secondline >> foo.c &&
 135        git add foo.c &&
 136        git commit -m c6 &&
 137        git tag c6
 138'
 139
 140# First do the merge with resolve and recursive then verify that
 141# recursive is chosen.
 142
 143test_expect_success 'merge picks up the best result' '
 144        git config --unset-all pull.twohead &&
 145        git reset --hard c5 &&
 146        test_must_fail git merge -s resolve c6 &&
 147        resolve_count=$(conflict_count) &&
 148        git reset --hard c5 &&
 149        test_must_fail git merge -s recursive c6 &&
 150        recursive_count=$(conflict_count) &&
 151        git reset --hard c5 &&
 152        test_must_fail git merge -s recursive -s resolve c6 &&
 153        auto_count=$(conflict_count) &&
 154        test $auto_count = $recursive_count &&
 155        test $auto_count != $resolve_count
 156'
 157
 158test_expect_success 'merge picks up the best result (from config)' '
 159        git config pull.twohead "recursive resolve" &&
 160        git reset --hard c5 &&
 161        test_must_fail git merge -s resolve c6 &&
 162        resolve_count=$(conflict_count) &&
 163        git reset --hard c5 &&
 164        test_must_fail git merge -s recursive c6 &&
 165        recursive_count=$(conflict_count) &&
 166        git reset --hard c5 &&
 167        test_must_fail git merge c6 &&
 168        auto_count=$(conflict_count) &&
 169        test $auto_count = $recursive_count &&
 170        test $auto_count != $resolve_count
 171'
 172
 173test_expect_success 'merge errors out on invalid strategy' '
 174        git config pull.twohead "foobar" &&
 175        git reset --hard c5 &&
 176        test_must_fail git merge c6
 177'
 178
 179test_expect_success 'merge errors out on invalid strategy' '
 180        git config --unset-all pull.twohead &&
 181        git reset --hard c5 &&
 182        test_must_fail git merge -s "resolve recursive" c6
 183'
 184
 185test_done