From 02aa889ecd54d69fd6c3708d2e7f8654d57ac1e8 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 19 Feb 2020 02:32:52 -0500 Subject: [PATCH] upload: add support for --yes This adds a CLI option to the existing autoupload gitconfig knob that allows people to automatically answer "yes" to the various prompts. Bug: https://crbug.com/gerrit/12368 Change-Id: I819ebca01b9a40240b33866ae05907c7469703e3 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/255892 Reviewed-by: David Pursehouse Tested-by: Mike Frysinger --- subcmds/upload.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/subcmds/upload.py b/subcmds/upload.py index 6ef4955e..856c7fb9 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py @@ -184,6 +184,9 @@ Gerrit Code Review: https://www.gerritcodereview.com/ p.add_option('-n', '--dry-run', dest='dryrun', default=False, action='store_true', help='Do everything except actually upload the CL.') + p.add_option('-y', '--yes', + default=False, action='store_true', + help='Answer yes to all safe prompts.') p.add_option('--no-cert-checks', dest='validate_certs', action='store_false', default=True, help='Disable verifying ssl certs (unsafe).') @@ -244,8 +247,12 @@ Gerrit Code Review: https://www.gerritcodereview.com/ print('to %s (y/N)? ' % remote.review, end='') # TODO: When we require Python 3, use flush=True w/print above. sys.stdout.flush() - answer = sys.stdin.readline().strip().lower() - answer = answer in ('y', 'yes', '1', 'true', 't') + if opt.yes: + print('<--yes>') + answer = True + else: + answer = sys.stdin.readline().strip().lower() + answer = answer in ('y', 'yes', '1', 'true', 't') if answer: if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD: @@ -384,7 +391,11 @@ Gerrit Code Review: https://www.gerritcodereview.com/ print('Continue uploading? (y/N) ', end='') # TODO: When we require Python 3, use flush=True w/print above. sys.stdout.flush() - a = sys.stdin.readline().strip().lower() + if opt.yes: + print('<--yes>') + a = 'yes' + else: + a = sys.stdin.readline().strip().lower() if a not in ('y', 'yes', 't', 'true', 'on'): print("skipping upload", file=sys.stderr) branch.uploaded = False