plandex-ai/plandex · error
error adding files to git repository for dir: %s, err: %v, o
Error message
error adding files to git repository for dir: %s, err: %v, output: %s
What it means
GitAdd shells out to `git -C <repoDir> add <path>`. This error is returned when that command exits non-zero, and it includes both the Go error and git's combined stdout/stderr output. It means the file(s) could not be staged into the index.
Source
Thrown at app/cli/lib/git.go:67
}
err := GitCommit(dir, message, paths, false)
if err != nil {
return fmt.Errorf("error committing files to git repository for dir: %s, err: %v", dir, err)
}
return nil
}
func GitAdd(repoDir, path string, lockMutex bool) error {
if lockMutex {
gitMutex.Lock()
defer gitMutex.Unlock()
}
res, err := exec.Command("git", "-C", repoDir, "add", path).CombinedOutput()
if err != nil {
return fmt.Errorf("error adding files to git repository for dir: %s, err: %v, output: %s", repoDir, err, string(res))
}
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()View on GitHub (pinned to e2d772072e)
Solutions
- Inspect the `output:` portion of the message — it contains git's exact complaint (e.g. 'not a git repository', 'pathspec did not match').
- Verify repoDir is a repository: `git -C <repoDir> rev-parse --git-dir`; run `git init` if needed.
- Confirm the path exists and is relative to/inside repoDir.
- Delete a stale `repoDir/.git/index.lock` if no git process is running.
- Check `git check-ignore <path>` and adjust .gitignore or use `add -f` semantics if the file is ignored.
Example fix
// before: adding a path that doesn't exist
err := lib.GitAdd(dir, "missing-file.txt", true)
// after: verify first
if _, statErr := os.Stat(filepath.Join(dir, "missing-file.txt")); statErr == nil {
err = lib.GitAdd(dir, "missing-file.txt", true)
} Defensive patterns
Strategy: validation
Validate before calling
// Go: validate repo and path before GitAdd
if _, err := os.Stat(filepath.Join(repoDir, ".git")); err != nil {
return fmt.Errorf("%s is not a git repository", repoDir)
}
if _, err := os.Stat(path); err != nil {
return fmt.Errorf("path to add does not exist: %s", path)
} Type guard
func isGitAddError(err error) bool {
return err != nil && strings.Contains(err.Error(), "error adding files to git repository for dir")
} Try / catch
if err := lib.GitAdd(repoDir, path, true); err != nil {
var out string
if isGitAddError(err) { out = extractAfter(err, "output: ") }
log.Printf("git add failed: %v (git said: %s)", err, out)
} Prevention
- Confirm repoDir contains .git before any git operation; git init if provisioning a fresh dir.
- Stat the path before adding; skip or re-resolve deleted files.
- Run `git check-ignore` if adds unexpectedly no-op or fail on ignored files.
- Serialize git operations (the library's gitMutex helps only in-process) across processes with file locks.
When it happens
Trigger: Calling GitAdd(repoDir, path, lockMutex) (directly or via GitAddAndCommit/GitAddAndCommitPaths) when repoDir is not a git repository, the path doesn't exist, the path is ignored/invalid pathspec, the index is locked (index.lock exists), or git itself is missing from PATH.
Common situations: Wrong repoDir passed (parent of the repo, or directory deleted); attempting to add a file that was deleted externally with a stale path; concurrent processes contending on .git/index.lock; adding files in a bare or uninitialized directory.
Related errors
- failed to commit changes: %s
- error committing files to git repository for dir: %s, err: %
- error checking for uncommitted changes: %v, output: %s
- error creating git stash: %v, output: %s
- error resetting staged changes | err: %v, output: %s
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/012b7a721a3f9f89.
Report an issue: GitHub.