diff options
Diffstat (limited to 'subcmds')
| -rw-r--r-- | subcmds/abandon.py | 24 | ||||
| -rw-r--r-- | subcmds/init.py | 12 | ||||
| -rw-r--r-- | subcmds/upload.py | 10 |
3 files changed, 35 insertions, 11 deletions
diff --git a/subcmds/abandon.py b/subcmds/abandon.py index ded287f6..896b348f 100644 --- a/subcmds/abandon.py +++ b/subcmds/abandon.py | |||
| @@ -20,6 +20,11 @@ import sys | |||
| 20 | from command import Command, DEFAULT_LOCAL_JOBS | 20 | from command import Command, DEFAULT_LOCAL_JOBS |
| 21 | from git_command import git | 21 | from git_command import git |
| 22 | from progress import Progress | 22 | from progress import Progress |
| 23 | from error import RepoError, RepoExitError | ||
| 24 | |||
| 25 | |||
| 26 | class AbandonError(RepoExitError): | ||
| 27 | """Exit error when abandon command fails.""" | ||
| 23 | 28 | ||
| 24 | 29 | ||
| 25 | class Abandon(Command): | 30 | class Abandon(Command): |
| @@ -68,28 +73,37 @@ It is equivalent to "git branch -D <branchname>". | |||
| 68 | branches = nb | 73 | branches = nb |
| 69 | 74 | ||
| 70 | ret = {} | 75 | ret = {} |
| 76 | errors = [] | ||
| 71 | for name in branches: | 77 | for name in branches: |
| 72 | status = project.AbandonBranch(name) | 78 | status = None |
| 79 | try: | ||
| 80 | status = project.AbandonBranch(name) | ||
| 81 | except RepoError as e: | ||
| 82 | status = False | ||
| 83 | errors.append(e) | ||
| 73 | if status is not None: | 84 | if status is not None: |
| 74 | ret[name] = status | 85 | ret[name] = status |
| 75 | return (ret, project) | 86 | |
| 87 | return (ret, project, errors) | ||
| 76 | 88 | ||
| 77 | def Execute(self, opt, args): | 89 | def Execute(self, opt, args): |
| 78 | nb = args[0].split() | 90 | nb = args[0].split() |
| 79 | err = defaultdict(list) | 91 | err = defaultdict(list) |
| 80 | success = defaultdict(list) | 92 | success = defaultdict(list) |
| 93 | aggregate_errors = [] | ||
| 81 | all_projects = self.GetProjects( | 94 | all_projects = self.GetProjects( |
| 82 | args[1:], all_manifests=not opt.this_manifest_only | 95 | args[1:], all_manifests=not opt.this_manifest_only |
| 83 | ) | 96 | ) |
| 84 | _RelPath = lambda p: p.RelPath(local=opt.this_manifest_only) | 97 | _RelPath = lambda p: p.RelPath(local=opt.this_manifest_only) |
| 85 | 98 | ||
| 86 | def _ProcessResults(_pool, pm, states): | 99 | def _ProcessResults(_pool, pm, states): |
| 87 | for results, project in states: | 100 | for results, project, errors in states: |
| 88 | for branch, status in results.items(): | 101 | for branch, status in results.items(): |
| 89 | if status: | 102 | if status: |
| 90 | success[branch].append(project) | 103 | success[branch].append(project) |
| 91 | else: | 104 | else: |
| 92 | err[branch].append(project) | 105 | err[branch].append(project) |
| 106 | aggregate_errors.extend(errors) | ||
| 93 | pm.update(msg="") | 107 | pm.update(msg="") |
| 94 | 108 | ||
| 95 | self.ExecuteInParallel( | 109 | self.ExecuteInParallel( |
| @@ -116,13 +130,13 @@ It is equivalent to "git branch -D <branchname>". | |||
| 116 | " " * len(err_msg) + " | %s" % _RelPath(proj), | 130 | " " * len(err_msg) + " | %s" % _RelPath(proj), |
| 117 | file=sys.stderr, | 131 | file=sys.stderr, |
| 118 | ) | 132 | ) |
| 119 | sys.exit(1) | 133 | raise AbandonError(aggregate_errors=aggregate_errors) |
| 120 | elif not success: | 134 | elif not success: |
| 121 | print( | 135 | print( |
| 122 | "error: no project has local branch(es) : %s" % nb, | 136 | "error: no project has local branch(es) : %s" % nb, |
| 123 | file=sys.stderr, | 137 | file=sys.stderr, |
| 124 | ) | 138 | ) |
| 125 | sys.exit(1) | 139 | raise AbandonError(aggregate_errors=aggregate_errors) |
| 126 | else: | 140 | else: |
| 127 | # Everything below here is displaying status. | 141 | # Everything below here is displaying status. |
| 128 | if opt.quiet: | 142 | if opt.quiet: |
diff --git a/subcmds/init.py b/subcmds/init.py index 6d7fd857..868d339e 100644 --- a/subcmds/init.py +++ b/subcmds/init.py | |||
| @@ -19,6 +19,8 @@ from color import Coloring | |||
| 19 | from command import InteractiveCommand, MirrorSafeCommand | 19 | from command import InteractiveCommand, MirrorSafeCommand |
| 20 | from git_command import git_require, MIN_GIT_VERSION_SOFT, MIN_GIT_VERSION_HARD | 20 | from git_command import git_require, MIN_GIT_VERSION_SOFT, MIN_GIT_VERSION_HARD |
| 21 | from wrapper import Wrapper | 21 | from wrapper import Wrapper |
| 22 | from error import UpdateManifestError | ||
| 23 | from error import RepoUnhandledExceptionError | ||
| 22 | 24 | ||
| 23 | _REPO_ALLOW_SHALLOW = os.environ.get("REPO_ALLOW_SHALLOW") | 25 | _REPO_ALLOW_SHALLOW = os.environ.get("REPO_ALLOW_SHALLOW") |
| 24 | 26 | ||
| @@ -156,7 +158,10 @@ to update the working directory files. | |||
| 156 | git_event_log=self.git_event_log, | 158 | git_event_log=self.git_event_log, |
| 157 | manifest_name=opt.manifest_name, | 159 | manifest_name=opt.manifest_name, |
| 158 | ): | 160 | ): |
| 159 | sys.exit(1) | 161 | manifest_name = opt.manifest_name |
| 162 | raise UpdateManifestError( | ||
| 163 | f"Unable to sync manifest {manifest_name}" | ||
| 164 | ) | ||
| 160 | 165 | ||
| 161 | def _Prompt(self, prompt, value): | 166 | def _Prompt(self, prompt, value): |
| 162 | print("%-10s [%s]: " % (prompt, value), end="", flush=True) | 167 | print("%-10s [%s]: " % (prompt, value), end="", flush=True) |
| @@ -346,14 +351,15 @@ to update the working directory files. | |||
| 346 | repo_verify=opt.repo_verify, | 351 | repo_verify=opt.repo_verify, |
| 347 | quiet=opt.quiet, | 352 | quiet=opt.quiet, |
| 348 | ) | 353 | ) |
| 349 | except wrapper.CloneFailure: | 354 | except wrapper.CloneFailure as e: |
| 350 | err_msg = "fatal: double check your --repo-rev setting." | 355 | err_msg = "fatal: double check your --repo-rev setting." |
| 351 | print( | 356 | print( |
| 352 | err_msg, | 357 | err_msg, |
| 353 | file=sys.stderr, | 358 | file=sys.stderr, |
| 354 | ) | 359 | ) |
| 355 | self.git_event_log.ErrorEvent(err_msg) | 360 | self.git_event_log.ErrorEvent(err_msg) |
| 356 | sys.exit(1) | 361 | raise RepoUnhandledExceptionError(e) |
| 362 | |||
| 357 | branch = rp.GetBranch("default") | 363 | branch = rp.GetBranch("default") |
| 358 | branch.merge = remote_ref | 364 | branch.merge = remote_ref |
| 359 | rp.work_git.reset("--hard", rev) | 365 | rp.work_git.reset("--hard", rev) |
diff --git a/subcmds/upload.py b/subcmds/upload.py index 8d949bef..d0c028b9 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
| @@ -21,7 +21,7 @@ from typing import List | |||
| 21 | 21 | ||
| 22 | from command import DEFAULT_LOCAL_JOBS, InteractiveCommand | 22 | from command import DEFAULT_LOCAL_JOBS, InteractiveCommand |
| 23 | from editor import Editor | 23 | from editor import Editor |
| 24 | from error import UploadError | 24 | from error import UploadError, RepoExitError |
| 25 | from git_command import GitCommand | 25 | from git_command import GitCommand |
| 26 | from git_refs import R_HEADS | 26 | from git_refs import R_HEADS |
| 27 | from hooks import RepoHook | 27 | from hooks import RepoHook |
| @@ -31,6 +31,10 @@ from project import ReviewableBranch | |||
| 31 | _DEFAULT_UNUSUAL_COMMIT_THRESHOLD = 5 | 31 | _DEFAULT_UNUSUAL_COMMIT_THRESHOLD = 5 |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | class UploadExitError(RepoExitError): | ||
| 35 | """Indicates that there is an upload command error requiring a sys exit.""" | ||
| 36 | |||
| 37 | |||
| 34 | def _VerifyPendingCommits(branches: List[ReviewableBranch]) -> bool: | 38 | def _VerifyPendingCommits(branches: List[ReviewableBranch]) -> bool: |
| 35 | """Perform basic safety checks on the given set of branches. | 39 | """Perform basic safety checks on the given set of branches. |
| 36 | 40 | ||
| @@ -86,7 +90,7 @@ def _VerifyPendingCommits(branches: List[ReviewableBranch]) -> bool: | |||
| 86 | def _die(fmt, *args): | 90 | def _die(fmt, *args): |
| 87 | msg = fmt % args | 91 | msg = fmt % args |
| 88 | print("error: %s" % msg, file=sys.stderr) | 92 | print("error: %s" % msg, file=sys.stderr) |
| 89 | sys.exit(1) | 93 | raise UploadExitError(msg) |
| 90 | 94 | ||
| 91 | 95 | ||
| 92 | def _SplitEmails(values): | 96 | def _SplitEmails(values): |
| @@ -697,7 +701,7 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
| 697 | ) | 701 | ) |
| 698 | 702 | ||
| 699 | if have_errors: | 703 | if have_errors: |
| 700 | sys.exit(1) | 704 | raise branch.error |
| 701 | 705 | ||
| 702 | def _GetMergeBranch(self, project, local_branch=None): | 706 | def _GetMergeBranch(self, project, local_branch=None): |
| 703 | if local_branch is None: | 707 | if local_branch is None: |
