{"record":{"id":"3d5be919090b52b8","repo":"plandex-ai/plandex","slug":"error-checking-for-uncommitted-changes-v-output","errorCode":null,"errorMessage":"error checking for uncommitted changes: %v, output: %s","messagePattern":"error checking for uncommitted changes: (.+?), output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/git.go","lineNumber":100,"sourceCode":"\t\targs = append(args, paths...)\n\t}\n\n\tres, err := exec.Command(\"git\", args...).CombinedOutput()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error committing files to git repository for dir: %s, err: %v, output: %s\", repoDir, err, string(res))\n\t}\n\n\treturn nil\n}\n\nfunc CheckUncommittedChanges() (bool, error) {\n\tgitMutex.Lock()\n\tdefer gitMutex.Unlock()\n\n\t// Check if there are any changes\n\tres, err := exec.Command(\"git\", \"status\", \"--porcelain\").CombinedOutput()\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"error checking for uncommitted changes: %v, output: %s\", err, string(res))\n\t}\n\n\t// If there's output, there are uncommitted changes\n\treturn strings.TrimSpace(string(res)) != \"\", nil\n}\n\nfunc GitStashCreate(message string) error {\n\tgitMutex.Lock()\n\tdefer gitMutex.Unlock()\n\n\tres, err := exec.Command(\"git\", \"stash\", \"push\", \"--include-untracked\", \"-m\", message).CombinedOutput()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error creating git stash: %v, output: %s\", err, string(res))\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/git.go#L82-L118","documentation":"CheckUncommittedChanges runs `git status --porcelain` (from the process working directory) and errors if that command fails. The error embeds git's exit error and combined output. Note it runs without `-C`, so it depends on the current working directory being a repository.","triggerScenarios":"Calling CheckUncommittedChanges() while the process working directory is not inside a git repository, git is not installed/on PATH, the .git directory is corrupted, or GIT_DIR/GIT_WORK_TREE env vars point somewhere invalid.","commonSituations":"Running the CLI from outside the project directory; running in a container image that lacks git; a detached or broken .git after a failed clone; git version too old to support a referenced option.","solutions":["Read the output in the message — 'not a git repository' means chdir into the repo (or os.Chdir) before calling.","Verify git is installed: `git --version`; install git in the container/host.","Run the process from the repository root or a subdirectory of it.","Check GIT_DIR/GIT_WORK_TREE env overrides aren't pointing to wrong locations.","If .git is corrupted, re-clone or restore the repository."],"exampleFix":"// before: called from arbitrary cwd\nhasChanges, err := lib.CheckUncommittedChanges()\n// after: ensure repo root first\nos.Chdir(projectRoot)\nhasChanges, err := lib.CheckUncommittedChanges()","handlingStrategy":"try-catch","validationCode":"// Go: ensure cwd is inside a repo before calling\nout, err := exec.Command(\"git\", \"rev-parse\", \"--is-inside-work-tree\").Output()\nif err != nil || strings.TrimSpace(string(out)) != \"true\" {\n    os.Chdir(projectRoot)\n}","typeGuard":"func isStatusCheckError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"error checking for uncommitted changes\")\n}","tryCatchPattern":"hasChanges, err := lib.CheckUncommittedChanges()\nif err != nil {\n    if isStatusCheckError(err) && strings.Contains(err.Error(), \"not a git repository\") {\n        os.Chdir(repoRoot)\n        hasChanges, err = lib.CheckUncommittedChanges()\n    }\n}","preventionTips":["Start the process with the repo root as working directory, or os.Chdir explicitly.","Verify git exists on PATH in your deployment image.","Avoid relying on GIT_DIR/GIT_WORK_TREE overrides unless intentional.","Remember this function ignores the dir argument style used elsewhere — it always uses cwd."],"tags":["git","status","cli","go"],"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"}