[depot tools] Remove `git cl issue --switch`

This was a duplicate of `git cl checkout`

Revert "[depot tools] Add `git cl issue --switch`"
Revert "[depot_tools] Use a function instead of reimplementing it."

This reverts commits 61ebd177ab and
7f9b0231c4.

Bug: 1428476
Change-Id: I54b70d7c7e98c847768cd980b337510fb91cdb20
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4405816
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Arthur Milchior <arthurmilchior@chromium.org>
changes/16/4405816/2
Arthur Milchior 2 years ago committed by LUCI CQ
parent bf6e21d9d7
commit 801a975021

@ -4218,10 +4218,22 @@ def write_json(path, contents):
json.dump(contents, f) json.dump(contents, f)
def _GetIssueBranchMap(): @subcommand.usage('[issue_number]')
# type: () -> Dict[int, List] @metrics.collector.collect_metrics('git cl issue')
"""Associate issues (as number) to the list of branches associated to this def CMDissue(parser, args):
issue.""" """Sets or displays the current code review issue number.
Pass issue number 0 to clear the current issue.
"""
parser.add_option('-r', '--reverse', action='store_true',
help='Lookup the branch(es) for the specified issues. If '
'no issues are specified, all branches with mapped '
'issues will be listed.')
parser.add_option('--json',
help='Path to JSON output file, or "-" for stdout.')
options, args = parser.parse_args(args)
if options.reverse:
branches = RunGit(['for-each-ref', 'refs/heads', branches = RunGit(['for-each-ref', 'refs/heads',
'--format=%(refname)']).splitlines() '--format=%(refname)']).splitlines()
# Reverse issue lookup. # Reverse issue lookup.
@ -4234,45 +4246,10 @@ def _GetIssueBranchMap():
git_config[name] = val git_config[name] = val
for branch in branches: for branch in branches:
issue = git_config.get('branch.%s.%s' % issue = git_config.get(
(scm.GIT.ShortBranchName(branch), ISSUE_CONFIG_KEY)) 'branch.%s.%s' % (scm.GIT.ShortBranchName(branch), ISSUE_CONFIG_KEY))
if issue: if issue:
issue_branch_map.setdefault(int(issue), []).append(branch) issue_branch_map.setdefault(int(issue), []).append(branch)
return issue_branch_map
def SwitchToIssue(options, args):
"""Switch to the branch associated to issue args[0]
Fail if the first arg is not a number. Fail if there are 0 such branch.
If there are multiple such branch, warns and behaves as
`git cl issue -r issue_number`.
"""
issue_branch_map = _GetIssueBranchMap()
if not args:
DieWithError('`git cl issue --switch` requires a number.')
try:
issue_num = int(args[0])
except ValueError:
DieWithError('Cannot parse issue number: %s' % args[0])
branches = issue_branch_map.get(issue_num, [])
if not branches:
DieWithError('No branch associated to issue: %d' % issue_num)
if len(branches) > 1:
# Print the various branches
PrintIssueToBranches(options, args)
DieWithError('Multiple branches associated to issue: %d' % issue_num)
RunGit(['switch', scm.GIT.ShortBranchName(branches[0])])
return 0
def PrintIssueToBranches(options, args):
"""Print the name of the branch(es) associated to the issue.
If no issue is specified, print issue -> branch(es) for all known issues"""
# Reverse issue lookup.
issue_branch_map = _GetIssueBranchMap()
if not args: if not args:
args = sorted(issue_branch_map.keys()) args = sorted(issue_branch_map.keys())
result = {} result = {}
@ -4289,35 +4266,6 @@ def PrintIssueToBranches(options, args):
write_json(options.json, result) write_json(options.json, result)
return 0 return 0
@subcommand.usage('[issue_number]')
@metrics.collector.collect_metrics('git cl issue')
def CMDissue(parser, args):
"""Sets or displays the current code review issue number.
Pass issue number 0 to clear the current issue.
--reverse and --switch option allow to access branch(es) from issue number.
"""
parser.add_option('-r', '--reverse', action='store_true',
help='Lookup the branch(es) for the specified issues. If '
'no issues are specified, all branches with mapped '
'issues will be listed.')
parser.add_option('-s',
'--switch',
action='store_true',
help='Switch to the branch linked to the specified issue. '
'If multiple branches are linked, list all of them.'
'Fail if `git switch` would fail in current state.')
parser.add_option('--json',
help='Path to JSON output file, or "-" for stdout.')
options, args = parser.parse_args(args)
if options.switch:
return SwitchToIssue(options, args)
if options.reverse:
return PrintIssueToBranches(options, args)
if len(args) > 0: if len(args) > 0:
issue = ParseIssueNumberArgument(args[0]) issue = ParseIssueNumberArgument(args[0])
if not issue.valid: if not issue.valid:

Loading…
Cancel
Save