Skip to content

fix: search workspaces under ignored directory names - #578

Open
engmohamedsalah wants to merge 1 commit into
andrewyng:mainfrom
engmohamedsalah:fix/grep-ignored-ancestor-dir
Open

fix: search workspaces under ignored directory names#578
engmohamedsalah wants to merge 1 commit into
andrewyng:mainfrom
engmohamedsalah:fix/grep-ignored-ancestor-dir

Conversation

@engmohamedsalah

Copy link
Copy Markdown

Fixes #576 (reported by @Dhevenddra, with the root cause already nailed down in the report — thanks!).

Root cause

ripgrep resolves --glob patterns against paths relative to the process cwd, not the search root. grep passed the absolute workspace path while the agent process runs elsewhere, so the exclusion globs (!**/node_modules/** and the rest) matched the workspace's own ancestor directories. A workspace located under e.g. .../node_modules/ws excluded itself entirely — rg exited 1 with zero output.

Reproduced on macOS: same invocation from the workspace's own directory works, from any other cwd it returns nothing. (On Windows this fires for every pytest temp dir, since tmp_path lands under AppData.)

Fix

  • Run rg with cwd anchored to the search base and . as the search target, so glob patterns can only match directory names inside the workspace
  • rg now emits paths relative to that base (./a.py); _rel() resolves them against the search base before relativizing to the workspace root, keeping the documented relative-path output contract

Tests

  • New: test_grep_works_when_workspace_sits_under_an_ignored_dir_name — workspace nested under node_modules, fails on current main (count: 0), passes with the fix
  • Existing grep suite unchanged and green (15/15)

Note on ordering

This touches _parse_rg's signature, which #123 also rewrites (NUL parsing) — the changes compose cleanly but conflict textually. Suggested order: merge #123 first, then I rebase this onto it. Happy to do that as soon as it lands.

ripgrep matches --glob patterns against paths relative to the process
cwd, not the search root. Passing the absolute workspace path while the
agent runs elsewhere made the exclusion globs (!**/node_modules/** and
friends) match the workspace's own ancestors, so a workspace located
under e.g. .../node_modules/ silently excluded itself: rg exited 1 with
no output.

Run rg with cwd anchored to the search base and '.' as the target so
only directories inside the workspace can match, and resolve rg's now
relative output paths against that base before relativizing to the
workspace root.

Regression-tested with a workspace nested under node_modules; the
existing glob/escape/ignore tests are unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

grep returns no results when the workspace path contains an ignored directory name

1 participant