currently broken. based on work done at Capgemini for SVN only.
src/plugins/scmhg/packaging/control/134plugin-scmhg.shortdesc -text
src/plugins/scmhg/packaging/dirs/plugin-scmhg -text
src/plugins/scmhg/packaging/install/plugin-scmhg -text
+src/plugins/scmhook/common/languages/Base.tab -text
+src/plugins/scmhook/common/scmhook-init.php -text
+src/plugins/scmhook/common/scmhookPlugin.class.php -text
+src/plugins/scmhook/cronjobs/updateScmRepo.php -text
+src/plugins/scmhook/db/scmhook-init.sql -text
+src/plugins/scmhook/etc/scmhook.ini -text
+src/plugins/scmhook/library/scmsvn/cronjobs/updateScmRepo.php -text
+src/plugins/scmhook/library/scmsvn/hooks/check-mime-type.pl -text
+src/plugins/scmhook/library/scmsvn/skel/pre-commit.check-mime-type.pl -text
+src/plugins/scmhook/library/scmsvn/skel/pre-commit.head -text
src/plugins/scmsvn/NAME -text
src/plugins/scmsvn/bin/install.sh svneol=native#text/x-sh
src/plugins/scmsvn/etc/scmsvn.ini -text
--- /dev/null
+#/**
+# *
+# * scmhook message catalog (English)
+# *
+# * GForge: Breaking Down the Barriers to Open Source Development
+# * Copyright 1999-2001 (c) VA Linux Systems
+# * 2005 (c) Daniel PĂ©rez <danielperez.arg@gmail.com>
+# * http://sourceforge.net
+# * Here you can add your own language customizations
+# *
+# *
+# */
+user_home view_scmhook View Personal scmhook
+project_admin scmhook View the scmhook Administration
--- /dev/null
+<?php
+/**
+ *
+ * This file is part of Fusionforge.
+ * Copyright 2011, Franck Villaume - Capgemini
+ *
+ * Fusionforge is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Fusionforge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Fusionforge; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+global $gfplugins;
+require_once $gfplugins.'scmhook/common/scmhookPlugin.class.php' ;
+
+$scmhookPluginObject = new scmhookPlugin;
+
+register_plugin($scmhookPluginObject);
+
+?>
--- /dev/null
+<?php
+/**
+ * scmhookPlugin Class
+ * Copyright 2011, Franck Villaume - Capgemini
+ *
+ * This file is part of FusionForge.
+ *
+ * FusionForge is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FusionForge; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+class scmhookPlugin extends Plugin {
+ function scmhookPlugin () {
+ $this->Plugin() ;
+ $this->name = "scmhook" ;
+ $this->text = "Scmhook" ; // To show in the tabs, use...
+ $this->hooks[] = "groupmenu" ; // To put into the project tabs
+ $this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
+ $this->hooks[] = "groupisactivecheckboxpost" ; //
+ $this->hooks[] = "adminScmHook";
+ $this->hooks[] = "scm_admin_update";
+ }
+
+ function CallHook($hookname, &$params) {
+ switch ($hookname) {
+ case "groupisactivecheckbox": {
+ //Check if the group is active
+ // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
+ $group_id=$params['group'];
+ $group = &group_get_object($group_id);
+ echo "<tr>";
+ echo "<td>";
+ echo ' <input type="CHECKBOX" name="use_scmhookplugin" value="1" ';
+ // CHECKED OR UNCHECKED?
+ if ( $group->usesPlugin($this->name)) {
+ echo "CHECKED";
+ }
+ echo "><br/>";
+ echo "</td>";
+ echo "<td>";
+ echo "<strong>Use ".$this->text." Plugin</strong>";
+ echo "</td>";
+ echo "</tr>";
+ break;
+ }
+ case "groupisactivecheckboxpost": {
+ // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
+ $group_id=$params['group'];
+ $group = &group_get_object($group_id);
+ $use_scmhookplugin = getStringFromRequest('use_scmhookplugin');
+ if ( $use_scmhookplugin == 1 ) {
+ $group->setPluginUse($this->name);
+ $this->add($group_id);
+ } else {
+ $group->setPluginUse($this->name, false);
+ $this->remove($group_id);
+ }
+ break;
+ }
+ case "adminScmHook": {
+ $group_id = $params['group_id'];
+ $group = &group_get_object($group_id);
+ if ($group->usesPlugin($this->name)) {
+ $this->displayScmHook($group_id);
+ }
+ break;
+ }
+ case "scm_admin_update": {
+ $this->update($params);
+ break;
+ }
+ }
+ }
+
+ function add($group_id) {
+ $res = db_query_params('INSERT INTO plugin_scmhook (id_group) VALUES ($1)', array($group_id));
+ if (!$res)
+ return false;
+
+ return true;
+ }
+
+ function remove($group_id) {
+ $res = db_query_params('DELETE FROM plugin_scmhook where id_group = $1', array($group_id));
+ if (!$res)
+ return false;
+
+ return true;
+ }
+
+ function update($params) {
+ $group_id = $params['group_id'];
+ $hooksString = '';
+ foreach($params as $key => $value) {
+ if ($key == strstr($key, 'hook_')) {
+ $hookname = substr_replace($key,'',0,strlen('hook_'));
+ $extensions = $this->getAllowedExtension();
+ foreach($extensions as $extension) {
+ $hookname = preg_replace('/_'.$extension.'$/', '.'.$extension, $hookname);
+ }
+ if (strlen($hooksString)) {
+ $hooksString .= '|'.$hookname;
+ } else {
+ $hooksString .= $hookname;
+ }
+ }
+ }
+ $res = db_query_params('UPDATE plugin_scmhook set hooks = $1, need_update = 1 where id_group = $2',
+ array($hooksString, $group_id));
+ if (!$res)
+ return false;
+ return true;
+ }
+
+ function displayScmHook($group_id) {
+ $hooksAvailable = $this->getAvailableHooks($group_id);
+ $statusDeploy = $this->getStatusDeploy($group_id);
+ if (count($hooksAvailable)) {
+ $hooksEnabled = $this->getEnabledHooks($group_id);
+ echo '<div id="scmhook">';
+ if ($statusDeploy)
+ echo '<p class="warning">'._('Hooks management update process waiting ...').'</p>';
+
+ echo '<table>';
+ echo '<thead><tr><th>'._('Enable Repository Hooks').'</th></tr></thead>';
+ echo '<tbody>';
+ for ($i = 0; $i < count($hooksAvailable); $i++) {
+ echo '<tr><td>';
+ echo '<input name="'.$hooksAvailable[$i].'" type="checkbox"';
+ if (in_array($hooksAvailable[$i], $hooksEnabled))
+ echo ' checked="checked"';
+
+ if ($statusDeploy)
+ echo ' disabled="disabled"';
+
+ echo '/>';
+ echo '<label>'.$hooksAvailable[$i].'</label>';
+ echo '</td></tr>';
+ }
+ echo '</tbody></table></div>';
+ }
+ }
+
+ function getStatusDeploy($group_id) {
+ $res = db_query_params('SELECT need_update FROM plugin_scmhook WHERE id_group = $1', array($group_id));
+ if (!$res)
+ return 1;
+
+ $row = db_fetch_array($res);
+ return $row['need_update'];
+ }
+
+ function getAvailableHooks($group_id) {
+ $listScm = $this->getListLibraryScm();
+ $group = &group_get_object($group_id);
+ for ($i = 0; $i < count($listScm); $i++) {
+ if ($group->usesPlugin($listScm[$i])) {
+ return $this->getListLibraryHook($listScm[$i]);
+ }
+ }
+ return array();
+ }
+
+ function getEnabledHooks($group_id) {
+ $res = db_query_params('SELECT hooks FROM plugin_scmhook WHERE id_group = $1', array($group_id));
+ if (!$res)
+ return false;
+
+ $row = db_fetch_array($res);
+ if (count($row)) {
+ return explode('|', $row['hooks']);
+ }
+
+ return array();
+ }
+
+ function getListLibraryScm() {
+ return array_values(array_diff(scandir(dirname(__FILE__).'/../library/'), Array('.', '..', '.svn')));
+ }
+
+ function getListLibraryHook($scm) {
+ $listHooks = array_values(array_diff(scandir(dirname(__FILE__).'/../library/'.$scm.'/hooks'), Array('.', '..', '.svn')));
+ $listPrecommit = array_values(array_diff(scandir(dirname(__FILE__).'/../library/'.$scm.'/skel'), Array('.', '..', '.svn', 'pre-commit.head')));
+ $validHooks = array();
+ foreach($listHooks as $hook) {
+ if (in_array('pre-commit.'.$hook, $listPrecommit)) {
+ $validHooks[] = $scm.'_'.$hook;
+ }
+ }
+ return $validHooks;
+ }
+
+ function getAllowedExtension() {
+ return array("sh", "pl");
+ }
+}
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
+?>
--- /dev/null
+<?php
+/**
+ *
+ * This file is part of Fusionforge.
+ * Copyright 2011, Franck Villaume - Capgemini
+ *
+ * Fusionforge is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Fusionforge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Fusionforge; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/**
+ * main cronjob for scmhook plugin
+ */
+
+require dirname(__FILE__).'/../../env.inc.php';
+
+require $gfwww.'include/squal_pre.php';
+require_once $gfcommon.'include/cron_utils.php';
+require_once $gfplugin.'scmhook/common/scmhookPlugin.class.php';
+
+define("CRON_ID", 21);
+
+function logger($level, $line) {
+ cron_logger($level, $line, CRON_ID);
+}
+
+function tracer(&$output) {
+ cron_tracer($output);
+}
+
+############
+###### START
+
+// get the list of project to be updated
+$res = db_query_params('SELECT groups.group_id, groups.scm_box, plugin_scmhook.hooks
+ FROM groups, plugin_scmhook
+ WHERE groups.status = $1
+ AND plugin_scmhook.id_group = groups.group_id
+ AND plugin_scmhook.need_update = $2
+ AND groups.use_scm = $3
+ AND groups.repo_created = $4',
+ array('A', 1, 1, 1));
+
+if (! $res) {
+ logger("FATAL", "Database Query Failed: " . db_error());
+}
+
+$scmhookPlugin = new scmhookPlugin;
+while ($row =& db_fetch_array($res)) {
+ $group_id = $row['group_id'];
+ $scm_box = $row['scm_box'];
+ $scmtype = '';
+ // find the scm type of the project
+ $listScm = $scmhookPlugin->getListLibraryScm();
+ $group = &group_get_object($group_id);
+ for ($i = 0; $i < count($listScm); $i++) {
+ if ($group->usesPlugin($listScm[$i])) {
+ $scmtype = $listScm[$i];
+ continue;
+ }
+ }
+ $returnvalue = true;
+ // call the right cronjob in the library
+ switch ($scmtype) {
+ case 'scmsvn': {
+ logger("INFO", "start updating hooks for project ".$group->getUnixName());
+ include $gfplugins.'scmhook/library/'.$scmtype.'/cronjobs/updateScmRepo.php';
+ global $svndir_prefix;
+ $params = array();
+ $params['group_id'] = $group_id;
+ $params['hooksString'] = $row['hooks'];
+ $params['scm_root'] = $svndir_prefix;
+
+ if (updateScmRepo($params)) {
+ $res = db_query_params('UPDATE plugin_scmhook set need_update = $1 where id_group = $2', array(0, $group_id));
+ if (!$res) {
+ $returnvalue = false;
+ }
+ }
+ break;
+ }
+ default: {
+ logger("WARNING", "No scm plugin found for this project ".$group->getUnixName()." or no cronjobs for thi type");
+ $returnvalue = false;
+ break;
+ }
+ }
+
+ if ($returnvalue) {
+ logger("INFO", "hooks updated for project ".$group->getUnixName());
+ } else {
+ logger("ERROR", "Unable to update hooks for project ".$group->getUnixName());
+ }
+}
+
+?>
--- /dev/null
+CREATE TABLE plugin_scmhook (
+ id serial PRIMARY KEY,
+ id_group integer NOT NULL,
+ need_update integer DEFAULT 0,
+ hooks text
+);
\ No newline at end of file
--- /dev/null
+[scmhook]
+
+; Current mantisbt is broken
+; plugin_status is a string.
+; valid means : production ready.
+; Any other strings means it's under work or broken and plugin
+; is available in installation_environment = development only.
+plugin_status = "development: current in rebase for trunk"
--- /dev/null
+<?php
+/**
+ *
+ * This file is part of Fusionforge.
+ * Copyright 2011, Franck Villaume - Capgemini
+ *
+ * Fusionforge is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Fusionforge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Fusionforge; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/**
+ * you need to implement only function updateScmRepo($params)
+ * $params is an array containing :
+ * $params['group_id'] = $group_id
+ * $params['hooksString'] = list of hooks to be deploy, separator is |
+ * $params['scm_root'] = directory containing the scm repository
+ */
+
+/**
+ * scmsvn_updateScmRepo - update the scmrepo with the new hooks
+ *
+ * @params Array the complete array description
+ * @return boolean success or not
+ */
+function updateScmRepo($params) {
+ global $sys_gforge_user;
+ global $sys_apache_user;
+ global $sys_apache_group;
+ $group_id = $params['group_id'];
+ $hooksString = $params['hooksString'];
+ $svndir_root = $params['scm_root'];
+ $group = &group_get_object($group_id);
+ $scmhookPlugin = new scmhookPlugin;
+ $hooksAvailable = $scmhookPlugin->getAvailableHooks($group_id);
+ $scm_box = $group->getSCMBox();
+ $unixname = $group->getUnixName();
+
+ $cr = 0;
+ // clean-up
+ $cr = passthru("ssh $sys_gforge_user@$scm_box \"[ -d $svndir_root/$unixname ]\"", $cr);
+ if ($cr == 0) {
+ $cr = passthru("ssh $sys_gforge_user@$scm_box \"sudo rm $svndir_root/$unixname/hooks/pre-commit\"", $cr);
+ foreach($hooksAvailable as $hookAvailable) {
+ $cr = passthru("ssh $sys_gforge_user@$scm_box \"sudo rm $svndir_root/$unixname/hooks/$hookAvailable\"", $cr);
+ }
+ }
+ // deploy new hooks
+ $newHooks = explode('|', $hooksString);
+ $cr = passthru("ssh $sys_gforge_user@$scm_box \"mkdir -p /tmp/hooks/$unixname\"", $cr);
+ if ($cr == 0) {
+ foreach($newHooks as $newHook) {
+ exec('scp '.dirname(__FILE__).'/../hooks/'.$newHook.' '.$sys_gforge_user.'@'.$scm_box.':/tmp/hooks/'.$unixname.'/');
+ }
+ $cr = passthru("ssh $sys_gforge_user@$scm_box sudo mv /tmp/hooks/$unixname/* $svndir_root/$unixname/hooks/", $cr);
+ $cr = passthru("ssh $sys_gforge_user@$scm_box sudo chown -R apache:apache $svndir_root/$unixname/hooks", $cr);
+ foreach($newHooks as $newHook) {
+ $cr = passthru("ssh $sys_gforge_user@$scm_box sudo chmod 755 $svndir_root/$unixname/hooks/$newHook", $cr);
+ }
+ }
+ // prepare the pre-commit
+ $file = fopen("/tmp/pre-commit-$unixname.tmp", "w");
+ fwrite($file, file_get_contents(dirname(__FILE__).'/../skel/pre-commit.head'));
+ $loopid = 0;
+ $string = '';
+ foreach($newHooks as $newHook) {
+ if ($loopid) {
+ //insert && \ between commands
+ $string .= ' && ';
+ }
+ $string .= rtrim(file_get_contents(dirname(__FILE__).'/../skel/pre-commit.'.$newHook));
+ $loopid = 1;
+ }
+ $string .= "\n";
+ fwrite($file,$string);
+ fclose($file);
+ logger ("INFO", "pre-commit file generated for project $unixname");
+ // deploy pre-commit
+ exec('scp /tmp/pre-commit-'.$unixname.'.tmp '.$sys_gforge_user.'@'.$scm_box.':/tmp/hooks/'.$unixname.'/pre-commit');
+ $cr = passthru("ssh $sys_gforge_user@$scm_box sudo mv /tmp/hooks/$unixname/pre-commit $svndir_root/$unixname/hooks/", $cr);
+ $cr = passthru("ssh $sys_gforge_user@$scm_box sudo chown -R apache:apache $svndir_root/$unixname/hooks", $cr);
+ $cr = passthru("ssh $sys_gforge_user@$scm_box sudo chmod 755 $svndir_root/$unixname/hooks/pre-commit", $cr);
+ // clean the tmp dirs
+ passthru("ssh $sys_gforge_user@$scm_box \"rm -rf /tmp/hooks/$unixname\"");
+ exec("rm /tmp/pre-commit-$unixname.tmp");
+ return true;
+}
+
+?>
--- /dev/null
+#!/bin/sh
+
+# PRE-COMMIT HOOK
+#
+# The pre-commit hook is invoked before a Subversion txn is
+# committed. Subversion runs this hook by invoking a program
+# (script, executable, binary, etc.) named 'pre-commit' (for which
+# this file is a template), with the following ordered arguments:
+#
+# [1] REPOS-PATH (the path to this repository)
+# [2] TXN-NAME (the name of the txn about to be committed)
+#
+# [STDIN] LOCK-TOKENS ** the lock tokens are passed via STDIN.
+#
+# If STDIN contains the line "LOCK-TOKENS:\n" (the "\n" denotes a
+# single newline), the lines following it are the lock tokens for
+# this commit. The end of the list is marked by a line containing
+# only a newline character.
+#
+# Each lock token line consists of a URI-escaped path, followed
+# by the separator character '|', followed by the lock token string,
+# followed by a newline.
+#
+# The default working directory for the invocation is undefined, so
+# the program should set one explicitly if it cares.
+#
+# If the hook program exits with success, the txn is committed; but
+# if it exits with failure (non-zero), the txn is aborted, no commit
+# takes place, and STDERR is returned to the client. The hook
+# program can use the 'svnlook' utility to help it examine the txn.
+#
+# On a Unix system, the normal procedure is to have 'pre-commit'
+# invoke other programs to do the real work, though it may do the
+# work itself too.
+#
+# *** NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN, EXCEPT ***
+# *** FOR REVISION PROPERTIES (like svn:log or svn:author). ***
+#
+# This is why we recommend using the read-only 'svnlook' utility.
+# In the future, Subversion may enforce the rule that pre-commit
+# hooks should not modify the versioned data in txns, or else come
+# up with a mechanism to make it safe to do so (by informing the
+# committing client of the changes). However, right now neither
+# mechanism is implemented, so hook writers just have to be careful.
+#
+# Note that 'pre-commit' must be executable by the user(s) who will
+# invoke it (typically the user httpd runs as), and that user must
+# have filesystem-level permission to access the repository.
+#
+# On a Windows system, you should name the hook program
+# 'pre-commit.bat' or 'pre-commit.exe',
+# but the basic idea is the same.
+#
+# The hook program typically does not inherit the environment of
+# its parent process. For example, a common problem is for the
+# PATH environment variable to not be set to its usual value, so
+# that subprograms fail to launch unless invoked via absolute path.
+# If you're having unexpected problems with a hook program, the
+# culprisage de log obligatoire !" may be unusual (or missing) environment variables.
+#
+# Here is an example hook script, for a Unix /bin/sh interpreter.
+# For more examples and pre-written hooks, see those in
+# the Subversion repository at
+# http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/ and
+# http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/
+
+REPOS="$1"
+TXN="$2"
+SVNLOOK=/usr/bin/svnlook
+
+$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" > /dev/null
+RESULT=$?
+if [ $RESULT -eq "0" ]; then
+ exit 0
+else
+ echo -e "-------------------------SIRHEN PRE COMMIT HOOK-------------------------" 1>&2
+ echo -e "\nChaque commit doit se voir accompagner d'un commentaire explicatif.\n" 1>&2
+ echo -e "-------------------------SIRHEN PRE COMMIT HOOK-------------------------" 1>&2
+ exit 1
+fi
+
+
+# Check that the author of this commit has the rights to perform
+# the commit on the files and directories being modified.
+#commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1
+
+# All checks passed, so allow the commit.
+exit 0
--- /dev/null
+#!/usr/bin/env perl\r
+\r
+# ====================================================================\r
+# commit-mime-type-check.pl: check that every added file has the\r
+# svn:mime-type property set and every added file with a mime-type\r
+# matching text/* also has svn:eol-style set. If any file fails this\r
+# test the user is sent a verbose error message suggesting solutions and\r
+# the commit is aborted.\r
+#\r
+# Usage: commit-mime-type-check.pl REPOS TXN-NAME\r
+# ====================================================================\r
+# Most of commit-mime-type-check.pl was taken from\r
+# commit-access-control.pl, Revision 9986, 2004-06-14 16:29:22 -0400.\r
+# ====================================================================\r
+# Copyright (c) 2000-2004 CollabNet. All rights reserved.\r
+#\r
+# This software is licensed as described in the file COPYING, which\r
+# you should have received as part of this distribution. The terms\r
+# are also available at http://subversion.tigris.org/license.html.\r
+# If newer versions of this license are posted there, you may use a\r
+# newer version instead, at your option.\r
+#\r
+# This software consists of voluntary contributions made by many\r
+# individuals. For exact contribution history, see the revision\r
+# history and logs, available at http://subversion.tigris.org/.\r
+# ====================================================================\r
+\r
+# Turn on warnings the best way depending on the Perl version.\r
+BEGIN {\r
+ if ( $] >= 5.006_000)\r
+ { require warnings; import warnings; }\r
+ else\r
+ { $^W = 1; }\r
+}\r
+\r
+use strict;\r
+use Carp;\r
+\r
+\r
+######################################################################\r
+# Configuration section.\r
+\r
+# Svnlook path.\r
+my $svnlook = "/usr/bin/svnlook";\r
+\r
+# Since the path to svnlook depends upon the local installation\r
+# preferences, check that the required program exists to insure that\r
+# the administrator has set up the script properly.\r
+{\r
+ my $ok = 1;\r
+ foreach my $program ($svnlook)\r
+ {\r
+ if (-e $program)\r
+ {\r
+ unless (-x $program)\r
+ {\r
+ warn "$0: required program `$program' is not executable, ",\r
+ "edit $0.\n";\r
+ $ok = 0;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ warn "$0: required program `$program' does not exist, edit $0.\n";\r
+ $ok = 0;\r
+ }\r
+ }\r
+ exit 1 unless $ok;\r
+}\r
+\r
+######################################################################\r
+# Initial setup/command-line handling.\r
+\r
+&usage unless @ARGV == 2;\r
+\r
+my $repos = shift;\r
+my $txn = shift;\r
+\r
+unless (-e $repos)\r
+ {\r
+ &usage("$0: repository directory `$repos' does not exist.");\r
+ }\r
+unless (-d $repos)\r
+ {\r
+ &usage("$0: repository directory `$repos' is not a directory.");\r
+ }\r
+\r
+# Define two constant subroutines to stand for read-only or read-write\r
+# access to the repository.\r
+sub ACCESS_READ_ONLY () { 'read-only' }\r
+sub ACCESS_READ_WRITE () { 'read-write' }\r
+\r
+\r
+######################################################################\r
+# Harvest data using svnlook.\r
+\r
+# Change into /tmp so that svnlook diff can create its .svnlook\r
+# directory.\r
+my $tmp_dir = '/tmp';\r
+chdir($tmp_dir)\r
+ or die "$0: cannot chdir `$tmp_dir': $!\n";\r
+\r
+# Figure out what files have added using svnlook.\r
+my @files_added;\r
+foreach my $line (&read_from_process($svnlook, 'changed', $repos, '-t', $txn))\r
+ {\r
+ # Add only files that were added to @files_added\r
+ if ($line =~ /^A. (.*[^\/])$/)\r
+ {\r
+ push(@files_added, $1);\r
+ }\r
+ }\r
+\r
+my @errors;\r
+foreach my $path ( @files_added )\r
+ {\r
+ my $mime_type;\r
+ my $eol_style;\r
+\r
+ # Parse the complete list of property values of the file $path to extract\r
+ # the mime-type and eol-style\r
+ foreach my $prop (&read_from_process($svnlook, 'proplist', $repos, '-t',\r
+ $txn, '--verbose', $path))\r
+ {\r
+ if ($prop =~ /^\s*svn:mime-type : (\S+)/)\r
+ {\r
+ $mime_type = $1;\r
+ }\r
+ elsif ($prop =~ /^\s*svn:eol-style : (\S+)/)\r
+ {\r
+ $eol_style = $1;\r
+ }\r
+ }\r
+\r
+ # Detect error conditions and add them to @errors\r
+ if (not $mime_type)\r
+ {\r
+ push @errors, "$path : svn:mime-type n'est pas defini";\r
+ }\r
+ elsif ($mime_type =~ /^text\// and not $eol_style)\r
+ {\r
+ push @errors, "$path : svn:eol-style n'est pas defini (svn:mime-type=$mime_type)";\r
+ }\r
+ }\r
+\r
+# If there are any errors list the problem files and give information\r
+# on how to avoid the problem. Hopefully people will set up auto-props\r
+# and will not see this verbose message more than once.\r
+if (@errors)\r
+ {\r
+ #warn "$0:\n\n",\r
+ warn "-------------------------SIRHEN PRE COMMIT HOOK-------------------------\n\nListe des fichiers en erreurs:\n\t",\r
+ join("\n\t", @errors), "\n\n",\r
+ <<EOS;\r
+Explications:\r
+\tChaque fichier ajoute sur SVN doit posseder la propriete:\r
+\t\tsvn:mime-type\r
+\tDe plus, les fichiers textes doivent egalement posseder la propriete:\r
+\t\tsvn:eol-style\r
+\r
+Configuration de l'environnement:\r
+\tSi votre environnement de developpement SIRHEN est correctement configure,\r
+\tce message ne devrait jamais s'afficher. Dans le cas contraire, verifiez la\r
+\tconfiguration automatique des proprietes SVN dans le menu MyEclipse:\r
+\t\tWindow > Preferences > Team > SVN > Properties Configuration\r
+\r
+Commandes en ligne:\r
+\tPour les fichiers binaires:\r
+\t\tsvn propset svn:mime-type application/octet-stream path/of/file\r
+\r
+\tPour les fichiers textes:\r
+\t\tsvn propset svn:mime-type text/plain path/of/file\r
+\t\tsvn propset svn:eol-style native path/of/file\r
+\r
+-------------------------SIRHEN PRE COMMIT HOOK-------------------------\r
+EOS\r
+ exit 1;\r
+ }\r
+else\r
+ {\r
+ exit 0;\r
+ }\r
+\r
+sub usage\r
+{\r
+ warn "@_\n" if @_;\r
+ die "usage: $0 REPOS TXN-NAME\n";\r
+}\r
+\r
+sub safe_read_from_pipe\r
+{\r
+ unless (@_)\r
+ {\r
+ croak "$0: safe_read_from_pipe passed no arguments.\n";\r
+ }\r
+ print "Running @_\n";\r
+ my $pid = open(SAFE_READ, '-|');\r
+ unless (defined $pid)\r
+ {\r
+ die "$0: cannot fork: $!\n";\r
+ }\r
+ unless ($pid)\r
+ {\r
+ open(STDERR, ">&STDOUT")\r
+ or die "$0: cannot dup STDOUT: $!\n";\r
+ exec(@_)\r
+ or die "$0: cannot exec `@_': $!\n";\r
+ }\r
+ my @output;\r
+ while (<SAFE_READ>)\r
+ {\r
+ chomp;\r
+ push(@output, $_);\r
+ }\r
+ close(SAFE_READ);\r
+ my $result = $?;\r
+ my $exit = $result >> 8;\r
+ my $signal = $result & 127;\r
+ my $cd = $result & 128 ? "with core dump" : "";\r
+ if ($signal or $cd)\r
+ {\r
+ warn "$0: pipe from `@_' failed $cd: exit=$exit signal=$signal\n";\r
+ }\r
+ if (wantarray)\r
+ {\r
+ return ($result, @output);\r
+ }\r
+ else\r
+ {\r
+ return $result;\r
+ }\r
+}\r
+\r
+sub read_from_process\r
+ {\r
+ unless (@_)\r
+ {\r
+ croak "$0: read_from_process passed no arguments.\n";\r
+ }\r
+ my ($status, @output) = &safe_read_from_pipe(@_);\r
+ if ($status)\r
+ {\r
+ if (@output)\r
+ {\r
+ die "$0: `@_' failed with this output:\n", join("\n", @output), "\n";\r
+ }\r
+ else\r
+ {\r
+ die "$0: `@_' failed with no output.\n";\r
+ }\r
+ }\r
+ else\r
+ {\r
+ return @output;\r
+ }\r
+}\r
--- /dev/null
+sh $SCRIPTPATH/check-log.sh "$1" "$2"
--- /dev/null
+perl $SCRIPTPATH/check-mime-type.pl "$1" "$2"
--- /dev/null
+#!/bin/sh
+
+SCRIPT=$(readlink -f $0)
+SCRIPTPATH=`dirname $SCRIPT`