Get list of changed files via git diff or svn status. For SVN working copies the *base* parameter is ignored; modified/added/ deleted files are detected from ``svn status``. Pass an SVN revision range (e.g. ``"r100:HEAD"``) as *base* to compare against a specific revision instead.
(repo_root: Path, base: str = "HEAD~1")
| 491 | |
| 492 | |
| 493 | def get_changed_files(repo_root: Path, base: str = "HEAD~1") -> list[str]: |
| 494 | """Get list of changed files via git diff or svn status. |
| 495 | |
| 496 | For SVN working copies the *base* parameter is ignored; modified/added/ |
| 497 | deleted files are detected from ``svn status``. Pass an SVN revision |
| 498 | range (e.g. ``"r100:HEAD"``) as *base* to compare against a specific |
| 499 | revision instead. |
| 500 | """ |
| 501 | if detect_vcs(repo_root) == "svn": |
| 502 | return _get_svn_changed_files(repo_root, base if _SAFE_SVN_REV.match(base) else None) |
| 503 | # Git path |
| 504 | if not _SAFE_GIT_REF.match(base): |
| 505 | logger.warning("Invalid git ref rejected: %s", base) |
| 506 | return [] |
| 507 | try: |
| 508 | result = subprocess.run( |
| 509 | ["git", "diff", "--name-only", base, "--"], |
| 510 | capture_output=True, |
| 511 | text=True, encoding='utf-8', cwd=str(repo_root), |
| 512 | timeout=_GIT_TIMEOUT, |
| 513 | stdin=subprocess.DEVNULL, |
| 514 | ) |
| 515 | if result.returncode != 0: |
| 516 | # Fallback: try diff against empty tree (initial commit) |
| 517 | result = subprocess.run( |
| 518 | ["git", "diff", "--name-only", "--cached"], |
| 519 | capture_output=True, |
| 520 | text=True, encoding='utf-8', cwd=str(repo_root), |
| 521 | timeout=_GIT_TIMEOUT, |
| 522 | stdin=subprocess.DEVNULL, |
| 523 | ) |
| 524 | files = [f.strip() for f in result.stdout.splitlines() if f.strip()] |
| 525 | return files |
| 526 | except (FileNotFoundError, subprocess.TimeoutExpired): |
| 527 | return [] |
| 528 | |
| 529 | |
| 530 | def _get_svn_changed_files(repo_root: Path, rev_range: str | None = None) -> list[str]: |