Hooks - GradedJestRisk/git-training GitHub Wiki
Hooks
Doc
https://git-scm.com/docs/githooks
List:
- post checkout
- pre-commit
- pre-push
https://git-scm.com/docs/githooks
Pre-commit
See also NodeJs
Post checkout
https://gist.github.com/sindresorhus/6465739
Install
#!/usr/bin/env bash
set -e
prevHEAD=$1
newHEAD=$2
checkoutType=$3
[ $checkoutType == 1 ](/GradedJestRisk/git-training/wiki/-$checkoutType-==-1-) && checkoutType='branch' || checkoutType='file' ;
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
[ $checkoutType = 'branch' ](/GradedJestRisk/git-training/wiki/-$checkoutType-=-'branch'-) && {
changed_files="$(git diff-tree -r --name-only --no-commit-id $prevHEAD $newHEAD)"
# node - use whichever works for you
check_run yarn.lock "yarn install"
# check_run package-lock.json "npm install"
# composer
check_run composer.lock "composer install"
}
Tools
To easy, you can use
- husky
- prem-commit (python)
pre-commit (python)
Generate configuration
pre-commit sample-config > .pre-commit-config.yaml
Install configuration
pre-commit install
Dry-run
pre-commit run --all-files