From 9e542ff6e067fc50e0ce999b18c62d2ce271e95e Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 14 Sep 2026 10:18:21 +0200 Subject: [PATCH] Show "HEAD detached at " 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) --- pkg/gui/controllers/helpers/repos_helper.go | 3 +- .../tests/misc/recent_repos_branch_column.go | 40 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 pkg/integration/tests/misc/recent_repos_branch_column.go diff --git a/pkg/gui/controllers/helpers/repos_helper.go b/pkg/gui/controllers/helpers/repos_helper.go index 1942bd735..d22230fd9 100644 --- a/pkg/gui/controllers/helpers/repos_helper.go +++ b/pkg/gui/controllers/helpers/repos_helper.go @@ -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 diff --git a/pkg/integration/tests/misc/recent_repos_branch_column.go b/pkg/integration/tests/misc/recent_repos_branch_column.go new file mode 100644 index 000000000..77562102b --- /dev/null +++ b/pkg/integration/tests/misc/recent_repos_branch_column.go @@ -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() + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index c2f536bfa..89ae48de0 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -365,6 +365,7 @@ var tests = []*components.IntegrationTest{ misc.DirenvUnloadsOnBlockedEnvrc, misc.FilterRecentRepos, misc.InitialOpen, + misc.RecentReposBranchColumn, misc.RecentReposColumnWidths, misc.RecentReposOnLaunch, misc.RecentReposWithLongNames,