1
0
Fork 0

Raise repo exit errors in place of sys.exit

Bug: b/293344017
Change-Id: I92d81c78eba8ff31b5252415f4c9a515a6c76411
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/381774
Tested-by: Jason Chang <jasonnc@google.com>
Reviewed-by: Joanna Wang <jojwang@google.com>
Commit-Queue: Jason Chang <jasonnc@google.com>
This commit is contained in:
Jason Chang 2023-08-03 14:38:00 -07:00 committed by LUCI
parent b8a7b4a629
commit f9aacd4087
9 changed files with 80 additions and 34 deletions

View file

@ -21,7 +21,7 @@ from typing import List
from command import DEFAULT_LOCAL_JOBS, InteractiveCommand
from editor import Editor
from error import UploadError
from error import UploadError, RepoExitError
from git_command import GitCommand
from git_refs import R_HEADS
from hooks import RepoHook
@ -31,6 +31,10 @@ from project import ReviewableBranch
_DEFAULT_UNUSUAL_COMMIT_THRESHOLD = 5
class UploadExitError(RepoExitError):
"""Indicates that there is an upload command error requiring a sys exit."""
def _VerifyPendingCommits(branches: List[ReviewableBranch]) -> bool:
"""Perform basic safety checks on the given set of branches.
@ -86,7 +90,7 @@ def _VerifyPendingCommits(branches: List[ReviewableBranch]) -> bool:
def _die(fmt, *args):
msg = fmt % args
print("error: %s" % msg, file=sys.stderr)
sys.exit(1)
raise UploadExitError(msg)
def _SplitEmails(values):
@ -697,7 +701,7 @@ Gerrit Code Review: https://www.gerritcodereview.com/
)
if have_errors:
sys.exit(1)
raise branch.error
def _GetMergeBranch(self, project, local_branch=None):
if local_branch is None: