{"record":{"id":"1194290b51c6eb2b","repo":"thedotmack/claude-mem","slug":"git-ls-files-failed-falling-back-to-directory-walk","errorCode":null,"errorMessage":"git ls-files failed, falling back to directory walk","messagePattern":"git ls-files failed, falling back to directory walk","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/cli/claude-md-commands.ts","lineNumber":74,"sourceCode":"    (obs.subtitle?.length || 0) +\n    (obs.narrative?.length || 0) +\n    (obs.facts?.length || 0);\n  return Math.ceil(size / 4);\n}\n\nfunction getTrackedFolders(workingDir: string): Set<string> {\n  const folders = new Set<string>();\n\n  let output: string;\n  try {\n    output = execSync('git ls-files', {\n      cwd: workingDir,\n      encoding: 'utf-8',\n      maxBuffer: 50 * 1024 * 1024\n    });\n  } catch (error) {\n    const errorMessage = error instanceof Error ? error.message : String(error);\n    logger.warn('CLAUDE_MD', 'git ls-files failed, falling back to directory walk', { error: errorMessage });\n    walkDirectoriesWithIgnore(workingDir, folders);\n    return folders;\n  }\n\n  const files = output.trim().split('\\n').filter(f => f);\n\n  for (const file of files) {\n    const absPath = path.join(workingDir, file);\n    let dir = path.dirname(absPath);\n\n    while (dir.length > workingDir.length && dir.startsWith(workingDir)) {\n      folders.add(dir);\n      dir = path.dirname(dir);\n    }\n  }\n\n  return folders;\n}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/cli/claude-md-commands.ts#L56-L92","documentation":"getTrackedFolders runs `git ls-files` to enumerate tracked folders for claude-md commands. If the git command fails (not a repo, git missing, permission errors), it logs the warning 'git ls-files failed, falling back to directory walk' and rebuilds the folder list via walkDirectoriesWithIgnore instead. This is a non-fatal degradation warning, not a thrown error.","triggerScenarios":"Running claude-md folder discovery in a directory that is not a git work tree, with git not installed/on PATH, or when git exits non-zero (permissions, dubious ownership, broken .git).","commonSituations":"Running the tool in a plain folder or tarball extract without .git; containers/minimal images lacking git; git's 'dubious ownership' safe.directory check failing in Docker; symlinked or read-only working directories.","solutions":["Initialize or clone a git repo in the working directory (git init / git clone) so ls-files works","Install git or fix PATH so the git binary is reachable","For 'dubious ownership' errors run: git config --global --add safe.directory <path>","Accept the fallback — it still returns folders via directory walk honoring ignore files — but expect slower/less accurate results than git-tracked enumeration"],"exampleFix":"// before (in a non-repo dir)\ngetTrackedFolders('/tmp/project'); // warns, walks directories\n// after\nexecSync('git init', { cwd: '/tmp/project' });\ngetTrackedFolders('/tmp/project'); // uses git ls-files","handlingStrategy":"fallback","validationCode":"import { execSync } from 'child_process';\nimport { existsSync } from 'fs';\nif (!existsSync(`${workingDir}/.git`)) console.warn('Not a git repo; folder discovery will use the slow directory-walk fallback');","typeGuard":null,"tryCatchPattern":"try {\n  execSync('git rev-parse --is-inside-work-tree', { cwd: workingDir, stdio: 'ignore' });\n} catch {\n  // not a repo or git missing: rely on walkDirectoriesWithIgnore fallback\n}","preventionTips":["Run claude-md folder discovery inside a proper git clone when possible","Ensure git is installed and on PATH in containers/CI images","Add safe.directory config for Docker volume-mounted repos to avoid ownership failures","Maintain ignore files (.gitignore) so the directory-walk fallback produces comparable results"],"tags":["git","cli","fallback","filesystem"],"backgroundTag":"git-command-failed","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}