@matheusbsbs / matheus-bagliano / commits / 865e23f532
Fork 0

t5543: never report what we do not push

When we push some references to the git server, we expect git to report the status of the references we are pushing; no more, no less. But when pusing with atomic mode, if some references cannot be pushed, Git reports the reject message on all references in the remote repository. Add new test cases in t5543, and fix them in latter commit. Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jiang Xin committed Apr 17, 2020 at 05:45 UTC 865e23f532fc78d207cf81587deee9f861c7a5aa
1 file changed +89
t/t5543-atomic-push.sh
+89
@@ -27,6 +27,12 @@ test_refs () {
27 test_cmp expect actual
28 }
29
30 +fmt_status_report () {
31 + sed -n \
32 + -e "/^To / { s/ */ /g; p; }" \
33 + -e "/^ ! / { s/ */ /g; p; }"
34 +}
35 +
36 test_expect_success 'atomic push works for a single branch' '
37 mk_repo_pair &&
38 (
@@ -191,4 +197,87 @@ test_expect_success 'atomic push is not advertised if configured' '
197 test_refs master HEAD@{1}
198 '
199
200 +# References in upstream : master(1) one(1) foo(1)
201 +# References in workbench: master(2) foo(1) two(2) bar(2)
202 +# Atomic push : master(2) two(2) bar(2)
203 +test_expect_failure 'atomic push reports (reject by update hook)' '
204 + mk_repo_pair &&
205 + (
206 + cd workbench &&
207 + test_commit one &&
208 + git branch foo &&
209 + git push up master one foo &&
210 + git tag -d one
211 + ) &&
212 + (
213 + mkdir -p upstream/.git/hooks &&
214 + cat >upstream/.git/hooks/update <<-EOF &&
215 + #!/bin/sh
216 +
217 + if test "\$1" = "refs/heads/bar"
218 + then
219 + echo >&2 "Pusing to branch bar is prohibited"
220 + exit 1
221 + fi
222 + EOF
223 + chmod a+x upstream/.git/hooks/update
224 + ) &&
225 + (
226 + cd workbench &&
227 + test_commit two &&
228 + git branch bar
229 + ) &&
230 + test_must_fail git -C workbench \
231 + push --atomic up master two bar >out 2>&1 &&
232 + fmt_status_report <out >actual &&
233 + cat >expect <<-EOF &&
234 + To ../upstream
235 + ! [remote rejected] master -> master (atomic push failure)
236 + ! [remote rejected] two -> two (atomic push failure)
237 + ! [remote rejected] bar -> bar (hook declined)
238 + EOF
239 + test_cmp expect actual
240 +'
241 +
242 +# References in upstream : master(1) one(1) foo(1)
243 +# References in workbench: master(2) foo(1) two(2) bar(2)
244 +test_expect_failure 'atomic push reports (mirror, but reject by update hook)' '
245 + (
246 + cd workbench &&
247 + git remote remove up &&
248 + git remote add up ../upstream
249 + ) &&
250 + test_must_fail git -C workbench \
251 + push --atomic --mirror up >out 2>&1 &&
252 + fmt_status_report <out >actual &&
253 + cat >expect <<-EOF &&
254 + To ../upstream
255 + ! [remote rejected] master -> master (atomic push failure)
256 + ! [remote rejected] one (atomic push failure)
257 + ! [remote rejected] bar -> bar (hook declined)
258 + ! [remote rejected] two -> two (atomic push failure)
259 + EOF
260 + test_cmp expect actual
261 +'
262 +
263 +# References in upstream : master(2) one(1) foo(1)
264 +# References in workbench: master(1) foo(1) two(2) bar(2)
265 +test_expect_failure 'atomic push reports (reject by non-ff)' '
266 + rm upstream/.git/hooks/update &&
267 + (
268 + cd workbench &&
269 + git push up master &&
270 + git reset --hard HEAD^
271 + ) &&
272 + test_must_fail git -C workbench \
273 + push --atomic up master foo bar >out 2>&1 &&
274 + fmt_status_report <out >actual &&
275 + cat >expect <<-EOF &&
276 + To ../upstream
277 + ! [rejected] master -> master (non-fast-forward)
278 + ! [rejected] bar -> bar (atomic push failed)
279 + EOF
280 + test_cmp expect actual
281 +'
282 +
283 test_done