Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 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 import sys | |
| 6 import re | |
| 7 | |
| 8 from git_common import current_branch, branches, run | |
| 9 | |
| 10 def main(argv): | |
| 11 # TODO(iannucci): Use argparse | |
|
agable
2014/02/28 20:14:16
Do this now.
Ryan Tseng
2014/02/28 21:22:05
How is this different than just "git branch -m"?
| |
| 12 assert 2 <= len(argv) < 3, "Must supply (<newname>) or (<oldname> <newname>)" | |
| 13 if len(argv) == 2: | |
| 14 old_name = current_branch() | |
| 15 new_name = argv[1] | |
| 16 else: | |
| 17 old_name = argv[1] | |
| 18 new_name = argv[2] | |
| 19 assert old_name in branches(), "<oldname> must exist" | |
|
agable
2014/02/28 20:14:16
Since it shells out, only make one call to branche
Ryan Tseng
2014/02/28 21:22:05
"Error: Branch \"%s\" does not exist" % old_name
| |
| 20 assert new_name not in branches(), "<newname> must not exist" | |
|
Ryan Tseng
2014/02/28 21:22:05
"Error: A branch named \"%s\" already exists" % ne
| |
| 21 | |
| 22 run('branch', '-m', old_name, new_name) | |
| 23 | |
| 24 matcher = re.compile(r'^branch\.(.*)\.merge$') | |
| 25 branches_to_fix = [] | |
| 26 for line in run('config', '-l').splitlines(): | |
| 27 key, value = line.split('=', 1) | |
| 28 if value == 'refs/heads/' + old_name: | |
| 29 m = matcher.match(key) | |
| 30 if m: | |
| 31 branch = m.group(1) | |
| 32 remote = run('config', '--get', 'branch.%s.remote' % branch) | |
| 33 if remote == '.': | |
| 34 branches_to_fix.append(branch) | |
| 35 for b in branches_to_fix: | |
| 36 run('config', 'branch.%s.merge' % b, 'refs/heads/' + new_name) | |
| 37 | |
| 38 | |
| 39 if __name__ == '__main__': | |
| 40 sys.exit(main(sys.argv)) | |
| OLD | NEW |