3 test_description='Test workflows involving pull request.'
7 test_expect_success 'setup' '
8 git init --bare upstream.git &&
9 git init --bare downstream.git &&
10 git clone upstream.git upstream-private &&
11 git clone downstream.git local &&
13 trash_url="file://$TRASH_DIRECTORY" &&
14 downstream_url="$trash_url/downstream.git/" &&
15 upstream_url="$trash_url/upstream.git/" &&
18 cd upstream-private &&
19 cat <<-\EOT >mnemonic.txt &&
20 Thirtey days hath November,
21 Aprile, June, and September:
23 git add mnemonic.txt &&
25 git commit -m "\"Thirty days\", a reminder of month lengths" &&
26 git tag -m "version 1" -a initial &&
27 git push --tags origin master
31 git remote add upstream "$trash_url/upstream.git" &&
33 git pull upstream master &&
34 cat <<-\EOT >>mnemonic.txt &&
35 Of twyecescore-eightt is but eine,
36 And all the remnante be thrycescore-eine.
37 O’course Leap yare comes an’pynes,
38 Ev’rie foure yares, gote it ryghth.
39 An’twyecescore-eight is but twyecescore-nyne.
41 git add mnemonic.txt &&
43 git commit -m "More detail" &&
44 git tag -m "version 2" -a full &&
45 git checkout -b simplify HEAD^ &&
46 mv mnemonic.txt mnemonic.standard &&
47 cat <<-\EOT >mnemonic.clarified &&
48 Thirty days has September,
49 All the rest I can’t remember.
51 git add -N mnemonic.standard mnemonic.clarified &&
52 git commit -a -m "Adapt to use modern, simpler English
54 But keep the old version, too, in case some people prefer it." &&
59 test_expect_success 'setup: two scripts for reading pull requests' '
60 downstream_url_for_sed=$(
61 printf "%s\n" "$downstream_url" |
62 sed -e '\''s/\\/\\\\/g'\'' -e '\''s/[[/.*^$]/\\&/g'\''
65 cat <<-\EOT >read-request.sed &&
67 # Note that a request could ask for "tag $tagname"
68 / in the git repository at:$/!d
71 s/ tag \([^ ]*\)$/ tag--\1/
72 s/^[ ]*\(.*\) \([^ ]*\)/please pull\
80 s/$downstream_url_for_sed/URL/g
83 s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
85 s/ [^ ].* (DATE)/ SUBJECT (DATE)/g
86 s/for-upstream/BRANCH/g
87 s/mnemonic.txt/FILENAME/g
88 s/^version [0-9]/VERSION/
89 /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat
90 /^AUTHOR ([0-9]*):\$/ b shortlog
95 / [0-9]* files* changed/ {
103 /^[a-zA-Z]* ([0-9]*):\$/ n
105 /^\n[a-zA-Z]* ([0-9]*):\$/!{
115 test_expect_success 'pull request when forgot to push' '
116 rm -fr downstream.git &&
117 git init --bare downstream.git &&
120 git checkout initial &&
121 git merge --ff-only master &&
122 test_must_fail git request-pull initial "$downstream_url" \
126 grep "No branch of.*is at:\$" err &&
127 grep "Are you sure you pushed" err
130 test_expect_success 'pull request after push' '
131 rm -fr downstream.git &&
132 git init --bare downstream.git &&
135 git checkout initial &&
136 git merge --ff-only master &&
137 git push origin master:for-upstream &&
138 git request-pull initial origin >../request
140 sed -nf read-request.sed <request >digest &&
148 cd upstream-private &&
149 git checkout initial &&
150 git pull --ff-only "$repository" "$branch"
152 test "$branch" = for-upstream &&
153 test_cmp local/mnemonic.txt upstream-private/mnemonic.txt
156 test_expect_success 'request names an appropriate branch' '
157 rm -fr downstream.git &&
158 git init --bare downstream.git &&
161 git checkout initial &&
162 git merge --ff-only master &&
163 git push --tags origin master simplify &&
164 git push origin master:for-upstream &&
165 git request-pull initial "$downstream_url" >../request
167 sed -nf read-request.sed <request >digest &&
174 test "$branch" = tags/full
177 test_expect_success 'pull request format' '
178 rm -fr downstream.git &&
179 git init --bare downstream.git &&
180 cat <<-\EOT >expect &&
181 The following changes since commit OBJECT_NAME:
185 are available in the git repository at:
189 for you to fetch changes up to OBJECT_NAME:
193 ----------------------------------------------------------------
196 ----------------------------------------------------------------
203 git checkout initial &&
204 git merge --ff-only master &&
205 git push origin master:for-upstream &&
206 git request-pull initial "$downstream_url" >../request
208 <request sed -nf fuzz.sed >request.fuzzy &&
209 test_i18ncmp expect request.fuzzy
212 test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
215 OPTIONS_KEEPDASHDASH=Yes &&
216 export OPTIONS_KEEPDASHDASH &&
217 git checkout initial &&
218 git merge --ff-only master &&
219 git push origin master:for-upstream &&
220 git request-pull -- initial "$downstream_url" >../request
224 test_expect_success 'pull request when pushed tag' '
225 rm -fr downstream.git &&
226 git init --bare downstream.git &&
229 git checkout initial &&
230 git merge --ff-only master &&
232 git push origin master:for-upstream full zeebra &&
233 git request-pull initial origin 2>../err
236 ! grep "You locally have .* but it does not (yet)" err
239 test_expect_success 'pull request with branch description' '
240 test_when_finished "(cd local && git checkout - && git branch -D for-upstream)" &&
241 rm -fr downstream.git &&
242 git init --bare downstream.git &&
245 git checkout -b for-upstream master &&
246 git config branch.for-upstream.description "Branch for upstream$LF" &&
247 git push origin for-upstream &&
248 git request-pull initial origin >../request
251 grep "(from the branch description for for-upstream local branch)" request &&
252 grep "Branch for upstream" request
255 test_expect_success 'pull request with branch description from rev' '
256 test_when_finished "(cd local && git checkout - && git branch -D for-upstream)" &&
257 rm -fr downstream.git &&
258 git init --bare downstream.git &&
261 git checkout -b for-upstream master &&
262 git config branch.for-upstream.description "Branch for upstream$LF" &&
263 git push origin for-upstream &&
264 git request-pull initial origin for-upstream >../request
267 grep "(from the branch description for for-upstream local branch)" request &&
268 grep "Branch for upstream" request
271 test_expect_success 'pull request with exact match' '
272 test_when_finished "(cd local && git checkout - && git branch -D for-upstream)" &&
273 rm -fr downstream.git &&
274 git init --bare downstream.git &&
277 git checkout -b for-upstream master &&
278 git push origin master:for-upstream master:zeebra &&
279 git request-pull initial origin for-upstream >../request
282 sed -nf read-request.sed <request >digest &&
289 test "$branch" = for-upstream