t / t3508-cherry-pick-many-commits.shon commit Merge branch 'mg/pretty-magic-space' (223a923)
   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        git checkout master &&
  27        git reset --hard first &&
  28        test_tick &&
  29        git cherry-pick first..fourth &&
  30        git diff --quiet other &&
  31        git diff --quiet HEAD other &&
  32        test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
  33'
  34
  35test_expect_success 'cherry-pick --ff first..fourth works' '
  36        git checkout master &&
  37        git reset --hard first &&
  38        test_tick &&
  39        git cherry-pick --ff first..fourth &&
  40        git diff --quiet other &&
  41        git diff --quiet HEAD other &&
  42        test "$(git rev-parse --verify HEAD)" = "$(git rev-parse --verify fourth)"
  43'
  44
  45test_expect_success 'cherry-pick -n first..fourth works' '
  46        git checkout master &&
  47        git reset --hard first &&
  48        test_tick &&
  49        git cherry-pick -n first..fourth &&
  50        git diff --quiet other &&
  51        git diff --cached --quiet other &&
  52        git diff --quiet HEAD first
  53'
  54
  55test_expect_success 'revert first..fourth works' '
  56        git checkout master &&
  57        git reset --hard fourth &&
  58        test_tick &&
  59        git revert first..fourth &&
  60        git diff --quiet first &&
  61        git diff --cached --quiet first &&
  62        git diff --quiet HEAD first
  63'
  64
  65test_expect_success 'revert ^first fourth works' '
  66        git checkout master &&
  67        git reset --hard fourth &&
  68        test_tick &&
  69        git revert ^first fourth &&
  70        git diff --quiet first &&
  71        git diff --cached --quiet first &&
  72        git diff --quiet HEAD first
  73'
  74
  75test_expect_success 'revert fourth fourth~1 fourth~2 works' '
  76        git checkout master &&
  77        git reset --hard fourth &&
  78        test_tick &&
  79        git revert fourth fourth~1 fourth~2 &&
  80        git diff --quiet first &&
  81        git diff --cached --quiet first &&
  82        git diff --quiet HEAD first
  83'
  84
  85test_expect_failure 'cherry-pick -3 fourth works' '
  86        git checkout master &&
  87        git reset --hard first &&
  88        test_tick &&
  89        git cherry-pick -3 fourth &&
  90        git diff --quiet other &&
  91        git diff --quiet HEAD other &&
  92        test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
  93'
  94
  95test_done