From 6a0a5c7887c44b3e5d00f9a0bec3e32aa24ff8a0 Mon Sep 17 00:00:00 2001 From: Sjoerd Langkemper Date: Fri, 1 Oct 2021 15:20:53 +0200 Subject: [PATCH 1/2] Raise exception when push fails Closes #621 --- git/remote.py | 10 +--------- test/test_remote.py | 21 +++++++-------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/git/remote.py b/git/remote.py index 2cf5678b6..d459d12ce 100644 --- a/git/remote.py +++ b/git/remote.py @@ -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 diff --git a/test/test_remote.py b/test/test_remote.py index 088fdad55..245be68fd 100644 --- a/test/test_remote.py +++ b/test/test_remote.py @@ -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) @@ -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) @@ -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) From 6230cff838602979b70182bb58fe1d39464bee45 Mon Sep 17 00:00:00 2001 From: Sjoerd Langkemper Date: Fri, 1 Oct 2021 15:50:55 +0200 Subject: [PATCH 2/2] Pass reference correctly when creating tag --- test/test_remote.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_remote.py b/test/test_remote.py index 245be68fd..ad82d8fba 100644 --- a/test/test_remote.py +++ b/test/test_remote.py @@ -354,7 +354,7 @@ 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, ref='HEAD~1', force=True) + new_tag = TagReference.create(rw_repo, to_be_updated, reference='HEAD~1', force=True) with self.assertRaises(GitCommandError): remote.push(tags=True)