Skip to content

Commit cc60dd4

Browse files
authored
Update grep.py
1 parent 86b5ed9 commit cc60dd4

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

python_agent_harness/tools/grep.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def run(self, args: dict, ctx: ToolContext) -> str:
4949
if context is not None:
5050
context = max(0, min(15, int(context)))
5151

52-
git_root = _git_root(path) if os.path.isdir(path) else None
52+
git_root = _git_root(path)
5353
if git_root:
5454
rel = os.path.relpath(path, git_root)
5555
pathspec = rel
@@ -84,6 +84,18 @@ def run(self, args: dict, ctx: ToolContext) -> str:
8484
proc = None
8585
if proc is not None and proc.returncode in (0, 1):
8686
return _grep_out(proc, "git")
87+
return self._fallback_rg_grep(regex, path, glob, context)
88+
89+
def _fallback_rg_grep(
90+
self, regex: str, path: str, glob: str | None, context: int | None
91+
) -> str:
92+
"""rg → grep fallback chain (no git grep).
93+
94+
Shared by :class:`Grep` (after git grep -P fails) and
95+
:class:`GrepMac` (after git grep -E fails). Extracted here so
96+
the Mac variant can skip the parent's ``git grep -P`` attempt
97+
without duplicating the rg/grep logic.
98+
"""
8799
if shutil.which("rg"):
88100
cmd = [
89101
"rg",

0 commit comments

Comments
 (0)