diff options
author | Jason Chang <jasonnc@google.com> | 2023-08-03 14:38:00 -0700 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-08-07 23:56:07 +0000 |
commit | f9aacd4087b02948da9a7878da48ea186ab99d5a (patch) | |
tree | b683190635cd6fcb7cf817837ad0c4259b53078f /subcmds/abandon.py | |
parent | b8a7b4a629c3435d77a3266a4e6dce51dc342bd9 (diff) | |
download | git-repo-f9aacd4087b02948da9a7878da48ea186ab99d5a.tar.gz |
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>
Diffstat (limited to 'subcmds/abandon.py')
-rw-r--r-- | subcmds/abandon.py | 24 |
1 files changed, 19 insertions, 5 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: |