gohugoio/hugo · error

git clone %s: %w: %s

Error message

git clone %s: %w: %s

What it means

The low-level failure behind module GitInfo cloning: the `git clone --filter=blob:none --no-checkout <url> <dir>` subprocess exited non-zero. Hugo wraps the exit error and appends git's captured stderr so the real cause (auth, DNS, not-a-repo) is visible in the message.

Source

Thrown at hugolib/gitinfo.go:214

		var stderr bytes.Buffer
		args := []any{
			"clone",
			"--filter=blob:none",
			"--no-checkout",
			origin.URL,
			cloneDir,
			hexec.WithStdout(io.Discard),
			hexec.WithStderr(&stderr),
		}

		cfg.Logger.Infof("Cloning gitinfo for repo %s into cache", origin.URL)

		cmd, err := cfg.Deps.ExecHelper.New("git", args...)
		if err != nil {
			return fmt.Errorf("git clone: %w", err)
		}
		if err := cmd.Run(); err != nil {
			return fmt.Errorf("git clone %s: %w: %s", origin.URL, err, stderr.String())
		}
		return nil
	})
	if err != nil {
		return "", err
	}
	return cfg.GitInfoCache.AbsFilenameFromID(info.Name), nil
}

func mapModuleRepo(cfg gitInfoConfig, repoDir, revision string) (*gitmap.GitRepo, error) {
	opts := gitmap.Options{
		Repository: repoDir,
		Revision:   revision,
		GetGitCommandFunc: func(stdout, stderr io.Writer, args ...string) (gitmap.Runner, error) {
			var argsv []any
			for _, arg := range args {
				argsv = append(argsv, arg)
			}

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Read the stderr appended to the message — it states the git-level cause; fix that (credentials, URL, network).
  2. For private modules in CI, configure a token, e.g. `git config --global url."https://x:${TOKEN}@github.com/".insteadOf "https://github.com/"`.
  3. Upgrade git to ≥2.19 so partial clone (--filter=blob:none) is supported.
  4. Verify the origin URL manually with `git clone --filter=blob:none --no-checkout <url> /tmp/t`.
Defensive patterns

Strategy: retry

Validate before calling

// pre-flight the exact clone Hugo will run
cmd := exec.Command("git", "clone", "--depth=1", repoURL, os.TempDir()+"/probe")
if out, err := cmd.CombinedOutput(); err != nil {
    log.Fatalf("clone pre-check failed: %v: %s", err, out)
}

Try / catch

err := build()
if err != nil && strings.Contains(err.Error(), "git clone") {
    // stderr is embedded in the error — inspect for auth vs network vs bad URL
    if strings.Contains(err.Error(), "Authentication failed") { /* fix credentials, don't retry */ } else { retryWithBackoff(build) }
}

Prevention

When it happens

Trigger: cmd.Run() failing in ensureClone: 'Repository not found'/authentication prompts for private repos in non-interactive builds, DNS or proxy failures, an origin URL that isn't a git repo, git versions too old to support --filter=blob:none (pre-2.19), or disk-full in the cache directory.

Common situations: Private Hugo module repos in CI without a token-based credential setup (GIT_ASKPASS unset, so clone fails instead of prompting); corporate proxies blocking git over https; extremely old git in a minimal container image.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/f7a470e383d711a7.json. Report an issue: GitHub ↗.