# KDEGitCommitHooks

This module provides a functionality to enforce formatting or in the future other QS checks.

This module provides the following function:

    kde_configure_git_pre_commit_hook(
       CHECKS <check1> [<check2> [...]
       [CUSTOM_SCRIPTS [<script paths> [<script paths> ...]]] # since 5.109
    )

This function will create a pre-commit hook which contains all the given checks. In addition to that, you can pass in paths to custom scripts that will be run as the pre-commit hook. If a custom hooks directory is set via `core.hooksPath`, a warning is issued.

The created pre-commit script will also execute any custom user-provided scripts located in .git/hooks/pre-commit.d directory.

Checks:

- `CLANG_FORMAT` With this check enabled the `git clang-format` tool will be used to make sure that the changed parts are properly formatted. In case the changes are not properly formatted an error message with the command to preview the formatting changes and to format the files in place will be displayed. This tool will reuse the existing `.clang-format` file, in case you want to use the one provided by ECM you can include `include(KDEClangFormat)` which will copy the file to the source dir. It is also recommended to reformat the entire project before enforcing the formatting using this commit hook.

- `JSON_SCHEMA` Since 5.110, uses the check-jsonschema CLI tool to ensure that all files are valid JSON and match the KPluginMetaData spec. This only applied if the JSON file has a “KPlugin” object in its root. To ignore invalid files, for example for testing error handling, given files can be excluded in the .kde-ci.yml file Define Options.json-validate-ignore with an array of the files you want to ignore

Example usage:

    include(KDEGitCommitHooks)
    kde_configure_git_pre_commit_hook(CHECKS JSON_SCHEMA CLANG_FORMAT)

Since 5.79