Opinionated set of git hooks.
At the moment supports JavaScript, CSS, shell scripts and markdown files.
npm install --save-dev @saji/git-hooks
- Add
git-install-hooks
to yourpostinstall
script
npm install -g @saji/git-hooks
- Run
git-install-hooks PATH_TO_YOUR_PROJECT
- Clone this repository anywhere
- Run
YOUR_ANYWHERE/install.sh PATH_TO_YOUR_PROJECT
- Clone this repository anywhere
- Run
git config core.hooksPath YOUR_ANYWHERE
(usegit config --global
if you want to do it globally)
You may also use git submodules. Or download files, drop them in your
.git/hooks
, I don’t care.
git config --type=int hooks.$HOOK_NAME.enabled false
# e.g. hooks.lint.enabled
You can also disable a hook for single run, e.g.
git -c hooks.npm-test.enabled=false push
As a shorthand you can omit .enabled
:
git -c hooks.npm-test=false push
Apart from passing --no-verify
you can also use hooks.enabled
config option.
git config --type=int hooks.verbosity 2
- -1: Only error messages
- 0: Also show celebratory success message (default)
- 1: Also print hook names as they run
- 2: Also print hook execution time after they finish.
- 7: Also print main commands for some hooks
- 9: Also run everything with
set -x
(TODO) If not specified in config, verbosity is controlled by number
of -v
parameter(s) passed to git-commit.
git config --type=bool hooks.tmpWorkspace true
Some hooks might run for a longer time (e.g. npm-test pre-push). With
this option enabled, they might choose to run in a temporary worktree
(see git worktree --help
for details) so that your main worktree is
not blocked — you can switch branches, commit etc. while your tests
run.
Detects if jest is being used for testing and if so, only runs tests that are related to modified files, but that heuristic is not perfect. This option enables you to additionally always run selected tests, e.g.
git config hooks.pre-push.npm-test.forcedFiles tests/storybook.test.js
Allows to set up a extended grep regular expression to match branches when pushing.
git config hooks.pre-push.branch-name.allow-regexp '^(feature|fix|doc|chore)/'
You don’t have to list your main branch.