husky: hook was ignored because it's not set as executable
Context I get following error on Mac/Linux machines:
hint: The '.husky/pre-commit' hook was ignored because it's not set as executable.
hint: You can disable this warning with git config advice.ignoredHook false.
STR I added husky 7 on Windows according to the recommendations. Then I committed all changes to git and updated on other machine (Mac/Linux). I ran yarn update, which caused โprepareโ script to run (husky install). then I tried to change something and commit, which showed me above errors and didnโt execute hooks.
Expected behavior: Husky should somehow prepare all related files to automatically work on any platform without additional manual steps, like chmod
Thank you!
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 13
- Comments: 23 (1 by maintainers)
Commits related to this issue
- ci: change permission of .husky files https://github.com/typicode/husky/issues/1177 — committed to XavierChevalier/labeilleviennoise by deleted user 2 years ago
- ci: change permission of .husky files https://github.com/typicode/husky/issues/1177 — committed to XavierChevalier/labeilleviennoise by deleted user 2 years ago
- fix: change file permission of .husky/post-merge script (#533) Changed the permission of .husky/post-merge script file to make executable https://github.com/typicode/husky/issues/1177#issuecomment-1... — committed to sendbird/sendbird-uikit-react by AhyoungRyu a year ago
- ๐ฆ Chore: ํ๋ก์ ํธ ์ด๊ธฐ ์ธํ eslint rule no-unused-vars ์ ๊ฑฐ์์ ์ ์ฉ์ผ๋ก ๋ณ๊ฒฝ ํ sample.ts ์์ git hook ์ด์์ฒด์ ๊ฐ ์ด์๋ก ์ธํด husky ์์ ์ฐธ์กฐ: (https://github.com/typicode/husky/issues/1177) — committed to Chagok-Integrated-for-DevProject/Chagok-Frontend by aggie97 a year ago
- ๐ฆ Chore: ํ๋ก์ ํธ ์ด๊ธฐ ์ธํ eslint - type import ๊ตฌ๋ถ์ ์ํ consistent-type-imoprts ์ค์น ๋ฐ ์ ์ฉ package.json - next lint --fix ๊ตฌ๋ฌธ ์ถ๊ฐ ์ฌ์ฉํ์ง ์๋ ํ์ผ ์ญ์ - global.css - Home.moudle.css ํ๋ก์ ํธ์ ํ์ํ ํด๋ ๊ตฌ์กฐ ์์ฑ ๋ฐ samp... — committed to Chagok-Integrated-for-DevProject/Chagok-Frontend by aggie97 a year ago
- fix: chmod ug+x .husky/pre-commit after writing structure (#719) ## PR Checklist - [x] Addresses an existing open issue: fixes #718 - [x] That issue was marked as [`status: accepting prs`](https... — committed to JoshuaKGoldberg/create-typescript-app by JoshuaKGoldberg 10 months ago
- ๐ฆ Chore: ํ๋ก์ ํธ ์ด๊ธฐ ์ธํ eslint - type import ๊ตฌ๋ถ์ ์ํ consistent-type-imoprts ์ค์น ๋ฐ ์ ์ฉ package.json - next lint --fix ๊ตฌ๋ฌธ ์ถ๊ฐ ์ฌ์ฉํ์ง ์๋ ํ์ผ ์ญ์ - global.css - Home.moudle.css ํ๋ก์ ํธ์ ํ์ํ ํด๋ ๊ตฌ์กฐ ์์ฑ ๋ฐ samp... — committed to Chagok-Integrated-for-DevProject/Chagok-Frontend by aggie97 a year ago
- :bug: Fix: GoogleOAuthProvider ์์น ๋ณ๊ฒฝ * Chore/ci-cd (#2) CI/CD ๊ตฌ์ถ 1. .github/workflows/* => github action 2. scripts/* => EC2 shell script (Code Deploy hook) 3. appSpec.yml => CodeDeploy ๋์ ์ ์ 4... — committed to Chagok-Integrated-for-DevProject/Chagok-Frontend by cgh96 10 months ago
- :bug: Fix: GoogleOAuthProvider ์์น ๋ณ๊ฒฝ * Chore/ci-cd (#2) CI/CD ๊ตฌ์ถ 1. .github/workflows/* => github action 2. scripts/* => EC2 shell script (Code Deploy hook) 3. appSpec.yml => CodeDeploy ๋์ ์ ์ 4... — committed to Chagok-Integrated-for-DevProject/Chagok-Frontend by cgh96 10 months ago
I had that problem in WSL after init on Windows 11. This is a scenario similar to the issue you raised.
I also posted an answer on stackoverflow, but I was able to solve it with the command below. If you commit after reflecting once, the problem does not occur continuously.
I think itโs probably a problem that wasnโt created taking into account the file permissions of Linux at the time of init on Windows.
chmod works, but it is not normal solution. It is trick. We all work under different OSs and tool should work correctly under each of them and tool setup should be portable among them by simple commit/checkout. The only acceptable one is some sort of automatic post-tune that automatically finds the error and fixes it (and maybe requests to commit changes).
It solved my problem
After doing some research, this seems to be because Windows does not keep track of the executable bit of a file.
When a git commit hook created by
husky
on a Windows computer is run on a Linux computer, it does not work due to differences in file permission handling between the two systems. In particular, Windows does not keep track of the executable bit of a file, whereas Unix-based systems rely on this information to determine whether a file can be executed as a program.Although Git on Windows does keep track of the executable bit, it is not being set properly on Windows systems. After committing (or staging) a new husky hook file you can see that the file is missing the executable bit
644 is equivalent to
-rw-r--r--
For the commit hook file to work on Unix systems, we need the file to have a permission mode of 755 (equivalent to
-rwxr-xr-x
).When
husky
creates a new commit hook file, it actually sets the permission mode to 755https://github.com/typicode/husky/blob/3c0e08d3ca4d01d04ebb92089e68c47e131ab6be/src/index.ts#LL70-L78C4
But, since Windows does not keep track of the executable bit, the executable bit gets lost, it is not written to the git repo, and the commit hook files will be missing the bit when the repo is cloned onto a Unix system.
The fix for existing projects is to set the file using the
git update-index
command. The previous commit hook file would be fixed as follows:For those wondering if project will be cloned and run as expected, add this second step to husky install script :
chmod ug+x .husky/*
^ this really can fixed but only for one time, โhook was ignored because itโs not set as executableโ error appears again once I run commit on second time.
update: i able to solve it by
git update-index --chmod=+x .husky/pre-commit
After doing chmod chmod ug+x .husky/* Iโm getting (after committing) env: sh\r: No such file or directory
chmod u+x .husky/*
with nog
was enough for me, see https://askubuntu.com/q/518259/792595.@parkgang had same issue on macbook
fixed my problem
The issue persists on macOS 13.2, VSCode 1.75.1, husky ^8.0.1.
git update-index --chmod=+x .husky/pre-commit
it doesnโt work for me. You mean if I try this only once, I donโt have to dochmod ug+x .husky/*
every time?@d-belic @40x To resolve
env: sh\r: No such file or directory
issue:Sometimes when files are transferred between different operating systems, the line endings can get converted to the wrong format, which can cause issues with shell scripts. Running dos2unix on the affected files is a quick and easy way to fix the line ending format and ensure that shell scripts can be executed without errors.
In my case, it was a transfer from Windows to MacOS.
This helped me:
brew install dos2unix
.sh
files in repo:find . -type f -name '*.sh' -exec dos2unix {} \;
dos2unix .husky/pre-commit
Hope itโll help you.
Hello!
I had the same issue since last week, on Windows with WSL2, on projects with many collaboratorsโฆ I tried several things, but the only one is worked for me, is using
chmod ug+x .husky/*
onmain
branch. Git get the mode change and update it. Itโs working with all others branchs, for everyone.@d-belic did you fix this issue?
same for me. but i tried to install the husky to my Mac machine, it works fine on both Mac and Windows
same for me. i initiated the setup in windows, but when moved to mac. the setup was not executable by default. this is really annoying since we are in the team each has different operating system.
https://stackoverflow.com/questions/8598639/why-is-my-git-pre-commit-hook-not-executable-by-default hope to help for you. @yury-tk
also for author. copy the git hook sample and change file. not create hook file