plandex-ai/plandex · error

error committing files to git repository for dir

Error message

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

What it means

GitCommit runs `git -C <repoDir> commit -m <msg> --allow-empty [paths...]`. This error is returned when the commit command exits non-zero; the message includes the Go error and git's combined output. Note --allow-empty is used, so 'nothing to commit' is not the cause.

Solutions

  1. Read the wrapped output in the message for git's exact error (identity missing, pathspec mismatch, unmerged files, hook failure).
  2. Configure identity: `git -C <dir> config user.name ...` and `user.email ...` if the message says 'Please tell me who you are'.
  3. Resolve unmerged paths (`git status`) and complete/abort any in-progress merge before committing.
  4. Ensure every path in `paths` was staged (via GitAdd) and exists in the repo.
  5. If a pre-commit hook fails, fix the hook or commit with the hook issue addressed; remove stale .git/index.lock.

Example fix

// before: commit with paths that were never added
lib.GitCommit(dir, "msg", []string{"new.txt"}, true)
// after
lib.GitAdd(dir, "new.txt", true)
lib.GitCommit(dir, "msg", []string{"new.txt"}, true)
Defensive patterns

Strategy: validation

Validate before calling

// Go: pre-flight identity and merge-state check
email, _ := exec.Command("git", "-C", repoDir, "config", "user.email").Output()
if len(strings.TrimSpace(string(email))) == 0 {
    exec.Command("git", "-C", repoDir, "config", "user.email", "bot@example.com").Run()
    exec.Command("git", "-C", repoDir, "config", "user.name", "bot").Run()
}
if out, err := exec.Command("git", "-C", repoDir, "status", "--porcelain").Output(); err == nil && strings.Contains(string(out), "UU") {
    // unmerged paths present — resolve before committing
}

Type guard

func isGitCommitError(err error) bool {
    return err != nil && strings.Contains(err.Error(), "error committing files to git repository for dir") && strings.Contains(err.Error(), "output:")
}

Try / catch

if err := lib.GitCommit(dir, msg, paths, true); err != nil {
    if isGitCommitError(err) {
        // parse output: identity missing → set config; unmerged → resolve; hook → inspect hook
        log.Printf("commit failed: %v", err)
    }
}

Prevention

When it happens

Trigger: Calling GitCommit (directly or via GitAddAndCommit/GitAddAndCommitPaths) with no git identity configured, repoDir not a repository, a pathspec that matches no staged files, merge/rebase in progress with unresolved conflicts, a corrupt or locked index, or pre-commit hooks failing.

Common situations: Fresh CI containers without user.name/user.email; committing explicit paths where the path arguments were never staged or don't exist; a conflicted merge state from an earlier failed operation; .git/hooks/pre-commit rejecting the commit.

Related errors


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

Appendix: source

Thrown at app/cli/lib/git.go:87

	return nil
}

func GitCommit(repoDir, commitMsg string, paths []string, lockMutex bool) error {
	if lockMutex {
		gitMutex.Lock()
		defer gitMutex.Unlock()
	}

	args := []string{"-C", repoDir, "commit", "-m", commitMsg, "--allow-empty"}

	if len(paths) > 0 {
		args = append(args, paths...)
	}

	res, err := exec.Command("git", args...).CombinedOutput()
	if err != nil {
		return fmt.Errorf("error committing files to git repository for dir: %s, err: %v, output: %s", repoDir, err, string(res))
	}

	return nil
}

func CheckUncommittedChanges() (bool, error) {
	gitMutex.Lock()
	defer gitMutex.Unlock()

	// Check if there are any changes
	res, err := exec.Command("git", "status", "--porcelain").CombinedOutput()
	if err != nil {
		return false, fmt.Errorf("error checking for uncommitted changes: %v, output: %s", err, string(res))
	}

	// If there's output, there are uncommitted changes
	return strings.TrimSpace(string(res)) != "", nil
}

View on GitHub (pinned to e2d772072e)