fix: correct main repo root detection for submodules (#849)

This commit is contained in:
Gero Hillebrandt
2026-01-02 21:39:21 +01:00
committed by GitHub
parent ad44b32835
commit f48ecce2b7
2 changed files with 56 additions and 3 deletions

View File

@@ -149,8 +149,13 @@ func GetMainRepoRoot() (string, error) {
if err != nil {
return "", err
}
// The main repo root is the parent of the .git directory (commonDir)
return filepath.Dir(ctx.commonDir), nil
if ctx.isWorktree {
// For worktrees, the main repo root is the parent of the shared .git directory.
return filepath.Dir(ctx.commonDir), nil
}
// For regular repos (including submodules), repoRoot is the correct root.
return ctx.repoRoot, nil
}
// GetRepoRoot returns the root directory of the current git repository.
@@ -196,4 +201,4 @@ func NormalizePath(path string) string {
func ResetCaches() {
gitCtxOnce = sync.Once{}
gitCtx = gitContext{}
}
}