t / t7601-merge-pull-config.shon commit fetch: ignore wildcarded refspecs that update local symbolic refs (f8fb971)
   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 'merge c1 with c2 (ours in pull.twohead)' '
  42        git reset --hard c1 &&
  43        git config pull.twohead ours &&
  44        git merge c2 &&
  45        test -f c1.c &&
  46        ! test -f c2.c
  47'
  48
  49test_expect_success 'merge c1 with c2 and c3 (recursive in pull.octopus)' '
  50        git reset --hard c1 &&
  51        git config pull.octopus "recursive" &&
  52        test_must_fail git merge c2 c3 &&
  53        test "$(git rev-parse c1)" = "$(git rev-parse HEAD)"
  54'
  55
  56test_expect_success 'merge c1 with c2 and c3 (recursive and octopus in pull.octopus)' '
  57        git reset --hard c1 &&
  58        git config pull.octopus "recursive octopus" &&
  59        git merge c2 c3 &&
  60        test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&
  61        test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" &&
  62        test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" &&
  63        test "$(git rev-parse c3)" = "$(git rev-parse HEAD^3)" &&
  64        git diff --exit-code &&
  65        test -f c0.c &&
  66        test -f c1.c &&
  67        test -f c2.c &&
  68        test -f c3.c
  69'
  70
  71conflict_count()
  72{
  73        {
  74                git diff-files --name-only
  75                git ls-files --unmerged
  76        } | wc -l
  77}
  78
  79# c4 - c5
  80#    \ c6
  81#
  82# There are two conflicts here:
  83#
  84# 1) Because foo.c is renamed to bar.c, recursive will handle this,
  85# resolve won't.
  86#
  87# 2) One in conflict.c and that will always fail.
  88
  89test_expect_success 'setup conflicted merge' '
  90        git reset --hard c0 &&
  91        echo A >conflict.c &&
  92        git add conflict.c &&
  93        echo contents >foo.c &&
  94        git add foo.c &&
  95        git commit -m c4 &&
  96        git tag c4 &&
  97        echo B >conflict.c &&
  98        git add conflict.c &&
  99        git mv foo.c bar.c &&
 100        git commit -m c5 &&
 101        git tag c5 &&
 102        git reset --hard c4 &&
 103        echo C >conflict.c &&
 104        git add conflict.c &&
 105        echo secondline >> foo.c &&
 106        git add foo.c &&
 107        git commit -m c6 &&
 108        git tag c6
 109'
 110
 111# First do the merge with resolve and recursive then verify that
 112# recusive is choosen.
 113
 114test_expect_success 'merge picks up the best result' '
 115        git config --unset-all pull.twohead &&
 116        git reset --hard c5 &&
 117        test_must_fail git merge -s resolve c6 &&
 118        resolve_count=$(conflict_count) &&
 119        git reset --hard c5 &&
 120        test_must_fail git merge -s recursive c6 &&
 121        recursive_count=$(conflict_count) &&
 122        git reset --hard c5 &&
 123        test_must_fail git merge -s recursive -s resolve c6 &&
 124        auto_count=$(conflict_count) &&
 125        test $auto_count = $recursive_count &&
 126        test $auto_count != $resolve_count
 127'
 128
 129test_expect_success 'merge picks up the best result (from config)' '
 130        git config pull.twohead "recursive resolve" &&
 131        git reset --hard c5 &&
 132        test_must_fail git merge -s resolve c6 &&
 133        resolve_count=$(conflict_count) &&
 134        git reset --hard c5 &&
 135        test_must_fail git merge -s recursive c6 &&
 136        recursive_count=$(conflict_count) &&
 137        git reset --hard c5 &&
 138        test_must_fail git merge c6 &&
 139        auto_count=$(conflict_count) &&
 140        test $auto_count = $recursive_count &&
 141        test $auto_count != $resolve_count
 142'
 143
 144test_expect_success 'merge errors out on invalid strategy' '
 145        git config pull.twohead "foobar" &&
 146        git reset --hard c5 &&
 147        test_must_fail git merge c6
 148'
 149
 150test_expect_success 'merge errors out on invalid strategy' '
 151        git config --unset-all pull.twohead &&
 152        git reset --hard c5 &&
 153        test_must_fail git merge -s "resolve recursive" c6
 154'
 155
 156test_done