Chromium Code Reviews| Index: git_rename_branch.py |
| diff --git a/git_rename_branch.py b/git_rename_branch.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..044cd9eb515edb76c119a57ae10d6a765e23c7b4 |
| --- /dev/null |
| +++ b/git_rename_branch.py |
| @@ -0,0 +1,44 @@ |
| +#!/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. |
| + |
|
agable
2014/03/25 19:37:23
still no docstring.
iannucci
2014/03/26 01:39:49
Done.
|
| +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: |
|
agable
2014/03/25 19:37:23
if current != 'HEAD':
remove lines 16,17.
iannucci
2014/03/26 01:39:49
Agree, but can't refactor :/
|
| + 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) |
| + |
| + 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__': |
| + sys.exit(main(sys.argv[1:])) |
|
agable
2014/03/25 19:37:23
why? argparse parse_args() automatically grabs sys
iannucci
2014/03/26 01:39:49
b/c tests
|