chiark / gitweb /
Add pre-commit hook with installer
authorDaniel Martí <mvdan@mvdan.cc>
Wed, 28 May 2014 07:28:28 +0000 (09:28 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Wed, 28 May 2014 07:28:28 +0000 (09:28 +0200)
Will enable pep8 once all the problems are gone

hooks/install-hooks.sh [new file with mode: 0755]
hooks/pre-commit [new file with mode: 0755]

diff --git a/hooks/install-hooks.sh b/hooks/install-hooks.sh
new file mode 100755 (executable)
index 0000000..69b314d
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# Install all the client hooks
+
+BASE_DIR="$(cd $(dirname $0); pwd -P)"
+HOOK_NAMES="applypatch-msg pre-applypatch post-applypatch pre-commit prepare-commit-msg commit-msg post-commit pre-rebase post-checkout post-merge pre-receive update post-receive post-update pre-auto-gc"
+HOOK_DIR="$(git rev-parse --show-toplevel)/.git/hooks"
+
+for hook in $HOOK_NAMES; do
+
+       shipped_hook="$BASE_DIR/$hook"
+       installed_hook="$HOOK_DIR/$hook"
+
+       # If we don't distribute it, continue
+       if [ ! -f "$shipped_hook" ]; then
+               continue
+       fi
+
+       if [ -h "$installed_hook" ]; then
+               echo "$installed_hook is a symlink - replacing."
+       elif [ -e "$installed_hook" ]; then
+               echo "$installed_hook hook already exists."
+               continue
+       fi
+
+       # Create the symlink
+       echo "ln -s -f \"$shipped_hook\" \"$installed_hook\""
+       ln -s -f "$shipped_hook" "$installed_hook"
+
+done
diff --git a/hooks/pre-commit b/hooks/pre-commit
new file mode 100755 (executable)
index 0000000..077aeab
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/sh
+#
+# Simple pre-commit hook to check that there are no errors in the fdroid
+# metadata files.
+
+# Redirect output to stderr.
+exec 1>&2
+
+FILES="fdroid makebuildserver examples/*.py fdroidserver/*.py"
+
+cmd_exists() {
+       command -v $1 1>/dev/null
+}
+
+# For systems that switched to python3, first check for the python2 versions
+if cmd_exists pyflakes-python2; then
+       PYFLAKES=pyflakes-python2
+elif cmd_exists pyflakes; then
+       PYFLAKES=pyflakes
+else
+       echo "pyflakes is not installed!"
+fi
+
+if cmd_exists pep8-python2; then
+       PEP8=pep8-python2
+elif cmd_exists pep8; then
+       PEP8=pep8
+else
+       echo "pep8 is not installed!"
+fi
+
+# If there are python errors or warnings, print them and fail.
+[ -n "$PYFLAKES" ] && $PYFLAKES $FILES
+#[ -n "$PEP8" ] && $PEP8 --ignore=E123,E501 $FILES