Git Hooks
Utilities for managing and running git hooks directly.
logger
module-attribute
logger = getLogger(__name__)
HOOK_TYPES
module-attribute
HOOK_TYPES = Literal[
"pre-commit",
"post-commit",
"commit-msg",
"pre-push",
"post-checkout",
]
get_git_hooks_dir
get_git_hooks_dir(repo_root: Path | None = None) -> Path
Get the .git/hooks directory for the current or given repo.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo_root
|
Path | None
|
Path to the repo root. Defaults to cwd. |
None
|
Returns:
Type | Description |
---|---|
Path
|
Path to the .git/hooks directory. |
Source code in src/codemap/utils/git_hooks.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
hook_exists
hook_exists(
hook_type: HOOK_TYPES, repo_root: Path | None = None
) -> bool
Check if a given hook exists and is executable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hook_type
|
HOOK_TYPES
|
The hook type ("pre-commit" or "pre-push"). |
required |
repo_root
|
Path | None
|
Path to the repo root. Defaults to cwd. |
None
|
Returns:
Type | Description |
---|---|
bool
|
True if the hook exists and is executable, False otherwise. |
Source code in src/codemap/utils/git_hooks.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
run_hook
run_hook(
hook_type: HOOK_TYPES, repo_root: Path | None = None
) -> int
Run the specified git hook directly using bash.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hook_type
|
HOOK_TYPES
|
The hook type ("pre-commit" or "pre-push"). |
required |
repo_root
|
Path | None
|
Path to the repo root. Defaults to cwd. |
None
|
Returns:
Type | Description |
---|---|
int
|
The exit code of the hook process (0 if hook doesn't exist). |
Source code in src/codemap/utils/git_hooks.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
run_all_hooks
run_all_hooks(
repo_root: Path | None = None,
) -> dict[str, int]
Run all supported hooks (pre-commit, pre-push) if they exist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo_root
|
Path | None
|
Path to the repo root. Defaults to cwd. |
None
|
Returns:
Type | Description |
---|---|
dict[str, int]
|
Dict mapping hook type to exit code. |
Source code in src/codemap/utils/git_hooks.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|