You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been migrating a monorepo from lerna + yarn workspaces, and it had git hooks before, except they were implemented by husky. And husky change the hooks installation path to it's own.
And rush doesn't acknowledge the setting in any way, so if you're unaware that hooksPath is a thing, debugging is really unfun. It would be great if rush could check the setting, and either respect it and install the hooks where it says, or warn to run git config --unset core.hooksPath
This looks to be the case. Thanks Dmitrii Kartashev (@Faithfinder) for reporting this! I don't really have the bandwidth to take a look at this myself, but if you wanted to take a look/make a fix, here's a couple places to start:
In the below file, we find the target directory for the .git folder and install our hooks into there:
There's really a couple approaches, either querying for the core.hooksPath value and using that as our destination to install the hooks to, or setting the git hooks folder to the one where we currently keep our git hooks (common/git-hooks) and avoiding an install process of any kind (though, this may be an issue with husky if it's already tinkering with the core.hooksPath). When this functionality was implemented in Rush, it's likely this property in Git wasn't available.
I've been migrating a monorepo from lerna + yarn workspaces, and it had git hooks before, except they were implemented by husky. And husky change the hooks installation path to it's own.
I see. In the past, Husky would use a postinstall script to wire up a bunch of Node.js script stubs under .git/hooks/*. As of Husky 7, it appears that they changed their strategy to leverage the new core.hooksPath setting to relocate the hooks path:
The setting is written into <repo>/.git/config on the developer's local machine
As Dmitrii Kartashev (@Faithfinder) pointed out, this setting persists between branches, even after Husky has been removed from your repo
My first thought was that Rush should simply query core.hooksPath and honor it. However... that seems problematic:
What if the hook scripts use relative paths that assume that they are installed under .git/hooks/pre-commit instead of .husky/pre-commit?
Or what if core.hooksPath is pointing to some unusual path outside the repo? (Git's docs suggest a use case where you’d like to centrally configure your Git hooks instead of configuring them on a per-repository basis.)
I wonder if it would be better for Rush to warn the user to do git config --unset core.hooksPath. To ensure deterministic behavior, that's probably what we'd prefer for a CI machine to do if there was a concern that Husky might have been invoked by someone's branch on that machine.
I'll defend the "honor the setting" approach, since that's what my PR does.
Both question are, basically, about relative paths.
I'm not sure it's reasonable for rush to concern itself with how people write their hooks. If the specific monorepo wants the hooks to be in a specific location, it can write an "Am I in the right place?" check at the beginning of the script.
And if it's a migration from another tool, like my case, then I can guarantee that whoever does the migration has to, anyway:
provide instructions for developers on how to work in the new world.
Rewrite the hooks from husky, since it's syntax is different anyway
The person doing the migration should check that their hooks are working. Since my PR now shows where they are installed, they have information they need to debug. They can either give an instruction to developers to unset the variable, or update the hook scripts to warn about non-standard location.
Activity
D4N14L commentedon Nov 4, 2021
This looks to be the case. Thanks Dmitrii Kartashev (@Faithfinder) for reporting this! I don't really have the bandwidth to take a look at this myself, but if you wanted to take a look/make a fix, here's a couple places to start:
In the below file, we find the target directory for the
.gitfolder and install our hooks into there:rushstack/apps/rush-lib/src/logic/base/BaseInstallManager.ts
Line 317 in 15222e4
There's really a couple approaches, either querying for the
core.hooksPathvalue and using that as our destination to install the hooks to, or setting the git hooks folder to the one where we currently keep our git hooks (common/git-hooks) and avoiding an install process of any kind (though, this may be an issue withhuskyif it's already tinkering with thecore.hooksPath). When this functionality was implemented in Rush, it's likely this property in Git wasn't available.octogonz commentedon Nov 9, 2021
I see. In the past, Husky would use a
postinstallscript to wire up a bunch of Node.js script stubs under.git/hooks/*. As of Husky 7, it appears that they changed their strategy to leverage the newcore.hooksPathsetting to relocate the hooks path:<repo>/.git/configon the developer's local machineMy first thought was that Rush should simply query
core.hooksPathand honor it. However... that seems problematic:.git/hooks/pre-commitinstead of.husky/pre-commit?core.hooksPathis pointing to some unusual path outside the repo? (Git's docs suggest a use case where you’d like to centrally configure your Git hooks instead of configuring them on a per-repository basis.)I wonder if it would be better for Rush to warn the user to do
git config --unset core.hooksPath. To ensure deterministic behavior, that's probably what we'd prefer for a CI machine to do if there was a concern that Husky might have been invoked by someone's branch on that machine.Faithfinder commentedon Nov 9, 2021
I'll defend the "honor the setting" approach, since that's what my PR does.Both question are, basically, about relative paths.
I'm not sure it's reasonable for
rushto concern itself with how people write their hooks. If the specific monorepo wants the hooks to be in a specific location, it can write an "Am I in the right place?" check at the beginning of the script.And if it's a migration from another tool, like my case, then I can guarantee that whoever does the migration has to, anyway:
husky, since it's syntax is different anywayThe person doing the migration should check that their hooks are working. Since my PR now shows where they are installed, they have information they need to debug. They can either give an instruction to developers to unset the variable, or update the hook scripts to warn about non-standard location.
The PR discussion is more relevant