Merge branch 'ar/submodule-add-config'
[git/debian.git] / t / t5150-request-pull.sh
blobcb67bac1c47487f451c2113c6b6fca60cb438bfd
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-lib.sh
10 if ! test_have_prereq PERL
11 then
12 skip_all='skipping request-pull tests, perl not available'
13 test_done
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:
32 EOT
33 git add mnemonic.txt &&
34 test_tick &&
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
38 ) &&
40 cd local &&
41 git remote add upstream "$trash_url/upstream.git" &&
42 git fetch upstream &&
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.
50 EOT
51 git add mnemonic.txt &&
52 test_tick &&
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.
60 EOT
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." &&
65 git checkout main
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'\''
75 ) &&
77 cat <<-\EOT >read-request.sed &&
78 #!/bin/sed -nf
79 # Note that a request could ask for "tag $tagname"
80 / in the Git repository at:$/!d
82 /^$/ n
83 s/ tag \([^ ]*\)$/ tag--\1/
84 s/^[ ]*\(.*\) \([^ ]*\)/please pull\
85 \1\
86 \2/p
88 EOT
90 cat <<-EOT >fuzz.sed
91 #!/bin/sed -nf
92 s/$downstream_url_for_sed/URL/g
93 s/$OID_REGEX/OBJECT_NAME/g
94 s/A U Thor/AUTHOR/g
95 s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
96 s/ [^ ].*/ SUBJECT/g
97 s/ [^ ].* (DATE)/ SUBJECT (DATE)/g
98 s|tags/full|BRANCH|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
105 : diffstat
107 / [0-9]* files* changed/ {
109 DIFFSTAT
112 b diffstat
113 : shortlog
114 /^ [a-zA-Z]/ n
115 /^[a-zA-Z]* ([0-9]*):\$/ n
116 /^\$/ N
117 /^\n[a-zA-Z]* ([0-9]*):\$/!{
119 SHORTLOG
123 b shortlog
128 test_expect_success 'pull request when forgot to push' '
130 rm -fr downstream.git &&
131 git init --bare downstream.git &&
133 cd local &&
134 git checkout initial &&
135 git merge --ff-only main &&
136 test_must_fail git request-pull initial "$downstream_url" \
137 2>../err
138 ) &&
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 &&
149 cd local &&
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
154 ) &&
155 sed -nf read-request.sed <request >digest &&
157 read task &&
158 read repository &&
159 read branch
160 } <digest &&
162 cd upstream-private &&
163 git checkout initial &&
164 git pull --ff-only "$repository" "$branch"
165 ) &&
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 &&
176 cd local &&
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
182 ) &&
183 sed -nf read-request.sed <request >digest &&
185 read task &&
186 read repository &&
187 read branch
188 } <digest &&
189 test -z "$branch"
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:
200 SUBJECT (DATE)
202 are available in the Git repository at:
204 URL BRANCH
206 for you to fetch changes up to OBJECT_NAME:
208 SUBJECT (DATE)
210 ----------------------------------------------------------------
211 VERSION
213 ----------------------------------------------------------------
214 SHORTLOG
216 DIFFSTAT
219 cd local &&
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
224 ) &&
225 <request sed -nf fuzz.sed >request.fuzzy &&
226 test_cmp expect request.fuzzy &&
229 cd local &&
230 git request-pull initial "$downstream_url" tags/full:refs/tags/full
231 ) >request &&
232 sed -nf fuzz.sed <request >request.fuzzy &&
233 test_cmp expect request.fuzzy &&
236 cd local &&
237 git request-pull initial "$downstream_url" full
238 ) >request &&
239 grep " tags/full\$" request
242 test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
245 cd local &&
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 &&
261 cd local &&
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 \
267 2>../err
268 ) &&
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 &&
279 cd local &&
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 \
284 2>../err
285 ) &&
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 &&
296 cd local &&
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 \
302 2>../err
303 ) &&
304 grep "points to a different object" err &&
305 grep "Are you sure you pushed" err
309 test_done