summaryrefslogtreecommitdiff
path: root/scripts/pre-commit.sample
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/pre-commit.sample')
-rwxr-xr-xscripts/pre-commit.sample28
1 files changed, 28 insertions, 0 deletions
diff --git a/scripts/pre-commit.sample b/scripts/pre-commit.sample
new file mode 100755
index 0000000..5324c3b
--- /dev/null
+++ b/scripts/pre-commit.sample
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+gitclangformat=$(which git-clang-format)
+
+if [ "$gitclangformat" == "" ]
+then
+ gitclangformat=$(find /usr/bin/ -name "git-clang-format*")
+fi
+
+against=`git rev-parse --verify HEAD 2>&1`
+
+if [ $against == "" ]
+then
+ # Initial commit: diff against an empty tree object
+ against=5394c6fa5bf40d9bc8619026cbc4c306211a8499
+fi
+
+$gitclangformat $against -f -q
+
+if [ $? != 0 ]
+then
+ echo "Format error!"
+ echo "Use git clang-format"
+ exit 1
+fi
+
+# Now update format changes and commit
+git add $(git diff --name-only --cached)