-
Notifications
You must be signed in to change notification settings - Fork 13k
Fix: Robust Cross-Platform Fallback for Git Hook Linking in [link-hooks.mjs](cci:7://file:///d:/Github/TypeScript/scripts/link-hooks.mjs:0:0-0:0) #61858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ks.mjs](cci:7://file:///d:/Github/TypeScript/scripts/link-hooks.mjs:0:0-0:0) Previously, [scripts/link-hooks.mjs](cci:7://file:///d:/Github/TypeScript/scripts/link-hooks.mjs:0:0-0:0) attempted to install git hooks using `fs.linkSync` to create hard links from the source-controlled hook scripts into `.git/hooks`. However, this approach fails on Windows in several common scenarios, such as: - When the repository is on a FAT/FAT32 drive (no hard link support) - When the working copy and `.git` are on different volumes (`EXDEV`) - When the user lacks the required privileges (`EPERM`) This prevented contributors on such systems from setting up the required git hooks, blocking or complicating development and contribution. **This PR adds a robust fallback:** - The script first tries to create a hard link as before. - If it fails with `EXDEV` or `EPERM`, it falls back to copying the hook file using `fs.copyFileSync`, ensuring the hook is still installed and functional. - All other errors are still thrown to avoid masking real issues. This change makes `npm run setup-hooks` reliable on all platforms, improving the onboarding and contribution experience for Windows and cross-device users, while still preferring hard links where possible to keep hooks in sync. --- **Summary:** Gracefully fall back to copying git hook scripts if hard-linking fails, ensuring contributors on all platforms can set up hooks without errors.
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
@microsoft-github-policy-service agree |
@microsoft-github-policy-service agree |
I'm sorry, but none of the above is correct. |
Previously, scripts/link-hooks.mjs attempted to install git hooks using
fs.linkSync
to create hard links from the source-controlled hook scripts into.git/hooks
. However, this approach fails on Windows in several common scenarios, such as:.git
are on different volumes (EXDEV
)EPERM
)This prevented contributors on such systems from setting up the required git hooks, blocking or complicating development and contribution.
This PR adds a robust fallback:
EXDEV
orEPERM
, it falls back to copying the hook file usingfs.copyFileSync
, ensuring the hook is still installed and functional.This change makes
npm run setup-hooks
reliable on all platforms, improving the onboarding and contribution experience for Windows and cross-device users, while still preferring hard links where possible to keep hooks in sync.Summary:
Gracefully fall back to copying git hook scripts if hard-linking fails, ensuring contributors on all platforms can set up hooks without errors.