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 148bf7cfe..0c6aebae6 100644 --- a/pkg/integration/tests/branch/merge_into_detached_head.go +++ b/pkg/integration/tests/branch/merge_into_detached_head.go @@ -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( diff --git a/pkg/integration/tests/branch/squash_merge_during_rebase.go b/pkg/integration/tests/branch/squash_merge_during_rebase.go index 9d8f1babc..0bbad6140 100644 --- a/pkg/integration/tests/branch/squash_merge_during_rebase.go +++ b/pkg/integration/tests/branch/squash_merge_during_rebase.go @@ -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(