summaryrefslogtreecommitdiff
path: root/hooks
diff options
context:
space:
mode:
authorEdward Hervey <bilboed@bilboed.com>2009-01-22 05:10:38 +0100
committerEdward Hervey <bilboed@bilboed.com>2009-01-22 05:10:38 +0100
commit137543b7e782c811bc88bf9210323e7e75835d18 (patch)
tree8fc233dcbd7e821b33a0215ed2a299b91cdfd0a4 /hooks
parent5dc8ae302733ce1aae5b1aaa613ce77a8ae4b3d9 (diff)
Adding git hooks
Diffstat (limited to 'hooks')
-rw-r--r--hooks/pre-commit.hook34
-rw-r--r--hooks/pre-receive.hook76
2 files changed, 110 insertions, 0 deletions
diff --git a/hooks/pre-commit.hook b/hooks/pre-commit.hook
new file mode 100644
index 0000000..34dd510
--- /dev/null
+++ b/hooks/pre-commit.hook
@@ -0,0 +1,34 @@
+#!/bin/sh
+#
+# Check that the code follows a consistant code style
+#
+
+# FIXME : Add a check for existence of indent, and return 0 if not present
+
+echo "--Checking style--"
+for file in `git-diff-index --name-only HEAD | grep "\.c$"` ; do
+tempfoo=`basename $0`
+ newfile=`mktemp /tmp/${tempfoo}.XXXXXX` || exit 1
+ indent \
+ --braces-on-if-line \
+ --case-brace-indentation0 \
+ --case-indentation2 \
+ --braces-after-struct-decl-line \
+ --line-length80 \
+ --no-tabs \
+ --cuddle-else \
+ --dont-line-up-parentheses \
+ --continuation-indentation4 \
+ --honour-newlines \
+ --tab-size8 \
+ --indent-level2 \
+ $file -o $newfile 2>> /dev/null
+ diff -u -p "${file}" "${newfile}"
+ r=$?
+ rm "${newfile}"
+ if [ $r != 0 ] ; then
+echo "Code style error in $file, please fix before commiting."
+ exit 1
+ fi
+done
+echo "--Checking style pass--"
diff --git a/hooks/pre-receive.hook b/hooks/pre-receive.hook
new file mode 100644
index 0000000..8ddcd87
--- /dev/null
+++ b/hooks/pre-receive.hook
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+import sys
+import os
+import subprocess
+
+# This server-side pre-receive hook is to be put and activated in all modules
+# that depend on the common submodule.
+#
+# It will check whether any modifications to the common 'submodule file' has a
+# a valid commit SHA1 that exists in the common module.
+
+def commit_exists(sha1, gitdir):
+ """Returns True if the sha1 is a valid commit in the given
+ git directory"""
+ # FIXME: We're using git-show for the time being, but there's a small
+ # risk that there might be a valid SHA1 for a non-commit object.
+ env = os.environ.copy()
+ env["GIT_DIR"] = gitdir
+ sub = subprocess.Popen(["git", "show", sha1], env=env,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ while True:
+ res = sub.poll()
+ if res != None:
+ return res == 0
+
+# location of the common git module
+COMMON_GIT_DIR = "/git/gstreamer/common.git"
+
+pushvalid = True
+
+print "=> Checking for integrity of common submodule changes"
+print
+
+for line in sys.stdin.readlines():
+ # ref is the ref to be modified
+ # old is the old commit it was pointing to
+ # new is the new commit it was pointing to
+ old, new, ref = line.split(' ', 2)
+
+ # 1. Get the latest change to common (if there was any changes)
+ sub = subprocess.Popen(["git-diff", "%s..%s" % (old, new, ), "--", "common"],
+ stdout=subprocess.PIPE)
+ stdout, stderr = sub.communicate()
+ if stdout != "":
+ # Format of submodule special files
+ # Subproject commit <SHA1>
+
+ # we get a diff, therefore only grab the last line
+ lastline = stdout.strip().rsplit('\n',1)[-1]
+ if not lastline.startswith("+Subproject commit"):
+ # this is bad, it means the diff has changed to something completely
+ # different
+ continue
+ subsha1 = lastline.rsplit(' ', 1)[-1]
+ print " Pack wants common to point to", subsha1
+ if not commit_exists(subsha1, COMMON_GIT_DIR):
+ print " /!\\ Commit does not exist in common git module /!\\"
+ print " /!\\ for ref", ref
+ pushvalid = False
+ break
+
+ # 2. Figure out if that commit exists in the common submodule
+ # (use GIT_DIR to execute commands in that directory)
+
+if pushvalid:
+ print " Incoming packet valid, proceeding to actual commit"
+ sys.exit(0)
+else:
+ print " Attempting to push commits containing modifications to common"
+ print " that have not been commited to the actuall common module."
+ print
+ print " First push your changes to common/ before pushing the changes"
+ print " to the module using it."
+ sys.exit(-1)
+