From 13acea3645e16ad97bfbeaa77af93e10879a852b Mon Sep 17 00:00:00 2001 From: Bruce Dawson Date: Tue, 3 May 2022 22:13:08 +0000 Subject: [PATCH] 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/+/3611025 Reviewed-by: Aravind Vasudevan Commit-Queue: Bruce Dawson --- git_cl.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/git_cl.py b/git_cl.py index 054f65905..8ceea3a2a 100755 --- a/git_cl.py +++ b/git_cl.py @@ -926,6 +926,9 @@ def ParseIssueNumberArgument(arg): def _create_description_from_log(args): """Pulls out the commit log to use as a base for the CL description.""" 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('.'): log_args = [args[0] + '..'] elif len(args) == 1 and args[0].endswith('...'): @@ -1185,7 +1188,8 @@ class Changelist(object): def GetIssue(self): """Returns the issue number as a int or None if not set.""" 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: self.issue = int(self.issue) self.lookedup_issue = True @@ -1224,7 +1228,8 @@ class Changelist(object): def GetPatchset(self): """Returns the patchset number as a int or None if not set.""" 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: self.patchset = int(self.patchset) self.lookedup_patchset = True @@ -4116,6 +4121,12 @@ def CMDpresubmit(parser, args): else: 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, may_prompt=False, verbose=options.verbose,