codebase-memory-mcp icon indicating copy to clipboard operation
codebase-memory-mcp copied to clipboard

fix(discover): honor .git/info/exclude during file discovery

Open ShauryaaSharma opened this issue 5 months ago • 0 comments

Fixes #489

Problem

index_repository honored .gitignore but silently ignored .git/info/exclude — the per-clone exclude file that Git itself treats as authoritative. Any paths excluded only via info/exclude (e.g. Sandcastle worktrees) were walked in full.

In the reported case this caused the indexer to traverse 661,430 files / 170 GB of worktree content and OOM.

Solution

Added cbm_gitignore_merge() to append patterns from one matcher into another. In cbm_discover_ex, after loading .gitignore, the code now also loads .git/info/exclude and merges its patterns in. If only the exclude file exists (no .gitignore), it is used directly. No downstream call paths change.

Changes

  • src/discover/discover.h — declare cbm_gitignore_merge
  • src/discover/gitignore.c — implement cbm_gitignore_merge
  • src/discover/discover.c — load and merge .git/info/exclude in cbm_discover_ex
  • tests/test_gitignore.c — 3 unit tests for cbm_gitignore_merge
  • tests/test_discover.c — 2 integration tests reproducing the issue scenario

Testing

Added discover_git_info_exclude and discover_git_info_exclude_stacks_with_gitignore to the discover suite, covering the exact reproduction case from the issue report.

ShauryaaSharma avatar Jun 17 '26 19:06 ShauryaaSharma