Skip to content

Commit 6a0a5c7

Browse files
committed
Raise exception when push fails
Closes gitpython-developers#621
1 parent 5e73cab commit 6a0a5c7

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

Diff for: git/remote.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -794,15 +794,7 @@ def stdout_handler(line: str) -> None:
794794
handle_process_output(proc, stdout_handler, progress_handler, finalizer=None, decode_streams=False,
795795
kill_after_timeout=kill_after_timeout)
796796
stderr_text = progress.error_lines and '\n'.join(progress.error_lines) or ''
797-
try:
798-
proc.wait(stderr=stderr_text)
799-
except Exception:
800-
# This is different than fetch (which fails if there is any std_err
801-
# even if there is an output)
802-
if not output:
803-
raise
804-
elif stderr_text:
805-
log.warning("Error lines received while fetching: %s", stderr_text)
797+
proc.wait(stderr=stderr_text)
806798

807799
return output
808800

Diff for: test/test_remote.py

+7-14
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,8 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):
330330

331331
# rejected - undo last commit
332332
lhead.reset("HEAD~1")
333-
res = remote.push(lhead.reference)
334-
self.assertTrue(res[0].flags & PushInfo.ERROR)
335-
self.assertTrue(res[0].flags & PushInfo.REJECTED)
336-
self._do_test_push_result(res, remote)
333+
with self.assertRaises(GitCommandError):
334+
remote.push(lhead.reference)
337335

338336
# force rejected pull
339337
res = remote.push('+%s' % lhead.reference)
@@ -356,11 +354,9 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):
356354

357355
# update push new tags
358356
# Rejection is default
359-
new_tag = TagReference.create(rw_repo, to_be_updated, reference='HEAD~1', force=True)
360-
res = remote.push(tags=True)
361-
self._do_test_push_result(res, remote)
362-
self.assertTrue(res[-1].flags & PushInfo.REJECTED)
363-
self.assertTrue(res[-1].flags & PushInfo.ERROR)
357+
new_tag = TagReference.create(rw_repo, to_be_updated, ref='HEAD~1', force=True)
358+
with self.assertRaises(GitCommandError):
359+
remote.push(tags=True)
364360

365361
# push force this tag
366362
res = remote.push("+%s" % new_tag.path)
@@ -386,11 +382,8 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):
386382

387383
# rejected stale delete
388384
force_with_lease = "%s:0000000000000000000000000000000000000000" % new_head.path
389-
res = remote.push(":%s" % new_head.path, force_with_lease=force_with_lease)
390-
self.assertTrue(res[0].flags & PushInfo.ERROR)
391-
self.assertTrue(res[0].flags & PushInfo.REJECTED)
392-
self.assertIsNone(res[0].local_ref)
393-
self._do_test_push_result(res, remote)
385+
with self.assertRaises(GitCommandError):
386+
remote.push(":%s" % new_head.path, force_with_lease=force_with_lease)
394387

395388
# delete new branch on the remote end and locally
396389
res = remote.push(":%s" % new_head.path)

0 commit comments

Comments
 (0)