Skip to content

Commit

Permalink
Execute locally configured pre-commit hooks (#39784)
Browse files Browse the repository at this point in the history
* Execute locally configured pre-commit hooks

This change enables users to add and execute locally configured pre-commit hookly configured pre-commit hooks. Previously this was not possible because kibana bootstrap installs its own pre-commit in the `.hooks` folder.

To add a locally configured pre-commit hook, simply create a `.pre-commit` file in the root folder. Kibana's pre-commit hook will check if this file exists and if it does, execute it.

* Address review feedback

* remove GIT_PARAMS, because https://git-scm.com/docs/githooks#_pre_commit
  • Loading branch information
dgieselaar authored Jul 1, 2019
1 parent c2a14e7 commit d4cd8d2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/dev/register_git_hook/register_git_hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ function getKbnPrecommitGitHookScript(rootPath, nodeHome, platform) {
# PLEASE RE-RUN 'yarn kbn bootstrap' or 'node scripts/register_git_hook' IN THE ROOT
# OF THE CURRENT PROJECT ${rootPath}
set -euo pipefail
# pre-commit script takes zero arguments: https://git-scm.com/docs/githooks#_pre_commit
# Export Git hook params
export GIT_PARAMS="$*"
set -euo pipefail
has_node() {
command -v node >/dev/null 2>&1
Expand Down Expand Up @@ -111,7 +110,16 @@ function getKbnPrecommitGitHookScript(rootPath, nodeHome, platform) {
exit 1
}
node scripts/precommit_hook || {
execute_precommit_hook() {
node scripts/precommit_hook
PRECOMMIT_FILE="./.git/hooks/pre-commit.local"
if [ -x "\${PRECOMMIT_FILE}" ]; then
echo "Executing local precommit hook found in \${PRECOMMIT_FILE}"
"$PRECOMMIT_FILE"
fi
}
execute_precommit_hook || {
echo "Pre-commit hook failed (add --no-verify to bypass)";
echo ' For eslint failures you can try running \`node scripts/precommit_hook --fix\`';
exit 1;
Expand Down

0 comments on commit d4cd8d2

Please sign in to comment.