Skip to content

Pre-commit hook fails to find the plugin script in a linked worktree - #391

Merged
reda-alaoui merged 3 commits into
masterfrom
linked-worktree-pre-commit-hook
Sep 30, 2026
Merged

reda-alaoui merged 3 commits into
masterfrom
linked-worktree-pre-commit-hook

Conversation

@reda-alaoui

@reda-alaoui reda-alaoui commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Fixes #390

Before, from a linked worktree:

  • The pre-commit base script looked for the plugin script under $(git rev-parse --git-dir)/hooks, which is .git/worktrees/<name>/hooks. That directory holds no hooks, so the commit failed.
  • install-hooks run from a worktree wrote the hooks to that same unused directory.
  • The plugin script ran Maven on the absolute pom path of the checkout that installed the hooks, so it formatted that checkout instead of the worktree being committed.

Now:

  • The hooks are installed in $(git rev-parse --git-common-dir)/hooks, where git runs them from, and the base script looks for the plugin script there. Reinstalling removes the former --git-dir call from existing base scripts.
  • The plugin script resolves the pom and the maven wrapper against $(git rev-parse --show-toplevel), the worktree being committed. A maven installation outside the repository keeps its absolute path.
  • gitBaseDir() returns the work tree, instead of the parent of the git directory (.git/worktrees in a worktree).

WorktreeTest commits from a real linked worktree, with the hooks installed from the main checkout and from the worktree.

@reda-alaoui
reda-alaoui marked this pull request as ready for review September 30, 2026 00:05
@reda-alaoui
reda-alaoui merged commit 0e37188 into master Sep 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pre-commit hook fails to find the plugin script in a linked worktree

1 participant