aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scripts/pre-commit.sh
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-06-12 22:52:32 +0200
committerEgor Tensin <egor@tensin.name>2026-06-12 22:52:32 +0200
commit847f4a6839838f2b9b547d67263103974ba92304 (patch)
tree76d99ec9ddcf9be7fa6b315a4259514e3b839cdc /scripts/pre-commit.sh
parentworkflows/ci: windows-2025 ships with VS 2026 now (diff)
downloadwinapi-utf8-847f4a6839838f2b9b547d67263103974ba92304.tar.gz
winapi-utf8-847f4a6839838f2b9b547d67263103974ba92304.zip
add scripts to setup git hooks
Diffstat (limited to '')
-rwxr-xr-xscripts/pre-commit.sh22
1 files changed, 22 insertions, 0 deletions
diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh
new file mode 100755
index 0000000..fd1f7dd
--- /dev/null
+++ b/scripts/pre-commit.sh
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+set -o errexit -o nounset -o pipefail
+shopt -s inherit_errexit lastpipe
+
+if ! command -v git-clang-format &> /dev/null; then
+ echo 'Please make sure git-clang-format is available.' >&2
+ exit 1
+fi
+
+output="$( git clang-format --style file --diff )" || true
+
+ok1='no modified files to format'
+ok2='clang-format did not modify any files'
+
+if [ "$output" != "$ok1" ] && [ "$output" != "$ok2" ]; then
+ echo "$output"
+ echo
+ echo 'clang-format required some formatting fixes.'
+ echo 'Please stage your changes, run `git clang-format`, review the formatting fixes, and commit.'
+ exit 1
+fi