Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index aef7c4ff93c0738a74e4a2d81fd1d16934208249..cf4be5f9dceec15f5f9ca01418b137b4488f4472 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -3541,6 +3541,50 @@ def CMDformat(parser, args): |
| return return_value |
| +@subcommand.usage('<codereview url or issue id>') |
| +def CMDcheckout(parser, args): |
| + """Checks out a branch associated with a given open Rietveld issue.""" |
|
Dirk Pranke
2015/09/22 19:23:17
how do you know that the issue is still open? I'd
scottmg
2015/09/22 19:34:22
When you `git cl land`, branch.<branch>.rietveldis
|
| + _, 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) == 0: |
| + print 'No branch with open issue found for %s.' % target_issue |
|
Dirk Pranke
2015/09/22 19:23:17
and reword this message
|
| + return 1 |
| + if len(branches) == 1: |
| + RunGit(['checkout', branches[0]]) |
| + else: |
| + 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 |
| + |
| + return 0 |
| + |
| + |
| def CMDlol(parser, args): |
| # This command is intentionally undocumented. |
| print zlib.decompress(base64.b64decode( |