-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
38 lines (31 loc) · 911 Bytes
/
pre-commit
File metadata and controls
38 lines (31 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh
# AKOS pre-commit hook — rejects commits with clang-format violations.
#
# Install:
# cp tools/pre-commit .git/hooks/pre-commit
# chmod +x .git/hooks/pre-commit
CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
if ! command -v "$CLANG_FORMAT" > /dev/null 2>&1; then
echo "warning: clang-format not found, skipping style check"
exit 0
fi
FAIL=0
FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(c|cpp|h|hpp)$')
if [ -z "$FILES" ]; then
exit 0
fi
for FILE in $FILES; do
"$CLANG_FORMAT" --dry-run --Werror "$FILE" 2>/dev/null
if [ $? -ne 0 ]; then
echo " style violation: $FILE"
FAIL=1
fi
done
if [ $FAIL -ne 0 ]; then
echo ""
echo "Commit rejected: clang-format violations found."
echo "Fix with: clang-format -i <file>"
echo "Or fix all: find . -name '*.c' -o -name '*.h' | xargs clang-format -i"
exit 1
fi
exit 0