Skip to main content

judge.base_commit

judge.base_commit(root)

The full SHA of HEAD, if the working tree is clean.

Untracked files below regen/runs/ (earlier runs) do not make the tree dirty.

Parameters

Name Type Description Default
root Path Repository root. required

Returns

Name Type Description
str str The 40-hex SHA of HEAD.

Raises

Name Type Description
ConfigurationError If a tracked file has a change, or an untracked file lies outside regen/runs/, or root is not a git repository with a commit.

Examples

import subprocess
from pathlib import Path
from tempfile import TemporaryDirectory

from spotregen.judge import base_commit

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,
        )
    print(len(base_commit(root)))
40