diff options
author | Jason Chang <jasonnc@google.com> | 2023-08-08 14:12:53 -0700 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-08-10 23:46:31 +0000 |
commit | 1a3612fe6d347e458a53d7a9e920a91ea502e6ba (patch) | |
tree | 02b1a61f1d97e32201ea5fa309bf1f1b6050e929 /subcmds/download.py | |
parent | f0aeb220def22edfac9838288ad251f86da782c1 (diff) | |
download | git-repo-1a3612fe6d347e458a53d7a9e920a91ea502e6ba.tar.gz |
Raise RepoExitError in place of sys.exit
Bug: b/293344017
Change-Id: Icae4932b00e4068cba502a5ab4a0274fd7854d9d
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/382214
Reviewed-by: Gavin Mak <gavinmak@google.com>
Tested-by: Jason Chang <jasonnc@google.com>
Reviewed-by: Aravind Vasudevan <aravindvasudev@google.com>
Commit-Queue: Jason Chang <jasonnc@google.com>
Diffstat (limited to 'subcmds/download.py')
-rw-r--r-- | subcmds/download.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/subcmds/download.py b/subcmds/download.py index 475c0bc2..18e555be 100644 --- a/subcmds/download.py +++ b/subcmds/download.py | |||
@@ -16,11 +16,15 @@ import re | |||
16 | import sys | 16 | import sys |
17 | 17 | ||
18 | from command import Command | 18 | from command import Command |
19 | from error import GitError, NoSuchProjectError | 19 | from error import GitError, NoSuchProjectError, RepoExitError |
20 | 20 | ||
21 | CHANGE_RE = re.compile(r"^([1-9][0-9]*)(?:[/\.-]([1-9][0-9]*))?$") | 21 | CHANGE_RE = re.compile(r"^([1-9][0-9]*)(?:[/\.-]([1-9][0-9]*))?$") |
22 | 22 | ||
23 | 23 | ||
24 | class DownloadCommandError(RepoExitError): | ||
25 | """Error raised when download command fails.""" | ||
26 | |||
27 | |||
24 | class Download(Command): | 28 | class Download(Command): |
25 | COMMON = True | 29 | COMMON = True |
26 | helpSummary = "Download and checkout a change" | 30 | helpSummary = "Download and checkout a change" |
@@ -137,15 +141,16 @@ If no project is specified try to use current directory as a project. | |||
137 | ) | 141 | ) |
138 | 142 | ||
139 | def Execute(self, opt, args): | 143 | def Execute(self, opt, args): |
144 | try: | ||
145 | self._ExecuteHelper(opt, args) | ||
146 | except Exception as e: | ||
147 | if isinstance(e, RepoExitError): | ||
148 | raise e | ||
149 | raise DownloadCommandError(aggregate_errors=[e]) | ||
150 | |||
151 | def _ExecuteHelper(self, opt, args): | ||
140 | for project, change_id, ps_id in self._ParseChangeIds(opt, args): | 152 | for project, change_id, ps_id in self._ParseChangeIds(opt, args): |
141 | dl = project.DownloadPatchSet(change_id, ps_id) | 153 | dl = project.DownloadPatchSet(change_id, ps_id) |
142 | if not dl: | ||
143 | print( | ||
144 | "[%s] change %d/%d not found" | ||
145 | % (project.name, change_id, ps_id), | ||
146 | file=sys.stderr, | ||
147 | ) | ||
148 | sys.exit(1) | ||
149 | 154 | ||
150 | if not opt.revert and not dl.commits: | 155 | if not opt.revert and not dl.commits: |
151 | print( | 156 | print( |
@@ -201,4 +206,4 @@ If no project is specified try to use current directory as a project. | |||
201 | % (project.name, mode, dl.commit), | 206 | % (project.name, mode, dl.commit), |
202 | file=sys.stderr, | 207 | file=sys.stderr, |
203 | ) | 208 | ) |
204 | sys.exit(1) | 209 | raise |