Install once, run everywhere.
Install the Hook Script Runner module in an existing project:
$ npm install --save-dev hook-script-runner
Add some commands to your package.json file:
{
"hooks": {
"commit-msg": "echo 'What would Tim Pope do?'",
"pre-commit": [
"npm test -s",
"npm run lint -s"
]
}
}
These can be anything you want so long as it's executable inside your curent environment. Each hook name will accept either a string or an array of strings. If multiple commands are provided they will be run in order.
You can test your setup by either triggering a Git event (e.g. authoring a commit in the above example) or simply by running them as they're just executables after all:
$ ./.git/hooks/commit-msg
What would Tim Pope do?
Good question.
The following hooks can be disabled by passing the --no-verify
option to
git commit
:
- commit-msg
- pre-commit
During the installation process your project's local .git/hooks/
directory is
backed up to .git/hooks.save/
and symlinked to a directory provided by this
module.
To uninstall:
- Remove the module:
rm -rf node_modules/hook-script-runner
- Reset your local Git directory:
rm .git/hooks # Delete the symlink
mv .git/hooks.save .git/hooks # Restore the original hooks directory
- Clean up your package.json file if you added anything.
For a list of all available hooks and a detailed description of each see Git's
documentation online or off: man githooks
.
For a more in-depth look at the hook system, check out these articles:
-
Pro Git
-
Atlassian Tutorials
-
Digital Ocean Community
How To Use Git Hooks To Automate Development and Deployment Tasks
To get started you'll need at least Node.js v0.12.x.
There's an outstanding issue with npm calling the "preinstall" script on
npm install
. You'll want to bypass scripts on install:
$ npm install --ignore-scripts
MIT