MCPcopy Create free account
hub / github.com/espnet/espnet / get_git_metadata

Function get_git_metadata

espnet3/utils/logging_utils.py:322–353  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

320
321
322def 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
356def _run_pip_freeze() -> str:

Callers 1

log_run_metadataFunction · 0.85

Calls 1

_run_git_commandFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…