diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 13612b158..df8c02d42 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -24,14 +24,6 @@ for file in $modified_files; do git checkout-index --prefix="$tmpdir/" -- $file - echo "Running clang-format..." - $project_folder/tools/git-clang-format $tmpdir/$file - CODE=$? - - if [ $CODE -ne 0 ]; then - break - fi - # Do not break header checker echo "Running header checker..." $project_folder/tools/header-checker.py $tmpdir/$file $file --amend-year @@ -39,7 +31,6 @@ for file in $modified_files; do if [ $CODE -ne 0 ]; then FAIL=1 fi - done; return ${FAIL} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..869991668 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,24 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black + args: # arguments to configure black + - --line-length=120 + - --include='\.pyi?$' + # these folders wont be formatted by black + - --exclude="""\.git | + \.__pycache__| + build| + libs| + .cache""" + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v13.0.0 + hooks: + - id: clang-format diff --git a/init b/init index b0fa6e4ea..b74f019bb 100755 --- a/init +++ b/init @@ -135,3 +135,7 @@ for hook in $(find $DIR/.githooks -type f -printf "%f\n"); do ln -s -f "$DIR/.githooks/$hook" "$DIR/.git/hooks/$hook" echo "Added $hook hook" done; + +# Install precommit hook +python3 -m pip install pre-commit +python3 -m pre_commit install