1#!/bin/sh
2
3test_description='Test workflows involving pull request.'
4
5. ./test-lib.sh
6
7test_expect_success 'setup' '
8
9 git init --bare upstream.git &&
10 git init --bare downstream.git &&
11 git clone upstream.git upstream-private &&
12 git clone downstream.git local &&
13
14 trash_url="file://$TRASH_DIRECTORY" &&
15 downstream_url="$trash_url/downstream.git/" &&
16 upstream_url="$trash_url/upstream.git/" &&
17
18 (
19 cd upstream-private &&
20 cat <<-\EOT >mnemonic.txt &&
21 Thirtey days hath November,
22 Aprile, June, and September:
23 EOT
24 git add mnemonic.txt &&
25 test_tick &&
26 git commit -m "\"Thirty days\", a reminder of month lengths" &&
27 git tag -m "version 1" -a initial &&
28 git push --tags origin master
29 ) &&
30 (
31 cd local &&
32 git remote add upstream "$trash_url/upstream.git" &&
33 git fetch upstream &&
34 git pull upstream master &&
35 cat <<-\EOT >>mnemonic.txt &&
36 Of twyecescore-eightt is but eine,
37 And all the remnante be thrycescore-eine.
38 O’course Leap yare comes an’pynes,
39 Ev’rie foure yares, gote it ryghth.
40 An’twyecescore-eight is but twyecescore-nyne.
41 EOT
42 git add mnemonic.txt &&
43 test_tick &&
44 git commit -m "More detail" &&
45 git tag -m "version 2" -a full &&
46 git checkout -b simplify HEAD^ &&
47 mv mnemonic.txt mnemonic.standard &&
48 cat <<-\EOT >mnemonic.clarified &&
49 Thirty days has September,
50 All the rest I can’t remember.
51 EOT
52 git add -N mnemonic.standard mnemonic.clarified &&
53 git commit -a -m "Adapt to use modern, simpler English
54
55But keep the old version, too, in case some people prefer it." &&
56 git checkout master
57 )
58
59'
60
61test_expect_success 'setup: two scripts for reading pull requests' '
62
63 downstream_url_for_sed=$(
64 printf "%s\n" "$downstream_url" |
65 sed -e '\''s/\\/\\\\/g'\'' -e '\''s/[[/.*^$]/\\&/g'\''
66 ) &&
67
68 cat <<-\EOT >read-request.sed &&
69 #!/bin/sed -nf
70 # Note that a request could ask for "tag $tagname"
71 / in the git repository at:$/!d
72 n
73 /^$/ n
74 s/ tag \([^ ]*\)$/ tag--\1/
75 s/^[ ]*\(.*\) \([^ ]*\)/please pull\
76 \1\
77 \2/p
78 q
79 EOT
80
81 cat <<-EOT >fuzz.sed
82 #!/bin/sed -nf
83 s/$_x40/OBJECT_NAME/g
84 s/A U Thor/AUTHOR/g
85 s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
86 s/ [^ ].*/ SUBJECT/g
87 s/ [^ ].* (DATE)/ SUBJECT (DATE)/g
88 s/$downstream_url_for_sed/URL/g
89 s/for-upstream/BRANCH/g
90 s/mnemonic.txt/FILENAME/g
91 s/^version [0-9]/VERSION/
92 /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat
93 /^AUTHOR ([0-9]*):\$/ b shortlog
94 p
95 b
96 : diffstat
97 n
98 / [0-9]* files changed/ {
99 a\\
100 DIFFSTAT
101 b
102 }
103 b diffstat
104 : shortlog
105 /^ [a-zA-Z]/ n
106 /^[a-zA-Z]* ([0-9]*):\$/ n
107 /^\$/ N
108 /^\n[a-zA-Z]* ([0-9]*):\$/!{
109 a\\
110 SHORTLOG
111 D
112 }
113 n
114 b shortlog
115 EOT
116
117'
118
119test_expect_success 'pull request when forgot to push' '
120
121 rm -fr downstream.git &&
122 git init --bare downstream.git &&
123 (
124 cd local &&
125 git checkout initial &&
126 git merge --ff-only master &&
127 test_must_fail git request-pull initial "$downstream_url" \
128 2>../err
129 ) &&
130 grep "No branch of.*is at:\$" err &&
131 grep "Are you sure you pushed" err
132
133'
134
135test_expect_success 'pull request after push' '
136
137 rm -fr downstream.git &&
138 git init --bare downstream.git &&
139 (
140 cd local &&
141 git checkout initial &&
142 git merge --ff-only master &&
143 git push origin master:for-upstream &&
144 git request-pull initial origin >../request
145 ) &&
146 sed -nf read-request.sed <request >digest &&
147 cat digest &&
148 {
149 read task &&
150 read repository &&
151 read branch
152 } <digest &&
153 (
154 cd upstream-private &&
155 git checkout initial &&
156 git pull --ff-only "$repository" "$branch"
157 ) &&
158 test "$branch" = for-upstream &&
159 test_cmp local/mnemonic.txt upstream-private/mnemonic.txt
160
161'
162
163test_expect_success 'request names an appropriate branch' '
164
165 rm -fr downstream.git &&
166 git init --bare downstream.git &&
167 (
168 cd local &&
169 git checkout initial &&
170 git merge --ff-only master &&
171 git push --tags origin master simplify &&
172 git push origin master:for-upstream &&
173 git request-pull initial "$downstream_url" >../request
174 ) &&
175 sed -nf read-request.sed <request >digest &&
176 cat digest &&
177 {
178 read task &&
179 read repository &&
180 read branch
181 } <digest &&
182 {
183 test "$branch" = full ||
184 test "$branch" = master ||
185 test "$branch" = for-upstream
186 }
187
188'
189
190test_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 master:for-upstream &&
220 git request-pull initial "$downstream_url" >../request
221 ) &&
222 <request sed -nf fuzz.sed >request.fuzzy &&
223 test_cmp expect request.fuzzy
224
225'
226
227test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
228
229 (
230 cd local &&
231 OPTIONS_KEEPDASHDASH=Yes &&
232 export OPTIONS_KEEPDASHDASH &&
233 git checkout initial &&
234 git merge --ff-only master &&
235 git push origin master:for-upstream &&
236 git request-pull -- initial "$downstream_url" >../request
237 )
238
239'
240
241test_done