Skip to content

Commit e1110c1

Browse files
committed
Raise exception when push fails
Closes gitpython-developers#621
1 parent ea43def commit e1110c1

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

Diff for: git/remote.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -739,13 +739,7 @@ def stdout_handler(line):
739739

740740
handle_process_output(proc, stdout_handler, progress_handler, finalizer=None, decode_streams=False)
741741
stderr_text = progress.error_lines and '\n'.join(progress.error_lines) or ''
742-
try:
743-
proc.wait(stderr=stderr_text)
744-
except Exception:
745-
if not output:
746-
raise
747-
elif stderr_text:
748-
log.warning("Error lines received while fetching: %s", stderr_text)
742+
proc.wait(stderr=stderr_text)
749743

750744
return output
751745

Diff for: test/test_remote.py

+6-13
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,8 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):
329329

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

337335
# force rejected pull
338336
res = remote.push('+%s' % lhead.reference)
@@ -356,10 +354,8 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):
356354
# update push new tags
357355
# Rejection is default
358356
new_tag = TagReference.create(rw_repo, to_be_updated, ref='HEAD~1', force=True)
359-
res = remote.push(tags=True)
360-
self._do_test_push_result(res, remote)
361-
self.assertTrue(res[-1].flags & PushInfo.REJECTED)
362-
self.assertTrue(res[-1].flags & PushInfo.ERROR)
357+
with self.assertRaises(GitCommandError):
358+
res = remote.push(tags=True)
363359

364360
# push force this tag
365361
res = remote.push("+%s" % new_tag.path)
@@ -385,11 +381,8 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):
385381

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

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

0 commit comments

Comments
 (0)