shortlog: allow multiple groups to be specified
[git] / t / t5150-request-pull.sh
1 #!/bin/sh
2
3 test_description='Test workflows involving pull request.'
4
5 . ./test-lib.sh
6
7 if ! test_have_prereq PERL
8 then
9         skip_all='skipping request-pull tests, perl not available'
10         test_done
11 fi
12
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
76         # Note that a request could ask for "tag $tagname"
77         / in the Git repository at:$/!d
78         n
79         /^$/ n
80         s/ tag \([^ ]*\)$/ tag--\1/
81         s/^[    ]*\(.*\) \([^ ]*\)/please pull\
82         \1\
83         \2/p
84         q
85         EOT
86
87         cat <<-EOT >fuzz.sed
88         #!/bin/sed -nf
89         s/$downstream_url_for_sed/URL/g
90         s/$OID_REGEX/OBJECT_NAME/g
91         s/A U Thor/AUTHOR/g
92         s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
93         s/        [^ ].*/        SUBJECT/g
94         s/  [^ ].* (DATE)/  SUBJECT (DATE)/g
95         s|tags/full|BRANCH|g
96         s/mnemonic.txt/FILENAME/g
97         s/^version [0-9]/VERSION/
98         /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat
99         /^AUTHOR ([0-9]*):\$/ b shortlog
100         p
101         b
102         : diffstat
103         n
104         / [0-9]* files* changed/ {
105                 a\\
106         DIFFSTAT
107                 b
108         }
109         b diffstat
110         : shortlog
111         /^        [a-zA-Z]/ n
112         /^[a-zA-Z]* ([0-9]*):\$/ n
113         /^\$/ N
114         /^\n[a-zA-Z]* ([0-9]*):\$/!{
115                 a\\
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         ) &&
136         grep "No match for commit .*" err &&
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 &&
150                 git request-pull initial origin master:for-upstream >../request
151         ) &&
152         sed -nf read-request.sed <request >digest &&
153         {
154                 read task &&
155                 read repository &&
156                 read branch
157         } <digest &&
158         (
159                 cd upstream-private &&
160                 git checkout initial &&
161                 git pull --ff-only "$repository" "$branch"
162         ) &&
163         test "$branch" = for-upstream &&
164         test_cmp local/mnemonic.txt upstream-private/mnemonic.txt
165
166 '
167
168 test_expect_success 'request asks HEAD to be pulled' '
169
170         rm -fr downstream.git &&
171         git init --bare downstream.git &&
172         (
173                 cd local &&
174                 git checkout initial &&
175                 git merge --ff-only master &&
176                 git push --tags origin master simplify &&
177                 git push origin master:for-upstream &&
178                 git request-pull initial "$downstream_url" >../request
179         ) &&
180         sed -nf read-request.sed <request >digest &&
181         {
182                 read task &&
183                 read repository &&
184                 read branch
185         } <digest &&
186         test -z "$branch"
187
188 '
189
190 test_expect_success 'pull request format' '
191
192         rm -fr downstream.git &&
193         git init --bare downstream.git &&
194         cat <<-\EOT >expect &&
195         The following changes since commit OBJECT_NAME:
196
197           SUBJECT (DATE)
198
199         are available in the Git repository at:
200
201           URL BRANCH
202
203         for you to fetch changes up to OBJECT_NAME:
204
205           SUBJECT (DATE)
206
207         ----------------------------------------------------------------
208         VERSION
209
210         ----------------------------------------------------------------
211         SHORTLOG
212
213         DIFFSTAT
214         EOT
215         (
216                 cd local &&
217                 git checkout initial &&
218                 git merge --ff-only master &&
219                 git push origin tags/full &&
220                 git request-pull initial "$downstream_url" tags/full >../request
221         ) &&
222         <request sed -nf fuzz.sed >request.fuzzy &&
223         test_i18ncmp expect request.fuzzy &&
224
225         (
226                 cd local &&
227                 git request-pull initial "$downstream_url" tags/full:refs/tags/full
228         ) >request &&
229         sed -nf fuzz.sed <request >request.fuzzy &&
230         test_i18ncmp expect request.fuzzy &&
231
232         (
233                 cd local &&
234                 git request-pull initial "$downstream_url" full
235         ) >request &&
236         grep " tags/full\$" request
237 '
238
239 test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
240
241         (
242                 cd local &&
243                 OPTIONS_KEEPDASHDASH=Yes &&
244                 export OPTIONS_KEEPDASHDASH &&
245                 git checkout initial &&
246                 git merge --ff-only master &&
247                 git push origin master:for-upstream &&
248                 git request-pull -- initial "$downstream_url" master:for-upstream >../request
249         )
250
251 '
252
253 test_expect_success 'request-pull quotes regex metacharacters properly' '
254
255         rm -fr downstream.git &&
256         git init --bare downstream.git &&
257         (
258                 cd local &&
259                 git checkout initial &&
260                 git merge --ff-only master &&
261                 git tag -mrelease v2.0 &&
262                 git push origin refs/tags/v2.0:refs/tags/v2-0 &&
263                 test_must_fail git request-pull initial "$downstream_url" tags/v2.0 \
264                         2>../err
265         ) &&
266         grep "No match for commit .*" err &&
267         grep "Are you sure you pushed" err
268
269 '
270
271 test_expect_success 'pull request with mismatched object' '
272
273         rm -fr downstream.git &&
274         git init --bare downstream.git &&
275         (
276                 cd local &&
277                 git checkout initial &&
278                 git merge --ff-only master &&
279                 git push origin HEAD:refs/tags/full &&
280                 test_must_fail git request-pull initial "$downstream_url" tags/full \
281                         2>../err
282         ) &&
283         grep "points to a different object" err &&
284         grep "Are you sure you pushed" err
285
286 '
287
288 test_expect_success 'pull request with stale object' '
289
290         rm -fr downstream.git &&
291         git init --bare downstream.git &&
292         (
293                 cd local &&
294                 git checkout initial &&
295                 git merge --ff-only master &&
296                 git push origin refs/tags/full &&
297                 git tag -f -m"Thirty-one days" full &&
298                 test_must_fail git request-pull initial "$downstream_url" tags/full \
299                         2>../err
300         ) &&
301         grep "points to a different object" err &&
302         grep "Are you sure you pushed" err
303
304 '
305
306 test_done