From 514515d641ebe554482b0ae746cbb2ab8b64f7dc Mon Sep 17 00:00:00 2001 From: Greg Brockman Date: Tue, 6 Jul 2010 00:28:00 -0400 Subject: [PATCH] Added git hooks to invirt-dev package svn path=/trunk/packages/invirt-dev/; revision=3038 --- debian/invirt-dev.dirs | 1 + debian/invirt-dev.install | 4 ++- debian/invirt-dev.postinst | 8 ++++++ git-hooks/other/post-receive | 1 + git-hooks/other/zephyr-post-receive | 1 + git-hooks/sub/post-receive | 8 ++++++ git-hooks/sub/update | 49 +++++++++++++++++++++++++++++++++++ git-hooks/sub/zephyr-post-receive | 49 +++++++++++++++++++++++++++++++++++ git-hooks/super/update | 26 +++++++++++++++++++ invirt-configure-git-hooks | 21 +++++++++++++++ 10 files changed, 167 insertions(+), 1 deletion(-) create mode 120000 git-hooks/other/post-receive create mode 120000 git-hooks/other/zephyr-post-receive create mode 100755 git-hooks/sub/post-receive create mode 100755 git-hooks/sub/update create mode 100755 git-hooks/sub/zephyr-post-receive create mode 100755 git-hooks/super/update create mode 100755 invirt-configure-git-hooks diff --git a/debian/invirt-dev.dirs b/debian/invirt-dev.dirs index da72f77..c74a563 100644 --- a/debian/invirt-dev.dirs +++ b/debian/invirt-dev.dirs @@ -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 diff --git a/debian/invirt-dev.install b/debian/invirt-dev.install index 8980a61..471b2e2 100644 --- a/debian/invirt-dev.install +++ b/debian/invirt-dev.install @@ -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 diff --git a/debian/invirt-dev.postinst b/debian/invirt-dev.postinst index d5c6961..88ca3f6 100755 --- a/debian/invirt-dev.postinst +++ b/debian/invirt-dev.postinst @@ -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 index 0000000..dc637f7 --- /dev/null +++ b/git-hooks/other/post-receive @@ -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 index 0000000..d62b744 --- /dev/null +++ b/git-hooks/other/zephyr-post-receive @@ -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 index 0000000..53bd274 --- /dev/null +++ b/git-hooks/sub/post-receive @@ -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 index 0000000..7bbac3d --- /dev/null +++ b/git-hooks/sub/update @@ -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 )" >&2 + exit 1 +fi + +if [ -z "$ref" ] || [ -z "$oldrev" ] || [ -z "$newrev" ]; then + echo "Usage: $0 " >&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 index 0000000..da91abe --- /dev/null +++ b/git-hooks/sub/zephyr-post-receive @@ -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 +# +# 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 diff --git a/git-hooks/super/update b/git-hooks/super/update new file mode 100755 index 0000000..3e74b23 --- /dev/null +++ b/git-hooks/super/update @@ -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 )" >&2 + exit 1 +fi + +if [ -z "$ref" ] || [ -z "$oldrev" ] || [ -z "$newrev" ]; then + echo "Usage: $0 " >&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 index 0000000..bed41b5 --- /dev/null +++ b/invirt-configure-git-hooks @@ -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 -- 1.7.9.5