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..b12210ff7ddeef3cad6847199cf7e5beb9109d94 |
| --- /dev/null |
| +++ b/git_rename_branch.py |
| @@ -0,0 +1,41 @@ |
| +#!/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/21 01:14:21
docstring
|
| +import sys |
| +import re |
| + |
| +from git_common import current_branch, branches, run |
| + |
| +def main(argv): |
| + # TODO(iannucci): Use argparse |
|
agable
2014/03/21 01:14:21
Do this now
|
| + assert 2 <= len(argv) < 3, "Must supply (<newname>) or (<oldname> <newname>)" |
| + if len(argv) == 2: |
| + old_name = current_branch() |
| + new_name = argv[1] |
| + else: |
| + old_name = argv[1] |
| + new_name = argv[2] |
| + assert old_name in branches(), "<oldname> must exist" |
| + assert new_name not in branches(), "<newname> must not exist" |
| + |
| + run('branch', '-m', old_name, new_name) |
| + |
| + matcher = re.compile(r'^branch\.(.*)\.merge$') |
| + branches_to_fix = [] |
| + for line in run('config', '-l').splitlines(): |
| + key, value = line.split('=', 1) |
|
agable
2014/03/21 01:14:21
does this properly strip? Lots of gitconfigs have
|
| + if value == 'refs/heads/' + old_name: |
| + m = matcher.match(key) |
| + if m: |
| + branch = m.group(1) |
| + remote = run('config', '--get', 'branch.%s.remote' % branch) |
| + if remote == '.': |
|
agable
2014/03/21 01:14:21
Please comment on what the special value '.' means
iannucci
2014/03/22 04:17:35
Er... why here? This is defined by git-config...
|
| + branches_to_fix.append(branch) |
| + for b in branches_to_fix: |
| + run('config', 'branch.%s.merge' % b, 'refs/heads/' + new_name) |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv)) |