import datetime
from pathlib import Path
import subprocess


def get_latest_commit_hash(base_dir: Path | str) -> str:
    return (
        subprocess.check_output("git rev-parse HEAD".split(" "), cwd=base_dir)
        .decode()
        .strip()
    )


def get_latest_commit_datetime(base_dir: Path | str) -> datetime.datetime:
    # See https://git-scm.com/docs/pretty-formats for info about the format string
    return datetime.datetime.fromtimestamp(
        int(
            subprocess.check_output(
                "git show --no-patch --format=%ct HEAD".split(" "), cwd=base_dir
            )
            .decode()
            .strip()
        )
    )
