Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Unified Diff: git_rename_branch.py

Issue 184253003: Add git-reup and friends (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@freeze_thaw
Patch Set: fix pylint Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « git_rebase_update.py ('k') | git_reparent_branch.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_rename_branch.py
diff --git a/git_rename_branch.py b/git_rename_branch.py
new file mode 100755
index 0000000000000000000000000000000000000000..cefa012ff614e5cf2626ea9f4b9a0f9ed381e6fd
--- /dev/null
+++ b/git_rename_branch.py
@@ -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:]))
« no previous file with comments | « git_rebase_update.py ('k') | git_reparent_branch.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698