{"record":{"id":"012b7a721a3f9f89","repo":"plandex-ai/plandex","slug":"error-adding-files-to-git-repository-for-dir-s-012b7a","errorCode":null,"errorMessage":"error adding files to git repository for dir: %s, err: %v, output: %s","messagePattern":"error adding files to git repository for dir: (.+?), err: (.+?), output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/git.go","lineNumber":67,"sourceCode":"\t}\n\n\terr := GitCommit(dir, message, paths, false)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error committing files to git repository for dir: %s, err: %v\", dir, err)\n\t}\n\n\treturn nil\n}\n\nfunc GitAdd(repoDir, path string, lockMutex bool) error {\n\tif lockMutex {\n\t\tgitMutex.Lock()\n\t\tdefer gitMutex.Unlock()\n\t}\n\n\tres, err := exec.Command(\"git\", \"-C\", repoDir, \"add\", path).CombinedOutput()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error adding files to git repository for dir: %s, err: %v, output: %s\", repoDir, err, string(res))\n\t}\n\n\treturn nil\n}\n\nfunc GitCommit(repoDir, commitMsg string, paths []string, lockMutex bool) error {\n\tif lockMutex {\n\t\tgitMutex.Lock()\n\t\tdefer gitMutex.Unlock()\n\t}\n\n\targs := []string{\"-C\", repoDir, \"commit\", \"-m\", commitMsg, \"--allow-empty\"}\n\n\tif len(paths) > 0 {\n\t\targs = append(args, paths...)\n\t}\n\n\tres, err := exec.Command(\"git\", args...).CombinedOutput()","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/git.go#L49-L85","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: adding a path that doesn't exist\nerr := lib.GitAdd(dir, \"missing-file.txt\", true)\n// after: verify first\nif _, statErr := os.Stat(filepath.Join(dir, \"missing-file.txt\")); statErr == nil {\n    err = lib.GitAdd(dir, \"missing-file.txt\", true)\n}","handlingStrategy":"validation","validationCode":"// Go: validate repo and path before GitAdd\nif _, err := os.Stat(filepath.Join(repoDir, \".git\")); err != nil {\n    return fmt.Errorf(\"%s is not a git repository\", repoDir)\n}\nif _, err := os.Stat(path); err != nil {\n    return fmt.Errorf(\"path to add does not exist: %s\", path)\n}","typeGuard":"func isGitAddError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"error adding files to git repository for dir\")\n}","tryCatchPattern":"if err := lib.GitAdd(repoDir, path, true); err != nil {\n    var out string\n    if isGitAddError(err) { out = extractAfter(err, \"output: \") }\n    log.Printf(\"git add failed: %v (git said: %s)\", err, out)\n}","preventionTips":["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."],"tags":["git","stage","cli","go"],"backgroundTag":"git-add-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}