Parcourir la source

upload: Confirm unusually large number of uploaded commit

Add a sentinel check to require a second explicit confirmation if the
user is attempting to upload (or upload --replace) an unusually large
number of commits.  This may help the user to catch an accidentally
incorrect rebase they had done previously.

Change-Id: I12c4d102f90a631d6ad193486a70ffd520ef6ae0
Dan Morrill il y a 15 ans
Parent
commit
879a9a5cf0
1 fichiers modifiés avec 29 ajouts et 0 suppressions
  1. 29 0
      subcmds/upload.py

+ 29 - 0
subcmds/upload.py

@@ -20,6 +20,17 @@ from command import InteractiveCommand
 from editor import Editor
 from editor import Editor
 from error import UploadError
 from error import UploadError
 
 
+UNUSUAL_COMMIT_THRESHOLD = 3
+
+def _ConfirmManyUploads(multiple_branches=False):
+  if multiple_branches:
+    print "ATTENTION: One or more branches has an unusually high number of commits."
+  else:
+    print "ATTENTION: You are uploading an unusually high number of commits."
+  print "YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across branches?)"
+  answer = raw_input("If you are sure you intend to do this, type 'yes': ").strip()
+  return answer == "yes"
+
 def _die(fmt, *args):
 def _die(fmt, *args):
   msg = fmt % args
   msg = fmt % args
   print >>sys.stderr, 'error: %s' % msg
   print >>sys.stderr, 'error: %s' % msg
@@ -128,6 +139,10 @@ Gerrit Code Review:  http://code.google.com/p/gerrit/
       answer = sys.stdin.readline().strip()
       answer = sys.stdin.readline().strip()
       answer = answer in ('y', 'Y', 'yes', '1', 'true', 't')
       answer = answer in ('y', 'Y', 'yes', '1', 'true', 't')
 
 
+    if answer:
+      if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD:
+        answer = _ConfirmManyUploads()
+
     if answer:
     if answer:
       self._UploadAndReport([branch], people)
       self._UploadAndReport([branch], people)
     else:
     else:
@@ -192,6 +207,16 @@ Gerrit Code Review:  http://code.google.com/p/gerrit/
         todo.append(branch)
         todo.append(branch)
     if not todo:
     if not todo:
       _die("nothing uncommented for upload")
       _die("nothing uncommented for upload")
+
+    many_commits = False
+    for branch in todo:
+      if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD:
+        many_commits = True
+        break
+    if many_commits:
+      if not _ConfirmManyUploads(multiple_branches=True):
+        _die("upload aborted by user")
+
     self._UploadAndReport(todo, people)
     self._UploadAndReport(todo, people)
 
 
   def _FindGerritChange(self, branch):
   def _FindGerritChange(self, branch):
@@ -258,6 +283,10 @@ Gerrit Code Review:  http://code.google.com/p/gerrit/
       print >>sys.stderr, "       use 'repo upload' without --replace"
       print >>sys.stderr, "       use 'repo upload' without --replace"
       sys.exit(1)
       sys.exit(1)
 
 
+    if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD:
+      if not _ConfirmManyUploads(multiple_branches=True):
+        _die("upload aborted by user")
+
     branch.replace_changes = to_replace
     branch.replace_changes = to_replace
     self._UploadAndReport([branch], people)
     self._UploadAndReport([branch], people)