#!/usr/bin/env python3
# Copyright 2026 Petri Koistinen. Licensed under the Apache License, Version 2.0.
#
# Refuses any commit containing whitespace errors or failing the lint gate.
# The gate is Scripts/test.py commit.
#
# Activate once per clone:
#   git config core.hooksPath Scripts/githooks

import subprocess
import sys
from pathlib import Path


def main():
    root = subprocess.check_output(
        ["git", "rev-parse", "--show-toplevel"], text=True
    ).strip()
    doc_proc = subprocess.run(
        [sys.executable, "-B", "Scripts/DocumentationGate.py", "commit"],
        cwd=root,
    )
    if doc_proc.returncode in (0, 2):
        sys.exit(doc_proc.returncode)

    res = subprocess.run(
        [sys.executable, "-B", "Scripts/test.py", "commit"],
        cwd=root,
    )
    sys.exit(res.returncode)


if __name__ == "__main__":
    main()
