[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: pre-commit hooks does not show any output

From: Ryan Schmidt <subversion-2008b_at_ryandesign.com>
Date: Fri, 16 May 2008 02:27:48 -0500

On May 15, 2008, at 4:02 PM, Hari Kodungallur wrote:

> But I believe the idea is to provide the user with information on
> how you can use the hooks to accomplish different things. Once you
> have the info, you are free to use any language you wish. [Unless
> some sort of 'web' is involved, I have not too many instances of
> php being used purely for scripting; but I could be wrong.].

Since version 4.3, PHP can be used for command-line scripts, not just
for making web pages. I write most of my command-line scripts in PHP,
so I don't have to learn yet another language.

Hook scripts can of course be written in PHP. Here's an example pre-
commit hook which checks that the log message is not empty:

#!/opt/local/bin/php
<?php

// Absolute paths to out helper programs.
define('SVNLOOK', '/opt/local/bin/svnlook');

// Get the command line arguments.
list(, $repo_path, $txn_name) = $_SERVER['argv'];

// Get the log message of the transaction.
$cmd = escapeshellarg(SVNLOOK)
        . ' log'
        . ' -t ' . escapeshellarg($txn_name)
        . ' ' . escapeshellarg($repo_path);
$output = array();
exec($cmd, $output, $error);
$log_message = trim(join("\n", $output));

if ($error) {
        fwrite(STDERR, "Error $error occurred trying to run svnlook.");
        exit($error);
} else if (empty($log_message)) {
        fwrite(STDERR, "Your log message was empty.");
        exit(1);
} else {
        // Allow the commit.
        exit(0);
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: users-help_at_subversion.tigris.org
Received on 2008-05-16 09:28:19 CEST

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.