3 test_description='Test workflows involving pull request.'
7 test_expect_success 'setup' '
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 &&
14 trash_url="file://$TRASH_DIRECTORY" &&
15 downstream_url="$trash_url/downstream.git/" &&
16 upstream_url="$trash_url/upstream.git/" &&
19 cd upstream-private &&
20 cat <<-\EOT >mnemonic.txt &&
21 Thirtey days hath November,
22 Aprile, June, and September:
24 git add mnemonic.txt &&
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
32 git remote add upstream "$trash_url/upstream.git" &&
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.
42 git add mnemonic.txt &&
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.
52 git add -N mnemonic.standard mnemonic.clarified &&
53 git commit -a -m "Adapt to use modern, simpler English
55 But keep the old version, too, in case some people prefer it." &&
61 test_expect_success 'setup: two scripts for reading pull requests' '
63 downstream_url_for_sed=$(
64 printf "%s\n" "$downstream_url" |
65 sed -e '\''s/\\/\\\\/g'\'' -e '\''s/[[/.*^$]/\\&/g'\''
68 cat <<-\EOT >read-request.sed &&
70 # Note that a request could ask for "tag $tagname"
71 / in the Git repository at:$/!d
74 s/ tag \([^ ]*\)$/ tag--\1/
75 s/^[ ]*\(.*\) \([^ ]*\)/please pull\
83 s/$downstream_url_for_sed/URL/g
84 s/$OID_REGEX/OBJECT_NAME/g
86 s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
88 s/ [^ ].* (DATE)/ SUBJECT (DATE)/g
90 s/mnemonic.txt/FILENAME/g
91 s/^version [0-9]/VERSION/
92 /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat
93 /^AUTHOR ([0-9]*):\$/ b shortlog
98 / [0-9]* files* changed/ {
106 /^[a-zA-Z]* ([0-9]*):\$/ n
108 /^\n[a-zA-Z]* ([0-9]*):\$/!{
119 test_expect_success 'pull request when forgot to push' '
121 rm -fr downstream.git &&
122 git init --bare downstream.git &&
125 git checkout initial &&
126 git merge --ff-only master &&
127 test_must_fail git request-pull initial "$downstream_url" \
130 grep "No match for commit .*" err &&
131 grep "Are you sure you pushed" err
135 test_expect_success 'pull request after push' '
137 rm -fr downstream.git &&
138 git init --bare downstream.git &&
141 git checkout initial &&
142 git merge --ff-only master &&
143 git push origin master:for-upstream &&
144 git request-pull initial origin master:for-upstream >../request
146 sed -nf read-request.sed <request >digest &&
154 cd upstream-private &&
155 git checkout initial &&
156 git pull --ff-only "$repository" "$branch"
158 test "$branch" = for-upstream &&
159 test_cmp local/mnemonic.txt upstream-private/mnemonic.txt
163 test_expect_success 'request asks HEAD to be pulled' '
165 rm -fr downstream.git &&
166 git init --bare downstream.git &&
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
175 sed -nf read-request.sed <request >digest &&
186 test_expect_success 'pull request format' '
188 rm -fr downstream.git &&
189 git init --bare downstream.git &&
190 cat <<-\EOT >expect &&
191 The following changes since commit OBJECT_NAME:
195 are available in the Git repository at:
199 for you to fetch changes up to OBJECT_NAME:
203 ----------------------------------------------------------------
206 ----------------------------------------------------------------
213 git checkout initial &&
214 git merge --ff-only master &&
215 git push origin tags/full &&
216 git request-pull initial "$downstream_url" tags/full >../request
218 <request sed -nf fuzz.sed >request.fuzzy &&
219 test_i18ncmp expect request.fuzzy &&
223 git request-pull initial "$downstream_url" tags/full:refs/tags/full
225 sed -nf fuzz.sed <request >request.fuzzy &&
226 test_i18ncmp expect request.fuzzy &&
230 git request-pull initial "$downstream_url" full
232 grep " tags/full\$" request
235 test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
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 &&
244 git request-pull -- initial "$downstream_url" master:for-upstream >../request