Return Git-tracked and unignored files, or None if Git is unavailable.
(root: Path)
| 117 | |
| 118 | |
| 119 | def git_candidate_files(root: Path) -> list[Path] | None: |
| 120 | """Return Git-tracked and unignored files, or None if Git is unavailable.""" |
| 121 | try: |
| 122 | result = subprocess.run( |
| 123 | [ |
| 124 | "git", |
| 125 | "-C", |
| 126 | str(root), |
| 127 | "ls-files", |
| 128 | "-z", |
| 129 | "--cached", |
| 130 | "--others", |
| 131 | "--exclude-standard", |
| 132 | ], |
| 133 | check=True, |
| 134 | capture_output=True, |
| 135 | ) |
| 136 | except (OSError, subprocess.CalledProcessError): |
| 137 | return None |
| 138 | |
| 139 | files = [] |
| 140 | for raw_path in result.stdout.split(b"\0"): |
| 141 | if raw_path: |
| 142 | files.append(Path(os.fsdecode(raw_path))) |
| 143 | return files |
| 144 | |
| 145 | |
| 146 | def is_git_ignored(root: Path, rel: Path) -> bool: |