- git version should be above 2.9
$ git --version
git version 2.9.0.windows.1-
Install husky into
package.jsonas a dev dependency$ npm install --save-dev husky -
Initialize the repository with below command:
$ npx husky initThis will create a./.huskydirectory where we can have our hook scripts and add prepare topackage.jsonas like below.
"scripts": {
//other commands here
"prepare": "husky"
}-
Verify if you are getting the path of the hook.
$ git config --local core.hooksPath$ git config --global core.hooksPath$ git config core.hooksPath -
To set the
core.hooksPathuse below command:$ git config core.hooksPath .husky
-
On running
npm run preparethe hooksPath should change to$ git config core.hooksPath ./.husky/_ -
In your custom hook file (pre-commit here) you can add below like commands
echo "Woof-woof by husky! Running pre-commit hook"
npm run lint:fix
npm run format
npm run test-
On running
npm run preparethe hooksPath should change to$ git config core.hooksPath ./frontend/webapp/.husky/_ -
In your custom hook file (pre-commit here) you can add below like commands
echo "Woof-woof by husky! Running pre-commit hook"
cd ./frontend/webapp/
npm run lint:fix
npm run format
npm run testNote: If you want to unset the hooksPath
$ git config --unset core.hooksPath