GitHub - gabyx/Githooks-Cpp: Githooks for C++ development (original) (raw)

Githooks for C++

This repository contains shared repository Git hooks for shell scripts ingithooks/* to be used with theGithooks Manager.

The following is included:

Requirements

Run themcontainerizedwhere only docker is required.

If you want to run them non-containerized, make the following installed on your system:

This works with Windows setups too.

Installation

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:

Hook: pre-commit/1-format/.format-cpp.h

Formats C++ files with clang-format.

By settings the global Git config value githooks-cpp.clangFormat to theclang-format dispatch utility, the correct clang-format version can be selected. The dispatch utility dispatches to the different clang-formatversions 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:

Git Config Variables

Hook: pre-commit/1-format/format-glsl.yaml

Same as pre-commit/1-format/format-cpp.yaml.

Hook: pre-commit/1-format/format-cmake.yaml

Formats all *.cmake and CMakeLists.txt files by usingconfigs/.cmake-format.json as well as the <repo-root>/cmake-format.jsonwhich 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 inconfigs/.cmake-format.json.

Hook: pre-commit/2-check/check-private-includes-cpp.yaml

If a project uses merged header placement as described inPR1204R0and also complies more or less to thePitchfork layout(at least for the src directory), this hook ensures that no private headers defined as

are included in files src/<other-lib-name>/.../.*. Such includes are by definition architectural design errors and can be enforced by this hook.

Hook: pre-commit/2-check/check-no-dead-includes-cpp.yaml

Checks that no commented includes are found in C++ files.

Scripts

The following scripts are provided:

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/.sh"

Testing

The containerized tests in tests/* are executed by

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]