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:
parent
a21b336138
commit
2b60ce484e
|
@ -7,10 +7,24 @@
|
||||||
# Based on clang-format pre-commit hook by Alex Eagle
|
# Based on clang-format pre-commit hook by Alex Eagle
|
||||||
# https://gist.github.com/alexeagle/c8ed91b14a407342d9a8e112b5ac7dab
|
# https://gist.github.com/alexeagle/c8ed91b14a407342d9a8e112b5ac7dab
|
||||||
|
|
||||||
# Set KICAD_CHECK_FORMAT to allow this hook to run
|
# Set kicad.check-format to allow this hook to run
|
||||||
# if not set, the hook always succeeds.
|
# If not set, the hook always succeeds.
|
||||||
if [ -z "$KICAD_CHECK_FORMAT" ]; then
|
|
||||||
exit 0
|
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
|
fi
|
||||||
|
|
||||||
check_clang_format() {
|
check_clang_format() {
|
||||||
|
|
|
@ -70,9 +70,13 @@ Set the `git clang-format` tool to use the provided `_clang-format` file:
|
||||||
|
|
||||||
git config clangFormat.style file
|
git config clangFormat.style file
|
||||||
|
|
||||||
Then, to enable the format checker, set the `KICAD_CHECK_FORMAT` environment
|
Then, to enable the format checker, set the `kicad.check-format` Git config
|
||||||
variable in your shell. Without this variable, the format checker will not
|
to "true" for the KiCad repo:
|
||||||
run on commit, but you can still check files staged for commit manually:
|
|
||||||
|
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
|
tools/check_coding.sh --diff
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue