plandex-ai/plandex · error

error committing plan: %v

Error message

error committing plan: %v

What it means

ApplyPlan finishes by creating a git commit summarizing the applied plan via repo.GitAddAndCommit(branchName, msg). If git add/commit fails, the error is wrapped with this message. The apply has already been recorded on disk, but the commit that materializes it on the branch did not happen.

Source

Thrown at app/server/db/result_helpers.go:784

	}
	sort.Strings(sortedFiles)
	for _, path := range sortedFiles {
		msg += fmt.Sprintf("\n • 📄 %s", path)
	}
	msg += "\n" + "✏️  " + params.CommitMsg

	if loadContextRes != nil && !loadContextRes.MaxTokensExceeded {
		msg += "\n\n" + loadContextRes.Msg
	}

	if updateContextRes != nil && !updateContextRes.MaxTokensExceeded {
		msg += "\n\n" + updateContextRes.Msg
	}

	err = repo.GitAddAndCommit(branchName, msg)

	if err != nil {
		return fmt.Errorf("error committing plan: %v", err)
	}

	return nil
}

func RejectAllResults(orgId, planId string) error {
	resultsDir := getPlanResultsDir(orgId, planId)

	files, err := os.ReadDir(resultsDir)

	if err != nil {
		if os.IsNotExist(err) {
			return nil
		}

		return fmt.Errorf("error reading results dir: %v", err)
	}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Inspect the wrapped git error; if it mentions index.lock, remove the stale .git/index.lock once no git process is running
  2. Confirm branchName exists and is checked out in the repo before ApplyPlan's commit step
  3. Configure git identity in the runtime environment: git config user.name/user.email
  4. Resolve any outstanding merge conflicts, then retry the apply

Example fix

// before
err = repo.GitAddAndCommit(branchName, msg)
if err != nil {
    return fmt.Errorf("error committing plan: %v", err)
}
// after: clean stale lock and ensure identity before committing
lockPath := filepath.Join(repo.Path, ".git", "index.lock")
if _, statErr := os.Stat(lockPath); statErr == nil {
    os.Remove(lockPath) // only when no other git process is active
}
if err := repo.GitAddAndCommit(branchName, msg); err != nil {
    return fmt.Errorf("error committing plan: %v", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := os.Stat(filepath.Join(repo.Path, ".git")); err != nil {
    return fmt.Errorf("not a git repo: %v", err)
}
if _, err := os.Stat(filepath.Join(repo.Path, ".git", "index.lock")); err == nil {
    return fmt.Errorf("git index is locked; another git operation may be running")
}

Try / catch

if err := repo.GitAddAndCommit(branchName, msg); err != nil {
    if strings.Contains(err.Error(), "index.lock") {
        log.Printf("git index locked; retry after removing stale lock")
    }
    return fmt.Errorf("error committing plan: %v", err)
}

Prevention

When it happens

Trigger: GitAddAndCommit fails — the branch does not exist or is not checked out, git index is locked (.git/index.lock), nothing staged, git identity (user.name/user.email) not configured, or the repo is in a detached/conflicted state.

Common situations: Concurrent operations leaving a stale index.lock; branch deleted or renamed between apply steps; fresh clone/CI container missing git config user.email; merge conflicts from earlier failed applies.

Related errors


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