plandex-ai/plandex · error

error committing files to git repository for dir: %s, err: %

Error message

error committing files to git repository for dir: %s, err: %v

What it means

After staging, GetPlanDiffs commits the original files with gitCommit(tempDirPath, "original files"). If `git commit` exits non-zero the error is wrapped with the directory. The commit is required as the baseline tree for the diff output.

Source

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

	}

	for range planState.ContextsByPath {
		err = <-errCh
		if err != nil {
			return "", fmt.Errorf("error writing original files to temp dir: %v", err)
		}
	}

	if hasAnyOriginal {
		// add and commit the files in the temp dir
		err := gitAdd(tempDirPath, ".")
		if err != nil {
			return "", fmt.Errorf("error adding files to git repository for dir: %s, err: %v", tempDirPath, err)
		}

		err = gitCommit(tempDirPath, "original files")
		if err != nil {
			return "", fmt.Errorf("error committing files to git repository for dir: %s, err: %v", tempDirPath, err)
		}
	}

	// write the current files to the temp dir
	errCh = make(chan error, len(files))

	for path, file := range files {
		go func(path, file string) {
			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
				}
			}()
			// ensure file directory exists
			err = os.MkdirAll(filepath.Dir(filepath.Join(tempDirPath, path)), 0755)
			if err != nil {

View on GitHub (pinned to e2d772072e)

Solutions

  1. Run `git -C <tempDir> commit -m 'original files'` manually to see git's stderr.
  2. Ensure user.name/user.email are set for the server user (git config --global or env GIT_AUTHOR_NAME/GIT_COMMITTER_* / -c overrides).
  3. Check for and clear a stale .git/index.lock.
  4. Disable hooks for internal commits by committing with --no-verify if hooks interfere.

Example fix

// before
err = gitCommit(tempDirPath, "original files")
// after (guarantee identity regardless of host config)
cmd := exec.Command("git", "-C", dir, "-c", "user.name=plandex", "-c", "user.email=plandex@localhost", "commit", "-m", msg, "--no-verify")
Defensive patterns

Strategy: validation

Validate before calling

// ensure a git identity exists before any commit is attempted
if os.Getenv("GIT_AUTHOR_NAME") == "" {
    if out, err := exec.Command("git", "config", "--global", "user.name").Output(); err != nil || len(out) == 0 {
        return fmt.Errorf("git identity (user.name/user.email) not configured")
    }
}

Try / catch

out, err := GetPlanDiffs(orgId, planId, plain)
if err != nil && strings.Contains(err.Error(), "error committing files to git repository") {
    if strings.Contains(err.Error(), "who you are") {
        // set identity via env: GIT_AUTHOR_NAME/EMAIL, GIT_COMMITTER_NAME/EMAIL, then retry
    }
}

Prevention

When it happens

Trigger: gitCommit runs `git commit` in the temp repo and fails: nothing staged (hasAnyOriginal true but add silently skipped everything), no user.name/user.email configured in the environment, index.lock present, or hooks failing.

Common situations: Missing git identity ("Please tell me who you are") on servers without global git config; pre-commit hooks inherited from system config; stale index.lock; git identity checks from newer git versions.

Related errors


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