Skip to main content

judge.head_state

judge.head_state(root)

The full SHA of HEAD and whether the working tree differs from it.

The tree differs when a tracked file has a change or an untracked file lies outside regen/runs/; an untracked earlier run does not count. Nothing is refused for a dirty tree: spotregen mutate copies the working tree and records the fact, where base_commit refuses.

Parameters

Name Type Description Default
root Path Repository root. required

Returns

Name Type Description
tuple[str, bool] tuple[str, bool]: The 40-hex SHA of HEAD and the dirty flag.

Raises

Name Type Description
ConfigurationError If root is not a git repository with a commit.
ExternalToolError If git is not installed.

Examples

import subprocess
from pathlib import Path
from tempfile import TemporaryDirectory

from spotregen.judge import head_state

with TemporaryDirectory() as tmp:
    root = Path(tmp)
    for args in (["init", "-q"], ["commit", "-q", "--allow-empty", "-m", "i"]):
        subprocess.run(
            ["git", "-c", "user.name=t", "-c", "user.email=t@example.org", *args],
            cwd=root, check=True, capture_output=True,
        )
    sha, dirty = head_state(root)
    print(len(sha), dirty)
    (root / "new.txt").write_text("x")
    print(head_state(root)[1])
40 False
True