From 03073c505617ceaa9b895b8d590d39be100433ff Mon Sep 17 00:00:00 2001 From: superjom Date: Wed, 22 Nov 2017 11:38:55 +0800 Subject: [PATCH] add backend autostyle --- .clang_format.hook | 15 +++++++++++++++ .pre-commit-config.yaml | 13 ++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100755 .clang_format.hook diff --git a/.clang_format.hook b/.clang_format.hook new file mode 100755 index 00000000..1d928216 --- /dev/null +++ b/.clang_format.hook @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +readonly VERSION="3.8" + +version=$(clang-format -version) + +if ! [[ $version == *"$VERSION"* ]]; then + echo "clang-format version check failed." + echo "a version contains '$VERSION' is needed, but get '$version'" + echo "you can install the right version, and make an soft-link to '\$PATH' env" + exit -1 +fi + +clang-format $@ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e4a0faf7..7cfe3b54 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,4 +11,15 @@ - id: check-symlinks - id: end-of-file-fixer - id: trailing-whitespace - - id: check-added-large-files \ No newline at end of file + - id: detect-private-key + - id: check-symlinks + - id: check-added-large-files + +- repo: local + hooks: + - id: clang-format-with-version-check + name: clang-format + description: Format files with ClangFormat. + entry: bash ./.clang_format.hook -i + language: system + files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto)$ -- GitLab