Post Subversion commit comments on Trac Tickets

9 views
Skip to first unread message

Mark van Sintfiet

unread,
Jul 23, 2007, 8:30:59 AM7/23/07
to Trac Users
I'm looking for a way to add Subversion commit comments to Trac
Tickets.

I enabled the field for entering Ticket ID's in the TorotoiseSVN
commit window with bugtraq settings. Now I want these comments to
appear in the "Change Historie" part of the Trac ID.

So like this :
06/22/07 11:24:57 changed by <user>
<subversion comment>
Done in revision or changeset <number>

I think I'm not the only and first one trying to do this and I hope
there is an easy way to get this working.

Rainer Sokoll

unread,
Jul 23, 2007, 8:33:36 AM7/23/07
to trac-...@googlegroups.com
On Mon, Jul 23, 2007 at 05:30:59AM -0700, Mark van Sintfiet wrote:

> I'm looking for a way to add Subversion commit comments to Trac
> Tickets.

You are looking for trac-post-commit-hook. It can be found in the
contrib directory of the source.

Rainer

Mark van SIntfiet

unread,
Jul 23, 2007, 10:17:23 AM7/23/07
to trac-...@googlegroups.com
I have been looking into that but I just don't understand how to enable it, in Trac/Subversion? I assume I need to eit configuration files but I don't know what and where.

I googled for a manual many times, is there a URL with a step-by-step guide to setup this thing.

Mark van Sintfiet

Emmanuel Blot

unread,
Jul 23, 2007, 10:29:47 AM7/23/07
to trac-...@googlegroups.com
Search "commit hook" in the Subversion book:

Basically, SVN calls a pre-commit hook before committing a change to
the repository, then calls a post-commit hook when/if the change has
been commited. These scripts need to be put into the 'hooks/'
subdirectory in your SVN repository tree (that is if /var/svn/project
is your SVN repository, put the scripts into /var/svn/project/hooks).
The name of the scripts does matter, as SVN seeks for a specific name
to invoke the appropriate scripts ("pre-commit" and "post-commit").
Remember that these scripts needs to be executable by the server that
runs SVN (Apache, on most installations).

You can then either invoke the Trac contrib scripts from here.

HTH,
Manu


--
Manu

Emmanuel Blot

unread,
Jul 23, 2007, 10:32:59 AM7/23/07
to trac-...@googlegroups.com
> You can then either invoke the Trac contrib scripts from here.
or add a small wrapper shell script that setup the Trac environment
(such as the PYTHONPATH env.var. and the like) and invoke the Trac
commit scripts with the appropriate options.

Mark van SIntfiet

unread,
Jul 24, 2007, 5:08:08 AM7/24/07
to trac-...@googlegroups.com

Okay, this is what I did:

1. I copied "trac-post-commit-hook" and "trac-post-commit-hook.cmd" to "/var/lib/svn/myproject/hooks" and made them readable by apache(www-data)

2. Then I copied "post-commit.tmpl" to "post-commit" in "/var/lib/svn/myproject/hooks" and I added 1 line to activate the "track-post-commit-hook", "post-commit" looks like:

<START>

REPOS="$1"

REV="$2"

 

/usr/share/subversion/hook-scripts/commit-email.pl "$REPOS" "$REV" commit-...@example.org

 

/usr/bin/python /var/lib/svn/P0001/hooks/trac-post-commit-hook -p "$TRAC_ENV" -r "$REV"

<END>

3. I made post-commit readable for apache

4. Now I committed something in Subversion and added this comment "test modification, refs #1" but nothing happens.

 

What do I do wrong?

-----Original Message-----
From: trac-...@googlegroups.com [mailto:trac-...@googlegroups.com] On Behalf Of Emmanuel Blot
Sent: maandag 23 juli 2007 16:33
To: trac-...@googlegroups.com
Subject: [Trac] Re: Post Subversion commit comments on Trac Tickets

 

 

> You can then either invoke the Trac contrib scripts from here.

Christopher Arndt

unread,
Jul 24, 2007, 5:23:40 AM7/24/07
to Trac Users
On 24 Jul., 11:08, "Mark van SIntfiet" <markvansintf...@gmail.com>
wrote:

> Okay, this is what I did:
> 3. I made post-commit readable for apache
> What do I do wrong?

You also need to make it executable for apache.

And don't forget to make all files that these scripts read/write
accessible for apache too.

Chris

Emmanuel Blot

unread,
Jul 24, 2007, 5:30:57 AM7/24/07
to trac-...@googlegroups.com
> 3. I made post-commit readable for apache
As I wrote earlier: executable permission is required (on a Un*x machine)

> 4. Now I committed something in Subversion and added this comment "test
> modification, refs #1" but nothing happens.

The nice thing with the post-commit script is that you can run it from
the command line to test it:
sudo -u <apache> /var/lib/svn/myproject/hooks/post-commit
/var/lib/svn/myproject <rev>
where <apache> is the Apache effective user, and <rev> is the revision
that you want to test.

Maybe you miss a PYTHONPATH setting in your shell script (depending on
how/where your Trac is installed).

HTH,
Manu

Mark van Sintfiet

unread,
Jul 24, 2007, 5:51:25 AM7/24/07
to Trac Users
okay, after running " sudo -u <apache> /var/lib/svn/myproject/hooks/
post-commit /var/lib/svn/myproject <rev>" I get this error:

IOError: [Errno 2] No such file or directory: '/var/lib/svn/P0001/
VERSION'

I think the VERSION directory is not a Subversion rep directory but a
Trac directory. The script has to look in "/var/lib/trac/P0001/
VERSION" .

Where can I specify the trac location for this script?

Emmanuel Blot

unread,
Jul 24, 2007, 6:05:00 AM7/24/07
to trac-...@googlegroups.com
/var/lib/svn/myproject in my previous example is the SVN repository,
while TRAC_ENV in your script is the Trac project directory

Cheers,
Manu


--
Manu

Mark van Sintfiet

unread,
Jul 24, 2007, 7:15:31 AM7/24/07
to Trac Users
Okay, it works when I running it from commandline, but I want it to
run automatically after commit. I thought creating a file "post-
commit" in the "hooks" dir was enough.

Is there a way to trouble-shooot the commit action? I can't find
entries in my syslog or apache error log?

Mark

Christian Boos

unread,
Jul 24, 2007, 8:05:24 AM7/24/07
to trac-...@googlegroups.com
Mark van Sintfiet wrote:
> Okay, it works when I running it from commandline, but I want it to
> run automatically after commit. I thought creating a file "post-
> commit" in the "hooks" dir was enough.
>

It must be set executable, I think.

> Is there a way to trouble-shooot the commit action? I can't find
> entries in my syslog or apache error log?
>

Also, keep in mind that the hook is run by Subversion without any
environment variable set.
So if you have to adjust the PYTHONPATH for example, or the
LD_LIBRARY_PATH for the svn libraries, this must be done in the hook
script itself.

-- Christian

Emmanuel Blot

unread,
Jul 24, 2007, 8:13:56 AM7/24/07
to trac-...@googlegroups.com
> Is there a way to trouble-shooot the commit action? I can't find
> entries in my syslog or apache error log?

You can redirect the output stream to a temp error file, and analyse
it if the execution fails.
My own scripts simply post the output error stream as an email to the
SVN admin in the event of an execution failure, for example

Cheers,
Manu

Reply all
Reply to author
Forward
0 new messages