bootstrap/specs/clang/template/.githooks/pre-commit

13 lines
254 B
Bash
Executable File

#!/usr/bin/env bash
set -e
FORMAT_FILES=$(
git --no-pager diff --name-status --no-color --cached | \
awk '$1 != "D" && $2 ~ /\.c$|\.h$/ {print $NF}'
)
if [ -n "$FORMAT_FILES" ]; then
clang-format -i "$FORMAT_FILES"
git add "$FORMAT_FILES"
fi