{"record":{"id":"07776cb795ecb9d5","repo":"plandex-ai/plandex","slug":"error-adding-file-s-to-git-repository-for-dir-s","errorCode":null,"errorMessage":"error adding file %s to git repository for dir: %s, err: %v","messagePattern":"error adding file (.+?) to git repository for dir: (.+?), err: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/git.go","lineNumber":47,"sourceCode":"\t}\n\n\treturn nil\n}\n\nfunc GitAddAndCommitPaths(dir, message string, paths []string, lockMutex bool) error {\n\tif len(paths) == 0 {\n\t\treturn nil\n\t}\n\n\tif lockMutex {\n\t\tgitMutex.Lock()\n\t\tdefer gitMutex.Unlock()\n\t}\n\n\tfor _, path := range paths {\n\t\terr := GitAdd(dir, path, false)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error adding file %s to git repository for dir: %s, err: %v\", path, dir, err)\n\t\t}\n\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()","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/git.go#L29-L65","documentation":"GitAddAndCommitPaths stages each specific path in dir with GitAdd(dir, path, false) and wraps a per-file failure with this message, naming the offending path. Unlike the whole-tree variant, a single bad path (deleted, ignored with constraints, or outside the repo) aborts the whole add loop before commit.","triggerScenarios":"Calling GitAddAndCommitPaths (e.g. from rewind or commitApplied) with a path that no longer exists on disk, lies outside the repository root, is an ignored submodule path, or when dir is not a git repository.","commonSituations":"Rewinding/committing after a file was deleted externally; path casing mismatches; passing absolute paths while git -C expects repo-relative ones; plan context referencing files removed between operations.","solutions":["Check the wrapped error for the named path; verify it exists with ls and is inside dir.","If the file was deleted intentionally, remove it from the paths list (or recreate it) before committing.","Use repo-relative paths rather than absolute paths when building the paths slice.","Confirm `git -C <dir> add <path>` manually reproduces/resolves the issue (e.g. .gitignore rules or submodule problems)."],"exampleFix":"// before\npaths := []string{\"/abs/path/context/file.ts\"}  # outside repo\n// after\nrel, _ := filepath.Rel(dir, absPath)\npaths := []string{rel}  # e.g. \"context/file.ts\"","handlingStrategy":"validation","validationCode":"// Filter paths to those that exist and are inside the repo before committing\nfunc validPaths(dir string, paths []string) []string {\n    var out []string\n    for _, p := range paths {\n        if !filepath.IsAbs(p) {\n            if _, err := os.Stat(filepath.Join(dir, p)); err == nil {\n                out = append(out, p)\n            }\n        }\n    }\n    return out\n}","typeGuard":"func isGitAddPathError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"error adding file \")\n}","tryCatchPattern":"if err := lib.GitAddAndCommitPaths(dir, msg, paths, true); err != nil {\n    if isGitAddPathError(err) {\n        // parse the offending path from the message and drop/recreate it\n        log.Printf(\"git add failed for a specific path: %v\", err)\n        return\n    }\n    return err\n}","preventionTips":["Use repo-relative paths, not absolute paths, when calling GitAddAndCommitPaths.","Skip paths that no longer exist on disk instead of failing the whole batch.","Re-verify file existence after rewind/apply operations that may delete files.","Check .gitignore/submodule rules for paths git refuses to add."],"tags":["go","git","add","paths"],"backgroundTag":"git-command-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}