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