Get all files tracked by git or svn. Args: repo_root: Repository root directory. recurse_submodules: If True, pass ``--recurse-submodules`` to ``git ls-files`` so that files inside git submodules are included. When *None* (default), falls back to the
(
repo_root: Path,
recurse_submodules: bool | None = None,
)
| 600 | |
| 601 | |
| 602 | def get_all_tracked_files( |
| 603 | repo_root: Path, |
| 604 | recurse_submodules: bool | None = None, |
| 605 | ) -> list[str]: |
| 606 | """Get all files tracked by git or svn. |
| 607 | |
| 608 | Args: |
| 609 | repo_root: Repository root directory. |
| 610 | recurse_submodules: If True, pass ``--recurse-submodules`` to |
| 611 | ``git ls-files`` so that files inside git submodules are |
| 612 | included. When *None* (default), falls back to the |
| 613 | ``CRG_RECURSE_SUBMODULES`` environment variable. |
| 614 | (Ignored for SVN working copies.) |
| 615 | """ |
| 616 | if detect_vcs(repo_root) == "svn": |
| 617 | return _get_svn_all_tracked_files(repo_root) |
| 618 | |
| 619 | if recurse_submodules is None: |
| 620 | recurse_submodules = _RECURSE_SUBMODULES |
| 621 | |
| 622 | cmd = ["git", "ls-files"] |
| 623 | if recurse_submodules: |
| 624 | cmd.append("--recurse-submodules") |
| 625 | |
| 626 | try: |
| 627 | result = subprocess.run( |
| 628 | cmd, |
| 629 | capture_output=True, |
| 630 | text=True, encoding='utf-8', cwd=str(repo_root), |
| 631 | timeout=_GIT_TIMEOUT, |
| 632 | stdin=subprocess.DEVNULL, |
| 633 | ) |
| 634 | return [f.strip() for f in result.stdout.splitlines() if f.strip()] |
| 635 | except (FileNotFoundError, subprocess.TimeoutExpired): |
| 636 | return [] |
| 637 | |
| 638 | |
| 639 | def _get_svn_all_tracked_files(repo_root: Path) -> list[str]: |