Datasets:
| """Best-effort read of the current repository commit for stage provenance. | |
| Every stage manifest records the code commit that produced it (``docs/02`` §1). | |
| Git is the source of truth but is never required for correctness: if it is | |
| unavailable (e.g. a tarball install), we record ``<unknown>`` rather than fail | |
| the pipeline. | |
| """ | |
| from __future__ import annotations | |
| import subprocess | |
| from .paths import repo_root | |
| def current_code_commit() -> str: | |
| """Return the HEAD commit hash, or ``<unknown>`` if git is unavailable.""" | |
| try: | |
| result = subprocess.run( | |
| ["git", "-C", str(repo_root()), "rev-parse", "HEAD"], | |
| capture_output=True, | |
| text=True, | |
| timeout=10.0, | |
| check=False, | |
| ) | |
| except (FileNotFoundError, subprocess.TimeoutExpired): | |
| return "<unknown>" | |
| out = result.stdout.strip() | |
| return out.splitlines()[0] if out else "<unknown>" | |