Added git hooks to invirt-dev package
authorGreg Brockman <gdb@mit.edu>
Tue, 6 Jul 2010 04:28:00 +0000 (00:28 -0400)
committerGreg Brockman <gdb@mit.edu>
Tue, 6 Jul 2010 04:28:00 +0000 (00:28 -0400)
svn path=/trunk/packages/invirt-dev/; revision=3038

debian/invirt-dev.dirs
debian/invirt-dev.install
debian/invirt-dev.postinst
git-hooks/other/post-receive [new symlink]
git-hooks/other/zephyr-post-receive [new symlink]
git-hooks/sub/post-receive [new file with mode: 0755]
git-hooks/sub/update [new file with mode: 0755]
git-hooks/sub/zephyr-post-receive [new file with mode: 0755]
git-hooks/super/update [new file with mode: 0755]
invirt-configure-git-hooks [new file with mode: 0755]

index da72f77..c74a563 100644 (file)
@@ -1,3 +1,4 @@
 var/lib/invirt-dev/queue
 var/log/invirt/builds
 usr/share/invirt-dev/build-hooks
+usr/share/invirt-dev/git-hooks
index 8980a61..471b2e2 100644 (file)
@@ -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
\ No newline at end of file
+build-hooks usr/share/invirt-dev
+git-hooks usr/share/invirt-dev
index d5c6961..88ca3f6 100755 (executable)
@@ -36,6 +36,14 @@ EOF
         echo "  adduser \$user sbuild"
         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 "-----"
+       }
     ;;
 
     abort-upgrade|abort-remove|abort-deconfigure)
diff --git a/git-hooks/other/post-receive b/git-hooks/other/post-receive
new file mode 120000 (symlink)
index 0000000..dc637f7
--- /dev/null
@@ -0,0 +1 @@
+../sub/post-receive
\ No newline at end of file
diff --git a/git-hooks/other/zephyr-post-receive b/git-hooks/other/zephyr-post-receive
new file mode 120000 (symlink)
index 0000000..d62b744
--- /dev/null
@@ -0,0 +1 @@
+../sub/zephyr-post-receive
\ No newline at end of file
diff --git a/git-hooks/sub/post-receive b/git-hooks/sub/post-receive
new file mode 100755 (executable)
index 0000000..53bd274
--- /dev/null
@@ -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
diff --git a/git-hooks/sub/update b/git-hooks/sub/update
new file mode 100755 (executable)
index 0000000..7bbac3d
--- /dev/null
@@ -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
diff --git a/git-hooks/sub/zephyr-post-receive b/git-hooks/sub/zephyr-post-receive
new file mode 100755 (executable)
index 0000000..da91abe
--- /dev/null
@@ -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/\e\[m/}@{/g' \
+         -e 's/\e\[33m/@color(yellow)/g' \
+         -e 's/\e\[31m/@color(red)/g' \
+         -e 's/\e\[32m/@color(green)/g' \
+         -e '1s/^/@{/' \
+         -e '$s/$/}/') |
+    zwrite -c "$class" -i "${instance:-$shortrev}" -s "${zsig:-Git}: $refname" -d
+  done
+done
diff --git a/git-hooks/super/update b/git-hooks/super/update
new file mode 100755 (executable)
index 0000000..3e74b23
--- /dev/null
@@ -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
diff --git a/invirt-configure-git-hooks b/invirt-configure-git-hooks
new file mode 100755 (executable)
index 0000000..bed41b5
--- /dev/null
@@ -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