fatal: cannot run .husky/pre-commit: No such file or directory on Mac-os
Filiphasan opened this issue ยท 7 comments
Version
0.5.4
Details
Hi, i have an issue for v0.5.4, my project already has pre-commit file in .husky folder
My pre-commit file is
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
#Run the command group in .husky/task-runner.json
dotnet husky run --group pre-commit
#Allow Committing
exit 0
My task-runner.json file is
{
"tasks": [
{
"name": "dotnet-format",
"group": "pre-commit",
"command": "dotnet",
"args": ["dotnet-format", "--include", "${staged}"],
"include": ["**/*.cs", "**/*.vb"]
}
]
}
My .confif/dotnet-tool.json file is
{
"version": 1,
"isRoot": true,
"tools": {
"husky": {
"version": "0.5.4",
"commands": [
"husky"
]
},
"dotnet-format": {
"version": "5.1.250801",
"commands": [
"dotnet-format"
]
}
}
}
Steps to reproduce
- I am on a branch with Husky installed in my project.
- Then, I switch to a branch without Husky installation.
- When I switch back to a branch with Husky installed and commit anything than I encounter this error.
- fatal: cannot run .husky/pre-commit: No such file or directory
It gives this error in different situations sometimes as well. For instance, I clone the project from scratch and then face this issue on a branch with Husky already installed. As far as I can understand, I encounter this error when changing branches locally.
Hi @Filiphasan,
Have you attached husky to one your projects? if not if you switch to a repo/branch that doesn't have all the husky files, you might encounter similar errors.
or just check if you manually install husky again, would it fix the problem?
I tried to reproduce the error but it is working on my two machines.
Hi @alirezanet
I manually configured the Husky for my project with the following tag in my .csproj file. I am experiencing the issue on macOS. When I tried it on Windows, I didn't encounter any problems. Thank you for your support.
<Target Name="husky" AfterTargets="Build" Condition="'$(HUSKY)' != 0">
<Exec Command="dotnet tool restore" WorkingDirectory="../" />
<Exec Command="dotnet husky install" WorkingDirectory="../" />
</Target>
Oh Unfortunately at the moment I only can test it in Linux/Windows operating systems, can you please verify if your git pre-commit hook have required permissions and it is executable on mac after installing husky? git hooks should have +x
permission
Yes, i have already +x permission
ls -l .husky/pre-commit
-rwxr-xr-x@ 1 hasan.erdal staff 162 Aug 25 11:20 .husky/pre-commit
well normally you have it, but I mean check it when you've faced the error... since the error message is:
fatal: cannot run .husky/pre-commit: No such file or directory
I think either the hook is missing for some reason or the hook doesn't have permission.
Hi @alirezanet,
I found the cause of my issue. My project has .gitattributes file for end-of-line settings and in this file there is "* text eol=crlf" settings for all files.
My old .gitattributes file
# Set end-of-line to CRLF for All files.
* text eol=crlf
And now
# Set end-of-line to CRLF for All files.
* text eol=crlf
# Exclude files or folders
.husky/** -text
This changes has solved my "fatal: cannot run .husky/pre-commit: No such file or directory" issues.
Thanks for your support
Hi @Filiphasan,
thank you for letting me know, happy that you've managed to solve the problem. ๐