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

Pre-commit hook to verify Perl syntax

From: Marcos Chaves <marcos.nospam_at_gmail.com>
Date: 2006-09-14 20:32:54 CEST

Hi. I couldn't find this in the archives.

I'm trying to create a pre-commit hook that only allows the commit of
Perl codes that pass the "perl -c" check. I have a initial version
(see below) that does exactly what I want IF the Perl code does not
use any customized module (.pm), because Perl can't find it when run
from the hook script.

Does anybody know how this could be done? I'm afraid that the hook
script would need to perform more tasks, like checking out the current
version of the path where the modules are located and then trying to
run "perl -c". Any ideas?

Thanks in advance,


- - - - - 8< - - - - -

#!/usr/bin/env perl -w

# pre-commit hook for Subversion
# deny commit of .pl and .pm Perl scripts if they don't pass the syntax check.
# under Windows, the contents of 'pre-commit.bat' should be:
# ...(repo path)...\hooks\pre-commit.pl %1 %2

$repos = shift;
$txn = shift;

# list files changed on this transaction
foreach $line (`svnlook changed -t $txn \"$repos\"`)
  if ($line !~ /^([AUD]).\s\s(.+)$/)
    print STDERR "Can't parse [$line].\n";
    $action = $1;
    $file = $2;

    # check syntax of new or modified .pl and .pm Perl files with 'perl -c'
    if (($file =~ /\.p[lm]$/) && ($action =~ /[AU]/))
      system("svnlook cat -t $txn \"$repos\" \"$file\" | perl -c");
      if ($? != 0)
        print STDERR "\n$file does not pass the syntax check.";


To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Thu Sep 14 20:33:39 2006

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