Allow review.URL.autoupload to skip prompting during `repo upload`
If review.URL.autoupload is set to true in a project's .git/config
or in ~/.gitconfig then `repo upload` will automatically upload,
and skip prompting the end-user.
Conversely, if review.URL.autoupload is set to false, then repo
will refuse to upload to that project.
Bug: REPO-25
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/subcmds/upload.py b/subcmds/upload.py
index 3e66405..6a98a8b 100644
--- a/subcmds/upload.py
+++ b/subcmds/upload.py
@@ -61,6 +61,28 @@
being uploaded. For each matched pair of change,commit the commit
will be added as a new patch set, completely replacing the set of
files and description associated with the change in Gerrit.
+
+Configuration
+-------------
+
+review.URL.autoupload:
+
+To disable the "Upload ... (y/n)?" prompt, you can set a per-project
+or global Git configuration option. If review.URL.autoupload is set
+to "true" then repo will assume you always answer "y" at the prompt,
+and will not prompt you further. If it is set to "false" then repo
+will assume you always answer "n", and will abort.
+
+The URL must match the review URL listed in the manifest XML file,
+or in the .git/config within the project. For example:
+
+ [remote "origin"]
+ url = git://git.example.com/project.git
+ review = http://review.example.com/
+
+ [review "http://review.example.com/"]
+ autoupload = true
+
"""
def _Options(self, p):
@@ -79,19 +101,29 @@
name = branch.name
date = branch.date
list = branch.commits
+ remote = project.GetBranch(name).remote
- print 'Upload project %s/:' % project.relpath
- print ' branch %s (%2d commit%s, %s):' % (
- name,
- len(list),
- len(list) != 1 and 's' or '',
- date)
- for commit in list:
- print ' %s' % commit
+ key = 'review.%s.autoupload' % remote.review
+ answer = project.config.GetBoolean(key)
- sys.stdout.write('(y/n)? ')
- answer = sys.stdin.readline().strip()
- if answer in ('y', 'Y', 'yes', '1', 'true', 't'):
+ if answer is False:
+ _die("upload blocked by %s = false" % key)
+
+ if answer is None:
+ print 'Upload project %s/:' % project.relpath
+ print ' branch %s (%2d commit%s, %s):' % (
+ name,
+ len(list),
+ len(list) != 1 and 's' or '',
+ date)
+ for commit in list:
+ print ' %s' % commit
+
+ sys.stdout.write('(y/n)? ')
+ answer = sys.stdin.readline().strip()
+ answer = answer in ('y', 'Y', 'yes', '1', 'true', 't')
+
+ if answer:
self._UploadAndReport([branch], people)
else:
_die("upload aborted by user")