learning-world-goliath / scripts /install_hooks.py
defenestrate's picture
Deploy LWC Goliath chat (repo commit 097f382)
3d5c3e3 verified
Raw History Blame Contribute Delete
678 Bytes
"""Install (or --check) the tracked pre-commit hook. Tolk pattern: edit tracked source, never .git/hooks directly."""
import shutil
import stat
import sys
from pathlib import Path
SRC = Path("scripts/hooks/pre-commit.sh")
DST = Path(".git/hooks/pre-commit")
def main() -> int:
if "--check" in sys.argv:
drifted = (not DST.exists()) or DST.read_bytes() != SRC.read_bytes()
print("hook DRIFTED" if drifted else "hook ok")
return 1 if drifted else 0
shutil.copyfile(SRC, DST)
DST.chmod(DST.stat().st_mode | stat.S_IEXEC)
print(f"installed {SRC} -> {DST}")
return 0
if __name__ == "__main__":
sys.exit(main())