MCPcopy
hub / github.com/google/adk-python / _git_grep

Function _git_grep

contributing/samples/adk_team/adk_documentation/tools.py:522–556  ·  view source on GitHub ↗

Uses 'git grep' to find all matching lines in a Git repository.

(
    repo_path: str,
    pattern: str,
    extensions: Optional[List[str]] = None,
    ignored_dirs: Optional[List[str]] = None,
)

Source from the content-addressed store, hash-verified

520
521
522def _git_grep(
523 repo_path: str,
524 pattern: str,
525 extensions: Optional[List[str]] = None,
526 ignored_dirs: Optional[List[str]] = None,
527) -> subprocess.CompletedProcess[Any]:
528 """Uses 'git grep' to find all matching lines in a Git repository."""
529 grep_command = [
530 "git",
531 "grep",
532 "-n",
533 "-I",
534 "-E",
535 "--ignore-case",
536 "-e",
537 pattern,
538 ]
539 pathspecs = []
540 if extensions:
541 pathspecs.extend([f"*.{ext}" for ext in extensions])
542 if ignored_dirs:
543 pathspecs.extend([f":(exclude){d}" for d in ignored_dirs])
544
545 if pathspecs:
546 grep_command.append("--")
547 grep_command.extend(pathspecs)
548
549 grep_process = subprocess.run(
550 grep_command,
551 cwd=repo_path,
552 capture_output=True,
553 text=True,
554 check=False, # Don't raise error on non-zero exit code (1 means no match)
555 )
556 return grep_process
557
558
559def get_file_diff_for_release(

Callers 1

search_local_git_repoFunction · 0.85

Calls 3

extendMethod · 0.45
appendMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected