Skip to content

Phase commit

phase_commit

Retrieve commit hashes for AXM protocol phases.

get_phase_commit(working_dir, phase_name, *, message_format='[axm] {phase}')

Retrieve the commit hash associated with an AXM phase.

Searches git log for commits whose message matches the format used by :class:CommitPhaseHook.

Parameters:

Name Type Description Default
working_dir Path

Repository root path.

required
phase_name str

Phase name to search for.

required
message_format str

Message pattern used by CommitPhaseHook (default "[axm] {phase}").

'[axm] {phase}'

Returns:

Type Description
str | None

Short commit hash if found, None otherwise.

Source code in packages/axm-git/src/axm_git/core/phase_commit.py
def get_phase_commit(
    working_dir: Path,
    phase_name: str,
    *,
    message_format: str = "[axm] {phase}",
) -> str | None:
    """Retrieve the commit hash associated with an AXM phase.

    Searches git log for commits whose message matches the format
    used by :class:`CommitPhaseHook`.

    Args:
        working_dir: Repository root path.
        phase_name: Phase name to search for.
        message_format: Message pattern used by CommitPhaseHook
            (default ``"[axm] {phase}"``).

    Returns:
        Short commit hash if found, ``None`` otherwise.
    """
    if not (working_dir / ".git").exists():
        return None

    needle = message_format.format(phase=phase_name)
    result = run_git(
        ["log", "--oneline", "--grep", needle, "--format=%h", "-1"],
        working_dir,
    )
    sha = result.stdout.strip()
    return sha if sha else None