{"record":{"id":"fbdfd162e9c85703","repo":"gastownhall/beads","slug":"failed-to-untrack-files-w-s","errorCode":null,"errorMessage":"failed to untrack files: %w\n%s","messagePattern":"failed to untrack files: %w\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/tracked_runtime.go","lineNumber":253,"sourceCode":"\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tif shouldFlagTrackedFile(rel) {\n\t\t\ttoUntrack = append(toUntrack, line)\n\t\t}\n\t}\n\n\tif len(toUntrack) == 0 {\n\t\treturn nil\n\t}\n\n\t// Untrack files (keeps local copies)\n\targs := append([]string{\"rm\", \"--cached\", \"--\"}, toUntrack...)\n\tcmd = exec.Command(\"git\", args...) // #nosec G204 - args are constructed from known parts\n\tcmd.Dir = repoRoot\n\tif out, err := cmd.CombinedOutput(); err != nil {\n\t\treturn fmt.Errorf(\"failed to untrack files: %w\\n%s\", err, string(out))\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":235,"sourceCodeEnd":258,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/tracked_runtime.go#L235-L258","documentation":"FixTrackedRuntimeFiles removes runtime files from git tracking with 'git rm --cached --' while keeping local copies. If that git command fails, the combined error and git output are wrapped with this message so the user can see git's own complaint.","triggerScenarios":"exec.Command(\"git\", [\"rm\",\"--cached\",\"--\",files...]).CombinedOutput() returns an error: not a git repo, files not actually tracked, pathspec mismatches, or index.lock contention.","commonSituations":"Running the fix outside a git worktree (repoRoot wrong); runtime files already untracked; another git process holding index.lock; case-sensitivity pathspec mismatch on macOS/Windows.","solutions":["Read the appended git output for the exact git error","Run 'git rm --cached -- <file>' manually for the listed files to see the failure directly","Ensure you are inside a git repository and no stale .git/index.lock exists (remove it if no git process is running)"],"exampleFix":"// before\nout, err := cmd.CombinedOutput() // fatal: pathspec 'runtime.db' did not match\n// after\nif isTracked(repoRoot, f) { untrack(f) } // skip files git does not track","handlingStrategy":"validation","validationCode":"func isTracked(repo, f string) bool {\n    out, err := exec.Command(\"git\", \"-C\", repo, \"ls-files\", \"--error-unmatch\", f).CombinedOutput()\n    return err == nil && len(out) > 0\n}\n// only pass tracked files to FixTrackedRuntimeFiles","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to untrack files\") {\n    log.Printf(\"git rm --cached failed: %s\", gitOutput) // appended after \\\\n\n}","preventionTips":["Verify repoRoot is inside a git worktree before fixing","Skip files git does not track (git ls-files check)","Clear stale .git/index.lock when no git process is active"],"tags":["beads","git","untrack","exec"],"backgroundTag":"git-command-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}