* Resolve the git hooks directory for a project, honoring `core.hooksPath` * and git worktrees. Returns an absolute path, or null when not a repo.
(projectRoot: string)
| 58 | * and git worktrees. Returns an absolute path, or null when not a repo. |
| 59 | */ |
| 60 | function gitHooksDir(projectRoot: string): string | null { |
| 61 | try { |
| 62 | const out = execFileSync('git', ['rev-parse', '--git-path', 'hooks'], { |
| 63 | cwd: projectRoot, |
| 64 | encoding: 'utf8', |
| 65 | stdio: ['ignore', 'pipe', 'ignore'], |
| 66 | windowsHide: true, |
| 67 | timeout: 5000, // same rationale as isGitRepo |
| 68 | }).trim(); |
| 69 | if (!out) return null; |
| 70 | return path.isAbsolute(out) ? out : path.resolve(projectRoot, out); |
| 71 | } catch { |
| 72 | return null; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** The shell snippet (between markers) injected into each hook. */ |
| 77 | function markerBlock(): string { |
no test coverage detected