Commit 13acea36 authored by Bruce Dawson's avatar Bruce Dawson Committed by LUCI CQ

Let git cl presubmit work with no branch

When doing presubmit bisects (walking back through git history to see
when a presubmit regression was introduced) it is inconvenient to have
to create a branch at every step, and clean up the branches later. This
change makes having a branch optional, when using --force mode.

Bug: 1309977
Change-Id: I9fb6235620cf6c2e856359d2c25f1ef00c5da554
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3611025Reviewed-by: 's avatarAravind Vasudevan <aravindvasudev@google.com>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
parent fb8cf9cc
...@@ -926,6 +926,9 @@ def ParseIssueNumberArgument(arg): ...@@ -926,6 +926,9 @@ def ParseIssueNumberArgument(arg):
def _create_description_from_log(args): def _create_description_from_log(args):
"""Pulls out the commit log to use as a base for the CL description.""" """Pulls out the commit log to use as a base for the CL description."""
log_args = [] log_args = []
if len(args) == 1 and args[0] == None:
# Handle the case where None is passed as the branch.
return ''
if len(args) == 1 and not args[0].endswith('.'): if len(args) == 1 and not args[0].endswith('.'):
log_args = [args[0] + '..'] log_args = [args[0] + '..']
elif len(args) == 1 and args[0].endswith('...'): elif len(args) == 1 and args[0].endswith('...'):
...@@ -1185,7 +1188,8 @@ class Changelist(object): ...@@ -1185,7 +1188,8 @@ class Changelist(object):
def GetIssue(self): def GetIssue(self):
"""Returns the issue number as a int or None if not set.""" """Returns the issue number as a int or None if not set."""
if self.issue is None and not self.lookedup_issue: if self.issue is None and not self.lookedup_issue:
self.issue = self._GitGetBranchConfigValue(ISSUE_CONFIG_KEY) if self.GetBranch():
self.issue = self._GitGetBranchConfigValue(ISSUE_CONFIG_KEY)
if self.issue is not None: if self.issue is not None:
self.issue = int(self.issue) self.issue = int(self.issue)
self.lookedup_issue = True self.lookedup_issue = True
...@@ -1224,7 +1228,8 @@ class Changelist(object): ...@@ -1224,7 +1228,8 @@ class Changelist(object):
def GetPatchset(self): def GetPatchset(self):
"""Returns the patchset number as a int or None if not set.""" """Returns the patchset number as a int or None if not set."""
if self.patchset is None and not self.lookedup_patchset: if self.patchset is None and not self.lookedup_patchset:
self.patchset = self._GitGetBranchConfigValue(PATCHSET_CONFIG_KEY) if self.GetBranch():
self.patchset = self._GitGetBranchConfigValue(PATCHSET_CONFIG_KEY)
if self.patchset is not None: if self.patchset is not None:
self.patchset = int(self.patchset) self.patchset = int(self.patchset)
self.lookedup_patchset = True self.lookedup_patchset = True
...@@ -4116,6 +4121,12 @@ def CMDpresubmit(parser, args): ...@@ -4116,6 +4121,12 @@ def CMDpresubmit(parser, args):
else: else:
description = _create_description_from_log([base_branch]) description = _create_description_from_log([base_branch])
if not base_branch:
if not options.force:
print('use --force to check even when not on a branch.')
return 1
base_branch = 'HEAD'
cl.RunHook(committing=not options.upload, cl.RunHook(committing=not options.upload,
may_prompt=False, may_prompt=False,
verbose=options.verbose, verbose=options.verbose,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment