]>
Commit | Line | Data |
---|---|---|
30c56eaa JN |
1 | #!/bin/sh |
2 | ||
3 | test_description='Test workflows involving pull request.' | |
4 | ||
966b4be2 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
30c56eaa JN |
8 | . ./test-lib.sh |
9 | ||
13ca8fb7 RA |
10 | if ! test_have_prereq PERL |
11 | then | |
12 | skip_all='skipping request-pull tests, perl not available' | |
13 | test_done | |
14 | fi | |
15 | ||
30c56eaa JN |
16 | test_expect_success 'setup' ' |
17 | ||
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 && | |
22 | ||
23 | trash_url="file://$TRASH_DIRECTORY" && | |
24 | downstream_url="$trash_url/downstream.git/" && | |
25 | upstream_url="$trash_url/upstream.git/" && | |
26 | ||
27 | ( | |
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 && | |
966b4be2 | 37 | git push --tags origin main |
30c56eaa JN |
38 | ) && |
39 | ( | |
40 | cd local && | |
41 | git remote add upstream "$trash_url/upstream.git" && | |
42 | git fetch upstream && | |
966b4be2 | 43 | git pull upstream main && |
30c56eaa JN |
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 | |
63 | ||
64 | But keep the old version, too, in case some people prefer it." && | |
966b4be2 | 65 | git checkout main |
30c56eaa JN |
66 | ) |
67 | ||
68 | ' | |
69 | ||
70 | test_expect_success 'setup: two scripts for reading pull requests' ' | |
71 | ||
72 | downstream_url_for_sed=$( | |
73 | printf "%s\n" "$downstream_url" | | |
74 | sed -e '\''s/\\/\\\\/g'\'' -e '\''s/[[/.*^$]/\\&/g'\'' | |
75 | ) && | |
76 | ||
77 | cat <<-\EOT >read-request.sed && | |
78 | #!/bin/sed -nf | |
fe46fa9d | 79 | # Note that a request could ask for "tag $tagname" |
e66d7c37 | 80 | / in the Git repository at:$/!d |
30c56eaa | 81 | n |
f2cabf6a | 82 | /^$/ n |
fe46fa9d | 83 | s/ tag \([^ ]*\)$/ tag--\1/ |
30c56eaa JN |
84 | s/^[ ]*\(.*\) \([^ ]*\)/please pull\ |
85 | \1\ | |
86 | \2/p | |
87 | q | |
88 | EOT | |
89 | ||
90 | cat <<-EOT >fuzz.sed | |
91 | #!/bin/sed -nf | |
d77fd050 | 92 | s/$downstream_url_for_sed/URL/g |
2ece6ad2 | 93 | s/$OID_REGEX/OBJECT_NAME/g |
30c56eaa | 94 | s/A U Thor/AUTHOR/g |
f2cabf6a | 95 | s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g |
30c56eaa | 96 | s/ [^ ].*/ SUBJECT/g |
f2cabf6a | 97 | s/ [^ ].* (DATE)/ SUBJECT (DATE)/g |
28ad685f | 98 | s|tags/full|BRANCH|g |
30c56eaa | 99 | s/mnemonic.txt/FILENAME/g |
d0504645 | 100 | s/^version [0-9]/VERSION/ |
30c56eaa JN |
101 | /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat |
102 | /^AUTHOR ([0-9]*):\$/ b shortlog | |
103 | p | |
104 | b | |
105 | : diffstat | |
106 | n | |
7f814632 | 107 | / [0-9]* files* changed/ { |
5bab6917 | 108 | a\\ |
30c56eaa JN |
109 | DIFFSTAT |
110 | b | |
111 | } | |
112 | b diffstat | |
113 | : shortlog | |
114 | /^ [a-zA-Z]/ n | |
115 | /^[a-zA-Z]* ([0-9]*):\$/ n | |
116 | /^\$/ N | |
6f89384f | 117 | /^\n[a-zA-Z]* ([0-9]*):\$/!{ |
5bab6917 | 118 | a\\ |
30c56eaa JN |
119 | SHORTLOG |
120 | D | |
121 | } | |
122 | n | |
123 | b shortlog | |
124 | EOT | |
125 | ||
126 | ' | |
127 | ||
128 | test_expect_success 'pull request when forgot to push' ' | |
129 | ||
130 | rm -fr downstream.git && | |
131 | git init --bare downstream.git && | |
132 | ( | |
133 | cd local && | |
134 | git checkout initial && | |
966b4be2 | 135 | git merge --ff-only main && |
30c56eaa JN |
136 | test_must_fail git request-pull initial "$downstream_url" \ |
137 | 2>../err | |
138 | ) && | |
28ad685f | 139 | grep "No match for commit .*" err && |
30c56eaa JN |
140 | grep "Are you sure you pushed" err |
141 | ||
142 | ' | |
143 | ||
144 | test_expect_success 'pull request after push' ' | |
145 | ||
146 | rm -fr downstream.git && | |
147 | git init --bare downstream.git && | |
148 | ( | |
149 | cd local && | |
150 | git checkout initial && | |
966b4be2 JS |
151 | git merge --ff-only main && |
152 | git push origin main:for-upstream && | |
153 | git request-pull initial origin main:for-upstream >../request | |
30c56eaa JN |
154 | ) && |
155 | sed -nf read-request.sed <request >digest && | |
30c56eaa JN |
156 | { |
157 | read task && | |
158 | read repository && | |
159 | read branch | |
160 | } <digest && | |
161 | ( | |
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 | |
168 | ||
169 | ' | |
170 | ||
28ad685f | 171 | test_expect_success 'request asks HEAD to be pulled' ' |
30c56eaa JN |
172 | |
173 | rm -fr downstream.git && | |
174 | git init --bare downstream.git && | |
175 | ( | |
176 | cd local && | |
177 | git checkout initial && | |
966b4be2 JS |
178 | git merge --ff-only main && |
179 | git push --tags origin main simplify && | |
180 | git push origin main:for-upstream && | |
30c56eaa JN |
181 | git request-pull initial "$downstream_url" >../request |
182 | ) && | |
183 | sed -nf read-request.sed <request >digest && | |
30c56eaa JN |
184 | { |
185 | read task && | |
186 | read repository && | |
187 | read branch | |
188 | } <digest && | |
28ad685f | 189 | test -z "$branch" |
30c56eaa JN |
190 | |
191 | ' | |
192 | ||
193 | test_expect_success 'pull request format' ' | |
194 | ||
195 | rm -fr downstream.git && | |
196 | git init --bare downstream.git && | |
197 | cat <<-\EOT >expect && | |
198 | The following changes since commit OBJECT_NAME: | |
30c56eaa | 199 | |
f2cabf6a | 200 | SUBJECT (DATE) |
30c56eaa | 201 | |
e66d7c37 | 202 | are available in the Git repository at: |
cf731666 | 203 | |
30c56eaa JN |
204 | URL BRANCH |
205 | ||
cf731666 JH |
206 | for you to fetch changes up to OBJECT_NAME: |
207 | ||
208 | SUBJECT (DATE) | |
209 | ||
d0504645 JH |
210 | ---------------------------------------------------------------- |
211 | VERSION | |
212 | ||
cf731666 | 213 | ---------------------------------------------------------------- |
30c56eaa JN |
214 | SHORTLOG |
215 | ||
216 | DIFFSTAT | |
217 | EOT | |
218 | ( | |
219 | cd local && | |
220 | git checkout initial && | |
966b4be2 | 221 | git merge --ff-only main && |
28ad685f JH |
222 | git push origin tags/full && |
223 | git request-pull initial "$downstream_url" tags/full >../request | |
30c56eaa JN |
224 | ) && |
225 | <request sed -nf fuzz.sed >request.fuzzy && | |
1108cea7 | 226 | test_cmp expect request.fuzzy && |
30c56eaa | 227 | |
5aae66bd JH |
228 | ( |
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 && | |
1108cea7 | 233 | test_cmp expect request.fuzzy && |
d952cbb1 JH |
234 | |
235 | ( | |
236 | cd local && | |
237 | git request-pull initial "$downstream_url" full | |
238 | ) >request && | |
644edd02 | 239 | grep " tags/full\$" request |
30c56eaa JN |
240 | ' |
241 | ||
50ab6558 JN |
242 | test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' ' |
243 | ||
244 | ( | |
245 | cd local && | |
246 | OPTIONS_KEEPDASHDASH=Yes && | |
247 | export OPTIONS_KEEPDASHDASH && | |
248 | git checkout initial && | |
966b4be2 JS |
249 | git merge --ff-only main && |
250 | git push origin main:for-upstream && | |
251 | git request-pull -- initial "$downstream_url" main:for-upstream >../request | |
50ab6558 JN |
252 | ) |
253 | ||
254 | ' | |
255 | ||
5731dfce PB |
256 | test_expect_success 'request-pull quotes regex metacharacters properly' ' |
257 | ||
258 | rm -fr downstream.git && | |
259 | git init --bare downstream.git && | |
260 | ( | |
261 | cd local && | |
262 | git checkout initial && | |
966b4be2 | 263 | git merge --ff-only main && |
5731dfce PB |
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 | |
271 | ||
272 | ' | |
273 | ||
0454220d PB |
274 | test_expect_success 'pull request with mismatched object' ' |
275 | ||
276 | rm -fr downstream.git && | |
277 | git init --bare downstream.git && | |
278 | ( | |
279 | cd local && | |
280 | git checkout initial && | |
966b4be2 | 281 | git merge --ff-only main && |
0454220d PB |
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 | |
288 | ||
289 | ' | |
290 | ||
291 | test_expect_success 'pull request with stale object' ' | |
292 | ||
293 | rm -fr downstream.git && | |
294 | git init --bare downstream.git && | |
295 | ( | |
296 | cd local && | |
297 | git checkout initial && | |
966b4be2 | 298 | git merge --ff-only main && |
0454220d PB |
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 | |
306 | ||
307 | ' | |
308 | ||
30c56eaa | 309 | test_done |