fix(install): honor repo-scoped core.hooksPath in worktrees#1673
fix(install): honor repo-scoped core.hooksPath in worktrees#1673schickling wants to merge 1 commit intoj178:masterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1673 +/- ##
==========================================
- Coverage 91.64% 90.38% -1.26%
==========================================
Files 96 96
Lines 18662 18704 +42
==========================================
- Hits 17102 16905 -197
- Misses 1560 1799 +239 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR makes prek install work correctly with Git worktrees and repo-scoped core.hooksPath configurations. Previously, prek would refuse to install when any core.hooksPath was detected. Now it distinguishes between externally-scoped (global/system) and repo-scoped (local/worktree) configurations, allowing the latter while still blocking the former for safety.
Changes:
- Allow installation when
core.hooksPathis set at local or worktree scope, while maintaining safety check for global/system scope - Use
git rev-parse --git-path hooksto resolve the effective hooks directory when repo-scoped hooksPath is configured - Add comprehensive test coverage for local and worktree-scoped hooksPath scenarios
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/prek/tests/install.rs | Adds two new tests: one for local hooksPath and one for worktree-scoped hooksPath with shared config preservation |
| crates/prek/src/git.rs | Adds get_git_hooks_dir() to resolve effective hooks directory and has_repo_hooks_path_set() to check for repo-scoped config |
| crates/prek/src/cli/install.rs | Updates install logic to check for repo-scoped hooksPath and use get_git_hooks_dir() when appropriate |
Comments suppressed due to low confidence (1)
crates/prek/src/cli/install.rs:49
- The error message is misleading now that local and worktree-scoped
core.hooksPathare allowed. The message suggests unsetting local hooksPath withgit config --unset-all --local core.hooksPath, but local hooksPath is now intentionally supported by this PR. Consider updating the error message to clarify that only global/system scoped hooksPath is problematic, or provide more accurate guidance.
anyhow::bail!(
"Cowardly refusing to install hooks with `core.hooksPath` set.\nhint: Run these commands to remove core.hooksPath:\nhint: {}\nhint: {}",
"git config --unset-all --local core.hooksPath".cyan(),
"git config --unset-all --global core.hooksPath".cyan()
);
| Ok(()) | ||
| } | ||
|
|
||
| #[test] |
There was a problem hiding this comment.
Missing test coverage for the safety check that prevents installation when global or system-scoped core.hooksPath is set. The existing tests only cover allowed scenarios (local and worktree scopes). Consider adding a test that sets global hooksPath and verifies that prek install still refuses to proceed with the "Cowardly refusing" error message. This ensures the safety mechanism isn't accidentally broken.
| #[test] | |
| #[test] | |
| fn install_with_global_core_hooks_path_fails() -> anyhow::Result<()> { | |
| let context = TestContext::new(); | |
| context.init_project(); | |
| git_cmd(context.work_dir()) | |
| .arg("config") | |
| .arg("--global") | |
| .arg("core.hooksPath") | |
| .arg(".global-hooks") | |
| .assert() | |
| .success(); | |
| cmd_snapshot!(context.filters(), context.install(), @r#" | |
| success: false | |
| exit_code: 1 | |
| ----- stdout ----- | |
| ----- stderr ----- | |
| Cowardly refusing to install hooks because `core.hooksPath` is set globally or system-wide. | |
| "#); | |
| Ok(()) | |
| } | |
| #[test] |
📦 Cargo Bloat ComparisonBinary size change: +0.00% (23.8 MiB → 23.8 MiB) Expand for cargo-bloat outputHead Branch ResultsBase Branch Results |
Summary
core.hooksPath(global/system), but allow install whencore.hooksPathis set in repo scopes (--localor--worktree)git rev-parse --path-format=absolute --git-path hookswhen repo-scoped hooksPath is configured, soprek installwrites to the effective hooks directory in linked worktreesWhy
Integrations using linked worktrees currently need custom wrapper logic around
prek installduecore.hooksPathhandling. This change makesprek installwork directly with repo-scoped hooksPath settings, reducing downstream complexity.Refs: #1672
Verification
cargo test -p prek --test install install_with_core_hooks_path_setcargo test -p prek --test install install_in_worktree_uses_worktree_hooks_pathHOME=/tmp/prek-test-home XDG_CONFIG_HOME=/tmp/prek-test-xdg cargo test -p prek --test installCreated by OpenCode on behalf of @schickling.