Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Unified Diff: git_cl.py

Issue 1357213003: Add `git cl checkout` to checkout by Rietveld issue (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: . Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cl.py
diff --git a/git_cl.py b/git_cl.py
index aef7c4ff93c0738a74e4a2d81fd1d16934208249..4964350b274285e3dad3883ecd84fefeca45080e 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 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) == 0:
+ print 'No branch found for issue %s.' % target_issue
+ 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(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698