commitizen / cz-cli

The commitizen command line utility. #BlackLivesMatter
http://commitizen.github.io/cz-cli/
MIT License
16.7k stars 547 forks source link

Update Documentation for pre-commit hooks with Husky 5 #810

Open paulmboyce opened 3 years ago

paulmboyce commented 3 years ago

Hi commitizeners :)

I love using commitizen on my projects, and with husky hooks for pre-commit is great.

BUT... There is a new version of Husky, (Husky 5) which breaks how hooks are set up. That means the commitizen documentation is now out of date (because it only describes from Husky 4).

PROBLEM:

The commitizen documentation is out of date for Husky 5.

Main Differences:

In Husky 4, you add a husky hook to package.json and install commitizen and husky. Husky automatically registers the hook.

Now... in Husky 5, the hooks are added to separate files (NOT package.json)

SOLUTION:

Brief instructions follow, which I suggest to be added to the commitizen documentation.

Using Commitizen with Husky 5

Install husky:

npm install--save-dev husky

Then run this to add a pre commit message hook:

npx husky add .husky/prepare-commit-msg "exec < /dev/tty && git cz --hook || true"

Note, you will probably want to add the resulting hook file to git:

.husky/prepare-commit-msg

UPDATE: If your hooks don't run, you can tell Husky to install them:

npx husky install

Hope that is helpful!

Jack-Barry commented 3 years ago

I'd like to add to the suggestions here, since my request affects the same part of the docs. I'd like to request that the suggested script be changed from git cz to npx cz where possible - it simplifies things for the developer by making the pre-commit-msg hook work even if they haven't installed commitizen globally.

Totally understand if this is considered a separate issue, but figure since it's in a related area of the docs I'd note it here to begin with.

Thanks