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,
)
| 520 | |
| 521 | |
| 522 | def _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 | |
| 559 | def get_file_diff_for_release( |
no test coverage detected