Skip to content

Grep returns 0 matches on Windows for path-prefixed file_glob and spaced tool paths #752

Closed

Description

@philippeback

Summary

Grep returns "No matches found" on Windows when:

  1. file_glob is a path-prefixed file or glob (e.g., file_glob: "pine_sources/Foo.pine" with directory: "."), because GNU grep --include and PowerShell -Filter only match basenames.
  2. tool_path contains spaces (e.g., C:\Users\First Last\scoop\shims\grep.EXE) and run_cmd_subprocess wraps the oslex.join(...) command inside powershell -EncodedCommand, which fails to parse "C:\..." without & and returns exit code 1 (silently treated as no matches).

Fix

  • Normalize single path-prefixed file_glob values relative to search_dir_path (resolving exact files to search_dir_path = candidate, file_pattern = "*" and dir/*.ext to search_dir_path = candidate.parent, file_pattern = candidate.name), and pass -H to GNU grep so single-file searches still include the filename.
  • Execute rg/ag/grep directly via subprocess.run(..., shell=False) with the argument list instead of shell-joining and re-wrapping through run_cmd_subprocess.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions