gohugoio/hugo · error

git clone: %w

Error message

git clone: %w

What it means

Returned inside ensureClone() when the git command object itself cannot be created via ExecHelper.New("git", ...). This is a command-construction failure (not a clone execution failure) — the helper refused to build the 'git clone ...' command.

Source

Thrown at hugolib/gitinfo.go:211

			return err
		}

		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

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Confirm git is installed and discoverable: `which git` / `git --version` in the build environment.
  2. Check that no security/exec policy (e.g. HUGO_DISABLEUNKNOWN) blocks running external git commands.
  3. If embedding Hugo, ensure ExecHelper is properly initialized on Deps.
  4. Disable gitinfo (enableGitInfo=false) if git is intentionally unavailable.

Example fix

# before: minimal CI image missing git
FROM alpine
RUN hugo build

# after: install git
FROM alpine
RUN apk add --no-cache git
RUN hugo build
Defensive patterns

Strategy: validation

Validate before calling

// Verify git binary presence before constructing the command.
if _, err := exec.LookPath("git"); err != nil { return fmt.Errorf("git required for gitinfo: %w", err) }

Try / catch

cmd, err := cfg.Deps.ExecHelper.New("git", args...)
if err != nil {
    // command construction failed; treat gitinfo as unavailable
    cfg.Logger.Warnf("gitinfo disabled: %v", err)
    return nil // non-fatal
}

Prevention

When it happens

Trigger: Raised at gitinfo.go:211 when cfg.Deps.ExecHelper.New("git", clone args...) returns an error — e.g. git binary not found, exec helper misconfigured, or an option/handler rejected the command before it could run.

Common situations: git executable missing in the container/CI image; exec helper blocked by a security policy; HUGO environment configured to disallow external commands; broken hexec setup during a Hugo upgrade.

Related errors


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