feat: fall back to main worktree config in linked worktrees#714
Open
KiaraGrouwstra wants to merge 1 commit into
Open
feat: fall back to main worktree config in linked worktrees#714KiaraGrouwstra wants to merge 1 commit into
KiaraGrouwstra wants to merge 1 commit into
Conversation
When using `git worktree add`, the linked worktree inherits `core.hooksPath` (pointing at the common git dir's hooks) but not the untracked `.pre-commit-config.yaml` symlink — that symlink is only created on shell entry via `installationScript`. Until then every `git commit` in the linked worktree fails with "No .pre-commit-config.yaml file was found". After `pre-commit install` writes the hook scripts, patch each one to splice a prelude after the shebang and rewrite the `--config=` literal in the `ARGS=` line to read from a variable resolved by that prelude. At hook runtime the prelude resolves the config path: 1. The current toplevel's `cfg.configPath` if present. 2. Otherwise, only in a linked worktree (detected by comparing `git rev-parse --git-dir` against `--git-common-dir`), the main worktree's config. 3. Otherwise `exit 0`. Behavior in the main worktree is unchanged: a missing config there still produces pre-commit's normal error. A marker comment makes the patch idempotent across repeated shell entries. Fixes cachix#710 Assisted-by: Claude:claude-sonnet-4-6
6a701a7 to
ba08995
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allows git worktrees to fall back to git hooks from their linked worktree.
Closes #710.
Assisted-by: Claude:claude-sonnet-4-6