Show "HEAD detached at <hash>" in the recent repos menu

A repo with no branch checked out puts a bare short hash in the branch
column, where it reads as a branch name. Spell it out the way the
worktrees panel already does.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller 2026-09-14 10:18:21 +02:00
parent a3e940e20e
commit 9e542ff6e0
3 changed files with 43 additions and 1 deletions

View file

@ -119,7 +119,8 @@ func (self *ReposHelper) getCurrentBranch(path string) string {
if head.branch != "" {
return head.branch
}
return utils.ShortHash(head.hash)
return utils.ResolvePlaceholderString(self.c.Tr.HeadDetachedAt,
map[string]string{"hash": utils.ShortHash(head.hash)})
}
// The most that the name and the branch column of the recent repos menu are

View file

@ -0,0 +1,40 @@
package misc
import (
"path/filepath"
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var RecentReposBranchColumn = NewIntegrationTest(NewIntegrationTestArgs{
Description: "The branch column of the recent repositories menu shows what each repo has checked out",
ExtraCmdArgs: []string{},
ExtraEnvVars: map[string]string{
"SHOW_RECENT_REPOS": "true",
},
Skip: false,
SetupConfig: func(cfg *config.AppConfig) {
// the first entry is the repo we're in, so it isn't offered
current, _ := filepath.Abs(".")
onBranch, _ := filepath.Abs("../on-branch")
detached, _ := filepath.Abs("../detached")
cfg.GetAppState().RecentRepos = []string{current, onBranch, detached}
},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("one")
shell.CloneNonBare("on-branch")
shell.CloneNonBare("detached")
shell.RunCommand([]string{"git", "-C", "../detached", "checkout", "--detach"})
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.ExpectPopup().Menu().
Title(Equals("Recent repositories")).
Lines(
Contains("on-branch").Contains("master").IsSelected(),
Contains("detached").MatchesRegexp(`HEAD detached at [0-9a-f]{8}`),
Contains("Cancel"),
).
Cancel()
},
})

View file

@ -365,6 +365,7 @@ var tests = []*components.IntegrationTest{
misc.DirenvUnloadsOnBlockedEnvrc,
misc.FilterRecentRepos,
misc.InitialOpen,
misc.RecentReposBranchColumn,
misc.RecentReposColumnWidths,
misc.RecentReposOnLaunch,
misc.RecentReposWithLongNames,