diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 64b046de07c31c10c972db0c4d737e490e272b84..0f6fb9121b1b1a1dac685ed80ff0c5abc464bd0d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,3 +46,7 @@ repos: - id: cmake-lint additional_dependencies: ["cmakelang[YAML]"] exclude: "scripts/cmake/jedbrown/.*|PackagingMacros.cmake|conan.cmake|CPM.cmake|FindFilesystem.cmake|ConanSetup.cmake|BuildExternalProject.cmake" + - repo: git://github.com/doublify/pre-commit-clang-format + rev: 62302476d0da01515660132d76902359bed0f782 + hooks: + - id: clang-format diff --git a/scripts/ci/jobs/pre-commit.yml b/scripts/ci/jobs/pre-commit.yml index b2a8378ccdde8e465731668ca78de176f52e334b..ccb8a091db3151af5acd1496d47122b465141a95 100644 --- a/scripts/ci/jobs/pre-commit.yml +++ b/scripts/ci/jobs/pre-commit.yml @@ -1,8 +1,10 @@ pre commit: stage: preparation image: $PRECOMMIT_IMAGE - needs: [ ci_images ] + needs: [ci_images] script: - pre-commit install - pre-commit run --all-files - git diff --check `git merge-base origin/master HEAD` HEAD -- . ':!*.md' ':!*.pandoc' ':!*.asc' ':!*.dat' ':!*.ts' + after_script: + - git diff diff --git a/scripts/docker/Dockerfile.pre-commit b/scripts/docker/Dockerfile.pre-commit index ed37f0400235f42d86a5cae82ceedad70e100caf..c915dc455a158440a3dd5bb300ce3569701954b2 100644 --- a/scripts/docker/Dockerfile.pre-commit +++ b/scripts/docker/Dockerfile.pre-commit @@ -3,5 +3,5 @@ FROM python:slim RUN pip install pre-commit==2.7.1 CMD ["bash"] RUN apt-get update \ - && apt-get install -y --no-install-recommends git gcc g++ \ + && apt-get install -y --no-install-recommends git gcc g++ clang-format \ && rm -rf /var/lib/apt/lists/* diff --git a/web/content/docs/devguide/development-workflows/code-format.md b/web/content/docs/devguide/development-workflows/code-format.md index ad1fe0966d2f0ea5c40009b1e9dc42d7d4a6054e..8f6b561933de6e5035aa2ed5f6d4fe2a3c339700 100644 --- a/web/content/docs/devguide/development-workflows/code-format.md +++ b/web/content/docs/devguide/development-workflows/code-format.md @@ -9,7 +9,7 @@ weight = 1014 parent = "development-workflows" +++ -We aim for a consistent and readable coding style. You do not need to worry about styling if you use the right tools we present in the following. +We aim for a consistent and readable coding style. You do not need to worry about styling if you use the right tools we present in the following. Please also enable [pre-commit]({{< ref "setup-fork.md#optional-enable-git-commit-hooks" >}}) in your repository to have these check run automatically for you on every commit! ## C++ @@ -21,8 +21,6 @@ Use [`clang-format`](https://clang.llvm.org/docs/ClangFormat.html). It can be ad The current style is defined in [.clang-format](https://gitlab.opengeosys.org/ogs/ogs/-/blob/master/.clang-format). -A pre-commit hook for git checking the code formatting can be found [here](https://gitlab.opengeosys.org/ogs/ogs-utils/-/tree/master/dev/code-formatting/clang-format-pre-commit-hook). - ## Python Use [`black`](https://black.readthedocs.io/en/stable/). It can be added to be automatically run on save in your editor / IDE: