[llvm] r367321 - Ask confirmation when `git llvm push` will push multiple commits

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 30 08:25:14 PDT 2019


Author: mehdi_amini
Date: Tue Jul 30 08:25:14 2019
New Revision: 367321

URL: http://llvm.org/viewvc/llvm-project?rev=367321&view=rev
Log:
Ask confirmation when `git llvm push` will push multiple commits

This can reduce unexpectedly pushing more than expected by the user.

Differential Revision: https://reviews.llvm.org/D64893

Modified:
    llvm/trunk/utils/git-svn/git-llvm

Modified: llvm/trunk/utils/git-svn/git-llvm
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/git-svn/git-llvm?rev=367321&r1=367320&r2=367321&view=diff
==============================================================================
--- llvm/trunk/utils/git-svn/git-llvm (original)
+++ llvm/trunk/utils/git-svn/git-llvm Tue Jul 30 08:25:14 2019
@@ -27,6 +27,11 @@ import time
 assert sys.version_info >= (2, 7)
 
 try:
+    exec("import __builtin__")  # To avoid IDE's grammar check
+except ImportError:
+    import builtins
+
+try:
     dict.iteritems
 except AttributeError:
     # Python 3
@@ -99,6 +104,21 @@ def die(msg):
     sys.exit(1)
 
 
+def ask_confirm(prompt):
+    # Python 2/3 compatibility
+    try:
+        input = eval("__builtin__.raw_input")
+    except NameError:
+        input = builtins.input
+
+    while True:
+        query = input('%s (y/N): ' % (prompt))
+        if query.lower() not in ['y','n', '']:
+           print('Expect y or n!')
+           continue
+        return query.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 +447,12 @@ def cmd_push(args):
          '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("Aborting")
+
     for r in revs:
         clean_svn(svn_root)
         svn_push_one_rev(svn_root, r, git_to_svn_mapping, dry_run)




More information about the llvm-commits mailing list