t / t3508-cherry-pick-many-commits.shon commit Merge branch 'jx/utf8-printf-width' into maint (75288cc)
   1#!/bin/sh
   2
   3test_description='test cherry-picking many commits'
   4
   5. ./test-lib.sh
   6
   7check_head_differs_from() {
   8        ! test_cmp_rev HEAD "$1"
   9}
  10
  11check_head_equals() {
  12        test_cmp_rev HEAD "$1"
  13}
  14
  15test_expect_success setup '
  16        echo first > file1 &&
  17        git add file1 &&
  18        test_tick &&
  19        git commit -m "first" &&
  20        git tag first &&
  21
  22        git checkout -b other &&
  23        for val in second third fourth
  24        do
  25                echo $val >> file1 &&
  26                git add file1 &&
  27                test_tick &&
  28                git commit -m "$val" &&
  29                git tag $val
  30        done
  31'
  32
  33test_expect_success 'cherry-pick first..fourth works' '
  34        git checkout -f master &&
  35        git reset --hard first &&
  36        test_tick &&
  37        git cherry-pick first..fourth &&
  38        git diff --quiet other &&
  39        git diff --quiet HEAD other &&
  40        check_head_differs_from fourth
  41'
  42
  43test_expect_success 'cherry-pick three one two works' '
  44        git checkout -f first &&
  45        test_commit one &&
  46        test_commit two &&
  47        test_commit three &&
  48        git checkout -f master &&
  49        git reset --hard first &&
  50        git cherry-pick three one two &&
  51        git diff --quiet three &&
  52        git diff --quiet HEAD three &&
  53        test "$(git log --reverse --format=%s first..)" = "three
  54one
  55two"
  56'
  57
  58test_expect_success 'output to keep user entertained during multi-pick' '
  59        cat <<-\EOF >expected &&
  60        [master OBJID] second
  61         Author: A U Thor <author@example.com>
  62         1 file changed, 1 insertion(+)
  63        [master OBJID] third
  64         Author: A U Thor <author@example.com>
  65         1 file changed, 1 insertion(+)
  66        [master OBJID] fourth
  67         Author: A U Thor <author@example.com>
  68         1 file changed, 1 insertion(+)
  69        EOF
  70
  71        git checkout -f master &&
  72        git reset --hard first &&
  73        test_tick &&
  74        git cherry-pick first..fourth >actual &&
  75        sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
  76        test_line_count -ge 3 actual.fuzzy &&
  77        test_i18ncmp expected actual.fuzzy
  78'
  79
  80test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
  81        git checkout -f master &&
  82        git reset --hard first &&
  83        test_tick &&
  84        git cherry-pick --strategy resolve first..fourth &&
  85        git diff --quiet other &&
  86        git diff --quiet HEAD other &&
  87        check_head_differs_from fourth
  88'
  89
  90test_expect_success 'output during multi-pick indicates merge strategy' '
  91        cat <<-\EOF >expected &&
  92        Trying simple merge.
  93        [master OBJID] second
  94         Author: A U Thor <author@example.com>
  95         1 file changed, 1 insertion(+)
  96        Trying simple merge.
  97        [master OBJID] third
  98         Author: A U Thor <author@example.com>
  99         1 file changed, 1 insertion(+)
 100        Trying simple merge.
 101        [master OBJID] fourth
 102         Author: A U Thor <author@example.com>
 103         1 file changed, 1 insertion(+)
 104        EOF
 105
 106        git checkout -f master &&
 107        git reset --hard first &&
 108        test_tick &&
 109        git cherry-pick --strategy resolve first..fourth >actual &&
 110        sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
 111        test_i18ncmp expected actual.fuzzy
 112'
 113
 114test_expect_success 'cherry-pick --ff first..fourth works' '
 115        git checkout -f master &&
 116        git reset --hard first &&
 117        test_tick &&
 118        git cherry-pick --ff first..fourth &&
 119        git diff --quiet other &&
 120        git diff --quiet HEAD other &&
 121        check_head_equals fourth
 122'
 123
 124test_expect_success 'cherry-pick -n first..fourth works' '
 125        git checkout -f master &&
 126        git reset --hard first &&
 127        test_tick &&
 128        git cherry-pick -n first..fourth &&
 129        git diff --quiet other &&
 130        git diff --cached --quiet other &&
 131        git diff --quiet HEAD first
 132'
 133
 134test_expect_success 'revert first..fourth works' '
 135        git checkout -f master &&
 136        git reset --hard fourth &&
 137        test_tick &&
 138        git revert first..fourth &&
 139        git diff --quiet first &&
 140        git diff --cached --quiet first &&
 141        git diff --quiet HEAD first
 142'
 143
 144test_expect_success 'revert ^first fourth works' '
 145        git checkout -f master &&
 146        git reset --hard fourth &&
 147        test_tick &&
 148        git revert ^first fourth &&
 149        git diff --quiet first &&
 150        git diff --cached --quiet first &&
 151        git diff --quiet HEAD first
 152'
 153
 154test_expect_success 'revert fourth fourth~1 fourth~2 works' '
 155        git checkout -f master &&
 156        git reset --hard fourth &&
 157        test_tick &&
 158        git revert fourth fourth~1 fourth~2 &&
 159        git diff --quiet first &&
 160        git diff --cached --quiet first &&
 161        git diff --quiet HEAD first
 162'
 163
 164test_expect_success 'cherry-pick -3 fourth works' '
 165        git checkout -f master &&
 166        git reset --hard first &&
 167        test_tick &&
 168        git cherry-pick -3 fourth &&
 169        git diff --quiet other &&
 170        git diff --quiet HEAD other &&
 171        check_head_differs_from fourth
 172'
 173
 174test_expect_success 'cherry-pick --stdin works' '
 175        git checkout -f master &&
 176        git reset --hard first &&
 177        test_tick &&
 178        git rev-list --reverse first..fourth | git cherry-pick --stdin &&
 179        git diff --quiet other &&
 180        git diff --quiet HEAD other &&
 181        check_head_differs_from fourth
 182'
 183
 184test_done