diff options
author | Mike Frysinger <vapier@google.com> | 2020-02-11 05:17:16 -0500 |
---|---|---|
committer | David Pursehouse <dpursehouse@collab.net> | 2020-02-12 04:18:49 +0000 |
commit | 21c1575ee429ff6be737e03e6517f03b8428d92e (patch) | |
tree | 45980b39d7e653b4ca5456c72df1d63573e2ce7c /subcmds/upload.py | |
parent | 8f9e02231a175b1d1e77476df98c3a1625b46d9f (diff) | |
download | git-repo-21c1575ee429ff6be737e03e6517f03b8428d92e.tar.gz |
upload: add a --ignore-hooks option
When upload hooks fail, people are forced to use --no-verify to upload
CLs anyways. When projects have flaky hooks, this trains people to
always use that option. This is obviously bad: hooks might get fixed,
or some of the hooks are always good & people should review.
Lets add an --ignore-hooks option. This still runs the hooks, but any
failures will be ignored and allow the user to upload anyways.
Bug: https://crbug.com/gerrit/12230
Change-Id: Ide2ac8a40a656bfcd6aae20c3ce8118e06bf909b
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/254452
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Diffstat (limited to 'subcmds/upload.py')
-rw-r--r-- | subcmds/upload.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/subcmds/upload.py b/subcmds/upload.py index 5c12aaee..f4633310 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
@@ -168,6 +168,9 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
168 | type='string', action='store', dest='dest_branch', | 168 | type='string', action='store', dest='dest_branch', |
169 | metavar='BRANCH', | 169 | metavar='BRANCH', |
170 | help='Submit for review on this target branch.') | 170 | help='Submit for review on this target branch.') |
171 | p.add_option('--no-cert-checks', | ||
172 | dest='validate_certs', action='store_false', default=True, | ||
173 | help='Disable verifying ssl certs (unsafe).') | ||
171 | 174 | ||
172 | # Options relating to upload hook. Note that verify and no-verify are NOT | 175 | # Options relating to upload hook. Note that verify and no-verify are NOT |
173 | # opposites of each other, which is why they store to different locations. | 176 | # opposites of each other, which is why they store to different locations. |
@@ -185,15 +188,16 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
185 | # Never run upload hooks, but upload anyway (AKA bypass hooks). | 188 | # Never run upload hooks, but upload anyway (AKA bypass hooks). |
186 | # - no-verify=True, verify=True: | 189 | # - no-verify=True, verify=True: |
187 | # Invalid | 190 | # Invalid |
188 | p.add_option('--no-cert-checks', | 191 | g = p.add_option_group('Upload hooks') |
189 | dest='validate_certs', action='store_false', default=True, | 192 | g.add_option('--no-verify', |
190 | help='Disable verifying ssl certs (unsafe).') | ||
191 | p.add_option('--no-verify', | ||
192 | dest='bypass_hooks', action='store_true', | 193 | dest='bypass_hooks', action='store_true', |
193 | help='Do not run the upload hook.') | 194 | help='Do not run the upload hook.') |
194 | p.add_option('--verify', | 195 | g.add_option('--verify', |
195 | dest='allow_all_hooks', action='store_true', | 196 | dest='allow_all_hooks', action='store_true', |
196 | help='Run the upload hook without prompting.') | 197 | help='Run the upload hook without prompting.') |
198 | g.add_option('--ignore-hooks', | ||
199 | dest='ignore_hooks', action='store_true', | ||
200 | help='Do not abort uploading if upload hooks fail.') | ||
197 | 201 | ||
198 | def _SingleBranch(self, opt, branch, people): | 202 | def _SingleBranch(self, opt, branch, people): |
199 | project = branch.project | 203 | project = branch.project |
@@ -488,12 +492,24 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
488 | abort_if_user_denies=True) | 492 | abort_if_user_denies=True) |
489 | pending_proj_names = [project.name for (project, available) in pending] | 493 | pending_proj_names = [project.name for (project, available) in pending] |
490 | pending_worktrees = [project.worktree for (project, available) in pending] | 494 | pending_worktrees = [project.worktree for (project, available) in pending] |
495 | passed = True | ||
491 | try: | 496 | try: |
492 | hook.Run(opt.allow_all_hooks, project_list=pending_proj_names, | 497 | hook.Run(opt.allow_all_hooks, project_list=pending_proj_names, |
493 | worktree_list=pending_worktrees) | 498 | worktree_list=pending_worktrees) |
499 | except SystemExit: | ||
500 | passed = False | ||
501 | if not opt.ignore_hooks: | ||
502 | raise | ||
494 | except HookError as e: | 503 | except HookError as e: |
504 | passed = False | ||
495 | print("ERROR: %s" % str(e), file=sys.stderr) | 505 | print("ERROR: %s" % str(e), file=sys.stderr) |
496 | return | 506 | |
507 | if not passed: | ||
508 | if opt.ignore_hooks: | ||
509 | print('\nWARNING: pre-upload hooks failed, but uploading anyways.', | ||
510 | file=sys.stderr) | ||
511 | else: | ||
512 | return | ||
497 | 513 | ||
498 | if opt.reviewers: | 514 | if opt.reviewers: |
499 | reviewers = _SplitEmails(opt.reviewers) | 515 | reviewers = _SplitEmails(opt.reviewers) |