]>
Commit | Line | Data |
---|---|---|
30c56eaa JN |
1 | #!/bin/sh |
2 | ||
3 | test_description='Test workflows involving pull request.' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
13ca8fb7 RA |
7 | if ! test_have_prereq PERL |
8 | then | |
9 | skip_all='skipping request-pull tests, perl not available' | |
10 | test_done | |
11 | fi | |
12 | ||
30c56eaa JN |
13 | test_expect_success 'setup' ' |
14 | ||
15 | git init --bare upstream.git && | |
16 | git init --bare downstream.git && | |
17 | git clone upstream.git upstream-private && | |
18 | git clone downstream.git local && | |
19 | ||
20 | trash_url="file://$TRASH_DIRECTORY" && | |
21 | downstream_url="$trash_url/downstream.git/" && | |
22 | upstream_url="$trash_url/upstream.git/" && | |
23 | ||
24 | ( | |
25 | cd upstream-private && | |
26 | cat <<-\EOT >mnemonic.txt && | |
27 | Thirtey days hath November, | |
28 | Aprile, June, and September: | |
29 | EOT | |
30 | git add mnemonic.txt && | |
31 | test_tick && | |
32 | git commit -m "\"Thirty days\", a reminder of month lengths" && | |
33 | git tag -m "version 1" -a initial && | |
34 | git push --tags origin master | |
35 | ) && | |
36 | ( | |
37 | cd local && | |
38 | git remote add upstream "$trash_url/upstream.git" && | |
39 | git fetch upstream && | |
40 | git pull upstream master && | |
41 | cat <<-\EOT >>mnemonic.txt && | |
42 | Of twyecescore-eightt is but eine, | |
43 | And all the remnante be thrycescore-eine. | |
44 | O’course Leap yare comes an’pynes, | |
45 | Ev’rie foure yares, gote it ryghth. | |
46 | An’twyecescore-eight is but twyecescore-nyne. | |
47 | EOT | |
48 | git add mnemonic.txt && | |
49 | test_tick && | |
50 | git commit -m "More detail" && | |
51 | git tag -m "version 2" -a full && | |
52 | git checkout -b simplify HEAD^ && | |
53 | mv mnemonic.txt mnemonic.standard && | |
54 | cat <<-\EOT >mnemonic.clarified && | |
55 | Thirty days has September, | |
56 | All the rest I can’t remember. | |
57 | EOT | |
58 | git add -N mnemonic.standard mnemonic.clarified && | |
59 | git commit -a -m "Adapt to use modern, simpler English | |
60 | ||
61 | But keep the old version, too, in case some people prefer it." && | |
62 | git checkout master | |
63 | ) | |
64 | ||
65 | ' | |
66 | ||
67 | test_expect_success 'setup: two scripts for reading pull requests' ' | |
68 | ||
69 | downstream_url_for_sed=$( | |
70 | printf "%s\n" "$downstream_url" | | |
71 | sed -e '\''s/\\/\\\\/g'\'' -e '\''s/[[/.*^$]/\\&/g'\'' | |
72 | ) && | |
73 | ||
74 | cat <<-\EOT >read-request.sed && | |
75 | #!/bin/sed -nf | |
fe46fa9d | 76 | # Note that a request could ask for "tag $tagname" |
e66d7c37 | 77 | / in the Git repository at:$/!d |
30c56eaa | 78 | n |
f2cabf6a | 79 | /^$/ n |
fe46fa9d | 80 | s/ tag \([^ ]*\)$/ tag--\1/ |
30c56eaa JN |
81 | s/^[ ]*\(.*\) \([^ ]*\)/please pull\ |
82 | \1\ | |
83 | \2/p | |
84 | q | |
85 | EOT | |
86 | ||
87 | cat <<-EOT >fuzz.sed | |
88 | #!/bin/sed -nf | |
d77fd050 | 89 | s/$downstream_url_for_sed/URL/g |
2ece6ad2 | 90 | s/$OID_REGEX/OBJECT_NAME/g |
30c56eaa | 91 | s/A U Thor/AUTHOR/g |
f2cabf6a | 92 | s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g |
30c56eaa | 93 | s/ [^ ].*/ SUBJECT/g |
f2cabf6a | 94 | s/ [^ ].* (DATE)/ SUBJECT (DATE)/g |
28ad685f | 95 | s|tags/full|BRANCH|g |
30c56eaa | 96 | s/mnemonic.txt/FILENAME/g |
d0504645 | 97 | s/^version [0-9]/VERSION/ |
30c56eaa JN |
98 | /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat |
99 | /^AUTHOR ([0-9]*):\$/ b shortlog | |
100 | p | |
101 | b | |
102 | : diffstat | |
103 | n | |
7f814632 | 104 | / [0-9]* files* changed/ { |
5bab6917 | 105 | a\\ |
30c56eaa JN |
106 | DIFFSTAT |
107 | b | |
108 | } | |
109 | b diffstat | |
110 | : shortlog | |
111 | /^ [a-zA-Z]/ n | |
112 | /^[a-zA-Z]* ([0-9]*):\$/ n | |
113 | /^\$/ N | |
6f89384f | 114 | /^\n[a-zA-Z]* ([0-9]*):\$/!{ |
5bab6917 | 115 | a\\ |
30c56eaa JN |
116 | SHORTLOG |
117 | D | |
118 | } | |
119 | n | |
120 | b shortlog | |
121 | EOT | |
122 | ||
123 | ' | |
124 | ||
125 | test_expect_success 'pull request when forgot to push' ' | |
126 | ||
127 | rm -fr downstream.git && | |
128 | git init --bare downstream.git && | |
129 | ( | |
130 | cd local && | |
131 | git checkout initial && | |
132 | git merge --ff-only master && | |
133 | test_must_fail git request-pull initial "$downstream_url" \ | |
134 | 2>../err | |
135 | ) && | |
28ad685f | 136 | grep "No match for commit .*" err && |
30c56eaa JN |
137 | grep "Are you sure you pushed" err |
138 | ||
139 | ' | |
140 | ||
141 | test_expect_success 'pull request after push' ' | |
142 | ||
143 | rm -fr downstream.git && | |
144 | git init --bare downstream.git && | |
145 | ( | |
146 | cd local && | |
147 | git checkout initial && | |
148 | git merge --ff-only master && | |
149 | git push origin master:for-upstream && | |
28ad685f | 150 | git request-pull initial origin master:for-upstream >../request |
30c56eaa JN |
151 | ) && |
152 | sed -nf read-request.sed <request >digest && | |
153 | cat digest && | |
154 | { | |
155 | read task && | |
156 | read repository && | |
157 | read branch | |
158 | } <digest && | |
159 | ( | |
160 | cd upstream-private && | |
161 | git checkout initial && | |
162 | git pull --ff-only "$repository" "$branch" | |
163 | ) && | |
164 | test "$branch" = for-upstream && | |
165 | test_cmp local/mnemonic.txt upstream-private/mnemonic.txt | |
166 | ||
167 | ' | |
168 | ||
28ad685f | 169 | test_expect_success 'request asks HEAD to be pulled' ' |
30c56eaa JN |
170 | |
171 | rm -fr downstream.git && | |
172 | git init --bare downstream.git && | |
173 | ( | |
174 | cd local && | |
175 | git checkout initial && | |
176 | git merge --ff-only master && | |
177 | git push --tags origin master simplify && | |
178 | git push origin master:for-upstream && | |
179 | git request-pull initial "$downstream_url" >../request | |
180 | ) && | |
181 | sed -nf read-request.sed <request >digest && | |
182 | cat digest && | |
183 | { | |
184 | read task && | |
185 | read repository && | |
186 | read branch | |
187 | } <digest && | |
28ad685f | 188 | test -z "$branch" |
30c56eaa JN |
189 | |
190 | ' | |
191 | ||
192 | test_expect_success 'pull request format' ' | |
193 | ||
194 | rm -fr downstream.git && | |
195 | git init --bare downstream.git && | |
196 | cat <<-\EOT >expect && | |
197 | The following changes since commit OBJECT_NAME: | |
30c56eaa | 198 | |
f2cabf6a | 199 | SUBJECT (DATE) |
30c56eaa | 200 | |
e66d7c37 | 201 | are available in the Git repository at: |
cf731666 | 202 | |
30c56eaa JN |
203 | URL BRANCH |
204 | ||
cf731666 JH |
205 | for you to fetch changes up to OBJECT_NAME: |
206 | ||
207 | SUBJECT (DATE) | |
208 | ||
d0504645 JH |
209 | ---------------------------------------------------------------- |
210 | VERSION | |
211 | ||
cf731666 | 212 | ---------------------------------------------------------------- |
30c56eaa JN |
213 | SHORTLOG |
214 | ||
215 | DIFFSTAT | |
216 | EOT | |
217 | ( | |
218 | cd local && | |
219 | git checkout initial && | |
220 | git merge --ff-only master && | |
28ad685f JH |
221 | git push origin tags/full && |
222 | git request-pull initial "$downstream_url" tags/full >../request | |
30c56eaa JN |
223 | ) && |
224 | <request sed -nf fuzz.sed >request.fuzzy && | |
5aae66bd | 225 | test_i18ncmp expect request.fuzzy && |
30c56eaa | 226 | |
5aae66bd JH |
227 | ( |
228 | cd local && | |
229 | git request-pull initial "$downstream_url" tags/full:refs/tags/full | |
230 | ) >request && | |
231 | sed -nf fuzz.sed <request >request.fuzzy && | |
d952cbb1 JH |
232 | test_i18ncmp expect request.fuzzy && |
233 | ||
234 | ( | |
235 | cd local && | |
236 | git request-pull initial "$downstream_url" full | |
237 | ) >request && | |
644edd02 | 238 | grep " tags/full\$" request |
30c56eaa JN |
239 | ' |
240 | ||
50ab6558 JN |
241 | test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' ' |
242 | ||
243 | ( | |
244 | cd local && | |
245 | OPTIONS_KEEPDASHDASH=Yes && | |
246 | export OPTIONS_KEEPDASHDASH && | |
247 | git checkout initial && | |
248 | git merge --ff-only master && | |
249 | git push origin master:for-upstream && | |
28ad685f | 250 | git request-pull -- initial "$downstream_url" master:for-upstream >../request |
50ab6558 JN |
251 | ) |
252 | ||
253 | ' | |
254 | ||
5731dfce PB |
255 | test_expect_success 'request-pull quotes regex metacharacters properly' ' |
256 | ||
257 | rm -fr downstream.git && | |
258 | git init --bare downstream.git && | |
259 | ( | |
260 | cd local && | |
261 | git checkout initial && | |
262 | git merge --ff-only master && | |
263 | git tag -mrelease v2.0 && | |
264 | git push origin refs/tags/v2.0:refs/tags/v2-0 && | |
265 | test_must_fail git request-pull initial "$downstream_url" tags/v2.0 \ | |
266 | 2>../err | |
267 | ) && | |
268 | grep "No match for commit .*" err && | |
269 | grep "Are you sure you pushed" err | |
270 | ||
271 | ' | |
272 | ||
0454220d PB |
273 | test_expect_success 'pull request with mismatched object' ' |
274 | ||
275 | rm -fr downstream.git && | |
276 | git init --bare downstream.git && | |
277 | ( | |
278 | cd local && | |
279 | git checkout initial && | |
280 | git merge --ff-only master && | |
281 | git push origin HEAD:refs/tags/full && | |
282 | test_must_fail git request-pull initial "$downstream_url" tags/full \ | |
283 | 2>../err | |
284 | ) && | |
285 | grep "points to a different object" err && | |
286 | grep "Are you sure you pushed" err | |
287 | ||
288 | ' | |
289 | ||
290 | test_expect_success 'pull request with stale object' ' | |
291 | ||
292 | rm -fr downstream.git && | |
293 | git init --bare downstream.git && | |
294 | ( | |
295 | cd local && | |
296 | git checkout initial && | |
297 | git merge --ff-only master && | |
298 | git push origin refs/tags/full && | |
299 | git tag -f -m"Thirty-one days" full && | |
300 | test_must_fail git request-pull initial "$downstream_url" tags/full \ | |
301 | 2>../err | |
302 | ) && | |
303 | grep "points to a different object" err && | |
304 | grep "Are you sure you pushed" err | |
305 | ||
306 | ' | |
307 | ||
30c56eaa | 308 | test_done |