3 test_description='Test workflows involving pull request.'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 if ! test_have_prereq PERL
12 skip_all='skipping request-pull tests, perl not available'
16 test_expect_success 'setup' '
18 git init --bare upstream.git &&
19 git init --bare downstream.git &&
20 git clone upstream.git upstream-private &&
21 git clone downstream.git local &&
23 trash_url="file://$TRASH_DIRECTORY" &&
24 downstream_url="$trash_url/downstream.git/" &&
25 upstream_url="$trash_url/upstream.git/" &&
28 cd upstream-private &&
29 cat <<-\EOT >mnemonic.txt &&
30 Thirtey days hath November,
31 Aprile, June, and September:
33 git add mnemonic.txt &&
35 git commit -m "\"Thirty days\", a reminder of month lengths" &&
36 git tag -m "version 1" -a initial &&
37 git push --tags origin main
41 git remote add upstream "$trash_url/upstream.git" &&
43 git pull upstream main &&
44 cat <<-\EOT >>mnemonic.txt &&
45 Of twyecescore-eightt is but eine,
46 And all the remnante be thrycescore-eine.
47 O’course Leap yare comes an’pynes,
48 Ev’rie foure yares, gote it ryghth.
49 An’twyecescore-eight is but twyecescore-nyne.
51 git add mnemonic.txt &&
53 git commit -m "More detail" &&
54 git tag -m "version 2" -a full &&
55 git checkout -b simplify HEAD^ &&
56 mv mnemonic.txt mnemonic.standard &&
57 cat <<-\EOT >mnemonic.clarified &&
58 Thirty days has September,
59 All the rest I can’t remember.
61 git add -N mnemonic.standard mnemonic.clarified &&
62 git commit -a -m "Adapt to use modern, simpler English
64 But keep the old version, too, in case some people prefer it." &&
70 test_expect_success 'setup: two scripts for reading pull requests' '
72 downstream_url_for_sed=$(
73 printf "%s\n" "$downstream_url" |
74 sed -e '\''s/\\/\\\\/g'\'' -e '\''s/[[/.*^$]/\\&/g'\''
77 cat <<-\EOT >read-request.sed &&
79 # Note that a request could ask for "tag $tagname"
80 / in the Git repository at:$/!d
83 s/ tag \([^ ]*\)$/ tag--\1/
84 s/^[ ]*\(.*\) \([^ ]*\)/please pull\
92 s/$downstream_url_for_sed/URL/g
93 s/$OID_REGEX/OBJECT_NAME/g
95 s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
97 s/ [^ ].* (DATE)/ SUBJECT (DATE)/g
99 s/mnemonic.txt/FILENAME/g
100 s/^version [0-9]/VERSION/
101 /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat
102 /^AUTHOR ([0-9]*):\$/ b shortlog
107 / [0-9]* files* changed/ {
115 /^[a-zA-Z]* ([0-9]*):\$/ n
117 /^\n[a-zA-Z]* ([0-9]*):\$/!{
128 test_expect_success 'pull request when forgot to push' '
130 rm -fr downstream.git &&
131 git init --bare downstream.git &&
134 git checkout initial &&
135 git merge --ff-only main &&
136 test_must_fail git request-pull initial "$downstream_url" \
139 grep "No match for commit .*" err &&
140 grep "Are you sure you pushed" err
144 test_expect_success 'pull request after push' '
146 rm -fr downstream.git &&
147 git init --bare downstream.git &&
150 git checkout initial &&
151 git merge --ff-only main &&
152 git push origin main:for-upstream &&
153 git request-pull initial origin main:for-upstream >../request
155 sed -nf read-request.sed <request >digest &&
162 cd upstream-private &&
163 git checkout initial &&
164 git pull --ff-only "$repository" "$branch"
166 test "$branch" = for-upstream &&
167 test_cmp local/mnemonic.txt upstream-private/mnemonic.txt
171 test_expect_success 'request asks HEAD to be pulled' '
173 rm -fr downstream.git &&
174 git init --bare downstream.git &&
177 git checkout initial &&
178 git merge --ff-only main &&
179 git push --tags origin main simplify &&
180 git push origin main:for-upstream &&
181 git request-pull initial "$downstream_url" >../request
183 sed -nf read-request.sed <request >digest &&
193 test_expect_success 'pull request format' '
195 rm -fr downstream.git &&
196 git init --bare downstream.git &&
197 cat <<-\EOT >expect &&
198 The following changes since commit OBJECT_NAME:
202 are available in the Git repository at:
206 for you to fetch changes up to OBJECT_NAME:
210 ----------------------------------------------------------------
213 ----------------------------------------------------------------
220 git checkout initial &&
221 git merge --ff-only main &&
222 git push origin tags/full &&
223 git request-pull initial "$downstream_url" tags/full >../request
225 <request sed -nf fuzz.sed >request.fuzzy &&
226 test_i18ncmp expect request.fuzzy &&
230 git request-pull initial "$downstream_url" tags/full:refs/tags/full
232 sed -nf fuzz.sed <request >request.fuzzy &&
233 test_i18ncmp expect request.fuzzy &&
237 git request-pull initial "$downstream_url" full
239 grep " tags/full\$" request
242 test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
246 OPTIONS_KEEPDASHDASH=Yes &&
247 export OPTIONS_KEEPDASHDASH &&
248 git checkout initial &&
249 git merge --ff-only main &&
250 git push origin main:for-upstream &&
251 git request-pull -- initial "$downstream_url" main:for-upstream >../request
256 test_expect_success 'request-pull quotes regex metacharacters properly' '
258 rm -fr downstream.git &&
259 git init --bare downstream.git &&
262 git checkout initial &&
263 git merge --ff-only main &&
264 git tag -mrelease v2.0 &&
265 git push origin refs/tags/v2.0:refs/tags/v2-0 &&
266 test_must_fail git request-pull initial "$downstream_url" tags/v2.0 \
269 grep "No match for commit .*" err &&
270 grep "Are you sure you pushed" err
274 test_expect_success 'pull request with mismatched object' '
276 rm -fr downstream.git &&
277 git init --bare downstream.git &&
280 git checkout initial &&
281 git merge --ff-only main &&
282 git push origin HEAD:refs/tags/full &&
283 test_must_fail git request-pull initial "$downstream_url" tags/full \
286 grep "points to a different object" err &&
287 grep "Are you sure you pushed" err
291 test_expect_success 'pull request with stale object' '
293 rm -fr downstream.git &&
294 git init --bare downstream.git &&
297 git checkout initial &&
298 git merge --ff-only main &&
299 git push origin refs/tags/full &&
300 git tag -f -m"Thirty-one days" full &&
301 test_must_fail git request-pull initial "$downstream_url" tags/full \
304 grep "points to a different object" err &&
305 grep "Are you sure you pushed" err