{"id":"fd73932ebf00c5f6","repo":"gohugoio/hugo","slug":"failed-to-map-git-repo-for-module-s-v","errorCode":null,"errorMessage":"failed to map git repo for module %s: %v","messagePattern":"failed to map git repo for module (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/gitinfo.go","lineNumber":176,"sourceCode":"}\n\nfunc (g *gitInfo) loadModuleRepos(cfg gitInfoConfig) error {\n\tfor _, mod := range cfg.Modules {\n\t\tif !isGitModule(mod) {\n\t\t\tcontinue\n\t\t}\n\n\t\tloadGitInfo := sync.OnceValues(func() (*gitmap.GitRepo, error) {\n\t\t\torigin := mod.Origin()\n\n\t\t\tcloneDir, err := ensureClone(cfg, origin)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to clone %s: %v\", origin.URL, err)\n\t\t\t}\n\n\t\t\trepo, err := mapModuleRepo(cfg, cloneDir, origin.Hash)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to map git repo for module %s: %v\", mod.Path(), err)\n\t\t\t}\n\t\t\treturn repo, nil\n\t\t})\n\n\t\tg.moduleRepoLoaders[mod.Dir()] = loadGitInfo\n\t}\n\n\treturn nil\n}\n\n// ensureClone ensures a blobless clone of the module's origin repo exists in the cache.\nfunc ensureClone(cfg gitInfoConfig, origin modules.ModuleOrigin) (string, error) {\n\tkey := \"repo_\" + hashing.XxHashFromStringHexEncoded(origin.URL)\n\tinfo, err := cfg.GitInfoCache.GetOrCreateInfo(key, func(id string) error {\n\t\tcloneDir := cfg.GitInfoCache.AbsFilenameFromID(id)\n\t\tif err := os.MkdirAll(cloneDir, 0o777); err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/gitinfo.go#L158-L194","documentation":"After successfully cloning a module's origin repo into the GitInfo cache, Hugo runs gitmap over that clone at the module's pinned revision (origin.Hash) to build a filename→commit map. This error means that mapping step failed — the clone exists but git log/rev operations against the recorded revision did not succeed.","triggerScenarios":"mapModuleRepo failing inside the sync.OnceValues loader in loadModuleRepos: the module's pinned hash (from go.sum/module origin metadata) not present in the blobless clone (e.g. force-pushed or GC'd upstream), a stale/corrupted cached clone, or git command failures when gitmap walks the revision.","commonSituations":"Module upstream rewrote history so the pinned commit no longer exists; the GitInfo cache holds an old clone that predates new commits and was not fetched; interrupted earlier clone leaving a broken repo in the cache; version-pinned modules whose tags were moved.","solutions":["Clear the GitInfo cache (remove the repo_* directories under Hugo's cache dir, or `hugo --gc` / delete cacheDir) so the clone is recreated fresh.","Run `hugo mod get -u <module>` to re-resolve the module to a revision that exists upstream.","Check the wrapped git error for the specific revision; verify it exists with `git ls-remote <origin>`.","If the upstream history was rewritten, pin the module to a valid tag/commit in your module config."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// confirm each module dir is inside a git work tree\nout, err := exec.Command(\"git\", \"-C\", moduleDir, \"rev-parse\", \"--is-inside-work-tree\").Output()\nif err != nil || strings.TrimSpace(string(out)) != \"true\" {\n    log.Printf(\"module %s not a git repo; GitInfo unavailable\", moduleDir)\n}","typeGuard":null,"tryCatchPattern":"if err := build(); err != nil && strings.Contains(err.Error(), \"failed to map git repo for module\") {\n    // fall back: build without git info for vendored/non-git modules\n    cfg.Set(\"enableGitInfo\", false)\n    err = build()\n}","preventionTips":["Don't enable GitInfo when modules are vendored or fetched without .git directories","Use full (non-shallow) clones in CI so module git metadata is complete","Verify each mounted module path is a real git checkout before enabling GitInfo"],"tags":["hugo","git","modules","gitinfo","cache"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}