Created
March 4, 2011 12:18
-
-
Save wpalmer/854532 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From cc44b6cf52d4fdb4341f18e29ee0244a222b8e3a Mon Sep 17 00:00:00 2001 | |
From: Will Palmer <wmpalmer@gmail.com> | |
Date: Fri, 11 Feb 2011 08:30:23 +0000 | |
Subject: [PATCH] add GL_POST_UPDATE_PRE_APPLY hook capability | |
One can use a "secondary" post-update hook to run additional tasks when | |
the gitolite-admin repository is updated. However, up until now there | |
was nowhere to prevent other, perhaps-dependent updates from running in | |
the event that those secondary tasks are known to be impossible or | |
undesired. This had the potential to leave the updates in a | |
"half-released" state, which is something some people want to avoid, as | |
one of the benefits of putting things in gitolite-admin is to keep a | |
history of gitolite states. | |
Here we narrow the gap by providing a place for a "post-update, | |
pre-apply" hooks, which can run additional checks on these secondary | |
tasks, and exit unsuccessfully if they determine that the secondary | |
tasks would not, or should not, complete. The main post-update hook can | |
then pick up on this, and refuse to run much in the same way it refuses | |
to run if its own checks fail. | |
--- | |
conf/example.gitolite.rc | 1 + | |
doc/2-admin.mkd | 10 ++++++++++ | |
doc/gitolite.rc.mkd | 11 +++++++++++ | |
hooks/gitolite-admin/post-update | 14 ++++++++++++++ | |
4 files changed, 36 insertions(+), 0 deletions(-) | |
diff --git a/conf/example.gitolite.rc b/conf/example.gitolite.rc | |
index d800357..dd5343b 100644 | |
--- a/conf/example.gitolite.rc | |
+++ b/conf/example.gitolite.rc | |
@@ -52,6 +52,7 @@ $HTPASSWD_FILE = ""; | |
$RSYNC_BASE = ""; | |
$SVNSERVE = ""; | |
# $UPDATE_CHAINS_TO = "hooks/update.secondary"; | |
+# $ADMIN_POST_UPDATE_PRE_APPLY = "hooks/gl-post-update-pre-apply"; | |
# $ADMIN_POST_UPDATE_CHAINS_TO = "hooks/post-update.secondary"; | |
# $GL_ADC_PATH = ""; | |
# $GL_GET_MEMBERSHIPS_PGM = "/usr/local/bin/expand-ldap-user-to-groups" | |
diff --git a/doc/2-admin.mkd b/doc/2-admin.mkd | |
index ebc1a4d..0b3eb88 100644 | |
--- a/doc/2-admin.mkd | |
+++ b/doc/2-admin.mkd | |
@@ -106,6 +106,16 @@ Sometimes it is necessary to do something whenever a new repo is created. If | |
you need this functionality, just supply a hook called "gl-post-init" with | |
whatever code you want in it. | |
+<a name="_gl_post_update_pre_apply"></a> | |
+ | |
+#### "gl-post-update-pre-apply" hook | |
+ | |
+It can be desirable to add additional checks on the state of the admin | |
+repository prior to allowing it to apply its updates. To allow this, gitolite | |
+will run an extra "gl-post-update-pre-apply" hook, if it exists, and use its | |
+exit status to determine whether or not to proceed with the update and further | |
+chained hooks. | |
+ | |
<a name="_hook_chaining"></a> | |
#### hook chaining | |
diff --git a/doc/gitolite.rc.mkd b/doc/gitolite.rc.mkd | |
index a0f2710..4f6cf03 100644 | |
--- a/doc/gitolite.rc.mkd | |
+++ b/doc/gitolite.rc.mkd | |
@@ -216,6 +216,17 @@ on feedback from my users to find or fix issues. | |
$SVNSERVE = "/usr/bin/svnserve -r /var/svn/ -t --tunnel-user=%u"; | |
+ * hook checking | |
+ | |
+ * `$ADMIN_POST_UPDATE_PRE_APPLY`, string, default | |
+ "hooks/gl-post-update-pre-apply" | |
+ | |
+ By default, the post-update hook in the admin repo checks the exit status | |
+ of the "gl-post-update-pre-apply" hook prior to running the guts of the | |
+ post-update. If you're okay with the default, there's no need to change | |
+ this, but you can use this variable to set a different name or path for the | |
+ hook if you want to. | |
+ | |
* hook chaining | |
* `$UPDATE_CHAINS_TO`, string, default "hooks/update.secondary" | |
diff --git a/hooks/gitolite-admin/post-update b/hooks/gitolite-admin/post-update | |
index b7cbbb0..54a8415 100755 | |
--- a/hooks/gitolite-admin/post-update | |
+++ b/hooks/gitolite-admin/post-update | |
@@ -13,6 +13,20 @@ GIT_WORK_TREE=$GL_ADMINDIR git ls-tree --name-only master | | |
exit 1 | |
} | |
+ADMIN_POST_UPDATE_PRE_APPLY=`$GL_BINDIR/gl-query-rc ADMIN_POST_UPDATE_PRE_APPLY` | |
+[ -n "$ADMIN_POST_UPDATE_PRE_APPLY" ] || ADMIN_POST_UPDATE_PRE_APPLY=hooks/gl-post-update-pre-apply | |
+if [ -f $ADMIN_POST_UPDATE_PRE_APPLY ] || [ -L $ADMIN_POST_UPDATE_PRE_APPLY ] | |
+then | |
+ $ADMIN_POST_UPDATE_PRE_APPLY "$@" | |
+ if [ $? -ne 0 ] | |
+ then | |
+ echo "*** ERROR ***" >&2 | |
+ echo "exiting due to nonzero exit status of POST_UPDATE_PRE_APPLY script" >&2 | |
+ echo "until that script exits successfully, the post-update hook will not run" >&2 | |
+ exit 1 | |
+ fi | |
+fi | |
+ | |
# checkout the master branch to $GL_ADMINDIR | |
# (the GL_ADMINDIR env var would have been set by gl-auth-command) | |
GIT_WORK_TREE=$GL_ADMINDIR git checkout -f --quiet master | |
-- | |
1.7.4.1.287.g1ecf2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment