Capture git state (HEAD, status, diff) to reproducibility directory. Args: project_root: Project root directory repro_dir: Reproducibility directory to write to
(project_root: Path, repro_dir: Path)
| 311 | |
| 312 | |
| 313 | def _capture_git_state(project_root: Path, repro_dir: Path) -> None: |
| 314 | """Capture git state (HEAD, status, diff) to reproducibility directory. |
| 315 | |
| 316 | Args: |
| 317 | project_root: Project root directory |
| 318 | repro_dir: Reproducibility directory to write to |
| 319 | """ |
| 320 | try: |
| 321 | # Check if this is a git repository |
| 322 | result = subprocess.run( |
| 323 | ["git", "-C", str(project_root), "rev-parse", "--is-inside-work-tree"], |
| 324 | capture_output=True, |
| 325 | text=True, |
| 326 | timeout=5, |
| 327 | ) |
| 328 | if result.returncode != 0: |
| 329 | (repro_dir / "git_HEAD.txt").write_text("not-a-git-repo\n") |
| 330 | return |
| 331 | |
| 332 | # Get HEAD commit SHA |
| 333 | result = subprocess.run( |
| 334 | ["git", "-C", str(project_root), "rev-parse", "HEAD"], |
| 335 | capture_output=True, |
| 336 | text=True, |
| 337 | timeout=5, |
| 338 | ) |
| 339 | if result.returncode == 0: |
| 340 | (repro_dir / "git_HEAD.txt").write_text(result.stdout) |
| 341 | |
| 342 | # Get git status |
| 343 | result = subprocess.run( |
| 344 | ["git", "-C", str(project_root), "status"], |
| 345 | capture_output=True, |
| 346 | text=True, |
| 347 | timeout=5, |
| 348 | ) |
| 349 | if result.returncode == 0: |
| 350 | (repro_dir / "git_status.txt").write_text(result.stdout) |
| 351 | |
| 352 | # Get git diff |
| 353 | result = subprocess.run( |
| 354 | ["git", "-C", str(project_root), "diff", "HEAD"], |
| 355 | capture_output=True, |
| 356 | text=True, |
| 357 | timeout=5, |
| 358 | ) |
| 359 | if result.returncode == 0: |
| 360 | (repro_dir / "git_diff.patch").write_text(result.stdout) |
| 361 | |
| 362 | except (subprocess.SubprocessError, FileNotFoundError, OSError): |
| 363 | # Git not available or other error - write placeholder |
| 364 | (repro_dir / "git_HEAD.txt").write_text("git-unavailable\n") |
no test coverage detected