3 test_description='Test workflows involving pull request.'
7 if ! test_have_prereq PERL
9 skip_all='skipping request-pull tests, perl not available'
13 test_expect_success 'setup' '
15 git init --bare upstream.git &&
16 git init --bare downstream.git &&
17 git clone upstream.git upstream-private &&
18 git clone downstream.git local &&
20 trash_url="file://$TRASH_DIRECTORY" &&
21 downstream_url="$trash_url/downstream.git/" &&
22 upstream_url="$trash_url/upstream.git/" &&
25 cd upstream-private &&
26 cat <<-\EOT >mnemonic.txt &&
27 Thirtey days hath November,
28 Aprile, June, and September:
30 git add mnemonic.txt &&
32 git commit -m "\"Thirty days\", a reminder of month lengths" &&
33 git tag -m "version 1" -a initial &&
34 git push --tags origin master
38 git remote add upstream "$trash_url/upstream.git" &&
40 git pull upstream master &&
41 cat <<-\EOT >>mnemonic.txt &&
42 Of twyecescore-eightt is but eine,
43 And all the remnante be thrycescore-eine.
44 O’course Leap yare comes an’pynes,
45 Ev’rie foure yares, gote it ryghth.
46 An’twyecescore-eight is but twyecescore-nyne.
48 git add mnemonic.txt &&
50 git commit -m "More detail" &&
51 git tag -m "version 2" -a full &&
52 git checkout -b simplify HEAD^ &&
53 mv mnemonic.txt mnemonic.standard &&
54 cat <<-\EOT >mnemonic.clarified &&
55 Thirty days has September,
56 All the rest I can’t remember.
58 git add -N mnemonic.standard mnemonic.clarified &&
59 git commit -a -m "Adapt to use modern, simpler English
61 But keep the old version, too, in case some people prefer it." &&
67 test_expect_success 'setup: two scripts for reading pull requests' '
69 downstream_url_for_sed=$(
70 printf "%s\n" "$downstream_url" |
71 sed -e '\''s/\\/\\\\/g'\'' -e '\''s/[[/.*^$]/\\&/g'\''
74 cat <<-\EOT >read-request.sed &&
76 # Note that a request could ask for "tag $tagname"
77 / in the Git repository at:$/!d
80 s/ tag \([^ ]*\)$/ tag--\1/
81 s/^[ ]*\(.*\) \([^ ]*\)/please pull\
89 s/$downstream_url_for_sed/URL/g
90 s/$OID_REGEX/OBJECT_NAME/g
92 s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
94 s/ [^ ].* (DATE)/ SUBJECT (DATE)/g
96 s/mnemonic.txt/FILENAME/g
97 s/^version [0-9]/VERSION/
98 /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat
99 /^AUTHOR ([0-9]*):\$/ b shortlog
104 / [0-9]* files* changed/ {
112 /^[a-zA-Z]* ([0-9]*):\$/ n
114 /^\n[a-zA-Z]* ([0-9]*):\$/!{
125 test_expect_success 'pull request when forgot to push' '
127 rm -fr downstream.git &&
128 git init --bare downstream.git &&
131 git checkout initial &&
132 git merge --ff-only master &&
133 test_must_fail git request-pull initial "$downstream_url" \
136 grep "No match for commit .*" err &&
137 grep "Are you sure you pushed" err
141 test_expect_success 'pull request after push' '
143 rm -fr downstream.git &&
144 git init --bare downstream.git &&
147 git checkout initial &&
148 git merge --ff-only master &&
149 git push origin master:for-upstream &&
150 git request-pull initial origin master:for-upstream >../request
152 sed -nf read-request.sed <request >digest &&
160 cd upstream-private &&
161 git checkout initial &&
162 git pull --ff-only "$repository" "$branch"
164 test "$branch" = for-upstream &&
165 test_cmp local/mnemonic.txt upstream-private/mnemonic.txt
169 test_expect_success 'request asks HEAD to be pulled' '
171 rm -fr downstream.git &&
172 git init --bare downstream.git &&
175 git checkout initial &&
176 git merge --ff-only master &&
177 git push --tags origin master simplify &&
178 git push origin master:for-upstream &&
179 git request-pull initial "$downstream_url" >../request
181 sed -nf read-request.sed <request >digest &&
192 test_expect_success 'pull request format' '
194 rm -fr downstream.git &&
195 git init --bare downstream.git &&
196 cat <<-\EOT >expect &&
197 The following changes since commit OBJECT_NAME:
201 are available in the Git repository at:
205 for you to fetch changes up to OBJECT_NAME:
209 ----------------------------------------------------------------
212 ----------------------------------------------------------------
219 git checkout initial &&
220 git merge --ff-only master &&
221 git push origin tags/full &&
222 git request-pull initial "$downstream_url" tags/full >../request
224 <request sed -nf fuzz.sed >request.fuzzy &&
225 test_i18ncmp expect request.fuzzy &&
229 git request-pull initial "$downstream_url" tags/full:refs/tags/full
231 sed -nf fuzz.sed <request >request.fuzzy &&
232 test_i18ncmp expect request.fuzzy &&
236 git request-pull initial "$downstream_url" full
238 grep " tags/full\$" request
241 test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
245 OPTIONS_KEEPDASHDASH=Yes &&
246 export OPTIONS_KEEPDASHDASH &&
247 git checkout initial &&
248 git merge --ff-only master &&
249 git push origin master:for-upstream &&
250 git request-pull -- initial "$downstream_url" master:for-upstream >../request
255 test_expect_success 'request-pull quotes regex metacharacters properly' '
257 rm -fr downstream.git &&
258 git init --bare downstream.git &&
261 git checkout initial &&
262 git merge --ff-only master &&
263 git tag -mrelease v2.0 &&
264 git push origin refs/tags/v2.0:refs/tags/v2-0 &&
265 test_must_fail git request-pull initial "$downstream_url" tags/v2.0 \
268 grep "No match for commit .*" err &&
269 grep "Are you sure you pushed" err
273 test_expect_success 'pull request with mismatched object' '
275 rm -fr downstream.git &&
276 git init --bare downstream.git &&
279 git checkout initial &&
280 git merge --ff-only master &&
281 git push origin HEAD:refs/tags/full &&
282 test_must_fail git request-pull initial "$downstream_url" tags/full \
285 grep "points to a different object" err &&
286 grep "Are you sure you pushed" err
290 test_expect_success 'pull request with stale object' '
292 rm -fr downstream.git &&
293 git init --bare downstream.git &&
296 git checkout initial &&
297 git merge --ff-only master &&
298 git push origin refs/tags/full &&
299 git tag -f -m"Thirty-one days" full &&
300 test_must_fail git request-pull initial "$downstream_url" tags/full \
303 grep "points to a different object" err &&
304 grep "Are you sure you pushed" err