aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scripts
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-09-07 13:17:52 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2022-09-07 13:17:52 +0200
commit894ebcbf26478ea7fd26b89636b53ecd2a750643 (patch)
tree00904bb81fc0a631ae216c187385af73838f9c22 /scripts
parentci: set some environment variables (diff)
downloadcimple-894ebcbf26478ea7fd26b89636b53ecd2a750643.tar.gz
cimple-894ebcbf26478ea7fd26b89636b53ecd2a750643.zip
add scripts (pre-commit hook, etc.)
Diffstat (limited to 'scripts')
-rw-r--r--scripts/.gitattributes1
-rwxr-xr-xscripts/pre-commit21
-rwxr-xr-xscripts/setup-hooks15
3 files changed, 37 insertions, 0 deletions
diff --git a/scripts/.gitattributes b/scripts/.gitattributes
new file mode 100644
index 0000000..fcadb2c
--- /dev/null
+++ b/scripts/.gitattributes
@@ -0,0 +1 @@
+* text eol=lf
diff --git a/scripts/pre-commit b/scripts/pre-commit
new file mode 100755
index 0000000..b75ea9f
--- /dev/null
+++ b/scripts/pre-commit
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+
+set -o errexit -o nounset -o pipefail
+
+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
diff --git a/scripts/setup-hooks b/scripts/setup-hooks
new file mode 100755
index 0000000..745c7c7
--- /dev/null
+++ b/scripts/setup-hooks
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+set -o errexit -o nounset -o pipefail
+
+script_dir="$( dirname -- "${BASH_SOURCE[0]}" )"
+script_dir="$( cd -- "$script_dir" && pwd )"
+
+cd -- "$script_dir"
+
+gitdir="$( git rev-parse --git-dir )"
+hooks_dir="$gitdir/hooks"
+
+symlink_dest="$( realpath "--relative-to=$hooks_dir" -- "$script_dir/pre-commit" )"
+
+ln -fs -- "$symlink_dest" "$hooks_dir/"