Show a readable name for a detached HEAD in the status panel (#6218)

When HEAD is detached, the status panel shows the full 40-character
commit hash after the repo name. This also happens during a rebase.
Before 5dec080719, the status panel showed the name of the branch being
rebased in that case. That commit made the name of a detached HEAD the
full hash, but the status panel kept displaying it.

During a rebase, we now show the name of the branch being rebased again,
e.g. "(rebasing) repo → mybranch". For any other detached HEAD, we show
the same text as the top row of the branches panel, e.g. "repo → (HEAD
detached at v1.2)".
This commit is contained in:
Stefan Haller authored and GitHub committed 2026-11-14 14:34:29 +00:00
commit cfb598fcdd
4 files changed
+19 -4

No files matched your search

@@ -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)
})
}
+10 -1
View File
@@ -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 := ""
@@ -26,6 +26,9 @@ var MergeIntoDetachedHead = NewIntegrationTest(NewIntegrationTestArgs{
Checkout("master^0")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Status().
Content(MatchesRegexp(`^repo → \(HEAD detached at [0-9a-f]+\)$`))
t.Views().Branches().
Focus().
Lines(
@@ -66,7 +66,8 @@ var SquashMergeDuringRebase = NewIntegrationTest(NewIntegrationTestArgs{
t.Common().AcknowledgeConflicts()
t.Views().Status().Content(Contains("(merging) repo → "))
t.Views().Status().
Content(Equals("(merging) repo → mybranch"))
t.GlobalPress(keys.Universal.CreateRebaseOptionsMenu)
t.ExpectPopup().Menu().
@@ -85,7 +86,8 @@ var SquashMergeDuringRebase = NewIntegrationTest(NewIntegrationTestArgs{
t.Common().ContinueOnConflictsResolved("merge")
t.Views().Status().Content(Contains("(rebasing) repo → "))
t.Views().Status().
Content(Equals("(rebasing) repo → mybranch"))
t.Views().Commits().
Lines(