typicode / husky

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

HUSKY=0 in .env file does not disable Husky #1464

Closed rubenswieringa closed 1 month ago

rubenswieringa commented 1 month ago

Steps to reproduction:

  1. In a project with working pre-commit hooks, set HUSKY=0 in your project’s .env file

Expected results:

Actual results:


I’m running Husky v9.0.11 on the commandline (iTerm) if that matters. Setting HUSKY=0 inline on the commandline when I commit does disable Husky, but I was assuming that having it in my .env file would do the same too.

typicode commented 1 month ago

You can do it like this if you have a recent version of node:

node --env-file=.env ./node_modules/.bin/husky

Or

node --run prepare --env-file=.env

AFAIK there's no Node API that could be used from husky.

rubenswieringa commented 1 month ago

You can do it like this if you have a recent version of node:

node --env-file=.env ./node_modules/.bin/husky

This would be what you’d put in the package.json "prepare" script?

Would that only work if the project dependencies haven’t already been installed?

typicode commented 1 month ago

This would be what you’d put in the package.json "prepare" script? Would that only work if the project dependencies haven’t already been installed?

Yes to both. But that's also the case when "prepare": "husky". When prepare runs, dependencies have already been installed.

If you need to handle cases where husky is not installed (for example, in prod), check:

https://typicode.github.io/husky/how-to.html#ci-server-and-docker

rubenswieringa commented 1 month ago

Well the reason I asked is because it didn’t immediately make sense that the HUSKY environment-variable was only evaluated during install.

One of the developers on my team doesn’t like the pre-commit linting/formatting we have configured in our project (using husky) and it seemed safe to assume that adding HUSKY=0 with npm-dependencies already installed at an earlier point would work.

Do you reckon that

  1. adding node pre-commit.js to my pre-commit hook
  2. loading the local .env file from the .js file
  3. and calling lint-staged from the .js file too

…would be significantly slower?

typicode commented 1 month ago

I assumed you wanted to prevent install, but husky also support HUSKY=0 during commit (even if installed)

https://typicode.github.io/husky/how-to.html#skipping-git-hooks

The dev can disable husky permanently (or you can make it opt-in for your team)