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
- Inspect the wrapped git error; if it mentions index.lock, remove the stale .git/index.lock once no git process is running
- Confirm branchName exists and is checked out in the repo before ApplyPlan's commit step
- Configure git identity in the runtime environment: git config user.name/user.email
- 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
- Configure git user.name/user.email in all runtime environments (CI containers included)
- Serialize git-mutating operations per repository with an application-level lock
- Verify the target branch exists and is checked out before starting ApplyPlan
- Clean stale .git/index.lock only after confirming no git process is active
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
- error committing files to git repository for dir: %s, err: %
- error committing files to git repository for dir: %s, err: %
- error committing rejected changes: %v
- error committing changes: %v
- error getting git root: %s
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/2d4125cc256c7f66.
Report an issue: GitHub.