gohugoio/hugo · error

git clone

Error message

git clone %s: %w: %s

What it means

Returned when the git clone command actually runs but exits non-zero. The message includes the origin URL (%s), the execution error (%w), and the captured stderr (%s) — so the real git failure (auth, network, not-found) is in stderr.

Solutions

  1. Read the trailing stderr in the message — it states the exact git failure (auth, not-found, network).
  2. Provide git credentials for private repos (SSH key, token, or git url.insteadOf rewrite).
  3. Clear the gitinfo cache dir for that repo (HUGO_CACHEDIR/repo_<hash>) and retry to rule out a corrupt partial clone.
  4. Verify network egress to the git host is allowed; retry with --debug if rate-limited.

Example fix

# before: public URL for a private repo, no creds
# stderr: fatal: Authentication failed for 'https://github.com/myorg/repo.git'

# after: use SSH or supply a token
git config --global url."git@github.com:".insteadOf "https://github.com/
rm -rf $HUGO_CACHEDIR/repo_*
Defensive patterns

Strategy: try-catch

Validate before calling

// Probe the origin URL before the build to catch auth/network issues early.
if out, err := exec.Command("git","ls-remote",originURL).CombinedOutput(); err != nil {
    return fmt.Errorf("origin unreachable: %s: %w", out, err)
}

Try / catch

if err := cmd.Run(); err != nil {
    if isAuthErr(stderr.String()) { configureCreds(); /* retry */ }
    if isTransient(stderr.String()) { time.Sleep(backoff); /* retry */ }
    return fmt.Errorf("git clone %s: %w: %s", origin.URL, err, stderr.String())
}

Prevention

When it happens

Trigger: Raised at gitinfo.go:214 when cmd.Run() fails for the 'git clone --filter=blob:none --no-checkout <url> <dir>' command. stderr is captured via WithStderr into the message for diagnostics.

Common situations: Repository does not exist or URL is wrong (404/Repository not found); authentication required and not provided (403/Permission denied); rate limiting or network/firewall blocking github.com; destination dir already a non-empty git repo from a corrupt cache.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/f7a470e383d711a7. Report an issue: GitHub.

Appendix: 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 52c9bd7908)