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