0f61495b2c2110eb3c11feeb07727aa43a14c8af
   1#!/bin/sh
   2
   3test_description='test cherry-picking many commits'
   4
   5. ./test-lib.sh
   6
   7check_head_differs_from() {
   8        head=$(git rev-parse --verify HEAD) &&
   9        arg=$(git rev-parse --verify "$1") &&
  10        test "$head" != "$arg"
  11}
  12
  13check_head_equals() {
  14        head=$(git rev-parse --verify HEAD) &&
  15        arg=$(git rev-parse --verify "$1") &&
  16        test "$head" = "$arg"
  17}
  18
  19test_expect_success setup '
  20        echo first > file1 &&
  21        git add file1 &&
  22        test_tick &&
  23        git commit -m "first" &&
  24        git tag first &&
  25
  26        git checkout -b other &&
  27        for val in second third fourth
  28        do
  29                echo $val >> file1 &&
  30                git add file1 &&
  31                test_tick &&
  32                git commit -m "$val" &&
  33                git tag $val
  34        done
  35'
  36
  37test_expect_success 'cherry-pick first..fourth works' '
  38        cat <<-EOF >expected &&
  39        Finished cherry-pick of commit $(git rev-parse --short second).
  40        Finished cherry-pick of commit $(git rev-parse --short third).
  41        Finished cherry-pick of commit $(git rev-parse --short fourth).
  42        EOF
  43
  44        git checkout -f master &&
  45        git reset --hard first &&
  46        test_tick &&
  47        git cherry-pick first..fourth 2>actual &&
  48        git diff --quiet other &&
  49        git diff --quiet HEAD other &&
  50        test_cmp expected actual &&
  51        check_head_differs_from fourth
  52'
  53
  54test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
  55        cat <<-EOF >expected &&
  56        Finished cherry-pick of commit $(git rev-parse --short second) with strategy resolve.
  57        Finished cherry-pick of commit $(git rev-parse --short third) with strategy resolve.
  58        Finished cherry-pick of commit $(git rev-parse --short fourth) with strategy resolve.
  59        EOF
  60
  61        git checkout -f master &&
  62        git reset --hard first &&
  63        test_tick &&
  64        git cherry-pick --strategy resolve first..fourth 2>actual &&
  65        git diff --quiet other &&
  66        git diff --quiet HEAD other &&
  67        test_cmp expected actual &&
  68        check_head_differs_from fourth
  69'
  70
  71test_expect_success 'cherry-pick --ff first..fourth works' '
  72        git checkout -f master &&
  73        git reset --hard first &&
  74        test_tick &&
  75        git cherry-pick --ff first..fourth &&
  76        git diff --quiet other &&
  77        git diff --quiet HEAD other &&
  78        check_head_equals fourth
  79'
  80
  81test_expect_success 'cherry-pick -n first..fourth works' '
  82        git checkout -f master &&
  83        git reset --hard first &&
  84        test_tick &&
  85        git cherry-pick -n first..fourth &&
  86        git diff --quiet other &&
  87        git diff --cached --quiet other &&
  88        git diff --quiet HEAD first
  89'
  90
  91test_expect_success 'revert first..fourth works' '
  92        git checkout -f master &&
  93        git reset --hard fourth &&
  94        test_tick &&
  95        git revert first..fourth &&
  96        git diff --quiet first &&
  97        git diff --cached --quiet first &&
  98        git diff --quiet HEAD first
  99'
 100
 101test_expect_success 'revert ^first fourth works' '
 102        git checkout -f master &&
 103        git reset --hard fourth &&
 104        test_tick &&
 105        git revert ^first fourth &&
 106        git diff --quiet first &&
 107        git diff --cached --quiet first &&
 108        git diff --quiet HEAD first
 109'
 110
 111test_expect_success 'revert fourth fourth~1 fourth~2 works' '
 112        git checkout -f master &&
 113        git reset --hard fourth &&
 114        test_tick &&
 115        git revert fourth fourth~1 fourth~2 &&
 116        git diff --quiet first &&
 117        git diff --cached --quiet first &&
 118        git diff --quiet HEAD first
 119'
 120
 121test_expect_success 'cherry-pick -3 fourth works' '
 122        git checkout -f master &&
 123        git reset --hard first &&
 124        test_tick &&
 125        git cherry-pick -3 fourth &&
 126        git diff --quiet other &&
 127        git diff --quiet HEAD other &&
 128        check_head_differs_from fourth
 129'
 130
 131test_expect_success 'cherry-pick --stdin works' '
 132        git checkout -f master &&
 133        git reset --hard first &&
 134        test_tick &&
 135        git rev-list --reverse first..fourth | git cherry-pick --stdin &&
 136        git diff --quiet other &&
 137        git diff --quiet HEAD other &&
 138        check_head_differs_from fourth
 139'
 140
 141test_done