Skip to content

Commit 02cbbfa

Browse files
committed
fix: respect core.hooksPath git config in commit hooks
1 parent 7a46dfc commit 02cbbfa

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

git/index/fun.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,21 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
8181
Arguments passed to hook file.
8282
8383
:raise git.exc.HookExecutionError:
84+
85+
:note:
86+
Respects the ``core.hooksPath`` git configuration option. When set, hooks are
87+
resolved relative to that path instead of the default ``.git/hooks`` directory.
8488
"""
85-
hp = hook_path(name, index.repo.git_dir)
89+
hooks_path = index.repo.config_reader().get(
90+
"core", "hooksPath", fallback=None
91+
)
92+
if hooks_path is not None:
93+
hp = osp.join(hooks_path, name)
94+
if not osp.isabs(hooks_path):
95+
# Relative hooksPath is resolved against the working tree root.
96+
hp = osp.join(index.repo.working_dir, hp)
97+
else:
98+
hp = hook_path(name, index.repo.git_dir)
8699
if not os.access(hp, os.X_OK):
87100
return
88101

0 commit comments

Comments
 (0)