-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Support install not in .git root #103
Comments
Hi @jods4, |
Thanks for the quick answer!
|
I have a monorep with both an Angular app (/web) and a .Net solution (/api). What mostly works is installing Husky.Net into the root folder (with the .git directory). You can use "cwd" in some way to pick the part of the monorep you want. The prepare script of the Angular App (/web) installs/activates husky. I haven't figured out a way to "activate" Husky on the .NET side. Missing a monorep tool, I suppose. {
"tasks": [
{
"name": "dotnet-format",
"cwd": "api",
"group": "pre-commit",
"command": "dotnet",
"args": ["format", "--include", "${staged} --severity error"],
"include": ["**/*.cs", "**/*.vb"]
},
{
"name": "eslint",
"group": "pre-commit",
"pathMode": "absolute",
"cwd": ".",
"command": "npx",
"args": ["lint-staged", "-r", "--cwd", "web"],
"include": ["**/*.ts", "**/*.js"]
},
{
"name": "prettier",
"group": "pre-commit",
"pathMode": "absolute",
"cwd": ".",
"command": "npx",
"args": ["prettier", "--write", "${staged}"],
"include": [
"**/*.ts",
"**/*.vue",
"**/*.jsx",
"**/*.js",
"**/*.json",
"**/*.yml",
"**/*.css",
"**/*.scss"
]
},
{
"name": "Welcome",
"output": "always",
"command": "bash",
"args": ["-c", "echo Nice work! 🥂"],
"windows": {
"command": "cmd",
"args": ["/c", "echo Nice work! 🥂"]
}
}
]
} |
Yes, this is the requirement that I would like to see lifted with this issue. Depending on your repo structure, which may be outside your control, it's not always ok to add .net tools at the root of the repo. |
Having the same issue. We use monorepo, and have several .net solutions inside. So, whenever I try to add pre-commit hook it says that cannot find .git folder |
Details
Currently, husky checks that it's being installed in the repository root, i.e. cwd contains a
.git
folder.Some repository contain more than a .net solution, it's not uncommon to have other folders at root such as docs, infra, front-end, etc. In our setup, dotnet solution and
.config
local tools live in aSource
folder, under root.The issue with this is that:
Source
because they're local and do not exist outside of that folder.Source
because it requires.git
in the same folder where it runs.As 1. and 2. are mutually exclusive, there's no working configuration :(
Note
Husky -- the NPM project that inspired Husky.Net -- has a "How to" for this topic in its documentation:
https://typicode.github.io/husky/how-to.html#project-not-in-git-root-directory
Their solution is simply to change working directory appropriately in install script and hook.
The blocker is that whereas
cd .. & husky
works in NPM scripts, there's no way parameter to change the working directory indotnet run
, sohusky init
can't be run in a different cwd.Suggested solution
Add a
--cwd
parameter to install command, so that the working directory can be changed before it runs:The reverse
cd
command should be inferred automatically (usingPath.GetRelativePath
) and introduced in hook script so that they run in the correct folder (otherwisedotnet husky
& other local .net tool tasks will not be found).The text was updated successfully, but these errors were encountered: