[PATCH] D66395: [util] Add check to git-llvm to avoid pushing to a non-trunk branch

Ayke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 18 11:41:06 PDT 2019


aykevl created this revision.
aykevl added a reviewer: hans.
Herald added a project: LLVM.

To prevent pushing to a release branch by accident, for example. This happened to me in https://reviews.llvm.org/D66379 and I'd like to make sure this doesn't happen again - at least for newer LLVM releases.

The cause was most likely that my git-llvm binary was pointing to a checkout that used to be at master but was switched to release_80, which meant that while I pushed from the master branch, it was actually pushing to release_80 due to the wrong version of git-llvm.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66395

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
@@ -44,9 +44,11 @@
     # Python 2
     from pipes import quote
 
+LLVM_MONOREPO_DIR = '/trunk'
+
 # It's *almost* a straightforward mapping from the monorepo to svn...
 LLVM_MONOREPO_SVN_MAPPING = {
-    d: (d + '/trunk')
+    d: (d + LLVM_MONOREPO_DIR)
     for d in [
         'clang-tools-extra',
         'compiler-rt',
@@ -67,10 +69,10 @@
         'pstl',
     ]
 }
-LLVM_MONOREPO_SVN_MAPPING.update({'clang': 'cfe/trunk'})
-LLVM_MONOREPO_SVN_MAPPING.update({'': 'monorepo-root/trunk'})
+LLVM_MONOREPO_SVN_MAPPING.update({'clang': 'cfe' + LLVM_MONOREPO_DIR})
+LLVM_MONOREPO_SVN_MAPPING.update({'': 'monorepo-root' + LLVM_MONOREPO_DIR})
 
-SPLIT_REPO_NAMES = {'llvm-' + d: d + '/trunk'
+SPLIT_REPO_NAMES = {'llvm-' + d: d + LLVM_MONOREPO_DIR
                     for d in ['www', 'zorg', 'test-suite', 'lnt']}
 
 VERBOSE = False
@@ -430,6 +432,11 @@
     Note: a current limitation is that git does not track file rename, so they
     will show up in SVN as delete+add.
     '''
+
+    # Check for the branch.
+    if LLVM_MONOREPO_DIR != '/trunk' and not args.force_branch:
+        die("Branch is not trunk (specify --force-branch to override)")
+
     # Get the git root
     git_root = git('rev-parse', '--show-toplevel')
     if not os.path.isdir(git_root):
@@ -543,6 +550,10 @@
     populates the git commit message with both the SVN revision and git hash of
     the change being reverted.'''
 
+    # Check for the branch.
+    if LLVM_MONOREPO_DIR != '/trunk' and not args.force_branch:
+        die("Branch is not trunk (specify --force-branch to override)")
+
     # Get the git root
     git_root = git('rev-parse', '--show-toplevel')
     if not os.path.isdir(git_root):
@@ -626,6 +637,11 @@
         help='Do everything other than commit to svn.  Leaves junk in the svn '
         'repo, so probably will not work well if you try to commit more '
         'than one rev.')
+    parser_push.add_argument(
+        '--force-branch',
+        dest='force_branch',
+        action='store_true',
+        help='Force pushing to a non-trunk branch.')
     parser_push.add_argument(
         'rev_range',
         metavar='GIT_REVS',
@@ -651,6 +667,11 @@
         action='store_true',
         help='Do everything other than perform a revert. Prints the git '
         'revert command it would have run.')
+    parser_revert.add_argument(
+        '--force-branch',
+        dest='force_branch',
+        action='store_true',
+        help='Force reverting a commit on a non-trunk branch.')
     parser_revert.set_defaults(func=cmd_revert)
 
     parser_svn_lookup = subcommands.add_parser(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66395.215786.patch
Type: text/x-patch
Size: 2770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190818/509be738/attachment.bin>


More information about the llvm-commits mailing list