From 9b3827929c68b4646c30155373e21dd6e1447975 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 14 Nov 2026 13:25:24 +0100 Subject: [PATCH 1/2] Add tests showing that the status panel shows a commit hash for a detached HEAD Co-Authored-By: Claude Opus 5.5 --- .../tests/branch/merge_into_detached_head.go | 6 ++++++ .../tests/branch/squash_merge_during_rebase.go | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/integration/tests/branch/merge_into_detached_head.go b/pkg/integration/tests/branch/merge_into_detached_head.go index 148bf7cfe..f6865c66b 100644 --- a/pkg/integration/tests/branch/merge_into_detached_head.go +++ b/pkg/integration/tests/branch/merge_into_detached_head.go @@ -26,6 +26,12 @@ var MergeIntoDetachedHead = NewIntegrationTest(NewIntegrationTestArgs{ Checkout("master^0") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Status(). + /* EXPECTED: + Content(MatchesRegexp(`^repo → \(HEAD detached at [0-9a-f]+\)$`)) + ACTUAL: */ + Content(MatchesRegexp(`^repo → [0-9a-f]{40}$`)) + t.Views().Branches(). Focus(). Lines( diff --git a/pkg/integration/tests/branch/squash_merge_during_rebase.go b/pkg/integration/tests/branch/squash_merge_during_rebase.go index 9d8f1babc..2edb23a11 100644 --- a/pkg/integration/tests/branch/squash_merge_during_rebase.go +++ b/pkg/integration/tests/branch/squash_merge_during_rebase.go @@ -66,7 +66,11 @@ var SquashMergeDuringRebase = NewIntegrationTest(NewIntegrationTestArgs{ t.Common().AcknowledgeConflicts() - t.Views().Status().Content(Contains("(merging) repo → ")) + t.Views().Status(). + /* EXPECTED: + Content(Equals("(merging) repo → mybranch")) + ACTUAL: */ + Content(MatchesRegexp(`^\(merging\) repo → [0-9a-f]{40}$`)) t.GlobalPress(keys.Universal.CreateRebaseOptionsMenu) t.ExpectPopup().Menu(). @@ -85,7 +89,11 @@ var SquashMergeDuringRebase = NewIntegrationTest(NewIntegrationTestArgs{ t.Common().ContinueOnConflictsResolved("merge") - t.Views().Status().Content(Contains("(rebasing) repo → ")) + t.Views().Status(). + /* EXPECTED: + Content(Equals("(rebasing) repo → mybranch")) + ACTUAL: */ + Content(MatchesRegexp(`^\(rebasing\) repo → [0-9a-f]{40}$`)) t.Views().Commits(). Lines( From a28738e04b63a526a02244f722baf1853994b101 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 14 Nov 2026 13:27:09 +0100 Subject: [PATCH 2/2] Show a readable name for a detached HEAD in the status panel If HEAD is detached, the status panel shows the full 40-character commit hash after the repo name. This also happens during a rebase, where it used to show the name of the branch being rebased. Since 5dec080719, the Name of a detached HEAD in the model is the full hash. That commit made the name work as a ref for git commands, but the status panel still shows it to the user. During a rebase, show the name of the branch being rebased again. For any other detached HEAD, show the same text as the top row of the branches panel, e.g. "(HEAD detached at v1.2)" or "(no branch, bisect started on master)". Co-Authored-By: Claude Opus 5.5 --- pkg/gui/controllers/helpers/refresh_helper.go | 3 ++- pkg/gui/presentation/status.go | 11 ++++++++++- .../tests/branch/merge_into_detached_head.go | 3 --- .../tests/branch/squash_merge_during_rebase.go | 6 ------ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index d1356c2aa..f29472e48 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -1745,6 +1745,7 @@ func (self *RefreshHelper) refreshStashEntries(filterPath string, env refreshEnv // never call this on its own, it should only be called from within refreshCommits() func (self *RefreshHelper) refreshStatus(env refreshEnv) { workingTreeState := env.git.Status.WorkingTreeState() + branchBeingRebased := env.git.Status.NameOfBranchBeingRebased() repoName := env.git.RepoPaths.RepoName() self.onUIThreadUnlessRepoChanged(env, func() { @@ -1759,7 +1760,7 @@ func (self *RefreshHelper) refreshStatus(env refreshEnv) { } linkedWorktreeName := self.worktreeHelper.GetLinkedWorktreeName() - status := presentation.FormatStatus(repoName, currentBranch, types.ItemOperationNone, linkedWorktreeName, workingTreeState, self.c.Tr, self.c.UserConfig()) + status := presentation.FormatStatus(repoName, currentBranch, branchBeingRebased, types.ItemOperationNone, linkedWorktreeName, workingTreeState, self.c.Tr, self.c.UserConfig()) self.c.SetViewContent(self.c.Views().Status, status) }) } diff --git a/pkg/gui/presentation/status.go b/pkg/gui/presentation/status.go index b636df647..3682e72a0 100644 --- a/pkg/gui/presentation/status.go +++ b/pkg/gui/presentation/status.go @@ -10,11 +10,13 @@ import ( "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/i18n" + "github.com/samber/lo" ) func FormatStatus( repoName string, currentBranch *models.Branch, + branchBeingRebased string, itemOperation types.ItemOperation, linkedWorktreeName string, workingTreeState models.WorkingTreeState, @@ -34,7 +36,14 @@ func FormatStatus( status += style.FgYellow.Sprintf("(%s) ", workingTreeState.LowerCaseTitle(tr)) } - name := GetBranchTextStyle(currentBranch.Name).Sprint(currentBranch.Name) + branchName := currentBranch.Name + if currentBranch.DetachedHead { + // The Name of a detached HEAD is a commit hash. Show the branch being + // rebased instead, or git's description of the detached HEAD, e.g. + // "(HEAD detached at v1.2)". + branchName = lo.Ternary(branchBeingRebased != "", branchBeingRebased, currentBranch.DisplayName) + } + name := GetBranchTextStyle(branchName).Sprint(branchName) // If the user is in a linked worktree (i.e. not the main worktree) we'll display that if linkedWorktreeName != "" { icon := "" diff --git a/pkg/integration/tests/branch/merge_into_detached_head.go b/pkg/integration/tests/branch/merge_into_detached_head.go index f6865c66b..0c6aebae6 100644 --- a/pkg/integration/tests/branch/merge_into_detached_head.go +++ b/pkg/integration/tests/branch/merge_into_detached_head.go @@ -27,10 +27,7 @@ var MergeIntoDetachedHead = NewIntegrationTest(NewIntegrationTestArgs{ }, Run: func(t *TestDriver, keys config.KeybindingConfig) { t.Views().Status(). - /* EXPECTED: Content(MatchesRegexp(`^repo → \(HEAD detached at [0-9a-f]+\)$`)) - ACTUAL: */ - Content(MatchesRegexp(`^repo → [0-9a-f]{40}$`)) t.Views().Branches(). Focus(). diff --git a/pkg/integration/tests/branch/squash_merge_during_rebase.go b/pkg/integration/tests/branch/squash_merge_during_rebase.go index 2edb23a11..0bbad6140 100644 --- a/pkg/integration/tests/branch/squash_merge_during_rebase.go +++ b/pkg/integration/tests/branch/squash_merge_during_rebase.go @@ -67,10 +67,7 @@ var SquashMergeDuringRebase = NewIntegrationTest(NewIntegrationTestArgs{ t.Common().AcknowledgeConflicts() t.Views().Status(). - /* EXPECTED: Content(Equals("(merging) repo → mybranch")) - ACTUAL: */ - Content(MatchesRegexp(`^\(merging\) repo → [0-9a-f]{40}$`)) t.GlobalPress(keys.Universal.CreateRebaseOptionsMenu) t.ExpectPopup().Menu(). @@ -90,10 +87,7 @@ var SquashMergeDuringRebase = NewIntegrationTest(NewIntegrationTestArgs{ t.Common().ContinueOnConflictsResolved("merge") t.Views().Status(). - /* EXPECTED: Content(Equals("(rebasing) repo → mybranch")) - ACTUAL: */ - Content(MatchesRegexp(`^\(rebasing\) repo → [0-9a-f]{40}$`)) t.Views().Commits(). Lines(