summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Klinger2016-09-29 15:48:49 +0200
committerChristian Klinger2016-09-29 15:48:49 +0200
commit692748a07684cf6caf67fa736db853781c58842f (patch)
tree1c07df56f24df8179518049e1522375b20bf52b2
parentastyle. (diff)
downloadpvs2-692748a07684cf6caf67fa736db853781c58842f.tar.gz
pvs2-692748a07684cf6caf67fa736db853781c58842f.tar.xz
pvs2-692748a07684cf6caf67fa736db853781c58842f.zip
added a pre-commit hook for astyle.
-rw-r--r--README.md22
-rwxr-xr-xscripts/astyle-check.sh32
2 files changed, 54 insertions, 0 deletions
diff --git a/README.md b/README.md
index c1bba45..96ee734 100644
--- a/README.md
+++ b/README.md
@@ -82,3 +82,25 @@ something like "xscreensaver-command --lock" or similar.
### Network Setup
+
+
+# FOR CONTRIBUTORS
+
+## Code Style
+Please check the file `.astylerc` for details. We recommend to install a
+pre-commit hook to make sure that one only commit complying code. Such a hook
+can be found in scripts/astyle-check.sh
+
+Steps to install the hook:
+ # install `astyle`
+ apt-get install astyle
+
+ cd pvs2
+ cd .git/hooks
+ ln -s ../../scripts/astyle-check.sh pre-commit
+ chmod +x pre-commit
+
+If a staged file does not comply to our coding style, you can use
+ `astyle --options=./.astylerc <FILE>` to correct the style.
+
+
diff --git a/scripts/astyle-check.sh b/scripts/astyle-check.sh
new file mode 100755
index 0000000..1e382c7
--- /dev/null
+++ b/scripts/astyle-check.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+# Support old version of astyle 2.04
+less -f `which astyle` | grep 2.04
+BUG=$?
+
+ASTYLE=$(which astyle)
+OPTIONS="--options=./.astylerc"
+
+RETURN=0
+
+FILES=`git diff --cached --name-only --diff-filter=ACMR | grep -E "\.(c|cpp|h|hpp)$"`
+for FILE in $FILES; do
+ if [ $BUG -ne 0 ]; then
+ $ASTYLE $OPTIONS < $FILE | cmp -s $FILE -
+ else
+ $ASTYLE $OPTIONS < $FILE | head -c -1 | cmp -s $FILE -
+ fi
+ if [ $? -ne 0 ]; then
+ echo "$?" >&2
+ 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 options:" >&2
+ echo "$OPTIONS" >&2
+ echo "on the file(s)" >&2
+fi
+
+exit $RETURN