I am using npm precommit hook, but it is not stopping a file with issues to be committed, nor am I getting the message "Pre commit checks" when I try to commit a file.
Package Json:
{
"name": "myfolder",
"version": "1.0.0",
"description": "",
"main": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 0",
"precommit-msg": "echo 'Pre-commit checks...' && exit 0",
"lint": "csslint global/css"
},
"author": "SR",
"license": "ISC",
"dependencies": {
"csslint": "^1.0.4",
"jshint": "^2.9.4",
"pre-commit": "^1.2.2"
},
"pre-commit": [
"precommit-msg",
"lint"
],
"devDependencies": {
"pre-commit": "^1.2.2"
}
}
Meaning, simple shell scripts will work right off the bat. For example, the Git hook pre-commit that ships with an initialization of a Git repository can be run without any modification. Navigate to the Git hooks directory with the command cd .git\hooks This directory holds all the Git hook scripts. Create a file named pre-commit. Note:
The way npm test is configured, in the same way, any other tasks can be executed. And of course for other tasks stash and unstash won't be compulsory. Here is the GitHub repo with an example. Containers Vs Virtual Machines, which is better and why? If you have reached here, then I did a satisfactory effort to keep you reading.
For example, when using the Husky Git hook plugin for NPM, along with the Prettier formatter, the commands do not map 1-1. Meaning that your pre-commit Git hook will fail on Windows. A Git hook is an executable script; however, you are using a command prompt script ( .cmd) and not a shell script ( .sh ).
Please, make sure that your 'package.json' file is in the same folder, where '.git' folder is (where git repository was initialized). When you install 'pre-commit' package, 'pre-commit' file should appear under '.git/hooks/'.
Just FYI I had this issue because the pre-commit
file was missing in the hooks folder.
Running npm i pre-commit --save-dev
again created the file and solved it for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With