mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
Add a family of git-commands to assist with the management of multiple CLs/branches.
git-rebase-update - ensure all branches are up to date git-new-branch - create branches git-rename-branch - rename a branch while preserving parentage relationships git-reparent-branch - change the parent of a branch, including rebasing it correctly onto that new parent. git-squash-branch - collapse a branch into a single commit git-upstream-diff - show the diff between the current branch and it's upstream branch git-mark-merge-base - explicitly set what you want the above tools to consider the merge-base for the current branch. R=agable@chromium.org, hinoka@chromium.org, stip@chromium.org, szager@chromium.org BUG=261738 Review URL: https://codereview.chromium.org/184253003 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@259520 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
50
git_rename_branch.py
Executable file
50
git_rename_branch.py
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright 2014 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
"""Rename the current branch while maintaining correct dependencies."""
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
import subprocess2
|
||||
|
||||
from git_common import current_branch, run, set_branch_config, branch_config
|
||||
from git_common import branch_config_map
|
||||
|
||||
def main(args):
|
||||
current = current_branch()
|
||||
if current == 'HEAD':
|
||||
current = None
|
||||
old_name_help = 'The old branch to rename.'
|
||||
if current:
|
||||
old_name_help += ' (default %(default)r)'
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('old_name', nargs=('?' if current else 1),
|
||||
help=old_name_help, default=current)
|
||||
parser.add_argument('new_name', help='The new branch name.')
|
||||
|
||||
opts = parser.parse_args(args)
|
||||
|
||||
# when nargs=1, we get a list :(
|
||||
if isinstance(opts.old_name, list):
|
||||
opts.old_name = opts.old_name[0]
|
||||
|
||||
try:
|
||||
run('branch', '-m', opts.old_name, opts.new_name)
|
||||
|
||||
# update the downstreams
|
||||
for branch, merge in branch_config_map('merge').iteritems():
|
||||
if merge == 'refs/heads/' + opts.old_name:
|
||||
# Only care about local branches
|
||||
if branch_config(branch, 'remote') == '.':
|
||||
set_branch_config(branch, 'merge', 'refs/heads/' + opts.new_name)
|
||||
except subprocess2.CalledProcessError as cpe:
|
||||
sys.stderr.write(cpe.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == '__main__': # pragma: no cover
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
Reference in New Issue
Block a user