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

Re: Precommit hook script for Windows. PLS HELP

From: Dang Nguyen <haidangwa_at_comcast.net>
Date: Fri, 04 Jul 2008 06:53:38 -0700

Depending on what you want to do with the bug reference ID after it's
committed, but in general, I would use the bugtraq properties instead of
writing a hook script. Most svn clients, like TortoiseSVN, support
bugtraq properties and you can control the UI by setting them on your
committed folders. With the bugtraq properties, you can set things like
force users to enter a number, customize the label for the field, and
append/prepend the reference to the commit log. In my opinion, though,
I would not force the users to enter a bug number, because not all
commits are a result of a bug.

In my implementation, I use the bugtraq properties to let developers
enter a Bugzilla bug number. When the developers commit, they can enter
one or more bug numbers in the field (comma-separated). The bug number
is appended to the commit log message. In my case, I have it state,
"Resolves: %BUGID%", where %BUGID% is automatically replaced by the
number(s) they've entered in the bugtraq field. Additionally, I have a
post-commit hook script that will parse for the appended string and get
the bug numbers. From there, the hook script sends an email to
Bugzilla's email_in.pl script to automatically mark the bug
"Resolved:FIXED" and adds a bug comment with the SVN revision number and
a link to WebSVN showing the files changed. Google for "Subversion
Bugzilla integration" and you'll find lots of info.

In my case, the only scripting I had to do was the part that sends an
email to Bugzilla to resolve the bug, and it was a VERY short Nant
script. If all you need is to append the bug reference to your commit
log, then there's no scripting needed. Just set the bugtraq properties
on all of your folders.

To your other inquiry, a hook script can be written in anything you
want. However, you will need to create a pre-commit.bat (.cmd) or
post-commit.bat (.cmd) file in your <repo>\hooks folder that invokes
your script. In my case, I invoke a Nant script.

My post-commit.cmd looks like this:

        nant.exe -buildfile:commit-hooks.build -D:repository.path=%1
-D:revision=%2

/%1 and %2 are passed into the hook script by Subversion./

(ref:
http://codebetter.com/blogs/jeffrey.palermo/archive/2007/12/13/easily-extend-post-commit-hook-in-subversion-using-nant-email-anyone.aspx)

Uzo okoye wrote:
>
> Hi,
>
>
>
> I am a newbie to Subversion and have no clue to writing scripts!!!
>
>
>
> I am trying to write a script for windows so that it forces users to
> add a bug reference id during a commit.
>
>
>
> Now for starters
>
>
>
> I want to know if its possible to write the hook script directly as a
> bat file and get it to work or must I to use sth else like Python?
>
>
>
> Sb helped me write the script in python and in trying to execute it,
>
> I realised that the I donít have the utility SVNLOOK installed , so
> to resolve this I manually copied the file across the bin directory.
>
> I still get errors. I donít know why.
>
>
>
> This is the python script written for the hook and the corresponding
> error message
>
> ---------------------------------------------------------------------------
>
> #!/usr/bin/python
>
> # commit acceptance python client for SVN
>
>
>
> import os
>
> import re
>
> import sys
>
> import urlparse
>
>
>
> # configure svnlook path
>
> svnlookPath = '\"C:\\Program Files\\VisualSVN Server\\bin\\svnlook.exe\"'
>
>
>
> # get committer
>
> try:
>
> f = os.popen(svnlookPath + ' author -t ' + sys.argv[2] + '
> ' + sys.argv[1])
>
> committer = f.read()
>
> if f.close():
>
> raise 1
>
> committer = committer.rstrip("\n\r")
>
> except:
>
> print >> sys.stderr, 'Unable to get committer with svnlook.'
>
> print >> sys.stderr, svnlookPath
>
> print >> sys.stderr, sys.argv[1]
>
> print >> sys.stderr, sys.argv[2]
>
> sys.exit(1)
>
>
>
> # get commit message
>
> try:
>
> f = os.popen(svnlookPath + ' log -t ' + sys.argv[2] + ' '
> + sys.argv[1])
>
> commitMessage = f.read()
>
> if f.close():
>
> raise 1
>
> commitMessage = commitMessage.rstrip('\n\r')
>
> except:
>
> print >> sys.stderr, 'Unable to get commit message with
> svnlook.'
>
> print >> sys.stderr, svnlookPath
>
> print >> sys.stderr, sys.argv[1]
>
> print >> sys.stderr, sys.argv[2]
>
> sys.exit(1)
>
>
>
> # print arguments
>
> # print >> sys.stderr, 'Committer: ' + committer
>
> print >> sys.stderr, 'Commit message: "' + commitMessage + '"'
>
>
>
> if (re.match('^[a-zA-Z]+-[0-9]+([\s]+|$)',commitMessage)):
>
> print >> sys.stderr, 'Commit accepted.'
>
> sys.exit(0)
>
> else:
>
> print >> sys.stderr, 'Commit rejected: This repository
> requires a commit message to begin with a REF issue number.\n\reg
> REFPRJ-1'
>
> sys.exit(1)
>
>
>
> Commit Error Msg
>
>
>
>
>
> Command: Commit
>
> Modified: data\TEST\added2.sql
>
> Sending content: data\TEST\added2.sql
>
> Error: Commit failed (details follow):
>
> Error: Commit blocked by pre-commit hook (exit code 1) with output:
>
> Error: Unable to get committer with svnlook.
>
> Error: "C:\Program Files\TortoiseSVN\bin\svnlook.exe"
>
> Error: C:\data2
>
> Error: 80-1
>
> Finished!:
>
>
>
> Any help will be appreciated to resolving this.
>
>
>
> Thanks
>
>
>
>
>
> ... Cast your burdens upon the Lord for He cares for you ...
> Enough to die for you!!!
> ------------------------------------------------------------------------
>
>
>
> ------------------------------------------------------------------------
> Get fish-slapping on Messenger! Play Now
> <http://clk.atdmt.com/UKM/go/101719805/direct/01/>
Received on 2008-07-04 15:53:54 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.