52

I've always found checkin (commit) mails to be very useful for keeping track of what work other people are doing in the codebase / repository. How do I set up SVN to email a distribution list on each commit?

I'm running clients on Windows and the Apache Subversion server on Linux. The answers below for various platforms will likely be useful to other people though.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Joe Ludwig
  • 6,756
  • 7
  • 30
  • 29

16 Answers16

31

You use the post-commit hooks.

Here's a sample Ruby script that sends an email after each commit: commit-email.rb

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
pix0r
  • 31,139
  • 18
  • 86
  • 102
20

Have a look at the standalone Subversion Notify tool (Windows only!) It can do emailing on commit and also much more!

bahrep
  • 29,961
  • 12
  • 103
  • 150
Marius
  • 2,494
  • 6
  • 31
  • 41
  • 1
    SubVersionNotify is really a brilliant little tool. Worked perfectly for me. Thanks. – NLV Nov 22 '10 at 10:25
3

You'll want to familiarize yourself with repository hooks, particularly the post-commit hook.

jxh
  • 69,070
  • 8
  • 110
  • 193
Rytmis
  • 31,467
  • 8
  • 60
  • 69
2

VisualSVN Server has useful commit e-mail notification hook VisualSVNServerHooks.exe. It supports colored diffs and can send commit notifications only when commit affects certain repository path.

See "Configuring Email Notifications in VisualSVN Server".

bahrep
  • 29,961
  • 12
  • 103
  • 150
2

1) Install svnnotify on a svn server using sudo apt-get

2) Use post-commit hook of your repo (read on post-commit hooks on svn website)

3) Open post-commit hook file and paste following code to send an email using smtp server. Using smtp is straight forward since you don't need to configure sendmail.

4) Make sure after \ (line break) you don't have an extra space.

#!/bin/sh

REPOS="$1"
REV="$2"
TO="xyz@yah.com" # who will receive the notifications
FROM="hello@goog.com" # what will be in "FROM" fields


 /usr/bin/svnnotify \

--repos-path "$REPOS" \
--revision "$REV" \
--to $TO \
--from $FROM \
--reply-to $FROM \
--smtp "YOUR.SMTP.MAIL.COM" \
--subject-prefix "[svn commit]" \
--attach-diff -a \
--header 'Message generated on Subversion Check-in.' \
--footer 'OpenSource Team. ' \
--svnlook "/usr/local/bin/svnlook" \
--handler HTML::ColorDiff # make diff pretty
1

I did it on Linux server in 3 steps:

  1. Create a mailing list (svn-notify@xy.com) and add people to the list.

  2. Edit /path_to_your_svn/svn/hooks/svn-notify/mailer.conf

    • to_addr = svn-notify@xy.com
    • from_addr = %(author)s@xy.com
    • commit_subject_prefix =[XY-SVN]
  3. Add this line to your /path_to_your_svn/svn/hooks/post-commit file:
    /path_to_your_svn/svn/hooks/svn-notify/mailer.py commit "$REPOS" "$REV" /path_to_your_svn/svn/hooks/svn-notify/mailer.conf
Danijel
  • 8,198
  • 18
  • 69
  • 133
1

I use a post-commit script similar to this one.

It's sends a nice HTML email. I updated it some where it highlights code that was removed in red and highlights code that was added in blue.

bahrep
  • 29,961
  • 12
  • 103
  • 150
Mark Spangler
  • 4,816
  • 2
  • 21
  • 23
  • Hi mark can you please advise how to add this script as I need exactly the same script through which I can get detailed mail now I am using SVN and I can access my repository through tortoise SVN browser please advise how to implement this script so that I can also start receiving the mails – user1633823 Jan 26 '14 at 17:43
  • @user1633823 you just need to follow the install instructions on the site. But basically you just copy the script to the hooks/post-commit directory where your svn server is running & make it executable. – Mark Spangler Jan 27 '14 at 18:51
1

In the "hooks" directory of your specific subversion branch there are 9 template files to get you started.

Key point: subversion will not execute any of the files until they are renamed. To get post-commit.tmpl to execute under unix, rename it "post-commit". Under Windows, rename it to "post-commit.bat" or "post-commit.exe". Subversion will not execute the file if it is named "post-commit.tmpl" or "post-commit.sh" or the like.

Also, make sure that the file is executable by the same user that runs subversion.

Logan
  • 4,177
  • 3
  • 20
  • 35
1

What platform?

On Mac OS X I have installed msmtp and created a post-commit script under hooks in the repository. A .msmtprc file needs to be setup for the svn (or www) user.

REPOS="`echo $1 | sed 's/\/{root of repository}//g'` "
REV="$2"
MSG=`/usr/local/bin/svn log -v -r HEAD https://localhost$REPOS`

/usr/local/bin/msmtp {list of recipients} <<EOF
Subject: SVN-Commit $REPOS#$REV
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8Bit

$MSG
EOF

Make {root of repository} and {list of recipients} specific for your needs. Note I have used UTF-8 because we have some special characters here in Sweden (åäö).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
epatel
  • 45,805
  • 17
  • 110
  • 144
1

There's a related question here on post-commit hooks. Personally, I prefer to send a message to something I can get an RSS feed from, as an email-per-commit would overload my inbox pretty quickly.

Community
  • 1
  • 1
Matt Miller
  • 3,501
  • 5
  • 27
  • 26
1

You could use buildbot. It's a tool that can take arbitrary action whenever a check-in occurs. It's a full featured continuous integration system but if you just want emails it can certainly handle that. It has plug-ins for a variety of SCMs including SVN.

whitney
  • 356
  • 4
  • 5
1

Seconding @Matt Miller on RSS feeds.

There's a useful tool called WebSVN that offers RSS feeds of every repository and individual branches/tags/folders with full commit messages. It's also a great web interface for quickly looking at file histories and commits/diffs without having to run an update and open your editor of choice.

Community
  • 1
  • 1
Jason Sparks
  • 1,306
  • 11
  • 11
1

As someone else said, 'what platform'. On Windows I've used 'blat', which is a freebie command line SMTP mailer to do this, along with a post-commit and another batch file.

The post commit looks like this: (Just calls another batch file)

 call d:\subversion\repos\rts\hooks\mail %1 %2

And mail.bat looked like this:

copy d:\subversion\repos\RTS\hooks\Commitmsg.txt %temp%\commit.txt
copy d:\subversion\repos\RTS\hooks\subjbase.txt %temp%\subject.txt
svnlook info -r %2 %1 >> %temp%\commit.txt
echo Revision %2 >> %temp%\commit.txt
svnlook changed -r %2 %1 >> %temp%\commit.txt
svnlook author -r %2 %1 >> %temp%\subject.txt
c:\utils\blat %temp%\commit.txt -t <me@my.email.com> -sf %temp%\subject.txt -server ServerName -f "SVN Admin <svn@my.email.com>" -noh2

The biggest gotcha in writing SVN hooks is that you might have basically NO environment set-up - no exe path, no temp path, etc. Though maybe that's improved in more recent SVN builds.

Will Dean
  • 39,055
  • 11
  • 90
  • 118
0

Also SVNMailer, which works on Linux.

kervin
  • 11,672
  • 5
  • 42
  • 59
0

Check the svn-mod-email package described here. The svn-mod-email is a powerful tool for SVN email notifications management that is delivered as a Debian archive. It's easily to install, configure and use.

Guardian
  • 68
  • 5
0

There is a (large) example written in Perl included in the Subversion source (it can be viewed here).

Sean Carpenter
  • 7,681
  • 3
  • 37
  • 38