From 068ce4ca5588a00b261c267e1f5d1e690c31adc6 Mon Sep 17 00:00:00 2001
From: Florian Kaltenberger <florian.kaltenberger@eurecom.fr>
Date: Wed, 22 Feb 2017 09:29:33 +0100
Subject: [PATCH] adding a client-side pre-commit script. This script needs to
 be installed by every developer manually. see comments in script.

---
 pre-commit | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 pre-commit

diff --git a/pre-commit b/pre-commit
new file mode 100644
index 00000000000..82587fce34c
--- /dev/null
+++ b/pre-commit
@@ -0,0 +1,31 @@
+
+#!/bin/bash
+# Installation:
+#   cp pre-commit .git/hooks
+#   chmod +x .git/hooks/pre-commit
+
+OPTIONS="--convert-tabs --indent=spaces=2 --indent-switches --indent-col1-comments --break-blocks --delete-empty-lines --align-pointer=name --keep-one-line-blocks --keep-one-line-statements --lineend=linux"
+
+RETURN=0
+ASTYLE=$(which astyle)
+if [ $? -ne 0 ]; then
+	echo "[!] astyle not installed. Unable to check source file format policy." >&2
+	exit 1
+fi
+
+FILES=`git diff --cached --name-only --diff-filter=ACMR | grep -E "\.(c|cpp|h)$"`
+for FILE in $FILES; do
+	$ASTYLE $OPTIONS < $FILE | cmp -s $FILE -
+	if [ $? -ne 0 ]; then
+		echo "[!] $FILE does not respect the agreed coding style." >&2
+		RETURN=1
+	fi
+done
+
+if [ $RETURN -eq 1 ]; then
+	echo "" >&2
+	echo "Make sure you have run astyle with the following options:" >&2
+	echo $OPTIONS >&2
+fi
+
+exit $RETURN
\ No newline at end of file
-- 
GitLab