Skip to content

fix: respect core.hooksPath git config in commit hooks#2173

Open
mangodxd wants to merge 1 commit into
gitpython-developers:mainfrom
mangodxd:hookspath-fix
Open

fix: respect core.hooksPath git config in commit hooks#2173
mangodxd wants to merge 1 commit into
gitpython-developers:mainfrom
mangodxd:hookspath-fix

Conversation

@mangodxd

Copy link
Copy Markdown

Description

When core.hooksPath is set in any git config file (system, global, or repository level), commit hooks should be resolved relative to that path instead of the default .git/hooks directory.

Currently, run_commit_hook() always uses hook_path() which hardcodes {git_dir}/hooks/{name}, ignoring the core.hooksPath setting.

Changes

In run_commit_hook(), before falling back to the default hook path via hook_path(), the function now reads core.hooksPath from the repo configuration using config_reader().get(). If the setting exists:

  • Hooks are resolved relative to that path
  • If the path is relative (following git's behavior), it's resolved against the working tree root
  • If not set, the existing behavior is preserved unchanged

Testing

  • Existing test test_run_commit_hook continues to pass
  • The change is minimal (14 lines added) and non-breaking

Fixes #2083

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Commit hooks don't respect core.hooksPath in config.

1 participant