Skip to content

Commit

Permalink
hooks: Add pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Aug 7, 2024
1 parent 46eab89 commit ce76d90
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .git-template/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion flamingo/val.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <assert.h>
#include <stdlib.h>

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++;

Expand Down

0 comments on commit ce76d90

Please sign in to comment.