Quellcode durchsuchen

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>
Shawn O. Pearce vor 17 Jahren
Ursprung
Commit
a608fb024b
1 geänderte Dateien mit 44 neuen und 12 gelöschten Zeilen
  1. 44 12
      subcmds/upload.py

+ 44 - 12
subcmds/upload.py

@@ -61,6 +61,28 @@ existing change(s) in Gerrit match up to the commits in the branch
 being uploaded.  For each matched pair of change,commit the commit
 being uploaded.  For each matched pair of change,commit the commit
 will be added as a new patch set, completely replacing the set of
 will be added as a new patch set, completely replacing the set of
 files and description associated with the change in Gerrit.
 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):
   def _Options(self, p):
@@ -79,19 +101,29 @@ files and description associated with the change in Gerrit.
     name = branch.name
     name = branch.name
     date = branch.date
     date = branch.date
     list = branch.commits
     list = branch.commits
+    remote = project.GetBranch(name).remote
+
+    key = 'review.%s.autoupload' % remote.review
+    answer = project.config.GetBoolean(key)
+
+    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')
 
 
-    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()
-    if answer in ('y', 'Y', 'yes', '1', 'true', 't'):
+    if answer:
       self._UploadAndReport([branch], people)
       self._UploadAndReport([branch], people)
     else:
     else:
       _die("upload aborted by user")
       _die("upload aborted by user")