t / t3508-cherry-pick-many-commits.shon commit transport-helper: add 'force' to 'export' helpers (510fa6f)
   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 'cherry-pick three one two: fails' '
  59        git checkout -f master &&
  60        git reset --hard first &&
  61        test_must_fail git cherry-pick three one two:
  62'
  63
  64test_expect_success 'output to keep user entertained during multi-pick' '
  65        cat <<-\EOF >expected &&
  66        [master OBJID] second
  67         Author: A U Thor <author@example.com>
  68         1 file changed, 1 insertion(+)
  69        [master OBJID] third
  70         Author: A U Thor <author@example.com>
  71         1 file changed, 1 insertion(+)
  72        [master OBJID] fourth
  73         Author: A U Thor <author@example.com>
  74         1 file changed, 1 insertion(+)
  75        EOF
  76
  77        git checkout -f master &&
  78        git reset --hard first &&
  79        test_tick &&
  80        git cherry-pick first..fourth >actual &&
  81        sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
  82        test_line_count -ge 3 actual.fuzzy &&
  83        test_i18ncmp expected actual.fuzzy
  84'
  85
  86test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
  87        git checkout -f master &&
  88        git reset --hard first &&
  89        test_tick &&
  90        git cherry-pick --strategy resolve first..fourth &&
  91        git diff --quiet other &&
  92        git diff --quiet HEAD other &&
  93        check_head_differs_from fourth
  94'
  95
  96test_expect_success 'output during multi-pick indicates merge strategy' '
  97        cat <<-\EOF >expected &&
  98        Trying simple merge.
  99        [master OBJID] second
 100         Author: A U Thor <author@example.com>
 101         1 file changed, 1 insertion(+)
 102        Trying simple merge.
 103        [master OBJID] third
 104         Author: A U Thor <author@example.com>
 105         1 file changed, 1 insertion(+)
 106        Trying simple merge.
 107        [master OBJID] fourth
 108         Author: A U Thor <author@example.com>
 109         1 file changed, 1 insertion(+)
 110        EOF
 111
 112        git checkout -f master &&
 113        git reset --hard first &&
 114        test_tick &&
 115        git cherry-pick --strategy resolve first..fourth >actual &&
 116        sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
 117        test_i18ncmp expected actual.fuzzy
 118'
 119
 120test_expect_success 'cherry-pick --ff first..fourth works' '
 121        git checkout -f master &&
 122        git reset --hard first &&
 123        test_tick &&
 124        git cherry-pick --ff first..fourth &&
 125        git diff --quiet other &&
 126        git diff --quiet HEAD other &&
 127        check_head_equals fourth
 128'
 129
 130test_expect_success 'cherry-pick -n first..fourth works' '
 131        git checkout -f master &&
 132        git reset --hard first &&
 133        test_tick &&
 134        git cherry-pick -n first..fourth &&
 135        git diff --quiet other &&
 136        git diff --cached --quiet other &&
 137        git diff --quiet HEAD first
 138'
 139
 140test_expect_success 'revert first..fourth works' '
 141        git checkout -f master &&
 142        git reset --hard fourth &&
 143        test_tick &&
 144        git revert first..fourth &&
 145        git diff --quiet first &&
 146        git diff --cached --quiet first &&
 147        git diff --quiet HEAD first
 148'
 149
 150test_expect_success 'revert ^first fourth works' '
 151        git checkout -f master &&
 152        git reset --hard fourth &&
 153        test_tick &&
 154        git revert ^first fourth &&
 155        git diff --quiet first &&
 156        git diff --cached --quiet first &&
 157        git diff --quiet HEAD first
 158'
 159
 160test_expect_success 'revert fourth fourth~1 fourth~2 works' '
 161        git checkout -f master &&
 162        git reset --hard fourth &&
 163        test_tick &&
 164        git revert fourth fourth~1 fourth~2 &&
 165        git diff --quiet first &&
 166        git diff --cached --quiet first &&
 167        git diff --quiet HEAD first
 168'
 169
 170test_expect_success 'cherry-pick -3 fourth works' '
 171        git checkout -f master &&
 172        git reset --hard first &&
 173        test_tick &&
 174        git cherry-pick -3 fourth &&
 175        git diff --quiet other &&
 176        git diff --quiet HEAD other &&
 177        check_head_differs_from fourth
 178'
 179
 180test_expect_success 'cherry-pick --stdin works' '
 181        git checkout -f master &&
 182        git reset --hard first &&
 183        test_tick &&
 184        git rev-list --reverse first..fourth | git cherry-pick --stdin &&
 185        git diff --quiet other &&
 186        git diff --quiet HEAD other &&
 187        check_head_differs_from fourth
 188'
 189
 190test_done