MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / install_hooks

Function install_hooks

src/codegraphcontext/cli/hook_manager.py:61–80  ·  view source on GitHub ↗
(start: Path | str | None = None, *, force: bool = False)

Source from the content-addressed store, hash-verified

59
60
61def install_hooks(start: Path | str | None = None, *, force: bool = False) -> HookStatus:
62 repo = find_git_repository(start)
63 hooks_dir = repo.git_dir / "hooks"
64 hooks_dir.mkdir(parents=True, exist_ok=True)
65
66 script = _hook_script(repo.root)
67 for hook_name in HOOK_NAMES:
68 hook_path = hooks_dir / hook_name
69 if hook_path.exists() and not _is_managed_hook(hook_path) and not force:
70 raise HookError(
71 f"{hook_name} already exists and is not managed by CGC. "
72 "Re-run with --force to replace it."
73 )
74 hook_path.write_text(script, encoding="utf-8")
75 mode = hook_path.stat().st_mode
76 hook_path.chmod(mode | stat.S_IXUSR | stat.S_IXGRP)
77
78 _ensure_gitattributes(repo.root)
79 _configure_merge_driver(repo.root)
80 return get_hook_status(repo.root)
81
82
83def uninstall_hooks(start: Path | str | None = None) -> HookStatus:

Calls 7

find_git_repositoryFunction · 0.85
_hook_scriptFunction · 0.85
_is_managed_hookFunction · 0.85
HookErrorClass · 0.85
_ensure_gitattributesFunction · 0.85
_configure_merge_driverFunction · 0.85
get_hook_statusFunction · 0.85