]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5150-request-pull.sh
tests for request-pull
[thirdparty/git.git] / t / t5150-request-pull.sh
CommitLineData
30c56eaa
JN
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 / in the git repository at:$/! d
71 n
72 /^$/! q
73 n
74 s/^[ ]*\(.*\) \([^ ]*\)/please pull\
75 \1\
76 \2/p
77 q
78 EOT
79
80 cat <<-EOT >fuzz.sed
81 #!/bin/sed -nf
82 s/$_x40/OBJECT_NAME/g
83 s/A U Thor/AUTHOR/g
84 s/ [^ ].*/ SUBJECT/g
85 s/$downstream_url_for_sed/URL/g
86 s/for-upstream/BRANCH/g
87 s/mnemonic.txt/FILENAME/g
88 /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat
89 /^AUTHOR ([0-9]*):\$/ b shortlog
90 p
91 b
92 : diffstat
93 n
94 / [0-9]* files changed/ {
95 a\
96 DIFFSTAT
97 b
98 }
99 b diffstat
100 : shortlog
101 /^ [a-zA-Z]/ n
102 /^[a-zA-Z]* ([0-9]*):\$/ n
103 /^\$/ N
104 /^\n[a-zA-Z]* ([0-9]*):\$/! {
105 a\
106 SHORTLOG
107 D
108 }
109 n
110 b shortlog
111 EOT
112
113'
114
115test_expect_success 'pull request when forgot to push' '
116
117 rm -fr downstream.git &&
118 git init --bare downstream.git &&
119 (
120 cd local &&
121 git checkout initial &&
122 git merge --ff-only master &&
123 test_must_fail git request-pull initial "$downstream_url" \
124 2>../err
125 ) &&
126 grep "No branch of.*is at:\$" err &&
127 grep "Are you sure you pushed" err
128
129'
130
131test_expect_success 'pull request after push' '
132
133 rm -fr downstream.git &&
134 git init --bare downstream.git &&
135 (
136 cd local &&
137 git checkout initial &&
138 git merge --ff-only master &&
139 git push origin master:for-upstream &&
140 git request-pull initial origin >../request
141 ) &&
142 sed -nf read-request.sed <request >digest &&
143 cat digest &&
144 {
145 read task &&
146 read repository &&
147 read branch
148 } <digest &&
149 (
150 cd upstream-private &&
151 git checkout initial &&
152 git pull --ff-only "$repository" "$branch"
153 ) &&
154 test "$branch" = for-upstream &&
155 test_cmp local/mnemonic.txt upstream-private/mnemonic.txt
156
157'
158
159test_expect_success 'request names an appropriate branch' '
160
161 rm -fr downstream.git &&
162 git init --bare downstream.git &&
163 (
164 cd local &&
165 git checkout initial &&
166 git merge --ff-only master &&
167 git push --tags origin master simplify &&
168 git push origin master:for-upstream &&
169 git request-pull initial "$downstream_url" >../request
170 ) &&
171 sed -nf read-request.sed <request >digest &&
172 cat digest &&
173 {
174 read task &&
175 read repository &&
176 read branch
177 } <digest &&
178 {
179 test "$branch" = master ||
180 test "$branch" = for-upstream
181 }
182
183'
184
185test_expect_success 'pull request format' '
186
187 rm -fr downstream.git &&
188 git init --bare downstream.git &&
189 cat <<-\EOT >expect &&
190 The following changes since commit OBJECT_NAME:
191 AUTHOR (1):
192 SUBJECT
193
194 are available in the git repository at:
195
196 URL BRANCH
197
198 SHORTLOG
199
200 DIFFSTAT
201 EOT
202 (
203 cd local &&
204 git checkout initial &&
205 git merge --ff-only master &&
206 git push origin master:for-upstream &&
207 git request-pull initial "$downstream_url" >../request
208 ) &&
209 <request sed -nf fuzz.sed >request.fuzzy &&
210 test_cmp expect request.fuzzy
211
212'
213
214test_done