summaryrefslogtreecommitdiffstats
path: root/subcmds/upload.py
diff options
context:
space:
mode:
authorDan Morrill <morrildl@google.com>2010-05-04 16:56:07 -0700
committerShawn O. Pearce <sop@google.com>2010-05-04 17:15:37 -0700
commit879a9a5cf0f4ed61df6544949068babbee4f60e2 (patch)
tree81d0a9a675e558f6255c50b6d378c5e4543247b8 /subcmds/upload.py
parentff6929dde8cae515f7221a60f21fff7c1297aade (diff)
downloadgit-repo-879a9a5cf0f4ed61df6544949068babbee4f60e2.tar.gz
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
Diffstat (limited to 'subcmds/upload.py')
-rw-r--r--subcmds/upload.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/subcmds/upload.py b/subcmds/upload.py
index aea399b6..4dc11d28 100644
--- a/subcmds/upload.py
+++ b/subcmds/upload.py
@@ -20,6 +20,17 @@ from command import InteractiveCommand
20from editor import Editor 20from editor import Editor
21from error import UploadError 21from error import UploadError
22 22
23UNUSUAL_COMMIT_THRESHOLD = 3
24
25def _ConfirmManyUploads(multiple_branches=False):
26 if multiple_branches:
27 print "ATTENTION: One or more branches has an unusually high number of commits."
28 else:
29 print "ATTENTION: You are uploading an unusually high number of commits."
30 print "YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across branches?)"
31 answer = raw_input("If you are sure you intend to do this, type 'yes': ").strip()
32 return answer == "yes"
33
23def _die(fmt, *args): 34def _die(fmt, *args):
24 msg = fmt % args 35 msg = fmt % args
25 print >>sys.stderr, 'error: %s' % msg 36 print >>sys.stderr, 'error: %s' % msg
@@ -129,6 +140,10 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
129 answer = answer in ('y', 'Y', 'yes', '1', 'true', 't') 140 answer = answer in ('y', 'Y', 'yes', '1', 'true', 't')
130 141
131 if answer: 142 if answer:
143 if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD:
144 answer = _ConfirmManyUploads()
145
146 if answer:
132 self._UploadAndReport([branch], people) 147 self._UploadAndReport([branch], people)
133 else: 148 else:
134 _die("upload aborted by user") 149 _die("upload aborted by user")
@@ -192,6 +207,16 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
192 todo.append(branch) 207 todo.append(branch)
193 if not todo: 208 if not todo:
194 _die("nothing uncommented for upload") 209 _die("nothing uncommented for upload")
210
211 many_commits = False
212 for branch in todo:
213 if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD:
214 many_commits = True
215 break
216 if many_commits:
217 if not _ConfirmManyUploads(multiple_branches=True):
218 _die("upload aborted by user")
219
195 self._UploadAndReport(todo, people) 220 self._UploadAndReport(todo, people)
196 221
197 def _FindGerritChange(self, branch): 222 def _FindGerritChange(self, branch):
@@ -258,6 +283,10 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
258 print >>sys.stderr, " use 'repo upload' without --replace" 283 print >>sys.stderr, " use 'repo upload' without --replace"
259 sys.exit(1) 284 sys.exit(1)
260 285
286 if len(branch.commits) > UNUSUAL_COMMIT_THRESHOLD:
287 if not _ConfirmManyUploads(multiple_branches=True):
288 _die("upload aborted by user")
289
261 branch.replace_changes = to_replace 290 branch.replace_changes = to_replace
262 self._UploadAndReport([branch], people) 291 self._UploadAndReport([branch], people)
263 292