Return git metadata for the current repository. This attempts to read commit hash, short hash, branch name, and worktree status from the git repository rooted at `cwd`. Args: cwd (Path | None): Directory within the target git repo. Returns: dict[str, str]: Collecte
(cwd: Path | None = None)
| 320 | |
| 321 | |
| 322 | def get_git_metadata(cwd: Path | None = None) -> dict[str, str]: |
| 323 | """Return git metadata for the current repository. |
| 324 | |
| 325 | This attempts to read commit hash, short hash, branch name, and worktree |
| 326 | status from the git repository rooted at `cwd`. |
| 327 | |
| 328 | Args: |
| 329 | cwd (Path | None): Directory within the target git repo. |
| 330 | |
| 331 | Returns: |
| 332 | dict[str, str]: Collected metadata keys, possibly including: |
| 333 | - "commit": Full commit hash. |
| 334 | - "short_commit": Abbreviated commit hash. |
| 335 | - "branch": Current branch name. |
| 336 | - "worktree": "clean", "dirty", or "unknown". |
| 337 | """ |
| 338 | cwd = cwd or Path.cwd() |
| 339 | status = _run_git_command(["git", "status", "--short"], cwd) |
| 340 | |
| 341 | dirty = "clean" |
| 342 | if status is None: |
| 343 | dirty = "unknown" |
| 344 | elif status: |
| 345 | dirty = "dirty" |
| 346 | |
| 347 | meta = { |
| 348 | "commit": _run_git_command(["git", "rev-parse", "HEAD"], cwd), |
| 349 | "short_commit": _run_git_command(["git", "rev-parse", "--short", "HEAD"], cwd), |
| 350 | "branch": _run_git_command(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd), |
| 351 | } |
| 352 | meta["worktree"] = dirty |
| 353 | return meta |
| 354 | |
| 355 | |
| 356 | def _run_pip_freeze() -> str: |
no test coverage detected
searching dependent graphs…