plandex-ai/plandex · error

error setting git config %s to %s for dir: %s, err: %v, outp

Error message

error setting git config %s to %s for dir: %s, err: %v, output: %s

What it means

setGitConfig runs `git -C <repoDir> config <key> <value>` and wraps any failure — non-zero exit or inability to execute git — into this error including the key, value, repo dir, and git's combined stdout/stderr output. It is called from initGitRepo, so repo initialization fails if git cannot write the config (typically user.name/user.email or similar settings).

Source

Thrown at app/server/db/git.go:650

	errs := []error{}
	for i := 0; i < len(paths); i++ {
		err := <-errCh
		if err != nil {
			errs = append(errs, err)
		}
	}

	if len(errs) > 0 {
		return fmt.Errorf("error removing lock files: %v", errs)
	}

	return nil
}

func setGitConfig(repoDir, key, value string) error {
	res, err := exec.Command("git", "-C", repoDir, "config", key, value).CombinedOutput()
	if err != nil {
		return fmt.Errorf("error setting git config %s to %s for dir: %s, err: %v, output: %s", key, value, repoDir, err, string(res))
	}
	return nil
}

func gitWriteOperation(operation func() error, repoDir, label string) error {
	log.Printf("[Git] gitWriteOperation - label: %s", label)
	var err error
	for attempt := 0; attempt < maxGitRetries; attempt++ {
		if attempt > 0 {
			delay := time.Duration(1<<uint(attempt-1)) * baseGitRetryDelay // Exponential backoff
			time.Sleep(delay)
			log.Printf("Retry attempt %d for git operation %s (delay: %v)\n", attempt+1, label, delay)
		}

		err = operation()
		if err == nil {
			return nil
		}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Read the `output` field in the error — git's own stderr names the exact cause (missing repo, bad key, permission denied).
  2. Verify the git binary is installed and on PATH: `which git`; install git if missing.
  3. Confirm repoDir exists and was successfully `git init`-ed before setGitConfig runs; check .git/config is writable by the app user.
  4. Validate the key/value: keys need a valid `section.subsection.name` form and must not be empty; escape appropriately.
  5. Check disk space (df -h) if git reports a write failure.

Example fix

// before
err := setGitConfig(repoDir, key, value) // fails: fatal: not in a git directory
// after: ensure repo exists and git is available first
if _, err := os.Stat(filepath.Join(repoDir, ".git")); os.IsNotExist(err) {
    if out, err := exec.Command("git", "init", repoDir).CombinedOutput(); err != nil {
        return fmt.Errorf("git init failed: %v: %s", err, out)
    }
}
if err := setGitConfig(repoDir, key, value); err != nil { ... }
Defensive patterns

Strategy: validation

Validate before calling

if _, err := exec.LookPath("git"); err != nil {
    return fmt.Errorf("git binary not found in PATH: %w", err)
}
if fi, err := os.Stat(filepath.Join(repoDir, ".git", "config")); err != nil || fi.IsDir() {
    return fmt.Errorf("%s is not an initialized git repo", repoDir)
}

Type guard

func isGitConfigErr(err error) bool {
    return err != nil && strings.Contains(err.Error(), "error setting git config")
}

Try / catch

if err := initGitRepo(repoDir); err != nil {
    if isGitConfigErr(err) && strings.Contains(err.Error(), "executable file not found") {
        return fmt.Errorf("install git (apt-get install git) and retry")
    }
    if isGitConfigErr(err) && strings.Contains(err.Error(), "not in a git directory") {
        if out, ierr := exec.Command("git", "init", repoDir).CombinedOutput(); ierr != nil {
            return fmt.Errorf("git init failed: %v: %s", ierr, out)
        }
        return initGitRepo(repoDir)
    }
    return err
}

Prevention

When it happens

Trigger: initGitRepo invokes setGitConfig when: the repoDir does not exist or is not a git repository (git exits with 'not in a git directory' style errors); the .git/config file is not writable (EACCES); the git binary is missing from PATH; the config key/value is malformed (e.g. empty key or invalid section syntax).

Common situations: Docker/container images without git installed; running the app as a non-root user in a repo initialized by root; passing an invalid config key with a bad section delimiter; repo directory deleted or moved between init steps; disk full preventing config write.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/8d66a111edae9f88. Report an issue: GitHub.