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 <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
diff --git a/subcmds/upload.py b/subcmds/upload.py
index 6ef4955..856c7fb 100644
--- a/subcmds/upload.py
+++ b/subcmds/upload.py
@@ -184,6 +184,9 @@
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 @@
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 @@
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