1#!/bin/sh
   2test_description='cherry picking and reverting a merge
   4                b---c
   6               /   /
   7        initial---a
   8'
  10. ./test-lib.sh
  12test_expect_success setup '
  14        >A &&
  16        >B &&
  17        git add A B &&
  18        git commit -m "Initial" &&
  19        git tag initial &&
  20        git branch side &&
  21        echo new line >A &&
  22        git commit -m "add line to A" A &&
  23        git tag a &&
  24        git checkout side &&
  25        echo new line >B &&
  26        git commit -m "add line to B" B &&
  27        git tag b &&
  28        git checkout master &&
  29        git merge side &&
  30        git tag c
  31'
  33test_expect_success 'cherry-pick -m complains of bogus numbers' '
  35        # expect 129 here to distinguish between cases where
  36        # there was nothing to cherry-pick
  37        test_expect_code 129 git cherry-pick -m &&
  38        test_expect_code 129 git cherry-pick -m foo b &&
  39        test_expect_code 129 git cherry-pick -m -1 b &&
  40        test_expect_code 129 git cherry-pick -m 0 b
  41'
  42test_expect_success 'cherry-pick explicit first parent of a non-merge' '
  44        git reset --hard &&
  46        git checkout a^0 &&
  47        git cherry-pick -m 1 b &&
  48        git diff --exit-code c --
  49'
  51test_expect_success 'cherry pick a merge without -m should fail' '
  53        git reset --hard &&
  55        git checkout a^0 &&
  56        test_must_fail git cherry-pick c &&
  57        git diff --exit-code a --
  58'
  60test_expect_success 'cherry pick a merge (1)' '
  62        git reset --hard &&
  64        git checkout a^0 &&
  65        git cherry-pick -m 1 c &&
  66        git diff --exit-code c
  67'
  69test_expect_success 'cherry pick a merge (2)' '
  71        git reset --hard &&
  73        git checkout b^0 &&
  74        git cherry-pick -m 2 c &&
  75        git diff --exit-code c
  76'
  78test_expect_success 'cherry pick a merge relative to nonexistent parent should fail' '
  80        git reset --hard &&
  82        git checkout b^0 &&
  83        test_must_fail git cherry-pick -m 3 c
  84'
  86test_expect_success 'revert explicit first parent of a non-merge' '
  88        git reset --hard &&
  90        git checkout c^0 &&
  91        git revert -m 1 b &&
  92        git diff --exit-code a --
  93'
  95test_expect_success 'revert a merge without -m should fail' '
  97        git reset --hard &&
  99        git checkout c^0 &&
 100        test_must_fail git revert c &&
 101        git diff --exit-code c
 102'
 104test_expect_success 'revert a merge (1)' '
 106        git reset --hard &&
 108        git checkout c^0 &&
 109        git revert -m 1 c &&
 110        git diff --exit-code a --
 111'
 113test_expect_success 'revert a merge (2)' '
 115        git reset --hard &&
 117        git checkout c^0 &&
 118        git revert -m 2 c &&
 119        git diff --exit-code b --
 120'
 122test_expect_success 'revert a merge relative to nonexistent parent should fail' '
 124        git reset --hard &&
 126        git checkout c^0 &&
 127        test_must_fail git revert -m 3 c &&
 128        git diff --exit-code c
 129'
 131test_done