aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scripts/pre-commit.sh
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-12-03 19:10:10 +0100
committerEgor Tensin <Egor.Tensin@gmail.com>2022-12-03 19:20:07 +0100
commite23958ba3b639a24f59c32a018efdbaddd4ca98b (patch)
tree376351d2c130bb5bea8f4ab2da1b5e6afc7b3e1c /scripts/pre-commit.sh
parentfix preludes in bash scripts (diff)
downloadcimple-e23958ba3b639a24f59c32a018efdbaddd4ca98b.tar.gz
cimple-e23958ba3b639a24f59c32a018efdbaddd4ca98b.zip
make .gitattributes more consistent
Diffstat (limited to 'scripts/pre-commit.sh')
-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..8a98a0e
--- /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 )"
+
+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