Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Test workflows involving pull request.' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_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 | |
| 55 | But keep the old version, too, in case some people prefer it." && |
| 56 | git checkout master |
| 57 | ) |
| 58 | |
| 59 | ' |
| 60 | |
| 61 | test_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 |
Junio C Hamano | fe46fa9 | 2011-12-16 09:00:11 -0800 | [diff] [blame] | 70 | # Note that a request could ask for "tag $tagname" |
Ann T Ropea | e66d7c3 | 2017-10-03 00:08:38 +0000 | [diff] [blame] | 71 | / in the Git repository at:$/!d |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 72 | n |
Jonathan Nieder | f2cabf6 | 2010-04-24 07:29:52 -0500 | [diff] [blame] | 73 | /^$/ n |
Junio C Hamano | fe46fa9 | 2011-12-16 09:00:11 -0800 | [diff] [blame] | 74 | s/ tag \([^ ]*\)$/ tag--\1/ |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 75 | s/^[ ]*\(.*\) \([^ ]*\)/please pull\ |
| 76 | \1\ |
| 77 | \2/p |
| 78 | q |
| 79 | EOT |
| 80 | |
| 81 | cat <<-EOT >fuzz.sed |
| 82 | #!/bin/sed -nf |
Dennis Kaarsemaker | d77fd05 | 2013-06-15 23:35:02 +0200 | [diff] [blame] | 83 | s/$downstream_url_for_sed/URL/g |
brian m. carlson | 2ece6ad | 2018-05-13 02:24:15 +0000 | [diff] [blame] | 84 | s/$OID_REGEX/OBJECT_NAME/g |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 85 | s/A U Thor/AUTHOR/g |
Jonathan Nieder | f2cabf6 | 2010-04-24 07:29:52 -0500 | [diff] [blame] | 86 | s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 87 | s/ [^ ].*/ SUBJECT/g |
Jonathan Nieder | f2cabf6 | 2010-04-24 07:29:52 -0500 | [diff] [blame] | 88 | s/ [^ ].* (DATE)/ SUBJECT (DATE)/g |
Junio C Hamano | 28ad685 | 2014-01-23 14:23:43 -0800 | [diff] [blame] | 89 | s|tags/full|BRANCH|g |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 90 | s/mnemonic.txt/FILENAME/g |
Junio C Hamano | d050464 | 2011-11-09 05:05:00 -0800 | [diff] [blame] | 91 | s/^version [0-9]/VERSION/ |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 92 | /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat |
| 93 | /^AUTHOR ([0-9]*):\$/ b shortlog |
| 94 | p |
| 95 | b |
| 96 | : diffstat |
| 97 | n |
Nguyễn Thái Ngọc Duy | 7f81463 | 2012-02-01 19:55:07 +0700 | [diff] [blame] | 98 | / [0-9]* files* changed/ { |
Junio C Hamano | 5bab691 | 2010-05-07 21:29:50 -0700 | [diff] [blame] | 99 | a\\ |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 100 | DIFFSTAT |
| 101 | b |
| 102 | } |
| 103 | b diffstat |
| 104 | : shortlog |
| 105 | /^ [a-zA-Z]/ n |
| 106 | /^[a-zA-Z]* ([0-9]*):\$/ n |
| 107 | /^\$/ N |
Brandon Casey | 6f89384 | 2010-06-01 19:13:42 -0500 | [diff] [blame] | 108 | /^\n[a-zA-Z]* ([0-9]*):\$/!{ |
Junio C Hamano | 5bab691 | 2010-05-07 21:29:50 -0700 | [diff] [blame] | 109 | a\\ |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 110 | SHORTLOG |
| 111 | D |
| 112 | } |
| 113 | n |
| 114 | b shortlog |
| 115 | EOT |
| 116 | |
| 117 | ' |
| 118 | |
| 119 | test_expect_success 'pull request when forgot to push' ' |
| 120 | |
| 121 | rm -fr downstream.git && |
| 122 | git init --bare downstream.git && |
| 123 | ( |
| 124 | cd local && |
| 125 | git checkout initial && |
| 126 | git merge --ff-only master && |
| 127 | test_must_fail git request-pull initial "$downstream_url" \ |
| 128 | 2>../err |
| 129 | ) && |
Junio C Hamano | 28ad685 | 2014-01-23 14:23:43 -0800 | [diff] [blame] | 130 | grep "No match for commit .*" err && |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 131 | grep "Are you sure you pushed" err |
| 132 | |
| 133 | ' |
| 134 | |
| 135 | test_expect_success 'pull request after push' ' |
| 136 | |
| 137 | rm -fr downstream.git && |
| 138 | git init --bare downstream.git && |
| 139 | ( |
| 140 | cd local && |
| 141 | git checkout initial && |
| 142 | git merge --ff-only master && |
| 143 | git push origin master:for-upstream && |
Junio C Hamano | 28ad685 | 2014-01-23 14:23:43 -0800 | [diff] [blame] | 144 | git request-pull initial origin master:for-upstream >../request |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 145 | ) && |
| 146 | sed -nf read-request.sed <request >digest && |
| 147 | cat digest && |
| 148 | { |
| 149 | read task && |
| 150 | read repository && |
| 151 | read branch |
| 152 | } <digest && |
| 153 | ( |
| 154 | cd upstream-private && |
| 155 | git checkout initial && |
| 156 | git pull --ff-only "$repository" "$branch" |
| 157 | ) && |
| 158 | test "$branch" = for-upstream && |
| 159 | test_cmp local/mnemonic.txt upstream-private/mnemonic.txt |
| 160 | |
| 161 | ' |
| 162 | |
Junio C Hamano | 28ad685 | 2014-01-23 14:23:43 -0800 | [diff] [blame] | 163 | test_expect_success 'request asks HEAD to be pulled' ' |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 164 | |
| 165 | rm -fr downstream.git && |
| 166 | git init --bare downstream.git && |
| 167 | ( |
| 168 | cd local && |
| 169 | git checkout initial && |
| 170 | git merge --ff-only master && |
| 171 | git push --tags origin master simplify && |
| 172 | git push origin master:for-upstream && |
| 173 | git request-pull initial "$downstream_url" >../request |
| 174 | ) && |
| 175 | sed -nf read-request.sed <request >digest && |
| 176 | cat digest && |
| 177 | { |
| 178 | read task && |
| 179 | read repository && |
| 180 | read branch |
| 181 | } <digest && |
Junio C Hamano | 28ad685 | 2014-01-23 14:23:43 -0800 | [diff] [blame] | 182 | test -z "$branch" |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 183 | |
| 184 | ' |
| 185 | |
| 186 | test_expect_success 'pull request format' ' |
| 187 | |
| 188 | rm -fr downstream.git && |
| 189 | git init --bare downstream.git && |
| 190 | cat <<-\EOT >expect && |
| 191 | The following changes since commit OBJECT_NAME: |
Jonathan Nieder | f2cabf6 | 2010-04-24 07:29:52 -0500 | [diff] [blame] | 192 | |
| 193 | SUBJECT (DATE) |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 194 | |
Ann T Ropea | e66d7c3 | 2017-10-03 00:08:38 +0000 | [diff] [blame] | 195 | are available in the Git repository at: |
Junio C Hamano | cf73166 | 2011-09-16 11:37:08 -0700 | [diff] [blame] | 196 | |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 197 | URL BRANCH |
| 198 | |
Junio C Hamano | cf73166 | 2011-09-16 11:37:08 -0700 | [diff] [blame] | 199 | for you to fetch changes up to OBJECT_NAME: |
| 200 | |
| 201 | SUBJECT (DATE) |
| 202 | |
| 203 | ---------------------------------------------------------------- |
Junio C Hamano | d050464 | 2011-11-09 05:05:00 -0800 | [diff] [blame] | 204 | VERSION |
| 205 | |
| 206 | ---------------------------------------------------------------- |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 207 | SHORTLOG |
| 208 | |
| 209 | DIFFSTAT |
| 210 | EOT |
| 211 | ( |
| 212 | cd local && |
| 213 | git checkout initial && |
| 214 | git merge --ff-only master && |
Junio C Hamano | 28ad685 | 2014-01-23 14:23:43 -0800 | [diff] [blame] | 215 | git push origin tags/full && |
| 216 | git request-pull initial "$downstream_url" tags/full >../request |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 217 | ) && |
| 218 | <request sed -nf fuzz.sed >request.fuzzy && |
Junio C Hamano | 5aae66b | 2014-02-25 13:44:46 -0800 | [diff] [blame] | 219 | test_i18ncmp expect request.fuzzy && |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 220 | |
Junio C Hamano | 5aae66b | 2014-02-25 13:44:46 -0800 | [diff] [blame] | 221 | ( |
| 222 | cd local && |
| 223 | git request-pull initial "$downstream_url" tags/full:refs/tags/full |
| 224 | ) >request && |
| 225 | sed -nf fuzz.sed <request >request.fuzzy && |
Junio C Hamano | d952cbb | 2014-05-16 10:18:25 -0700 | [diff] [blame] | 226 | test_i18ncmp expect request.fuzzy && |
| 227 | |
| 228 | ( |
| 229 | cd local && |
| 230 | git request-pull initial "$downstream_url" full |
| 231 | ) >request && |
Johannes Sixt | 644edd0 | 2014-06-02 09:06:56 +0200 | [diff] [blame] | 232 | grep " tags/full\$" request |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 233 | ' |
| 234 | |
Jonathan Nieder | 50ab655 | 2010-04-24 07:15:37 -0500 | [diff] [blame] | 235 | test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' ' |
| 236 | |
| 237 | ( |
| 238 | cd local && |
| 239 | OPTIONS_KEEPDASHDASH=Yes && |
| 240 | export OPTIONS_KEEPDASHDASH && |
| 241 | git checkout initial && |
| 242 | git merge --ff-only master && |
| 243 | git push origin master:for-upstream && |
Junio C Hamano | 28ad685 | 2014-01-23 14:23:43 -0800 | [diff] [blame] | 244 | git request-pull -- initial "$downstream_url" master:for-upstream >../request |
Jonathan Nieder | 50ab655 | 2010-04-24 07:15:37 -0500 | [diff] [blame] | 245 | ) |
| 246 | |
| 247 | ' |
| 248 | |
Jonathan Nieder | 30c56ea | 2010-04-24 07:11:51 -0500 | [diff] [blame] | 249 | test_done |