From d2321ca27bd9d690bec8a524a6f4726c764ee200 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 14 Nov 2026 14:08:13 +0100 Subject: [PATCH] Show the short hash and subject of a detached HEAD in the new branch prompt If you press `n` on the row of a detached HEAD in the branches panel, the title of the prompt contains the full 40-character commit hash. Since 5dec080719, the Name of a detached HEAD is the full hash. Describe the commit in the same way as when you press `n` on it in the commits panel. Co-Authored-By: Claude Opus 5.5 --- pkg/gui/controllers/branches_controller.go | 7 ++++++- pkg/integration/tests/branch/detached_head.go | 3 --- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 37ac90261..a51666ba1 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -746,7 +746,12 @@ func (self *BranchesController) rename(branch *models.Branch) error { } func (self *BranchesController) newBranch(selectedBranch *models.Branch) error { - return self.c.Helpers().Refs.NewBranch(selectedBranch.FullRefName(), selectedBranch.RefName(), "") + fromName := selectedBranch.RefName() + if selectedBranch.DetachedHead { + // The RefName of a detached HEAD is the full hash of its commit + fromName = models.CommitDescription(selectedBranch.Name, selectedBranch.Subject) + } + return self.c.Helpers().Refs.NewBranch(selectedBranch.FullRefName(), fromName, "") } func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Branch, checkedOutBranch *models.Branch) error { diff --git a/pkg/integration/tests/branch/detached_head.go b/pkg/integration/tests/branch/detached_head.go index 06f77a15c..368087e75 100644 --- a/pkg/integration/tests/branch/detached_head.go +++ b/pkg/integration/tests/branch/detached_head.go @@ -25,10 +25,7 @@ var DetachedHead = NewIntegrationTest(NewIntegrationTestArgs{ Press(keys.Universal.New) t.ExpectPopup().Prompt(). - /* EXPECTED: Title(MatchesRegexp(`^New branch name \(branch is off of '[0-9a-f]{7} commit-09'\)$`)). - ACTUAL: */ - Title(MatchesRegexp(`^New branch name \(branch is off of '[0-9a-f]{40}'\)$`)). Type("new-branch"). Confirm()