Get list of files tracked by git (excluding files staged for deletion).
()
| 218 | |
| 219 | |
| 220 | def get_git_files() -> list[str] | None: |
| 221 | """Get list of files tracked by git (excluding files staged for deletion).""" |
| 222 | try: |
| 223 | result = subprocess.run( |
| 224 | ["git", "ls-files"], check=False, capture_output=True, text=True, cwd=Path.cwd() |
| 225 | ) |
| 226 | if result.returncode != 0: |
| 227 | print("Error: Could not get git files. Make sure you're in a git repository.") |
| 228 | print("Git command failed:", result.stderr.strip()) |
| 229 | return None |
| 230 | all_files = {line.strip() for line in result.stdout.split("\n") if line.strip()} |
| 231 | # Exclude files staged for deletion so the header check does not |
| 232 | # report errors for files that are intentionally being removed. |
| 233 | deleted_result = subprocess.run( |
| 234 | ["git", "ls-files", "--deleted"], |
| 235 | check=False, |
| 236 | capture_output=True, |
| 237 | text=True, |
| 238 | cwd=Path.cwd(), |
| 239 | ) |
| 240 | if deleted_result.returncode == 0: |
| 241 | deleted = {line.strip() for line in deleted_result.stdout.split("\n") if line.strip()} |
| 242 | all_files -= deleted |
| 243 | elif deleted_result.stderr: |
| 244 | print(f"Warning: 'git ls-files --deleted' failed: {deleted_result.stderr.strip()}") |
| 245 | return sorted(all_files) |
| 246 | except FileNotFoundError: |
| 247 | print("Error: Git not found. This tool requires git to be installed.") |
| 248 | return None |
| 249 | |
| 250 | |
| 251 | def copyright_line(line: str) -> bool: |
no test coverage detected
searching dependent graphs…