criss cross rename failure workaround
[git/dscho.git] / t / t5150-request-pull.sh
blob9cc0a42ea977e184be7af02e05352da8155c4728
1 #!/bin/sh
3 test_description='Test workflows involving pull request.'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
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 &&
14 trash_url="file://$TRASH_DIRECTORY" &&
15 downstream_url="$trash_url/downstream.git/" &&
16 upstream_url="$trash_url/upstream.git/" &&
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 ) &&
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
55 But keep the old version, too, in case some people prefer it." &&
56 git checkout master
61 test_expect_success 'setup: two scripts for reading pull requests' '
63 downstream_url_for_sed=$(
64 printf "%s\n" "$downstream_url" |
65 sed -e '\''s/\\/\\\\/g'\'' -e '\''s/[[/.*^$]/\\&/g'\''
66 ) &&
68 cat <<-\EOT >read-request.sed &&
69 #!/bin/sed -nf
70 / in the git repository at:$/!d
72 /^$/ n
73 s/^[ ]*\(.*\) \([^ ]*\)/please pull\
74 \1\
75 \2/p
77 EOT
79 cat <<-EOT >fuzz.sed
80 #!/bin/sed -nf
81 s/$_x40/OBJECT_NAME/g
82 s/A U Thor/AUTHOR/g
83 s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
84 s/ [^ ].*/ SUBJECT/g
85 s/ [^ ].* (DATE)/ SUBJECT (DATE)/g
86 s/$downstream_url_for_sed/URL/g
87 s/for-upstream/BRANCH/g
88 s/mnemonic.txt/FILENAME/g
89 /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat
90 /^AUTHOR ([0-9]*):\$/ b shortlog
93 : diffstat
95 / [0-9]* files changed/ {
96 a\\
97 DIFFSTAT
100 b diffstat
101 : shortlog
102 /^ [a-zA-Z]/ n
103 /^[a-zA-Z]* ([0-9]*):\$/ n
104 /^\$/ N
105 /^\n[a-zA-Z]* ([0-9]*):\$/!{
107 SHORTLOG
111 b shortlog
116 test_expect_success 'pull request when forgot to push' '
118 rm -fr downstream.git &&
119 git init --bare downstream.git &&
121 cd local &&
122 git checkout initial &&
123 git merge --ff-only master &&
124 test_must_fail git request-pull initial "$downstream_url" \
125 2>../err
126 ) &&
127 grep "No branch of.*is at:\$" err &&
128 grep "Are you sure you pushed" err
132 test_expect_success 'pull request after push' '
134 rm -fr downstream.git &&
135 git init --bare downstream.git &&
137 cd local &&
138 git checkout initial &&
139 git merge --ff-only master &&
140 git push origin master:for-upstream &&
141 git request-pull initial origin >../request
142 ) &&
143 sed -nf read-request.sed <request >digest &&
144 cat digest &&
146 read task &&
147 read repository &&
148 read branch
149 } <digest &&
151 cd upstream-private &&
152 git checkout initial &&
153 git pull --ff-only "$repository" "$branch"
154 ) &&
155 test "$branch" = for-upstream &&
156 test_cmp local/mnemonic.txt upstream-private/mnemonic.txt
160 test_expect_success 'request names an appropriate branch' '
162 rm -fr downstream.git &&
163 git init --bare downstream.git &&
165 cd local &&
166 git checkout initial &&
167 git merge --ff-only master &&
168 git push --tags origin master simplify &&
169 git push origin master:for-upstream &&
170 git request-pull initial "$downstream_url" >../request
171 ) &&
172 sed -nf read-request.sed <request >digest &&
173 cat digest &&
175 read task &&
176 read repository &&
177 read branch
178 } <digest &&
180 test "$branch" = master ||
181 test "$branch" = for-upstream
186 test_expect_success 'pull request format' '
188 rm -fr downstream.git &&
189 git init --bare downstream.git &&
190 cat <<-\EOT >expect &&
191 The following changes since commit OBJECT_NAME:
193 SUBJECT (DATE)
195 are available in the git repository at:
196 URL BRANCH
198 SHORTLOG
200 DIFFSTAT
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
214 test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' '
217 cd local &&
218 OPTIONS_KEEPDASHDASH=Yes &&
219 export OPTIONS_KEEPDASHDASH &&
220 git checkout initial &&
221 git merge --ff-only master &&
222 git push origin master:for-upstream &&
223 git request-pull -- initial "$downstream_url" >../request
228 test_done