typicode / husky

Git hooks made easy 🐶 woof!
https://typicode.github.io/husky
MIT License
32.44k stars 1.02k forks source link

husky v9 lint-staged not triggered on pre-commit #1447

Open chrisjbrown opened 4 months ago

chrisjbrown commented 4 months ago

Context Please describe your issue and provide some context:

husky 9.0.11 lint-staged 15.2.2

Used https://github.com/uulm-mrm/git_hooks to get a basic husky+lint-staged+prettier+eslint setup. If I run npx lint-staged myself in a terminal I see the expected scripts run but committing doesn't trigger the scripts and allows the commit to go through.

Running git config core.hooksPath outputs .husky/_ git --version output git version 2.45.1

troubleshooting section says to be on git 2.9 which feels like a mistake as 2.45.1 is latest

package.json

"scripts": {
    ....
    "prepare": "husky"
},
...
"lint-staged": {
    "*.js": "eslint --cache --fix",
    "*.{js,mjs,css,md,hbs}": "prettier --write"
}

.husky/pre-commit

npx lint-staged
ghost commented 4 months ago

I also had the same problem

orochi-kazu commented 4 months ago

Any chance your package.json isn't in the root directory of your repo?

I thought mine was broken (which is how I came across this issue), but then I found an adjusted config from a similar repo, and it's working fine now. My change is just "prepare": "cd .. && husky", but that may be irrelevant for you 🤔

shuo-hiwintech commented 3 months ago

I also had the same problem

vicasas commented 3 months ago

I have been facing the same issue where Husky's execution suddenly stops working without apparent reason.

After investigating in my repository, I noticed that this error occurs in all Husky hooks, specifically when the following scenario happens:

  1. I initialize a project with Git using git init.
  2. I install Husky in the project following the standard recommendation.
  3. I delete the .git folder from the project using the command rm -rf .git.
  4. I reinitialize Git in the project with git init.
  5. I try to execute a Husky hook, but I observe that it stops working immediately.

To temporarily solve this issue, the only effective measure I have found is to reinstall Husky every time the .git folder is deleted.

I hope these detailed steps clarify the issue I have been experiencing with Husky in my repository.

Lonli-Lokli commented 3 months ago

Happens when I manually migrated v8 -> v9

Lonli-Lokli commented 3 months ago

Seems like the problem is Linux\Windows separator issue. As part of migration Git config (located in .git/config file) has been changed, to reflect husky's simplified hooks path before

[core]
 hooksPath = .husky

after

[core]
 hooksPath = .husky\\_

So if I change hooks path to .husky/_ - everything started to work again