-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_hooks.py
More file actions
71 lines (55 loc) · 2.46 KB
/
Copy pathinstall_hooks.py
File metadata and controls
71 lines (55 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Install cart-freshness git hooks into every bird-repo clone (Laythros/<bird>-AIE).
post-commit and post-checkout (Graphify pattern, 2026-07-19): touch the dirty marker so
the running rift-verify server refreshes on its NEXT call, then spawn a detached prewarm
(prewarm_cache.py) so that refresh finds the parse/embed caches already current. Hooks
return immediately — git is never blocked.
Idempotent: hooks already carrying the marker comment are skipped; existing foreign hooks
get the block appended, never overwritten.
Run: .venv/Scripts/python.exe install_hooks.py
"""
from __future__ import annotations
from pathlib import Path
PLUGINS = Path(r"C:\Users\layth\Documents\Unreal Projects\RiftSuite58AIE\Plugins")
ESTATE = Path(__file__).resolve().parent
MARK = "# aporia-cart-freshness"
def _posix(p: Path) -> str:
return str(p).replace("\\", "/")
BLOCK = f"""{MARK}
: > "{_posix(ESTATE / '.corpus_dirty_rift')}"
"{_posix(ESTATE / '.venv' / 'Scripts' / 'python.exe')}" "{_posix(ESTATE / 'prewarm_cache.py')}" >/dev/null 2>&1 &
"""
def _hooks_dir(clone: Path) -> Path | None:
git = clone / ".git"
if git.is_dir():
return git / "hooks"
if git.is_file(): # worktree/submodule: gitdir pointer
target = git.read_text(encoding="utf-8").split("gitdir:", 1)[-1].strip()
return (clone / target).resolve() / "hooks"
return None
def main() -> int:
if not PLUGINS.exists():
print(f"plugins dir missing: {PLUGINS}")
return 1
installed = skipped = 0
for clone in sorted(p for p in PLUGINS.iterdir() if p.name.endswith("-AIE")):
hooks = _hooks_dir(clone)
if hooks is None:
print(f" {clone.name}: not a git clone — skipped")
continue
hooks.mkdir(exist_ok=True)
for name in ("post-commit", "post-checkout"):
hook = hooks / name
if hook.exists():
text = hook.read_text(encoding="utf-8")
if MARK in text:
skipped += 1
continue
hook.write_text(text.rstrip("\n") + "\n" + BLOCK, encoding="utf-8", newline="\n")
else:
hook.write_text("#!/bin/sh\n" + BLOCK, encoding="utf-8", newline="\n")
installed += 1
print(f" {clone.name}/{name}: installed")
print(f"\n{installed} hook(s) installed, {skipped} already current")
return 0
if __name__ == "__main__":
raise SystemExit(main())