plandex-ai/plandex · error

error initializing git repo: %v

Error message

error initializing git repo: %v

What it means

This error wraps a failure from initGitRepo(tempDirPath), which runs `git init` in a freshly created temp directory while building plan diffs. GetPlanDiffs needs a scratch git repo to stage and commit the original file versions before writing the current versions and computing a diff. If `git init` (or any setup step inside initGitRepo) fails, the whole diff computation cannot proceed.

Source

Thrown at app/server/db/diff_helpers.go:40

		return "", fmt.Errorf("error getting current plan state: %v", err)
	}

	// create temp directory
	tempDirPath, err := os.MkdirTemp(getOrgDir(orgId), "tmp-diffs-*")

	if err != nil {
		return "", fmt.Errorf("error creating temp dir: %v", err)
	}

	defer func() {
		go os.RemoveAll(tempDirPath)
	}()

	// init a git repo in the temp dir
	err = initGitRepo(tempDirPath)

	if err != nil {
		return "", fmt.Errorf("error initializing git repo: %v", err)
	}

	files := planState.CurrentPlanFiles.Files
	removed := planState.CurrentPlanFiles.Removed

	// write the original files to the temp dir
	errCh := make(chan error, len(planState.ContextsByPath))
	hasAnyOriginal := false

	for path, context := range planState.ContextsByPath {
		go func(path string, context *shared.Context) {
			defer func() {
				if r := recover(); r != nil {
					log.Printf("panic in GetPlanDiffs: %v\n%s", r, debug.Stack())
					errCh <- fmt.Errorf("panic in GetPlanDiffs: %v\n%s", r, debug.Stack())
					runtime.Goexit() // don't allow outer function to continue and double-send to channel
				}
			}()

View on GitHub (pinned to e2d772072e)

Solutions

  1. Install git on the server host or fix PATH so `git init` is executable (verify with `git --version` as the server user).
  2. Check filesystem permissions and free space on the org directory / temp dir; ensure the process user can write there.
  3. Run `initGitRepo` logic manually against a scratch dir to see the underlying wrapped message and fix that root cause.
  4. If the org dir is read-only, correct the getOrgDir configuration to a writable location.

Example fix

// before (host missing git, fails at runtime)
err = initGitRepo(tempDirPath)
// after (fail fast with a clear message at startup)
if _, err := exec.LookPath("git"); err != nil {
    log.Fatalf("git binary not found in PATH: %v", err)
}
Defensive patterns

Strategy: validation

Validate before calling

if _, err := exec.LookPath("git"); err != nil {
    return fmt.Errorf("git binary required but not found in PATH")
}
if err := isWritableDir(getOrgDir(orgId)); err != nil {
    return fmt.Errorf("org dir not writable: %w", err)
}

Try / catch

out, err := someDiffCall()
if err != nil && strings.Contains(err.Error(), "error initializing git repo") {
    // check git availability / disk, then retry once
    log.Printf("git init failed, checking environment: %v", err)
}

Prevention

When it happens

Trigger: GetPlanDiffs is called and initGitRepo fails: the git binary is missing from PATH, the temp dir (os.MkdirTemp result) was removed or is not writable, disk is full, or the underlying exec of `git init` returns non-zero for another reason.

Common situations: Server host without git installed or with a broken git install; org data directory (getOrgDir) on a read-only or full filesystem; misconfigured TMPDIR/permissions preventing directory use; restricted containers that strip git or /tmp space.

Related errors


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