Up until recently -- I only noticed this a couple days ago -- my git pre-commit hook was working. I'm writing a react app and using Husky, TSLint, and Prettier to clean and lint my code before committing. Now, when I change and commit files, the pre-commit hook doesn't run.
My project structure looks like this:
- project
- .git/
- react/ <- the frontend
- node_modules/
- src/
- package.json
- (other files)
- nodejs/ <- the server
- node_modules/
- src/
- package.json
- (other files)
- package.json
- (other files)
If I manually execute the hook, it seems to run fine:
[/project/react] # git status
On branch fixHusky
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: MyFile.ts
[/project/react] # ../.git/hooks/pre-commit
husky > pre-commit (node v12.6.0)
↓ Stashing changes... [skipped]
→ No partially staged files found...
✔ Running linters...
[/project/react] #
But when I actually try to commit, husky doesn't run:
[/project/react] # git commit -m "testing husky"
[fixHusky cf17a6b] testing husky
1 file changed, 1 insertion(+), 1 deletion(-)
[/project/react] #
Any idea why it isn't running?
Updating Husky by running yarn add --dev husky
fixed the problem. I have no idea why it stopped working, but husky was very out of date anyways.
Check if git config core.hooksPath has been set to a different path than its default: $GIT_DIR/hooks
Check also that GIT_DIR
(environment variable) is not currently set.
In both cases, Git would look for that hook not where you would expect (and currently have your pre-commit hook)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With