From ab2af87fe059abdd6fb11e83d83ffb98a8c56f29 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Tue, 31 Aug 2021 13:24:04 +0200 Subject: [PATCH] build: setup ng-dev format pre-commit hook Whenever a commit is being created, the `yarn ng-dev format changed` command is being executed. This means that the formatter does not need to be run manually. (cherry picked from commit 59002e1649123922df3532f4be78c485a73c5bc1) --- .husky/pre-commit | 11 +++++++++++ DEV_ENVIRONMENT.md | 15 +++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 000000000000..7c7220b3d4de --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,11 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +# Allow for the formatting command to fail without exiting the script. +set +e + +yarn -s ng-dev format staged 2>/dev/null + +if [ $? -ne 0 ]; then + echo "WARNING: failed to run file formatting (ng-dev format staged)" +fi \ No newline at end of file diff --git a/DEV_ENVIRONMENT.md b/DEV_ENVIRONMENT.md index dd897e26824c..e24b2e2ac045 100644 --- a/DEV_ENVIRONMENT.md +++ b/DEV_ENVIRONMENT.md @@ -64,3 +64,18 @@ packages locally and test them by either of the following ways: If you're making changes to a public API, they need to be propagated to our public API golden files. To save the changes you can run `yarn approve-api ` and to review the changes, you can look at the file under `tools/public_api_guard/.d.ts`. + + +### Disabling Git hooks + +If your development workflow does not intend the commit message validation to run automatically +when commits are being created, or if you do not want to run the formatter upon `git commit`, you +can disable any installed Git hooks by setting `HUSKY=0` in your shell environment. e.g. + +```bash +# .zshrc +export HUSKY=0 + +# .bashrc +export HUSKY=0 +``` \ No newline at end of file