Formatting: prefer a Git config variable to env var

The keeps all the formatting config together in the Git ecosystem
and keeps the config on a per-repo basis, unless the user explicitly
sets it --global.

Keep the old env var behaviour for now for backwards compatibility.

(cherry picked from commit a7270f8c1c)
This commit is contained in:
John Beard 2019-03-29 14:46:10 +00:00
parent a21b336138
commit 2b60ce484e
2 changed files with 25 additions and 7 deletions

View File

@ -7,10 +7,24 @@
# Based on clang-format pre-commit hook by Alex Eagle
# https://gist.github.com/alexeagle/c8ed91b14a407342d9a8e112b5ac7dab
# Set KICAD_CHECK_FORMAT to allow this hook to run
# if not set, the hook always succeeds.
if [ -z "$KICAD_CHECK_FORMAT" ]; then
exit 0
# Set kicad.check-format to allow this hook to run
# If not set, the hook always succeeds.
do_format=false
# Check if formatting is configured
if [ "$(git config --get kicad.check-format)" = true ]; then
do_format=true
fi
# Older env variable method
if [ ! -z "$KICAD_CHECK_FORMAT" ]; then
do_format=true
fi
if [ ! ${do_format} = true ]; then
# No formatting required
exit 0;
fi
check_clang_format() {

View File

@ -70,9 +70,13 @@ Set the `git clang-format` tool to use the provided `_clang-format` file:
git config clangFormat.style file
Then, to enable the format checker, set the `KICAD_CHECK_FORMAT` environment
variable in your shell. Without this variable, the format checker will not
run on commit, but you can still check files staged for commit manually:
Then, to enable the format checker, set the `kicad.check-format` Git config
to "true" for the KiCad repo:
git config kicad.check-format true
Without this config, the format checker will not run on commit, but you can
still check files staged for commit manually:
tools/check_coding.sh --diff