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

Re: pre commit trigger

From: Alain Palamara <alain.p_at_ces.ch>
Date: Wed, 13 May 2009 17:25:06 +0200

Hello,

I'm not a Perl expert but I read that the arguments of the script are passed
through the @ARGV array, so I thing your problem is you did not have anything
in your $1, $2 variable and therefore the svnlook command fails.

Replace $1 by @ARGV[0] and $2 by @ARGV[1] in your script and it should be ok.

Hope this help.
Regards,
Alain

Refere to http://cslibrary.stanford.edu/108/EssentialPerl.html chap. "Match Variables" explain
what is $1, $2, ..

At 16:28 13.05.2009, you wrote:
>Two things: 1). Use the repository path passed in by the script. It
>might not be the one you're trying to use. 2). For giggles, put a few
>other print statements inside your script that guarantees that your
>script will definitely be printing something out. Note that I added
>four more "print" statements to your hook. This script is guaranteed
>to print out at least three lines to STDERR no matter what the value
>of @cmd is:
>
>#! /usr/bin/env perl
>
>print STDERR qq(DEBUG: Repository = "$1"\n);
>print STDERR qq(DEBUG: Transaction = "$2"\n);
>$svnlook = "/usr/bin/svnlook";
>$repo = "/usr/local/svn/projects";
>my @cmd = qx($svnlook changed -t $2 $repo);
>print STDERR qq(DEBUG: Command = ") . join(":", @cmd) . qq("\n);
>foreach(@cmd)
>{
> print STDERR qq(DEBUG: Now looking at "$_"\n);
> if ($_ =~/^A/)
> {
> print STDERR "added\n";
> exit 1;
> }
> else{
> print STDERR "not added\n";
> exit 1;
> }
>}
>
>If your script is actually being executed, the above version is
>guaranteed to print something, and might help you understand exactly
>what your error could be.
>
>If the script isn't printing anything, then it means that Subversion
>isn't executing your script:
>
>There are several conditions that must be met in order for a
>pre-commit hook script to work:
>
>* It must be called "pre-commit" on Unix, or "pre-commit.*" on Windows
>where the suffix of the hook script is in the PATHEXT environment
>variable. 90% of the time, it will be pre-commit.bat, but I've seen
>places where they add in the "py" or "pl" suffix into the PATHEXT
>environment variable and called the pre-commit hook "pre-commit.pl" or
>"pre-commit.py".
>
>* On Unix, f you are using something other than the standard shell
>script, you must have the "shebang" on the first line pointing to the
>correct interpreter to use.
>
>* The hook script must live in the hooks folder inside the Repository folder.
>
>* MOST IMPORTANTLY: On Unix, the hook script must be marked as being
>executable. That is, the permission should be something like 7xx or
>5xx and should be owned by the user who is executing the Subversion
>server process.
>
>
>The script Subversion runs is called pre-commit on Unix, and
>pre-commit.bat or pre-commit.exe on Windows (your extension must be in
>the list of executable file suffixes in the PATHEXT environment
>variable.)
>
>On Unix systems, not only does the script name must be pre-commit, but
>it must live in the hooks directory inside the repository AND (most
>importantly) be marked as executable (that is, the mode of the file
>should probably be either 5xx or 7xx) and owned by the process that
>runs your Subversion server.
>
>It is normally this last requirement, marking the file as executable,
>that most people forget.
>
>And, since you're using Perl, you must have the "#!" on the first line
>pointing to your Perl interpreter, or use "#! /usr/bin/env perl" on
>the first line and make sure your Perl interpreter is in the PATH.
>
>And, one hint to writing a Perl script: You should use the "open"
>statement to execute a command instead of using the qx(). This way,
>you can check the output of the open comment to verify it actually
>works:
>
>Instead of:
>
>my @cmd = qx($svnlook changed -t $2 $repo);
>print STDERR qq(DEBUG: Command = ") . join(":", @cmd) . qq("\n);
>foreach(@cmd)
>{
> ....
>}
>
>Try this:
>
>my $cmd = qq($svnlook changed -t $2 $repo);
>open (CMD, "$cmd|")
> or die qq(ERROR: Can't execute "$cmd" for reading: $!\n);
>while (<CMD>) {
> ....
>}
>
>This way, if your svnlook command doesn't execute for some reason,
>you'll know it. Using your syntax, you can't say for certain whether
>your svnlook command actually worked.
>
>On Wed, May 13, 2009 at 5:21 AM, Irfan Sayed <irfu.sayed_at_gmail.com> wrote:
>> i tried both the things but still not working. please help
>> here is my small script
>>
>> $svnlook = "/usr/bin/svnlook";
>> $repo = "/usr/local/svn/projects";
>> my @cmd = `$svnlook changed -t $2 $repo`;
>> foreach(@cmd)
>> {
>> Â if ($_ =~/^A/)
>> {
>> Â print STDERR "added\n";
>> Â exit 1;
>> }
>> else{
>> Â print STDERR "not added\n";
>> Â exit 1;
>> }
>> }
>>
>> this is just the sample simple script which i want to execute before commit.
>> it is not giving any output when i add or midify any file
>>
>> Please advise
>>
>> Regards
>> Irf
>>
>>
>> On Tue, May 12, 2009 at 7:46 PM, Ryan Schmidt
>> <subversion-2009b_at_ryandesign.com> wrote:
>>>
>>> On May 12, 2009, at 09:03, Irfan Sayed wrote:
>>>
>>>> here is the command i am using...
>>>>
>>>> svnlook changed -t $2 $repo
>>>> where $2 is the transaction no as given by pre-commit hook and $repo
>>>> contains the name of the repository.
>>>> isuue is that command is executing but all the print statement which i
>>>> mentioned in perl script i am not able to see
>>>> i am using tortise SVN client
>>>
>>> You will only see the output of your print statements on the client if you
>>> do 2 things:
>>>
>>> 1. Print to stderr instead of stdout.
>>> 2. Exit from the pre-commit hook script with a status other than 0. Yes,
>>> this will cause your pre-commit hook to fail. You cannot show output to the
>>> client unless your script fails.
>>>
>>> Are you doing both of those things?
>>>
>>> For example, in bash, you could do this:
>>>
>>>
>>> #!/bin/bash
>>>
>>> echo "This message will be seen by the client" 1>&2
>>> exit 1
>>>
>>>
>>>
>>
>>
>
>
>
>--
>David Weintraub
>qazwart_at_gmail.com
>
>------------------------------------------------------
>http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2238820
>
>To unsubscribe from this discussion, e-mail: [users-unsubscribe_at_subversion.tigris.org].

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=2239307

To unsubscribe from this discussion, e-mail: [users-unsubscribe_at_subversion.tigris.org].
Received on 2009-05-13 17:26:21 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.