Skip to content

[rush] Install Git hooks where Git reads them in linked worktrees - #6248

Open
Ultranmus (Ultranmus) wants to merge 1 commit into
microsoft:mainfrom
Ultranmus:fix-worktree-git-hooks
Open

Ultranmus (Ultranmus) wants to merge 1 commit into
microsoft:mainfrom
Ultranmus:fix-worktree-git-hooks

Conversation

@Ultranmus

Copy link
Copy Markdown

Summary

When rush install or rush update runs in a linked Git worktree, Rush copies common/git-hooks into the worktree's own Git folder (<common-git-dir>/worktrees/<name>/hooks). Git never reads hooks from there, so in that setup the hooks never run and commits skip them without any warning.

Rush now installs the hooks in <common-git-dir>/hooks, which is where Git reads them and what getIsHooksPathDefaultAsync() already treats as the default.

Fixes #6246

Details

  • Git.getHooksFolder() returns the hooks folder of commonGitDir instead of worktreeGitDir. In a normal clone the two are the same folder, so nothing changes there.
  • Since the hooks folder is now shared by all worktrees, the wrapper no longer points at the scripts of the worktree that ran rush install. It finds them from git rev-parse --show-toplevel, so each worktree runs its own common/git-hooks scripts, and removing the worktree that installed them doesn't silently disable the hooks for the others. The path from the repo root to common/git-hooks comes from getRepoRoot().

How it was tested

  • Added a unit test for getHooksFolder() in a linked worktree; it fails before the change.
  • Built rush-lib and ran its tests. Git, BaseInstallManager, PublishGit and InstallAction pass. The TarExecutable and OperationBuildCacheDeferredWrites tar tests fail on my macOS machine on main as well.
  • Manually: a bare clone with two worktrees (git -C bare worktree add ...), with the new wrapper in bare/hooks/pre-commit. git rev-parse --git-path hooks returns bare/hooks, and committing in each worktree (also from a subfolder) ran that worktree's own common/git-hooks/pre-commit.

@Ultranmus

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@github-project-automation github-project-automation Bot moved this to Needs triage in Bug Triage Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs triage

Development

Successfully merging this pull request may close these issues.

[rush] Git hooks installed into the per-worktree folder never run in linked worktrees

1 participant