Open jods4 opened 4 months ago
Hi @jods4,
have you tried using the install's --dir
option, you can move your .husky folder to the subdirectories if needed, just for the first time installing husky to the git repository you have to do it from the root folder. (if you don't want to add the .config folder in your root folder, you can install husky.net globally ). maybe I'm missing the point, in that case would be nice if you could provide a test project with your desired layers/folders ...
Thanks for the quick answer!
--dir
doesn't help. I'm ok with having the folder at the root next to .git
, or lower in Source
. Both would be fine.
husky install
does not even run because of this safety guard: https://github.com/alirezanet/Husky.Net/blob/master/src/Husky/Cli/InstallCommand.cs#L73-L79
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! 🥂"]
}
}
]
}
What mostly works is installing Husky.Net into the root folder
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 :(
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).