@@ -117,36 +117,60 @@ def get_local_hook_dir_path() -> Path:
117117 """
118118 Return the directory where local hooks should be installed.
119119
120- If core.hooksPath is configured, honor it and detect Husky-managed repositories
121- to avoid overwriting Husky's shim scripts.
120+ Respects git's core.hooksPath configuration while handling special cases:
121+ - Husky-managed repositories: returns .husky instead of .husky/_ to avoid
122+ overwriting Husky's shim scripts
123+ - Custom hooks path: returns the configured path
124+ - Default: returns .git/hooks
125+
126+ Returns:
127+ Path object pointing to the appropriate hooks directory.
122128 """
123129 hooks_path = get_local_hooks_path ()
130+
124131 if hooks_path is None :
125132 return Path (".git/hooks" )
126133
134+ # Husky uses .husky/_ for shim scripts - install alongside, not inside
127135 if is_husky_hooks_path (hooks_path ):
128136 return hooks_path .parent
129137
130138 return hooks_path
131139
132140
133141def get_local_hooks_path () -> Optional [Path ]:
134- """Return the hooks path defined in the repository config, if any."""
142+ """
143+ Reads the 'core.hooksPath' configuration from git's local repository
144+ config.
145+
146+ Returns:
147+ Configured hooks path, or None if core.hooksPath is not set.
148+
149+ Note:
150+ Does not validate that the returned path exists or is accessible.
151+ """
135152 try :
136153 out = git (
137154 ["config" , "--local" , "--get" , "core.hooksPath" ], ignore_git_config = False
138155 )
156+ # Strip whitespace and expand ~ to user home directory
157+ return Path (click .format_filename (out )).expanduser ()
139158 except subprocess .CalledProcessError :
159+ # core.hooksPath not configured in local repository
140160 return None
141- return Path (click .format_filename (out )).expanduser ()
142161
143162
144163def is_husky_hooks_path (path : Path ) -> bool :
145- """Detect Husky-generated hooks directories (.husky/_)."""
146- try :
147- return path .name == "_" and path .parent .name == ".husky"
148- except IndexError :
149- return False
164+ """
165+ Detect Husky-generated hooks directories.
166+
167+ Husky v6+ uses a .husky/_ directory for hook shim scripts.
168+ This function identifies that pattern to avoid overwriting Husky's setup.
169+
170+ Args:
171+ path: Path to check for Husky pattern.
172+ """
173+ return path .name == "_" and path .parent .name == ".husky"
150174
151175
152176def create_hook (
0 commit comments