Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index aef7c4ff93c0738a74e4a2d81fd1d16934208249..8b33d6e529ca4e64fa2bd7302c8328373e7992b7 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -3541,6 +3541,49 @@ def CMDformat(parser, args): |
| return return_value |
| +@subcommand.usage('<codereview url or issue id>') |
| +def CMDco(parser, args): |
|
Dirk Pranke
2015/09/22 17:52:34
it seems like this should probably be CMDcheckout,
scottmg
2015/09/22 17:57:23
Done.
|
| + """Checks out a branch associated with a given Rietveld issue.""" |
| + _, args = parser.parse_args(args) |
| + |
| + if len(args) != 1: |
| + parser.print_help() |
| + return 1 |
| + |
| + if re.match(r'\d+', args[0]): |
| + target_issue = args[0] |
| + elif args[0].startswith('http'): |
| + target_issue = re.sub(r'.*/(\d+)/?', r'\1', args[0]) |
| + else: |
| + parser.print_help() |
| + return 1 |
| + |
| + key_and_issues = [x.split() for x in RunGit( |
| + ['config', '--local', '--get-regexp', r'branch\..*\.rietveldissue']) |
| + .splitlines()] |
| + branches = [] |
| + for key, issue in key_and_issues: |
| + if issue == target_issue: |
| + branches.append(re.sub(r'branch\.(.*)\.rietveldissue', r'\1', key)) |
| + |
| + if len(branches) == 1: |
| + RunGit(['checkout', branches[0]]) |
| + else: |
|
Dirk Pranke
2015/09/22 17:52:34
what if there's no match?
scottmg
2015/09/22 17:57:23
Done.
|
| + print 'Multiple branches match issue %s:' % target_issue |
| + for i in range(len(branches)): |
| + print '%d: %s' % (i, branches[i]) |
| + which = raw_input('Choose by index: ') |
| + try: |
| + RunGit(['checkout', branches[int(which)]]) |
| + except (IndexError, ValueError): |
| + print 'Invalid selection, not checking out any branch.' |
| + return 1 |
| + |
| + cl = Changelist() |
| + print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) |
|
Dirk Pranke
2015/09/22 17:52:34
Why print anything? You told it the issue number o
scottmg
2015/09/22 17:57:23
Done.
|
| + return 0 |
| + |
| + |
| def CMDlol(parser, args): |
| # This command is intentionally undocumented. |
| print zlib.decompress(base64.b64decode( |