Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Raise exception when push fails
Closes #621
  • Loading branch information
Sjord committed Oct 1, 2021
commit 6a0a5c7887c44b3e5d00f9a0bec3e32aa24ff8a0
10 changes: 1 addition & 9 deletions git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,15 +794,7 @@ def stdout_handler(line: str) -> None:
handle_process_output(proc, stdout_handler, progress_handler, finalizer=None, decode_streams=False,
kill_after_timeout=kill_after_timeout)
stderr_text = progress.error_lines and '\n'.join(progress.error_lines) or ''
try:
proc.wait(stderr=stderr_text)
except Exception:
# This is different than fetch (which fails if there is any std_err
# even if there is an output)
if not output:
raise
elif stderr_text:
log.warning("Error lines received while fetching: %s", stderr_text)
proc.wait(stderr=stderr_text)

return output

Expand Down
21 changes: 7 additions & 14 deletions test/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,8 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):

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

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

# update push new tags
# Rejection is default
new_tag = TagReference.create(rw_repo, to_be_updated, reference='HEAD~1', force=True)
res = remote.push(tags=True)
self._do_test_push_result(res, remote)
self.assertTrue(res[-1].flags & PushInfo.REJECTED)
self.assertTrue(res[-1].flags & PushInfo.ERROR)
new_tag = TagReference.create(rw_repo, to_be_updated, ref='HEAD~1', force=True)
with self.assertRaises(GitCommandError):
remote.push(tags=True)

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

# rejected stale delete
force_with_lease = "%s:0000000000000000000000000000000000000000" % new_head.path
res = remote.push(":%s" % new_head.path, force_with_lease=force_with_lease)
self.assertTrue(res[0].flags & PushInfo.ERROR)
self.assertTrue(res[0].flags & PushInfo.REJECTED)
self.assertIsNone(res[0].local_ref)
self._do_test_push_result(res, remote)
with self.assertRaises(GitCommandError):
remote.push(":%s" % new_head.path, force_with_lease=force_with_lease)

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