Commit ba08995
committed
feat: fall back to main worktree config in linked worktrees
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 #710
Assisted-by: Claude:claude-sonnet-4-61 parent 61ab0e8 commit ba08995
1 file changed
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
543 | 543 | | |
544 | 544 | | |
545 | 545 | | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
546 | 577 | | |
547 | 578 | | |
548 | 579 | | |
| |||
0 commit comments