diff --git a/pkg/gui/controllers/helpers/repos_helper.go b/pkg/gui/controllers/helpers/repos_helper.go index d22230fd9..d12238f33 100644 --- a/pkg/gui/controllers/helpers/repos_helper.go +++ b/pkg/gui/controllers/helpers/repos_helper.go @@ -88,7 +88,16 @@ func gitDirOfRepo(repoPath string) (string, bool) { if err != nil { return "", false } - return strings.CutPrefix(strings.TrimSpace(string(content)), "gitdir: ") + gitDir, ok := strings.CutPrefix(strings.TrimSpace(string(content)), "gitdir: ") + if !ok { + return "", false + } + // A relative name is relative to the repo. Git writes one for a submodule, + // and for a worktree created with --relative-paths. + if !filepath.IsAbs(gitDir) { + gitDir = filepath.Join(repoPath, gitDir) + } + return gitDir, true } // readHeadInfo reads the HEAD file of the repo at repoPath to find out what it diff --git a/pkg/gui/controllers/helpers/repos_helper_test.go b/pkg/gui/controllers/helpers/repos_helper_test.go index 55e0508bd..5b6f5bb4b 100644 --- a/pkg/gui/controllers/helpers/repos_helper_test.go +++ b/pkg/gui/controllers/helpers/repos_helper_test.go @@ -52,13 +52,9 @@ func TestReadHeadInfo(t *testing.T) { "repo/.git/worktrees/wt/HEAD": "ref: refs/heads/mybranch\n", "wt/.git": "gitdir: ../repo/.git/worktrees/wt\n", }, - /* EXPECTED: repoPath: "wt", expected: headInfo{branch: "mybranch"}, expectedOk: true, - ACTUAL: */ - repoPath: "wt", - expectedOk: false, }, { name: "submodule, whose .git file always names the git dir relatively", @@ -66,13 +62,9 @@ func TestReadHeadInfo(t *testing.T) { "repo/.git/modules/sub/HEAD": "ref: refs/heads/mybranch\n", "repo/sub/.git": "gitdir: ../.git/modules/sub\n", }, - /* EXPECTED: repoPath: "repo/sub", expected: headInfo{branch: "mybranch"}, expectedOk: true, - ACTUAL: */ - repoPath: "repo/sub", - expectedOk: false, }, { name: "directory without a .git entry", diff --git a/pkg/integration/tests/misc/recent_repos_branch_column.go b/pkg/integration/tests/misc/recent_repos_branch_column.go index 9c0257edb..3460d9bea 100644 --- a/pkg/integration/tests/misc/recent_repos_branch_column.go +++ b/pkg/integration/tests/misc/recent_repos_branch_column.go @@ -38,10 +38,7 @@ var RecentReposBranchColumn = NewIntegrationTest(NewIntegrationTestArgs{ Lines( Contains("on-branch").Contains("master").IsSelected(), Contains("detached").MatchesRegexp(`HEAD detached at [0-9a-f]{8}`), - /* EXPECTED: Contains("sub").MatchesRegexp(`HEAD detached at [0-9a-f]{8}`), - ACTUAL: */ - Contains("sub").Contains("Branch unknown"), Contains("Cancel"), ). Cancel()