{"record":{"id":"642445d043063bdd","repo":"plandex-ai/plandex","slug":"error-resetting-staged-changes-err-v-output","errorCode":null,"errorMessage":"error resetting staged changes | err: %v, output: %s","messagePattern":"error resetting staged changes \\| err: (.+?), output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/git.go","lineNumber":179,"sourceCode":"\t\t\treturn nil\n\t\t} else {\n\t\t\tlog.Println(\"No conflicts detected\")\n\n\t\t\treturn fmt.Errorf(\"error popping git stash: %v\", string(res))\n\t\t}\n\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))","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/git.go#L161-L197","documentation":"GitClearUncommittedChanges runs `git reset --hard` to discard all staged/unstaged tracked changes (from the process working directory, no -C flag). This error is returned when that reset fails, embedding the git error and output. It is destructive-by-design; a failure here usually indicates a repository-state or environment problem rather than local modifications.","triggerScenarios":"Calling GitClearUncommittedChanges() when cwd is not a git repository, git is missing from PATH, the index is locked (index.lock), the repo is in a conflicted/blocked state that reset --hard cannot clean, or .git is corrupt.","commonSituations":"Process launched outside the repo directory; concurrent git operations holding index.lock; container images without git installed; broken .git after interrupted clone or disk-full during a previous write.","solutions":["Read the wrapped output for git's exact reason ('not a git repository' → chdir to repo root first).","Remove a stale .git/index.lock if no git process is running.","Verify git is installed and on PATH (`git --version`).","If the repo state is broken, repair or re-clone; check disk space.","Note: the follow-up `git clean -d -f` failure raises a different message — this one is specifically the reset step."],"exampleFix":"// before: called from wrong cwd, reset hits non-repo\nerr := lib.GitClearUncommittedChanges()\n// after\nos.Chdir(repoRoot)\nerr := lib.GitClearUncommittedChanges()","handlingStrategy":"validation","validationCode":"// Go: verify repo + git availability before destructive reset\nif out, err := exec.Command(\"git\", \"rev-parse\", \"--is-inside-work-tree\").Output(); err != nil || strings.TrimSpace(string(out)) != \"true\" {\n    os.Chdir(repoRoot)\n}\nif _, err := exec.Command(\"git\", \"--version\").Output(); err != nil {\n    // git not installed — fail early with a clear message\n}","typeGuard":"func isResetHardError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"error resetting staged changes\")\n}","tryCatchPattern":"if err := lib.GitClearUncommittedChanges(); err != nil {\n    if isResetHardError(err) {\n        if strings.Contains(err.Error(), \"index.lock\") {\n            os.Remove(filepath.Join(\".git\", \"index.lock\"))\n            err = lib.GitClearUncommittedChanges()\n        }\n    }\n}","preventionTips":["Run from the repository root — this function uses no -C flag and operates on cwd.","Treat this call as destructive: snapshot or stash valuable local changes first.","Clear stale .git/index.lock after crashed git processes.","Verify git is installed in minimal container images before invoking."],"tags":["git","reset","cli","go"],"backgroundTag":"git-reset-hard-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"}