Index: trunk/packages/invirt-dev/debian/invirt-dev.dirs
===================================================================
--- trunk/packages/invirt-dev/debian/invirt-dev.dirs	(revision 3037)
+++ trunk/packages/invirt-dev/debian/invirt-dev.dirs	(revision 3038)
@@ -2,2 +2,3 @@
 var/log/invirt/builds
 usr/share/invirt-dev/build-hooks
+usr/share/invirt-dev/git-hooks
Index: trunk/packages/invirt-dev/debian/invirt-dev.install
===================================================================
--- trunk/packages/invirt-dev/debian/invirt-dev.install	(revision 3037)
+++ trunk/packages/invirt-dev/debian/invirt-dev.install	(revision 3038)
@@ -1,3 +1,5 @@
 reprepro-env usr/bin
+invirt-configure-git-hooks usr/bin
 repository-config/* srv/repository/conf
 build-hooks usr/share/invirt-dev
+git-hooks usr/share/invirt-dev
Index: trunk/packages/invirt-dev/debian/invirt-dev.postinst
===================================================================
--- trunk/packages/invirt-dev/debian/invirt-dev.postinst	(revision 3037)
+++ trunk/packages/invirt-dev/debian/invirt-dev.postinst	(revision 3038)
@@ -37,4 +37,12 @@
         echo "to make individual users that will build packages."
         echo "-----"
+
+	invirt-configure-git-hooks || {
+            echo "-----"
+            echo "invirt-dev: Could not configure git hooks."
+	    echo "Run 'invirt-configure-git-hooks'once you"
+	    echo "have configured your repositories appropriately."
+            echo "-----"
+	}
     ;;
 
Index: trunk/packages/invirt-dev/git-hooks/other/post-receive
===================================================================
--- trunk/packages/invirt-dev/git-hooks/other/post-receive	(revision 3038)
+++ trunk/packages/invirt-dev/git-hooks/other/post-receive	(revision 3038)
@@ -0,0 +1,1 @@
+link ../sub/post-receive
Index: trunk/packages/invirt-dev/git-hooks/other/zephyr-post-receive
===================================================================
--- trunk/packages/invirt-dev/git-hooks/other/zephyr-post-receive	(revision 3038)
+++ trunk/packages/invirt-dev/git-hooks/other/zephyr-post-receive	(revision 3038)
@@ -0,0 +1,1 @@
+link ../sub/zephyr-post-receive
Index: trunk/packages/invirt-dev/git-hooks/sub/post-receive
===================================================================
--- trunk/packages/invirt-dev/git-hooks/sub/post-receive	(revision 3038)
+++ trunk/packages/invirt-dev/git-hooks/sub/post-receive	(revision 3038)
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+file=`mktemp -t git-post-receive.XXXXXX` || exit $?
+cat >$file
+
+"$PWD"/hooks/zephyr-post-receive <$file
+
+rm -f $file
Index: trunk/packages/invirt-dev/git-hooks/sub/update
===================================================================
--- trunk/packages/invirt-dev/git-hooks/sub/update	(revision 3038)
+++ trunk/packages/invirt-dev/git-hooks/sub/update	(revision 3038)
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+ref="$1"
+oldrev="$2"
+newrev="$3"
+
+# --- Safety check
+
+if [ -z "$GIT_DIR" ]; then
+        echo "Don't run this script from the command line." >&2
+        echo " (if you want, you could supply GIT_DIR then run" >&2
+        echo "  $0 <ref> <oldrev> <newrev>)" >&2
+        exit 1
+fi
+
+if [ -z "$ref" ] || [ -z "$oldrev" ] || [ -z "$newrev" ]; then
+        echo "Usage: $0 <ref> <oldrev> <newrev>" >&2
+        exit 1
+fi
+
+# --- Disallow pushing to the branches for pockets
+
+pocket_to_git() {
+    local pocket git
+    pocket="$1"
+    git="$(invirt-getconf "git.pockets.$pocket.git" 2>/dev/null)"
+    if [ $? != 0 ]; then
+	git="$pocket"
+    fi
+    echo "$git"
+}
+
+for pocket in $(invirt-getconf -l build.pockets); do
+    if [ "$ref" = "refs/heads/$(pocket_to_git "$pocket")" ]; then
+	echo "*** Pushing to a pocket branch in this repository is not allowed" >&2
+	exit 1
+    fi
+done
+
+# --- Disallow pushing tags
+
+case "$ref" in
+    refs/heads/*)
+	;;
+    *)
+        echo "*** Pushing non-branches to this repository is not allowed" >&2
+        exit 1
+        ;;
+esac
Index: trunk/packages/invirt-dev/git-hooks/sub/zephyr-post-receive
===================================================================
--- trunk/packages/invirt-dev/git-hooks/sub/zephyr-post-receive	(revision 3038)
+++ trunk/packages/invirt-dev/git-hooks/sub/zephyr-post-receive	(revision 3038)
@@ -0,0 +1,49 @@
+#!/bin/sh
+#
+# This script is run after receive-pack has accepted a pack and the
+# repository has been updated.  It is passed arguments in through stdin
+# in the form
+#  <oldrev> <newrev> <refname>
+# For example:
+#  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
+
+base=build.hooks.post_commit.zephyr
+
+class=$(invirt-getconf "$base.class" 2>/dev/null)
+instance=$(invirt-getconf "$base.instance" 2>/dev/null)
+zsig=$(invirt-getconf "$base.zsig" 2>/dev/null)
+color=$(invirt-getconf "$base.color" 2>/dev/null)
+
+if [ "${color:-true}" = "true" ]; then
+    usecolor="--color"
+else
+    usecolor=""
+fi
+
+if [ -z "$class" ]; then
+  echo "I don't know where to send a commit zephyr!" >&2
+  echo "Please provide a value for $base.class in" >&2
+  echo "your invirt config file." >&2
+  exit 1
+fi
+while read oldrev newrev refname; do
+  if [ "$oldrev" = "0000000000000000000000000000000000000000" ]; then
+    # dammit git
+    zwrite -c "$class" -i "$(basename "$refname")" -s "${zsig:-Git}: $refname" -d \
+      -m "New branch created."
+    continue
+  fi
+  git rev-list --first-parent --reverse "$oldrev..$newrev" | while read rev; do
+    shortrev=`git log -1 --pretty=format:%h "$rev"`
+    (git show --stat -M $usecolor "$rev" |
+     sed -e 's/@/@@/g' \
+         -e 's/}/@(})/g' \
+         -e 's/\[m/}@{/g' \
+         -e 's/\[33m/@color(yellow)/g' \
+         -e 's/\[31m/@color(red)/g' \
+         -e 's/\[32m/@color(green)/g' \
+         -e '1s/^/@{/' \
+         -e '$s/$/}/') |
+    zwrite -c "$class" -i "${instance:-$shortrev}" -s "${zsig:-Git}: $refname" -d
+  done
+done
Index: trunk/packages/invirt-dev/git-hooks/super/update
===================================================================
--- trunk/packages/invirt-dev/git-hooks/super/update	(revision 3038)
+++ trunk/packages/invirt-dev/git-hooks/super/update	(revision 3038)
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+ref="$1"
+oldrev="$2"
+newrev="$3"
+
+# --- Safety check
+
+if [ -z "$GIT_DIR" ]; then
+        echo "Don't run this script from the command line." >&2
+        echo " (if you want, you could supply GIT_DIR then run" >&2
+        echo "  $0 <ref> <oldrev> <newrev>)" >&2
+        exit 1
+fi
+
+if [ -z "$ref" ] || [ -z "$oldrev" ] || [ -z "$newrev" ]; then
+        echo "Usage: $0 <ref> <oldrev> <newrev>" >&2
+        exit 1
+fi
+
+# --- Disallow all pushes
+
+echo "*** Pushing to the superproject is not allowed" >&2
+echo "***" >&2
+echo "*** If you would like to update the superproject, use remctl" >&2
+exit 1
Index: trunk/packages/invirt-dev/invirt-configure-git-hooks
===================================================================
--- trunk/packages/invirt-dev/invirt-configure-git-hooks	(revision 3038)
+++ trunk/packages/invirt-dev/invirt-configure-git-hooks	(revision 3038)
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+set -e
+set -u
+
+link_to() {
+    rm -rf "$1"
+    ln -s "$2" "$1"
+}
+
+package_base=/srv/git/invirt
+hook_base=/usr/share/invirt-dev/git-hooks
+
+link_to "$package_base/packages.git/hooks" "$hook_base/super"
+
+for pkg in "$package_base"/*/*.git; do
+    case "$pkg" in
+	"$package_base/packages/*.git") link_to "$pkg/hooks" "$hook_base/sub" ;;
+	*) link_to "$pkg/hooks" "$hook_base/other" ;;
+    esac
+done
