From 46ade108f87c0dfcc3b0b5890a22386b85f2d701 Mon Sep 17 00:00:00 2001 From: Matt Stark Date: Fri, 8 Nov 2024 02:49:00 +0000 Subject: [PATCH] Update the error message for detached head. This allows for better support for both jj and git-branchless, both of which require no branches. Change-Id: I63d9273ed5f38f6b6bb24a1ba2ecd559983120a5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6002155 Commit-Queue: Matt Stark Reviewed-by: Josip Sokcevic --- git_cl.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/git_cl.py b/git_cl.py index aa5468d19..1e1e88821 100755 --- a/git_cl.py +++ b/git_cl.py @@ -171,6 +171,11 @@ assert len(_KNOWN_GERRIT_TO_SHORT_URLS) == len( # at once. Picked arbitrarily. _MAX_STACKED_BRANCHES_UPLOAD = 20 +_NO_BRANCH_ERROR = ( + 'Unable to determine base commit in detached HEAD state. ' + 'Get on a branch or run `git cl upload --no-squash ` to ' + 'upload all commits since base!') + class GitPushError(Exception): pass @@ -2151,8 +2156,7 @@ class Changelist(object): custom_cl_base = base_branch = git_diff_args[0] else: if self.GetBranch() is None: - DieWithError( - 'Can\'t upload from detached HEAD state. Get on a branch!') + DieWithError(_NO_BRANCH_ERROR) # Default to diffing against common ancestor of upstream branch base_branch = self.GetCommonAncestorWithUpstream() @@ -5531,7 +5535,7 @@ def _UploadAllPrecheck( """ cl = Changelist() if cl.GetBranch() is None: - DieWithError('Can\'t upload from detached HEAD state. Get on a branch!') + DieWithError(_NO_BRANCH_ERROR) branch_ref = None cls: List[Changelist] = []