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

pre-commit hook script problems on Windows with perl

From: <scott_at_thurlow.textdrive.com>
Date: 2007-02-10 00:03:16 CET

I'm having problems getting a pre-commit hook script running. Inspired
by this bash script: http://svn.haxx.se/users/archive-2005-12/0596.shtml

I want to see if a lock has been set on a file(s) before allowing a
commit. The batch file runs (as far as I can tell), but it doesn't
appear that Tortoise svn ever gets the error message from the batch
file, as the commit goes through each time without a lock.

In the hooks directory are the two files below, first one is a batch
script and second is a perl file.

pre-commit.bat:
----------
@echo off

set repo=%1
set trx=%2

D:\Perl\bin\perl.exe -w "%repo%\hooks\pre-commit-lock-check.pl"
"%repo%" "%trx%"

set err=%errorlevel%

exit %err%
 ----------

pre-commit-lock-check.pl
-------
#!D:/Perl/bin/perl.exe
$ENV{'PATH'}="C\:\\Program
Files\\Subversion\\bin:C\:\\Program Files\\GnuWin32\\bin";

sub isFileLocked
{
chomp(@lines = `svnlook changed -t $TXN $REPOS`);
foreach (@lines) {
    print $_;
    # get the list of files that were changed
    chomp($_ = `echo $_ | cut -c 5-`);
    # look to see if any of those are locked, and if so count bytes
    $LOCKSET=`svnlook lock $REPOS $_ | grep "UUID Token" | wc -c`;
    if ($LOCKSET == 0 ) {
        $REPLY=$_;
        return 1;
    } # end if loop
} # end foreach loop

$REPLY="";
return 0;
} # end subroutine

$REPOS=$ARGV[0];
$TXN=$ARGV[1];

$lock = &isFileLocked;
if ($lock==1) {
    print(`"Failed commit because file '$REPLY' wasn't locked before
commit!" 1>&2`);
    exit 1;
}

# All checks passed, so allow the commit.
exit 0;
-------

I never get an error code back to Tortoise or via the command line,
whichever way I run the commit. Been pulling hair out over this, so any
advice appreciated.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Sat Feb 10 00:03:35 2007

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.