diff --git a/scripts/git-post-update b/scripts/git-post-update new file mode 100755 index 0000000..2284d40 --- /dev/null +++ b/scripts/git-post-update @@ -0,0 +1,22 @@ +#!/bin/sh +# +# This hook does only one thing: +# +# 1. It calls the gitpostupdate.php script with the current $GIT_DIR +# as argument. The gitpostupdate.php script will then trigger +# the 'gitpostupdate.php::run' event with the $GIT_DIR as argument +# together with merged $_ENV and $_SERVER array. +# +# This hook is normally installed automatically at the creation of your +# repository if you have everything configured correctly. If you want +# to enable it later, you need to symlink it as "post-update" in your +# $GIT_DIR/hooks folder. +# +# git$ cd /home/git/repositories/project.git/hooks +# git$ ln -s /home/www/indefero/scripts/git-post-update post-update +# + +SCRIPTDIR=$(dirname $(readlink -f $0)) +PHP_POST_UPDATE=$SCRIPTDIR/gitpostupdate.php + +echo php $PHP_POST_UPDATE $GIT_DIR | at now diff --git a/scripts/gitpostupdate.php b/scripts/gitpostupdate.php new file mode 100644 index 0000000..7ef0fa1 --- /dev/null +++ b/scripts/gitpostupdate.php @@ -0,0 +1,58 @@ + '/path/to/git/repository.git', + * 'env' => array_merge($_ENV, $_SERVER)); + * + */ +$params = array('git_dir' => $argv[1], + 'env' => array_merge($_ENV, $_SERVER)); +Pluf_Signal::send('gitpostupdate.php::run', 'gitpostupdate.php', $params); + + diff --git a/src/IDF/Plugin/SyncGit.php b/src/IDF/Plugin/SyncGit.php index 9e69143..063f85c 100644 --- a/src/IDF/Plugin/SyncGit.php +++ b/src/IDF/Plugin/SyncGit.php @@ -42,11 +42,41 @@ class IDF_Plugin_SyncGit */ static public function entry($signal, &$params) { + Pluf_Log::event('IDF_Plugin_SyncGit called.'); // First check for the single mandatory config variable. if (!Pluf::f('idf_plugin_syncgit_sync_file', false)) { + Pluf_Log::debug('IDF_Plugin_SyncGit plugin not configured.'); return; } - @touch(Pluf::f('idf_plugin_syncgit_sync_file')); - @chmod(Pluf::f('idf_plugin_syncgit_sync_file'), 0777); + if ($signal != 'gitpostupdate.php::run') { + @touch(Pluf::f('idf_plugin_syncgit_sync_file')); + @chmod(Pluf::f('idf_plugin_syncgit_sync_file'), 0777); + } else { + self::postUpdate($signal, $params); + } + } + + /** + * Entry point for the post-update signal. + * + * It tries to find the name of the project, when found it runs an + * update of the timeline. + */ + static public function postUpdate($signal, &$params) + { + // Find the corresponding project. + $git_dir = substr($params['git_dir'], 0, -4); // Chop the ".git" + $elts = explode('#/#', $git_dir, -1, PREG_SPLIT_NO_EMPTY); + $pname = array_pop($elts); + try { + $project = IDF_Project::getOr404($pname); + } catch (Pluf_HTTP_Error404 $e) { + Pluf_Log::event(array('IDF_Plugin_SyncGit::postUpdate', 'Project not found.', array($pname, $params))); + return false; // Project not found + } + // Now we have the project and can update the timeline + Pluf_Log::debug(array('IDF_Plugin_SyncGit::postUpdate', 'Project found', $pname, $project->id)); + IDF_Scm::syncTimeline($project, true); + Pluf_Log::event(array('IDF_Plugin_SyncGit::postUpdate', 'sync', array($pname, $project->id))); } }