The eighth batch
[git.git] / t / t5150-request-pull.sh
blob86bee3316070373a1e93fc9f1dac2599483ca114
1 #!/bin/sh
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
9 . ./test-lib.sh
11 if ! test_have_prereq PERL
12 then
13 skip_all='skipping request-pull tests, perl not available'
14 test_done
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:
33 EOT
34 git add mnemonic.txt &&
35 test_tick &&
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
39 ) &&
41 cd local &&
42 git remote add upstream "$trash_url/upstream.git" &&
43 git fetch upstream &&
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.
51 EOT
52 git add mnemonic.txt &&
53 test_tick &&
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.
61 EOT
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." &&
66 git checkout main
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'\''
76 ) &&
78 cat <<-\EOT >read-request.sed &&
79 #!/bin/sed -nf
80 # Note that a request could ask for "tag $tagname"
81 / in the Git repository at:$/!d
83 /^$/ n
84 s/ tag \([^ ]*\)$/ tag--\1/
85 s/^[ ]*\(.*\) \([^ ]*\)/please pull\
86 \1\
87 \2/p
89 EOT
91 cat <<-EOT >fuzz.sed
92 #!/bin/sed -nf
93 s/$downstream_url_for_sed/URL/g
94 s/$OID_REGEX/OBJECT_NAME/g
95 s/A U Thor/AUTHOR/g
96 s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
97 s/ [^ ].*/ SUBJECT/g
98 s/ [^ ].* (DATE)/ SUBJECT (DATE)/g
99 s|tags/full|BRANCH|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
106 : diffstat
108 / [0-9]* files* changed/ {
110 DIFFSTAT
113 b diffstat
114 : shortlog
115 /^ [a-zA-Z]/ n
116 /^[a-zA-Z]* ([0-9]*):\$/ n
117 /^\$/ N
118 /^\n[a-zA-Z]* ([0-9]*):\$/!{
120 SHORTLOG
124 b shortlog
129 test_expect_success 'pull request when forgot to push' '
131 rm -fr downstream.git &&
132 git init --bare downstream.git &&
134 cd local &&
135 git checkout initial &&
136 git merge --ff-only main &&
137 test_must_fail git request-pull initial "$downstream_url" \
138 2>../err
139 ) &&
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 &&
150 cd local &&
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
155 ) &&
156 sed -nf read-request.sed <request >digest &&
158 read task &&
159 read repository &&
160 read branch
161 } <digest &&
163 cd upstream-private &&
164 git checkout initial &&
165 git pull --ff-only "$repository" "$branch"
166 ) &&
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 &&
177 cd local &&
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
183 ) &&
184 sed -nf read-request.sed <request >digest &&
186 read task &&
187 read repository &&
188 read branch
189 } <digest &&
190 test -z "$branch"
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:
201 SUBJECT (DATE)
203 are available in the Git repository at:
205 URL BRANCH
207 for you to fetch changes up to OBJECT_NAME:
209 SUBJECT (DATE)
211 ----------------------------------------------------------------
212 VERSION
214 ----------------------------------------------------------------
215 SHORTLOG
217 DIFFSTAT
220 cd local &&
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
225 ) &&
226 <request sed -nf fuzz.sed >request.fuzzy &&
227 test_cmp expect request.fuzzy &&
230 cd local &&
231 git request-pull initial "$downstream_url" tags/full:refs/tags/full
232 ) >request &&
233 sed -nf fuzz.sed <request >request.fuzzy &&
234 test_cmp expect request.fuzzy &&
237 cd local &&
238 git request-pull initial "$downstream_url" full
239 ) >request &&
240 grep " tags/full\$" request
243 test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
246 cd local &&
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 &&
262 cd local &&
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 \
268 2>../err
269 ) &&
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 &&
280 cd local &&
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 \
285 2>../err
286 ) &&
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 &&
297 cd local &&
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 \
303 2>../err
304 ) &&
305 grep "points to a different object" err &&
306 grep "Are you sure you pushed" err
310 test_done