Written by: Svend Gundestrup
Category: Linux
Hits: 5686

problem: since upgrating to ubuntu 9.04 commit mailer was not working.

here is the solution from: http://blog.charlvn.com/2008/02/setting-up-commit-emailpl.html

 

Setting up commit-email.pl

How would you like to receive an e-mail every time a commit is made to a certain subversion repository? No problem. SSH into your server and do the following.

Firstly, change your working directory to the hooks directory of your repository. For example, if my repository is located at /var/svn/myproject I would type the following:

cd /var/svn/myproject/hooks

If you haven't done this already, enable the post-commit hook.

cp post-commit.tmpl post-commit
chmod +x post-commit

Get the commit-email.pl script. You can search for it on your local system. For example:

locate commit-email.pl

And you might get something like:

/usr/share/doc/subversion-1.2.3/tools/hook-scripts/commit-email.pl

If you do, it would normally be the easiest just to copy this file, for example:

cp /usr/share/doc/subversion-1.2.3/tools/hook-scripts/commit-email.pl .

Otherwise, download the script:

wget http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/commit-email.pl.in

If you download the above file, you need to replace all occurrences of @SVN_BINDIR@ with the directory of your subversion tools. First, find this directory. For example, if you type:

whereis svn

You might get:

svn: /usr/bin/svn /usr/share/man/man1/svn.1.gz

In this case, your directory will be /usr/bin. Just run the replace, for example with sed:

sed 's/@SVN_BINDIR@/\/usr\/bin/' commit-email.pl.in > commit-email.pl

Now of course just make sure this script is executable:

chmod +x commit-email.pl

Now test the script as there is probably like a million things that can go wrong here:

./commit-email.pl /var/svn/myproject 1 

In my case, I got this:

./commit-email.pl: use of either `-h' or `--from' is mandatory when sending email using direct SMTP.

At least simple to fix:

./commit-email.pl /var/svn/myproject 1  --from 

Now it works. Well, if you see nothing, it should work. Check your inbox. If you don't receive the mail, maybe you're just being impatient, but if you don't after a day or two, you're not necessarily farked, but good luck in debugging that bastard...

(By the way, in this case with me, I received the mail but the mail headers were stuffed.)

That was with the script I downloaded, if I try the copy that existed on my machine, I got this:

Use of uninitialized value in -d at ./commit-email.pl line 224.

On line 224, we have:

my $tmp_dir = ( -d $ENV{'TEMP'} ? $ENV{'TEMP'} : '/tmp' );

I just replaced this with:

my $tmp_dir = '/tmp';

Now it worked perfectly, no obvious issues.

Anyway, next thing is to trigger this from your post-commit script. Just edit the script with whatever you want, like:

vim post-commit

Then add this line:

$REPOS/hooks/commit-email.pl "$REPOS" "$REV"