{"record":{"id":"f9cbcfe72f6267d2","repo":"plandex-ai/plandex","slug":"error-creating-git-stash-v-output-s","errorCode":null,"errorMessage":"error creating git stash: %v, output: %s","messagePattern":"error creating git stash: (.+?), output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/git.go","lineNumber":113,"sourceCode":"\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\n// this matches output for git version 2.39.3\n// need to test on other versions and check for more variations\n// there isn't any structured way to get stash conflicts from git, unfortunately\nconst PopStashConflictMsg = \"overwritten by merge\"\nconst ConflictMsgFilesEnd = \"commit your changes\"\n\nfunc GitStashPop(forceOverwrite bool) error {\n\tgitMutex.Lock()\n\tdefer gitMutex.Unlock()\n\n\tres, err := exec.Command(\"git\", \"stash\", \"pop\").CombinedOutput()\n\n\t// we should no longer have conflicts since we are forcing an update before","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/git.go#L95-L131","documentation":"GitStashCreate runs `git stash push --include-untracked -m <message>` (from the process working directory) to snapshot all changes including untracked files. This error is returned when the stash command exits non-zero, embedding the git error and its combined output.","triggerScenarios":"Calling GitStashCreate(message) outside a git repository, with git missing from PATH, when the index is locked, when there are unmerged/conflicted paths that stash refuses to handle, or when untracked files would be clobbered in pathological states.","commonSituations":"Process started outside the repo working directory; a previous failed stash pop left conflict state (unmerged entries) so stash push fails; container without git; .git/index.lock held by another process.","solutions":["Check the wrapped output — 'You do not have the initial commit' means the repo has no commits yet; make an initial commit first.","If unmerged paths exist, resolve/abort them (`git status`, `git merge --abort` or checkout) before stashing.","Ensure the process cwd is inside the repository (this function uses no `-C` flag).","Remove stale .git/index.lock if no git process is active.","Confirm git is installed and on PATH."],"exampleFix":"// before: stash in repo with conflicts pending\nlib.GitStashCreate(\"auto-save\")\n// after\nexec.Command(\"git\", \"checkout\", \"--\", \".\").Run() // or resolve unmerged paths first\nlib.GitStashCreate(\"auto-save\")","handlingStrategy":"validation","validationCode":"// Go: check repo health and no unmerged paths before stashing\nout, err := exec.Command(\"git\", \"status\", \"--porcelain\").Output()\nif err != nil { /* not a repo or git missing */ }\nif strings.Contains(string(out), \"UU\") || strings.Contains(string(out), \"AA\") {\n    // resolve conflicts before GitStashCreate\n}","typeGuard":"func isStashCreateError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"error creating git stash\")\n}","tryCatchPattern":"if err := lib.GitStashCreate(\"pre-update\"); err != nil {\n    if isStashCreateError(err) {\n        log.Printf(\"stash failed: %v — resolve unmerged paths or check repo state\", err)\n        // fall back to aborting the update flow rather than proceeding dirty\n    }\n}","preventionTips":["Ensure the repo has at least one commit before stashing (stash fails on unborn branch).","Resolve or abort any in-progress merge before stash operations.","Run from the repo working directory — this function uses no -C flag.","Clear stale index.lock files after crashed runs."],"tags":["git","stash","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"}