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
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.linkSyncto create hard links from the source-controlled hook scripts into.git/hooks. However, this approach fails on Windows in several common scenarios, such as:.gitare 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:
EXDEVorEPERM, it falls back to copying the hook file usingfs.copyFileSync, ensuring the hook is still installed and functional.This change makes
npm run setup-hooksreliable 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.