3 test_description
='Test workflows involving pull request.'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 if ! test_have_prereq PERL
13 skip_all
='skipping request-pull tests, perl not available'
17 test_expect_success
'setup' '
19 git init --bare upstream.git &&
20 git init --bare downstream.git &&
21 git clone upstream.git upstream-private &&
22 git clone downstream.git local &&
24 trash_url="file://$TRASH_DIRECTORY" &&
25 downstream_url="$trash_url/downstream.git/" &&
26 upstream_url="$trash_url/upstream.git/" &&
29 cd upstream-private &&
30 cat <<-\EOT >mnemonic.txt &&
31 Thirtey days hath November,
32 Aprile, June, and September:
34 git add mnemonic.txt &&
36 git commit -m "\"Thirty days\", a reminder of month lengths" &&
37 git tag -m "version 1" -a initial &&
38 git push --tags origin main
42 git remote add upstream "$trash_url/upstream.git" &&
44 git pull upstream main &&
45 cat <<-\EOT >>mnemonic.txt &&
46 Of twyecescore-eightt is but eine,
47 And all the remnante be thrycescore-eine.
48 O’course Leap yare comes an’pynes,
49 Ev’rie foure yares, gote it ryghth.
50 An’twyecescore-eight is but twyecescore-nyne.
52 git add mnemonic.txt &&
54 git commit -m "More detail" &&
55 git tag -m "version 2" -a full &&
56 git checkout -b simplify HEAD^ &&
57 mv mnemonic.txt mnemonic.standard &&
58 cat <<-\EOT >mnemonic.clarified &&
59 Thirty days has September,
60 All the rest I can’t remember.
62 git add -N mnemonic.standard mnemonic.clarified &&
63 git commit -a -m "Adapt to use modern, simpler English
65 But keep the old version, too, in case some people prefer it." &&
71 test_expect_success
'setup: two scripts for reading pull requests' '
73 downstream_url_for_sed=$(
74 printf "%s\n" "$downstream_url" |
75 sed -e '\''s/\\/\\\\/g'\'' -e '\''s/[[/.*^$]/\\&/g'\''
78 cat <<-\EOT >read-request.sed &&
80 # Note that a request could ask for "tag $tagname"
81 / in the Git repository at:$/!d
84 s/ tag \([^ ]*\)$/ tag--\1/
85 s/^[ ]*\(.*\) \([^ ]*\)/please pull\
93 s/$downstream_url_for_sed/URL/g
94 s/$OID_REGEX/OBJECT_NAME/g
96 s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
98 s/ [^ ].* (DATE)/ SUBJECT (DATE)/g
100 s/mnemonic.txt/FILENAME/g
101 s/^version [0-9]/VERSION/
102 /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat
103 /^AUTHOR ([0-9]*):\$/ b shortlog
108 / [0-9]* files* changed/ {
116 /^[a-zA-Z]* ([0-9]*):\$/ n
118 /^\n[a-zA-Z]* ([0-9]*):\$/!{
129 test_expect_success
'pull request when forgot to push' '
131 rm -fr downstream.git &&
132 git init --bare downstream.git &&
135 git checkout initial &&
136 git merge --ff-only main &&
137 test_must_fail git request-pull initial "$downstream_url" \
140 grep "No match for commit .*" err &&
141 grep "Are you sure you pushed" err
145 test_expect_success
'pull request after push' '
147 rm -fr downstream.git &&
148 git init --bare downstream.git &&
151 git checkout initial &&
152 git merge --ff-only main &&
153 git push origin main:for-upstream &&
154 git request-pull initial origin main:for-upstream >../request
156 sed -nf read-request.sed <request >digest &&
163 cd upstream-private &&
164 git checkout initial &&
165 git pull --ff-only "$repository" "$branch"
167 test "$branch" = for-upstream &&
168 test_cmp local/mnemonic.txt upstream-private/mnemonic.txt
172 test_expect_success
'request asks HEAD to be pulled' '
174 rm -fr downstream.git &&
175 git init --bare downstream.git &&
178 git checkout initial &&
179 git merge --ff-only main &&
180 git push --tags origin main simplify &&
181 git push origin main:for-upstream &&
182 git request-pull initial "$downstream_url" >../request
184 sed -nf read-request.sed <request >digest &&
194 test_expect_success
'pull request format' '
196 rm -fr downstream.git &&
197 git init --bare downstream.git &&
198 cat <<-\EOT >expect &&
199 The following changes since commit OBJECT_NAME:
203 are available in the Git repository at:
207 for you to fetch changes up to OBJECT_NAME:
211 ----------------------------------------------------------------
214 ----------------------------------------------------------------
221 git checkout initial &&
222 git merge --ff-only main &&
223 git push origin tags/full &&
224 git request-pull initial "$downstream_url" tags/full >../request
226 <request sed -nf fuzz.sed >request.fuzzy &&
227 test_cmp expect request.fuzzy &&
231 git request-pull initial "$downstream_url" tags/full:refs/tags/full
233 sed -nf fuzz.sed <request >request.fuzzy &&
234 test_cmp expect request.fuzzy &&
238 git request-pull initial "$downstream_url" full
240 grep " tags/full\$" request
243 test_expect_success
'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
247 OPTIONS_KEEPDASHDASH=Yes &&
248 export OPTIONS_KEEPDASHDASH &&
249 git checkout initial &&
250 git merge --ff-only main &&
251 git push origin main:for-upstream &&
252 git request-pull -- initial "$downstream_url" main:for-upstream >../request
257 test_expect_success
'request-pull quotes regex metacharacters properly' '
259 rm -fr downstream.git &&
260 git init --bare downstream.git &&
263 git checkout initial &&
264 git merge --ff-only main &&
265 git tag -mrelease v2.0 &&
266 git push origin refs/tags/v2.0:refs/tags/v2-0 &&
267 test_must_fail git request-pull initial "$downstream_url" tags/v2.0 \
270 grep "No match for commit .*" err &&
271 grep "Are you sure you pushed" err
275 test_expect_success
'pull request with mismatched object' '
277 rm -fr downstream.git &&
278 git init --bare downstream.git &&
281 git checkout initial &&
282 git merge --ff-only main &&
283 git push origin HEAD:refs/tags/full &&
284 test_must_fail git request-pull initial "$downstream_url" tags/full \
287 grep "points to a different object" err &&
288 grep "Are you sure you pushed" err
292 test_expect_success
'pull request with stale object' '
294 rm -fr downstream.git &&
295 git init --bare downstream.git &&
298 git checkout initial &&
299 git merge --ff-only main &&
300 git push origin refs/tags/full &&
301 git tag -f -m"Thirty-one days" full &&
302 test_must_fail git request-pull initial "$downstream_url" tags/full \
305 grep "points to a different object" err &&
306 grep "Are you sure you pushed" err