From eebed47257f394949f20ccdbfd08f216a6be6f20 Mon Sep 17 00:00:00 2001 From: Antonio Cardace Date: Wed, 2 Sep 2020 18:25:02 +0200 Subject: [PATCH] contrib: add git-hook to verify code-style Signed-off-by: Antonio Cardace --- .../scripts/code-style-git-post-commit-hook | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 contrib/scripts/code-style-git-post-commit-hook diff --git a/contrib/scripts/code-style-git-post-commit-hook b/contrib/scripts/code-style-git-post-commit-hook new file mode 100755 index 0000000000..24c702c0c9 --- /dev/null +++ b/contrib/scripts/code-style-git-post-commit-hook @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e + +DISABLED=${NM_HOOK_DISABLED:0} + +if [ "$DISABLED" == 1 ]; then + echo "COMMIT HOOK DISABLED" + exit 0 +fi + +FORMATTER=contrib/scripts/nm-code-format.sh + +# Filter only C source files +CHANGED_FILES=$(git log --pretty='' --name-only -n1 | grep -E '\.c$|\.h$' | tr '\n' ' ') + +echo $CHANGED_FILES + +if [ -x "$FORMATTER" ] && [ ! -z "$CHANGED_FILES" ]; then + "$FORMATTER" "${CHANGED_FILES}" +fi