t / t3033-merge-toplevel.shon commit t1430: clean up broken refs/tags/shadow (45669a7)
   1#!/bin/sh
   2
   3test_description='"git merge" top-level frontend'
   4
   5. ./test-lib.sh
   6
   7t3033_reset () {
   8        git checkout -B master two &&
   9        git branch -f left three &&
  10        git branch -f right four
  11}
  12
  13test_expect_success setup '
  14        test_commit one &&
  15        git branch left &&
  16        git branch right &&
  17        test_commit two &&
  18        git checkout left &&
  19        test_commit three &&
  20        git checkout right &&
  21        test_commit four &&
  22        git checkout master
  23'
  24
  25# Local branches
  26
  27test_expect_success 'merge an octopus into void' '
  28        t3033_reset &&
  29        git checkout --orphan test &&
  30        git rm -fr . &&
  31        test_must_fail git merge left right &&
  32        test_must_fail git rev-parse --verify HEAD &&
  33        git diff --quiet &&
  34        test_must_fail git rev-parse HEAD
  35'
  36
  37test_expect_success 'merge an octopus, fast-forward (ff)' '
  38        t3033_reset &&
  39        git reset --hard one &&
  40        git merge left right &&
  41        # one is ancestor of three (left) and four (right)
  42        test_must_fail git rev-parse --verify HEAD^3 &&
  43        git rev-parse HEAD^1 HEAD^2 | sort >actual &&
  44        git rev-parse three four | sort >expect &&
  45        test_cmp expect actual
  46'
  47
  48test_expect_success 'merge octopus, non-fast-forward (ff)' '
  49        t3033_reset &&
  50        git reset --hard one &&
  51        git merge --no-ff left right &&
  52        # one is ancestor of three (left) and four (right)
  53        test_must_fail git rev-parse --verify HEAD^4 &&
  54        git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
  55        git rev-parse one three four | sort >expect &&
  56        test_cmp expect actual
  57'
  58
  59test_expect_success 'merge octopus, fast-forward (does not ff)' '
  60        t3033_reset &&
  61        git merge left right &&
  62        # two (master) is not an ancestor of three (left) and four (right)
  63        test_must_fail git rev-parse --verify HEAD^4 &&
  64        git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
  65        git rev-parse two three four | sort >expect &&
  66        test_cmp expect actual
  67'
  68
  69test_expect_success 'merge octopus, non-fast-forward' '
  70        t3033_reset &&
  71        git merge --no-ff left right &&
  72        test_must_fail git rev-parse --verify HEAD^4 &&
  73        git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
  74        git rev-parse two three four | sort >expect &&
  75        test_cmp expect actual
  76'
  77
  78# The same set with FETCH_HEAD
  79
  80test_expect_success 'merge FETCH_HEAD octopus into void' '
  81        t3033_reset &&
  82        git checkout --orphan test &&
  83        git rm -fr . &&
  84        git fetch . left right &&
  85        test_must_fail git merge FETCH_HEAD &&
  86        test_must_fail git rev-parse --verify HEAD &&
  87        git diff --quiet &&
  88        test_must_fail git rev-parse HEAD
  89'
  90
  91test_expect_success 'merge FETCH_HEAD octopus fast-forward (ff)' '
  92        t3033_reset &&
  93        git reset --hard one &&
  94        git fetch . left right &&
  95        git merge FETCH_HEAD &&
  96        # one is ancestor of three (left) and four (right)
  97        test_must_fail git rev-parse --verify HEAD^3 &&
  98        git rev-parse HEAD^1 HEAD^2 | sort >actual &&
  99        git rev-parse three four | sort >expect &&
 100        test_cmp expect actual
 101'
 102
 103test_expect_success 'merge FETCH_HEAD octopus non-fast-forward (ff)' '
 104        t3033_reset &&
 105        git reset --hard one &&
 106        git fetch . left right &&
 107        git merge --no-ff FETCH_HEAD &&
 108        # one is ancestor of three (left) and four (right)
 109        test_must_fail git rev-parse --verify HEAD^4 &&
 110        git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
 111        git rev-parse one three four | sort >expect &&
 112        test_cmp expect actual
 113'
 114
 115test_expect_success 'merge FETCH_HEAD octopus fast-forward (does not ff)' '
 116        t3033_reset &&
 117        git fetch . left right &&
 118        git merge FETCH_HEAD &&
 119        # two (master) is not an ancestor of three (left) and four (right)
 120        test_must_fail git rev-parse --verify HEAD^4 &&
 121        git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
 122        git rev-parse two three four | sort >expect &&
 123        test_cmp expect actual
 124'
 125
 126test_expect_success 'merge FETCH_HEAD octopus non-fast-forward' '
 127        t3033_reset &&
 128        git fetch . left right &&
 129        git merge --no-ff FETCH_HEAD &&
 130        test_must_fail git rev-parse --verify HEAD^4 &&
 131        git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
 132        git rev-parse two three four | sort >expect &&
 133        test_cmp expect actual
 134'
 135
 136test_done