From ce76d9009c1bfd15c6d670ac92608a185de1a8c4 Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Thu, 8 Aug 2024 01:34:44 +0200 Subject: [PATCH] hooks: Add pre-commit hook --- .git-template/hooks/pre-commit | 21 +++++++++++++++++++++ flamingo/val.c | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 .git-template/hooks/pre-commit diff --git a/.git-template/hooks/pre-commit b/.git-template/hooks/pre-commit new file mode 100755 index 0000000..ae7406b --- /dev/null +++ b/.git-template/hooks/pre-commit @@ -0,0 +1,21 @@ +#!/bin/sh +set -e + +# Redirect output to stderr. + +exec 1>&2 + +# Don't allow non-ASCII characters in filenames. + +if test $(git diff --cached --name-only --diff-filter=A -z HEAD | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0; then + echo "Tryna add non-ASCII filenames" + exit 1 +fi + +# If there are terminating whitespaces, print the offending file names and fail. + +git diff-index --check --cached HEAD -- + +# Run `clang-format` and fail if it fails. + +exec find . -name "*.[ch]" | xargs clang-format18 -i diff --git a/flamingo/val.c b/flamingo/val.c index e43b51d..494901a 100644 --- a/flamingo/val.c +++ b/flamingo/val.c @@ -8,7 +8,7 @@ #include #include -static flamingo_val_t* val_incref(flamingo_val_t* val) { + static flamingo_val_t* val_incref(flamingo_val_t* val) { assert(val->ref_count > 0); // value has already been freed val->ref_count++;