t / t5150-request-pull.shon commit Merge branch 'master' of git://repo.or.cz/git-gui (73c6b35)
   1#!/bin/sh
   2
   3test_description='Test workflows involving pull request.'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup' '
   8
   9        git init --bare upstream.git &&
  10        git init --bare downstream.git &&
  11        git clone upstream.git upstream-private &&
  12        git clone downstream.git local &&
  13
  14        trash_url="file://$TRASH_DIRECTORY" &&
  15        downstream_url="$trash_url/downstream.git/" &&
  16        upstream_url="$trash_url/upstream.git/" &&
  17
  18        (
  19                cd upstream-private &&
  20                cat <<-\EOT >mnemonic.txt &&
  21                Thirtey days hath November,
  22                Aprile, June, and September:
  23                EOT
  24                git add mnemonic.txt &&
  25                test_tick &&
  26                git commit -m "\"Thirty days\", a reminder of month lengths" &&
  27                git tag -m "version 1" -a initial &&
  28                git push --tags origin master
  29        ) &&
  30        (
  31                cd local &&
  32                git remote add upstream "$trash_url/upstream.git" &&
  33                git fetch upstream &&
  34                git pull upstream master &&
  35                cat <<-\EOT >>mnemonic.txt &&
  36                Of twyecescore-eightt is but eine,
  37                And all the remnante be thrycescore-eine.
  38                O’course Leap yare comes an’pynes,
  39                Ev’rie foure yares, gote it ryghth.
  40                An’twyecescore-eight is but twyecescore-nyne.
  41                EOT
  42                git add mnemonic.txt &&
  43                test_tick &&
  44                git commit -m "More detail" &&
  45                git tag -m "version 2" -a full &&
  46                git checkout -b simplify HEAD^ &&
  47                mv mnemonic.txt mnemonic.standard &&
  48                cat <<-\EOT >mnemonic.clarified &&
  49                Thirty days has September,
  50                All the rest I can’t remember.
  51                EOT
  52                git add -N mnemonic.standard mnemonic.clarified &&
  53                git commit -a -m "Adapt to use modern, simpler English
  54
  55But keep the old version, too, in case some people prefer it." &&
  56                git checkout master
  57        )
  58
  59'
  60
  61test_expect_success 'setup: two scripts for reading pull requests' '
  62
  63        downstream_url_for_sed=$(
  64                printf "%s\n" "$downstream_url" |
  65                sed -e '\''s/\\/\\\\/g'\'' -e '\''s/[[/.*^$]/\\&/g'\''
  66        ) &&
  67
  68        cat <<-\EOT >read-request.sed &&
  69        #!/bin/sed -nf
  70        / in the git repository at:$/!d
  71        n
  72        /^$/ n
  73        s/^[    ]*\(.*\) \([^ ]*\)/please pull\
  74        \1\
  75        \2/p
  76        q
  77        EOT
  78
  79        cat <<-EOT >fuzz.sed
  80        #!/bin/sed -nf
  81        s/$_x40/OBJECT_NAME/g
  82        s/A U Thor/AUTHOR/g
  83        s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
  84        s/        [^ ].*/        SUBJECT/g
  85        s/  [^ ].* (DATE)/  SUBJECT (DATE)/g
  86        s/$downstream_url_for_sed/URL/g
  87        s/for-upstream/BRANCH/g
  88        s/mnemonic.txt/FILENAME/g
  89        s/^version [0-9]/VERSION/
  90        /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat
  91        /^AUTHOR ([0-9]*):\$/ b shortlog
  92        p
  93        b
  94        : diffstat
  95        n
  96        / [0-9]* files changed/ {
  97                a\\
  98        DIFFSTAT
  99                b
 100        }
 101        b diffstat
 102        : shortlog
 103        /^        [a-zA-Z]/ n
 104        /^[a-zA-Z]* ([0-9]*):\$/ n
 105        /^\$/ N
 106        /^\n[a-zA-Z]* ([0-9]*):\$/!{
 107                a\\
 108        SHORTLOG
 109                D
 110        }
 111        n
 112        b shortlog
 113        EOT
 114
 115'
 116
 117test_expect_success 'pull request when forgot to push' '
 118
 119        rm -fr downstream.git &&
 120        git init --bare downstream.git &&
 121        (
 122                cd local &&
 123                git checkout initial &&
 124                git merge --ff-only master &&
 125                test_must_fail git request-pull initial "$downstream_url" \
 126                        2>../err
 127        ) &&
 128        grep "No branch of.*is at:\$" err &&
 129        grep "Are you sure you pushed" err
 130
 131'
 132
 133test_expect_success 'pull request after push' '
 134
 135        rm -fr downstream.git &&
 136        git init --bare downstream.git &&
 137        (
 138                cd local &&
 139                git checkout initial &&
 140                git merge --ff-only master &&
 141                git push origin master:for-upstream &&
 142                git request-pull initial origin >../request
 143        ) &&
 144        sed -nf read-request.sed <request >digest &&
 145        cat digest &&
 146        {
 147                read task &&
 148                read repository &&
 149                read branch
 150        } <digest &&
 151        (
 152                cd upstream-private &&
 153                git checkout initial &&
 154                git pull --ff-only "$repository" "$branch"
 155        ) &&
 156        test "$branch" = for-upstream &&
 157        test_cmp local/mnemonic.txt upstream-private/mnemonic.txt
 158
 159'
 160
 161test_expect_success 'request names an appropriate branch' '
 162
 163        rm -fr downstream.git &&
 164        git init --bare downstream.git &&
 165        (
 166                cd local &&
 167                git checkout initial &&
 168                git merge --ff-only master &&
 169                git push --tags origin master simplify &&
 170                git push origin master:for-upstream &&
 171                git request-pull initial "$downstream_url" >../request
 172        ) &&
 173        sed -nf read-request.sed <request >digest &&
 174        cat digest &&
 175        {
 176                read task &&
 177                read repository &&
 178                read branch
 179        } <digest &&
 180        {
 181                test "$branch" = master ||
 182                test "$branch" = for-upstream
 183        }
 184
 185'
 186
 187test_expect_success 'pull request format' '
 188
 189        rm -fr downstream.git &&
 190        git init --bare downstream.git &&
 191        cat <<-\EOT >expect &&
 192        The following changes since commit OBJECT_NAME:
 193
 194          SUBJECT (DATE)
 195
 196        are available in the git repository at:
 197
 198          URL BRANCH
 199
 200        for you to fetch changes up to OBJECT_NAME:
 201
 202          SUBJECT (DATE)
 203
 204        ----------------------------------------------------------------
 205        VERSION
 206
 207        ----------------------------------------------------------------
 208        SHORTLOG
 209
 210        DIFFSTAT
 211        EOT
 212        (
 213                cd local &&
 214                git checkout initial &&
 215                git merge --ff-only master &&
 216                git push origin master:for-upstream &&
 217                git request-pull initial "$downstream_url" >../request
 218        ) &&
 219        <request sed -nf fuzz.sed >request.fuzzy &&
 220        test_cmp expect request.fuzzy
 221
 222'
 223
 224test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
 225
 226        (
 227                cd local &&
 228                OPTIONS_KEEPDASHDASH=Yes &&
 229                export OPTIONS_KEEPDASHDASH &&
 230                git checkout initial &&
 231                git merge --ff-only master &&
 232                git push origin master:for-upstream &&
 233                git request-pull -- initial "$downstream_url" >../request
 234        )
 235
 236'
 237
 238test_done