{"record":{"id":"0f599d2ac6d7ca4c","repo":"plandex-ai/plandex","slug":"error-cleaning-untracked-files-err-v-output","errorCode":null,"errorMessage":"error cleaning untracked files | err: %v, output: %s","messagePattern":"error cleaning untracked files \\| err: (.+?), output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/git.go","lineNumber":185,"sourceCode":"\t}\n\n\treturn nil\n}\n\nfunc GitClearUncommittedChanges() error {\n\tgitMutex.Lock()\n\tdefer gitMutex.Unlock()\n\n\t// Reset staged changes\n\tres, err := exec.Command(\"git\", \"reset\", \"--hard\").CombinedOutput()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error resetting staged changes | err: %v, output: %s\", err, string(res))\n\t}\n\n\t// Clean untracked files\n\tres, err = exec.Command(\"git\", \"clean\", \"-d\", \"-f\").CombinedOutput()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error cleaning untracked files | err: %v, output: %s\", err, string(res))\n\t}\n\n\treturn nil\n}\n\nfunc GitFileHasUncommittedChanges(path string) (bool, error) {\n\tgitMutex.Lock()\n\tdefer gitMutex.Unlock()\n\n\tres, err := exec.Command(\"git\", \"status\", \"--porcelain\", path).CombinedOutput()\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"error checking for uncommitted changes for file %s | err: %v, output: %s\", path, err, string(res))\n\t}\n\n\treturn strings.TrimSpace(string(res)) != \"\", nil\n}\n\nfunc GitCheckoutFile(path string) error {","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/git.go#L167-L203","documentation":"GitClearUncommittedChanges runs `git reset --hard` then `git clean -d -f` to force the working tree back to HEAD. This error means the `git clean` step itself failed to execute; the combined stderr/stdout of the command is embedded in the message. It is not about files being dirty — it is the cleanup command erroring (or git being unavailable/misconfigured).","triggerScenarios":"Calling GitClearUncommittedChanges() when `git clean -d -f` exits non-zero: git binary missing or not on PATH, the working directory is not inside a git repository, a permission error prevents deletion, or a nested/foreign repo rejects the clean.","commonSituations":"Running the CLI outside a git repo (e.g. in a temp dir or home dir), a sandboxed/containerized environment where the git binary is absent, or untracked files with restrictive permissions that clean cannot remove.","solutions":["Verify the cwd is a git repository: run `git rev-parse --is-inside-work-tree` and initialize with `git init` if not.","Confirm `git` is installed and on PATH (`which git`; install git if missing).","Read the embedded `output:` portion of the message to see git's own stderr (e.g. permission denied) and fix that underlying issue.","Manually run `git clean -d -f` in the repo to reproduce and inspect interactively."],"exampleFix":"// before\nres, err = exec.Command(\"git\", \"clean\", \"-d\", \"-f\").CombinedOutput()\n// after\nif _, statErr := os.Stat(\".git\"); statErr != nil {\n    return fmt.Errorf(\"not a git repository, cannot clean: %w\", statErr)\n}\nres, err = exec.Command(\"git\", \"clean\", \"-d\", \"-f\").CombinedOutput()","handlingStrategy":"validation","validationCode":"if _, err := exec.LookPath(\"git\"); err != nil { return fmt.Errorf(\"git not installed\") }\nif out, err := exec.Command(\"git\", \"rev-parse\", \"--is-inside-work-tree\").Output(); err != nil || strings.TrimSpace(string(out)) != \"true\" {\n    return fmt.Errorf(\"not a git repository\")\n}","typeGuard":null,"tryCatchPattern":"if err := GitClearUncommittedChanges(); err != nil {\n    if strings.Contains(err.Error(), \"error cleaning untracked files\") {\n        log.Printf(\"git clean failed, inspect manually: %v\", err)\n    }\n    return err\n}","preventionTips":["Only call inside a confirmed git work tree","Ensure git is on PATH in all environments (CI images especially)","Avoid untracked files with root-only permissions","Read the embedded `output:` field before retrying"],"tags":["git","cli","subprocess"],"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-14T00:17:10.932Z"}