This repository contains shared repository Git hooks for shell scripts in
githooks/*
to be used with the
Githooks Manager.
The following is included:
- Hook to format C++ files with
clang-format
(pre-commit). A configuration file to use in your repository isconfig/.clang-format
. - Hook to format CMake files with
cmake-format
(pre-commit). - Hook to check for dead includes in C++ files (pre-commit).
- Hook to check for private includes pre-commit).
- Scripts to format/check all files according to the hooks.
Table of Content (click to expand)
Run them
containerized
where only docker
is required.
If you want to run them non-containerized, make the following installed on your system:
clang-format
cmake-format
bash
- GNU
grep
- GNU
sed
- GNU
find
- GNU
xargs
- GNU
parallel
[optional]
This works with Windows setups too.
The hooks can be used by simply using this repository as a shared hook repository inside C++ projects. See further documentation.
You should configure the shared hook repository in your project to use this
repos main
branch by using the following .githooks/.shared.yaml
:
version: 1
urls:
- https://github.com/gabyx/githooks-cpp.git@main`.
Formats C++ files with clang-format
.
By settings the global Git config value githooks-cpp.clangFormat
to the
clang-format
dispatch utility, the correct clang-format
version can be
selected. The dispatch utility dispatches to the different clang-format
versions depending on the header in the found clang format config file, that
means a .clang-format
config can define the version to be used by the
following comment header:
# Version: 12.0.0
githooks-cpp.clangFormat
: Auxiliary path to aclang-format
executable (any Git config level).
Same as pre-commit/1-format/format-cpp.yaml
.
Formats all *.cmake
and CMakeLists.txt
files by using
configs/.cmake-format.json
as well as the <repo-root>/cmake-format.json
which can contain project-specific additional_commands
overrides. This hook
needs cmake-format
installed.
Because CMake is a macro language, the formatter needs to know how to format
commands and therefore we use this repository's config in
configs/.cmake-format.json
.
If a project uses merged header placement as described in
PR1204R0
and also complies more or less to the
Pitchfork layout
(at least for the src
directory), this hook ensures that no private headers
defined as
- files in
src/<lib-name>.*/private/.*
- files in
src/<lib-name>.*/details/.*
are included in files src/<other-lib-name>/.../.*
. Such includes are by
definition architectural design errors and can be enforced by this hook.
Checks that no commented includes are found in C++ files.
The following scripts are provided:
format-cpp-all.sh
: Script to format all C++ files in a directory recursively. See documentation.format-cmake-all.sh
: Script to format all CMake files in a directory recursively. See documentation.
They can be used in scripts by doing the following trick inside a repo which uses this hook:
shellHooks=$(git hooks shared root ns:githooks-cpp)
"$shellHooks/githooks/scripts/<script-name>.sh"
The containerized tests in tests/*
are executed by
tests/test.sh
or only special tests steps by
tests/test.sh --seq 001..010
For showing the output also in case of success use:
tests/test.sh --show-output [other-args]