summaryrefslogtreecommitdiffstats
path: root/tools/enable-pre-commit-hook.sh
diff options
context:
space:
mode:
authorJosh Kearney <josh@jk0.org>2011-10-17 14:17:52 -0500
committerJosh Kearney <josh@jk0.org>2011-10-17 14:39:25 -0500
commit16582ce70c44b5d1eb88ede75f072ef6e684fb35 (patch)
treeb6d5e9d50328f8ccbd2c2a05cfe5255a177854dc /tools/enable-pre-commit-hook.sh
parent6589c44418fefc6bdb962c33c9880006c06c69a4 (diff)
downloadnova-16582ce70c44b5d1eb88ede75f072ef6e684fb35.tar.gz
nova-16582ce70c44b5d1eb88ede75f072ef6e684fb35.tar.xz
nova-16582ce70c44b5d1eb88ede75f072ef6e684fb35.zip
Utility script that makes enforcing PEP8 within git's pre-commit hook as easy as possible.
This should be mandatory for all developers, IMHO. Change-Id: I83e8a7ab0a82df0fd08a2bef80295344b3a00a86
Diffstat (limited to 'tools/enable-pre-commit-hook.sh')
-rwxr-xr-xtools/enable-pre-commit-hook.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/enable-pre-commit-hook.sh b/tools/enable-pre-commit-hook.sh
new file mode 100755
index 000000000..f4f73ee77
--- /dev/null
+++ b/tools/enable-pre-commit-hook.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+# Copyright 2011 OpenStack LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+PRE_COMMIT_SCRIPT=.git/hooks/pre-commit
+
+make_hook() {
+ echo "exec ./run_tests.sh -N -p" >> $PRE_COMMIT_SCRIPT
+ chmod +x $PRE_COMMIT_SCRIPT
+
+ if [ -w $PRE_COMMIT_SCRIPT -a -x $PRE_COMMIT_SCRIPT ]; then
+ echo "pre-commit hook was created successfully"
+ else
+ echo "unable to create pre-commit hook"
+ fi
+}
+
+# NOTE(jk0): Make sure we are in nova's root directory before adding the hook.
+if [ ! -d ".git" ]; then
+ echo "unable to find .git; moving up a directory"
+ cd ..
+ if [ -d ".git" ]; then
+ make_hook
+ else
+ echo "still unable to find .git; hook not created"
+ fi
+else
+ make_hook
+fi
+