Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
|
agable
2014/03/25 19:37:23
still no docstring.
iannucci
2014/03/26 01:39:49
Done.
| |
| 6 import argparse | |
| 7 import sys | |
| 8 | |
| 9 import subprocess2 | |
| 10 | |
| 11 from git_common import current_branch, run, set_branch_config, branch_config | |
| 12 from git_common import branch_config_map | |
| 13 | |
| 14 def main(args): | |
| 15 current = current_branch() | |
| 16 if current == 'HEAD': | |
| 17 current = None | |
| 18 old_name_help = 'The old branch to rename.' | |
| 19 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 :/
| |
| 20 old_name_help += ' (default %(default)r)' | |
| 21 | |
| 22 parser = argparse.ArgumentParser() | |
| 23 parser.add_argument('old_name', nargs=('?' if current else 1), | |
| 24 help=old_name_help, default=current) | |
| 25 parser.add_argument('new_name', help='The new branch name.') | |
| 26 | |
| 27 opts = parser.parse_args(args) | |
| 28 | |
| 29 try: | |
| 30 run('branch', '-m', opts.old_name, opts.new_name) | |
| 31 | |
| 32 # update the downstreams | |
| 33 for branch, merge in branch_config_map('merge').iteritems(): | |
| 34 if merge == 'refs/heads/' + opts.old_name: | |
| 35 # Only care about local branches | |
| 36 if branch_config(branch, 'remote') == '.': | |
| 37 set_branch_config(branch, 'merge', 'refs/heads/' + opts.new_name) | |
| 38 except subprocess2.CalledProcessError as cpe: | |
| 39 sys.stderr.write(cpe.stderr) | |
| 40 return 1 | |
| 41 | |
| 42 | |
| 43 if __name__ == '__main__': | |
| 44 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
| |
| OLD | NEW |