Search code examples
githusky

Why isn't my git pre-commit hook running?


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?


Solution

  • 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.