{"id":"c8a8d78983650d23","repo":"gohugoio/hugo","slug":"failed-to-clone-s-v","errorCode":null,"errorMessage":"failed to clone %s: %v","messagePattern":"failed to clone (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/gitinfo.go","lineNumber":171,"sourceCode":"\n\tg.contentDir = gitRepo.TopLevelAbsPath\n\tg.repo = gitRepo\n\n\treturn g, nil\n}\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)","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/gitinfo.go#L153-L189","documentation":"When `enableGitInfo` is on and the site uses Hugo Modules backed by Git, Hugo (since v0.157.0) lazily creates a blobless clone of each module's origin repository in its GitInfo cache so it can attach commit metadata to module-mounted content. This error means ensureClone failed to produce that cached clone for the module's origin URL.","triggerScenarios":"A build with enableGitInfo=true and Git-backed modules where `git clone --filter=blob:none --no-checkout <origin.URL> <cacheDir>` cannot run or complete: git binary missing or blocked by Hugo's security exec allowlist, no network access to the origin URL, auth required for a private module repo, or the cache directory not writable (os.MkdirAll failure).","commonSituations":"CI environments without network egress or git credentials for private module repos; sandboxed builds (Netlify/Vercel/Docker) missing the git binary; upgrading to Hugo ≥0.157.0 which added module GitInfo and suddenly attempting clones that older versions never did; `security.exec.allow` not permitting `git`.","solutions":["Check the wrapped error: if it's an exec/security error, allow git via `[security.exec] allow = ['^git$', ...]`; if network/auth, provide credentials (e.g. git credential helper or GIT_CONFIG token rewrite) for the module origin.","Ensure the git binary is installed in the build environment.","Verify the origin URL is reachable from the build machine (`git ls-remote <url>`).","If module GitInfo isn't needed, disable enableGitInfo or avoid it in offline CI.","Clear a corrupted GitInfo cache (hugo's cacheDir gitinfo entries) and rebuild."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// verify git is available and remote reachable before enabling GitInfo\nif _, err := exec.LookPath(\"git\"); err != nil { log.Fatal(\"git not on PATH\") }\nexec.Command(\"git\", \"ls-remote\", \"--exit-code\", repoURL, \"HEAD\").Run()","typeGuard":null,"tryCatchPattern":"for attempt := 0; attempt < 3; attempt++ {\n    err = build()\n    if err == nil || !strings.Contains(err.Error(), \"failed to clone\") { break }\n    time.Sleep(time.Duration(1<<attempt) * time.Second) // transient network\n}","preventionTips":["Ensure git binary is installed in CI images when enableGitInfo is on","Pre-check network access and credentials to the module remotes","Cache cloned repos between CI runs to avoid repeated clone failures","Disable enableGitInfo for builds where git metadata isn't needed"],"tags":["hugo","git","modules","gitinfo","network"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}