t / t3508-cherry-pick-many-commits.shon commit git-svn: use YAML format for mergeinfo cache when possible (68f532f)
   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        git checkout -f master &&
  39        git reset --hard first &&
  40        test_tick &&
  41        git cherry-pick first..fourth &&
  42        git diff --quiet other &&
  43        git diff --quiet HEAD other &&
  44        check_head_differs_from fourth
  45'
  46
  47test_expect_success 'output to keep user entertained during multi-pick' '
  48        cat <<-\EOF >expected &&
  49        [master OBJID] second
  50         Author: A U Thor <author@example.com>
  51         1 file changed, 1 insertion(+)
  52        [master OBJID] third
  53         Author: A U Thor <author@example.com>
  54         1 file changed, 1 insertion(+)
  55        [master OBJID] fourth
  56         Author: A U Thor <author@example.com>
  57         1 file changed, 1 insertion(+)
  58        EOF
  59
  60        git checkout -f master &&
  61        git reset --hard first &&
  62        test_tick &&
  63        git cherry-pick first..fourth >actual &&
  64        sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
  65        test_line_count -ge 3 actual.fuzzy &&
  66        test_i18ncmp expected actual.fuzzy
  67'
  68
  69test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
  70        git checkout -f master &&
  71        git reset --hard first &&
  72        test_tick &&
  73        git cherry-pick --strategy resolve first..fourth &&
  74        git diff --quiet other &&
  75        git diff --quiet HEAD other &&
  76        check_head_differs_from fourth
  77'
  78
  79test_expect_success 'output during multi-pick indicates merge strategy' '
  80        cat <<-\EOF >expected &&
  81        Trying simple merge.
  82        [master OBJID] second
  83         Author: A U Thor <author@example.com>
  84         1 file changed, 1 insertion(+)
  85        Trying simple merge.
  86        [master OBJID] third
  87         Author: A U Thor <author@example.com>
  88         1 file changed, 1 insertion(+)
  89        Trying simple merge.
  90        [master OBJID] fourth
  91         Author: A U Thor <author@example.com>
  92         1 file changed, 1 insertion(+)
  93        EOF
  94
  95        git checkout -f master &&
  96        git reset --hard first &&
  97        test_tick &&
  98        git cherry-pick --strategy resolve first..fourth >actual &&
  99        sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
 100        test_i18ncmp expected actual.fuzzy
 101'
 102
 103test_expect_success 'cherry-pick --ff first..fourth works' '
 104        git checkout -f master &&
 105        git reset --hard first &&
 106        test_tick &&
 107        git cherry-pick --ff first..fourth &&
 108        git diff --quiet other &&
 109        git diff --quiet HEAD other &&
 110        check_head_equals fourth
 111'
 112
 113test_expect_success 'cherry-pick -n first..fourth works' '
 114        git checkout -f master &&
 115        git reset --hard first &&
 116        test_tick &&
 117        git cherry-pick -n first..fourth &&
 118        git diff --quiet other &&
 119        git diff --cached --quiet other &&
 120        git diff --quiet HEAD first
 121'
 122
 123test_expect_success 'revert first..fourth works' '
 124        git checkout -f master &&
 125        git reset --hard fourth &&
 126        test_tick &&
 127        git revert first..fourth &&
 128        git diff --quiet first &&
 129        git diff --cached --quiet first &&
 130        git diff --quiet HEAD first
 131'
 132
 133test_expect_success 'revert ^first fourth works' '
 134        git checkout -f master &&
 135        git reset --hard fourth &&
 136        test_tick &&
 137        git revert ^first fourth &&
 138        git diff --quiet first &&
 139        git diff --cached --quiet first &&
 140        git diff --quiet HEAD first
 141'
 142
 143test_expect_success 'revert fourth fourth~1 fourth~2 works' '
 144        git checkout -f master &&
 145        git reset --hard fourth &&
 146        test_tick &&
 147        git revert fourth fourth~1 fourth~2 &&
 148        git diff --quiet first &&
 149        git diff --cached --quiet first &&
 150        git diff --quiet HEAD first
 151'
 152
 153test_expect_success 'cherry-pick -3 fourth works' '
 154        git checkout -f master &&
 155        git reset --hard first &&
 156        test_tick &&
 157        git cherry-pick -3 fourth &&
 158        git diff --quiet other &&
 159        git diff --quiet HEAD other &&
 160        check_head_differs_from fourth
 161'
 162
 163test_expect_success 'cherry-pick --stdin works' '
 164        git checkout -f master &&
 165        git reset --hard first &&
 166        test_tick &&
 167        git rev-list --reverse first..fourth | git cherry-pick --stdin &&
 168        git diff --quiet other &&
 169        git diff --quiet HEAD other &&
 170        check_head_differs_from fourth
 171'
 172
 173test_done