[PATCH] D64893: Ask confirmation when `git llvm push` will push multiple commits

Mehdi AMINI via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 17 15:38:51 PDT 2019


mehdi_amini created this revision.
Herald added a project: LLVM.

This can reduce unexpectedly pushing more than expected for users.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64893

Files:
  llvm/utils/git-svn/git-llvm


Index: llvm/utils/git-svn/git-llvm
===================================================================
--- llvm/utils/git-svn/git-llvm
+++ llvm/utils/git-svn/git-llvm
@@ -99,6 +99,21 @@
     sys.exit(1)
 
 
+def ask_confirm(prompt):
+    # Python 2/3 compatibility
+    if hasattr(__builtin__, 'raw_input'):
+        input = __builtin__.raw_input
+    else:
+        input = builtins.input
+
+    while True:
+        query = raw_input('%s (y/n): ' % (prompt))
+        if query == '' or not query[0].lower() in ['y','n']:
+           print('Expect y or n!')
+           continue
+        return query[0].lower() == 'y'
+
+
 def split_first_path_component(d):
     # Assuming we have a git path, it'll use slashes even on windows...I hope.
     if '/' in d:
@@ -427,6 +442,12 @@
          's' if len(revs) != 1 else '',
          '\n'.join('  ' + git('show', '--oneline', '--quiet', c)
                    for c in revs)))
+
+    # Ask confirmation if multiple commits are about to be pushed
+    if len(revs) != 1:
+        if not ask_confirm("Are you sure?"):
+            die("abort")
+
     for r in revs:
         clean_svn(svn_root)
         svn_push_one_rev(svn_root, r, git_to_svn_mapping, dry_run)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64893.210443.patch
Type: text/x-patch
Size: 1207 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190717/f394ccb1/attachment.bin>


More information about the llvm-commits mailing list