{"record":{"id":"b51e0aa041373d79","repo":"plandex-ai/plandex","slug":"error-checking-out-file-s-err-v-output-s","errorCode":null,"errorMessage":"error checking out file %s | err: %v, output: %s","messagePattern":"error checking out file (.+?) \\| err: (.+?), output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/git.go","lineNumber":211,"sourceCode":"\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 {\n\tgitMutex.Lock()\n\tdefer gitMutex.Unlock()\n\n\tres, err := exec.Command(\"git\", \"checkout\", path).CombinedOutput()\n\tif err != nil {\n\t\tlog.Println(\"Error checking out file:\", string(res))\n\n\t\treturn fmt.Errorf(\"error checking out file %s | err: %v, output: %s\", path, err, string(res))\n\t}\n\n\treturn nil\n}\n\nconst GitLogTimestampFormat = \"Mon Jan 2, 2006 | 3:04:05pm\"\n\nvar GitLogTimestampRegex = regexp.MustCompile(`\\w{3} \\w{3} \\d{1,2}, \\d{4} \\| \\d{1,2}:\\d{2}:\\d{2}(am|pm) UTC`)\n\nfunc GetGitLogTimestamp(log string) (time.Time, error) {\n\tmatches := GitLogTimestampRegex.FindStringSubmatch(log)\n\tif len(matches) < 2 {\n\t\treturn time.Time{}, fmt.Errorf(\"no timestamp found in log\")\n\t}\n\n\treturn time.Parse(GitLogTimestampFormat, strings.TrimSuffix(matches[0], \" UTC\"))\n}\n","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/git.go#L193-L229","documentation":"GitCheckoutFile runs `git checkout <path>` to revert a single file to HEAD. This error means that command failed; the git stderr is logged and embedded in the message. Typical causes include the file being untracked or unknown to the index, so there is no committed version to restore.","triggerScenarios":"Calling GitCheckoutFile(path) for a path that is untracked (never committed), a path that does not match any index entry, a pathspec ambiguity, or when git itself is unavailable/not in a repo.","commonSituations":"Trying to discard changes in a newly created (never committed) file, a typo'd or renamed path, operating outside a git repository, or the user already staged-and-committed state conflicting with expectations.","solutions":["Check the file is tracked: `git ls-files --error-unmatch <path>`; untracked files cannot be checked out.","Guard the call with GitFileHasUncommittedChanges and skip checkout for untracked files.","Fix the path (relative to repo root, correct spelling).","Confirm cwd is a git repo and the git binary exists on PATH."],"exampleFix":"// before\nif dirty, _ := GitFileHasUncommittedChanges(path); dirty {\n    GitCheckoutFile(path)\n}\n// after\ntracked, _ := exec.Command(\"git\", \"ls-files\", \"--error-unmatch\", path).Run() == nil\nif tracked {\n    if dirty, _ := GitFileHasUncommittedChanges(path); dirty {\n        GitCheckoutFile(path)\n    }\n}","handlingStrategy":"validation","validationCode":"func fileIsTracked(path string) bool {\n    return exec.Command(\"git\", \"ls-files\", \"--error-unmatch\", path).Run() == nil\n}\n// call GitCheckoutFile only if fileIsTracked(path) && dirty","typeGuard":null,"tryCatchPattern":"if err := GitCheckoutFile(path); err != nil {\n    log.Printf(\"could not revert %s: %v\", path, err) // git output embedded in err\n    return fmt.Errorf(\"file not reverted, may be untracked: %w\", err)\n}","preventionTips":["Skip checkout for untracked (never committed) files","Confirm the path matches an index entry","Run inside the repo root or pass repo-relative paths","Keep git installed and on PATH"],"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-12T22:17:10.623Z"}