• Javascript
  • Python
  • Go

Making Subversion (SVN) Send Emails on Check-Ins

Subversion, also known as SVN, is a popular version control system used by developers to manage source code. One of its key features is the ...

Subversion, also known as SVN, is a popular version control system used by developers to manage source code. One of its key features is the ability to send emails on check-ins, providing teams with real-time notifications of code changes. In this article, we will explore how to set up and configure Subversion to send emails on check-ins.

Firstly, let's understand why sending emails on check-ins is beneficial. When working on a project with multiple developers, it's crucial to have a clear understanding of code changes. This is where Subversion's email feature comes in. Whenever a developer commits changes to the repository, an email is sent to a designated recipient, typically the team lead or project manager. This allows for better collaboration and transparency within the team.

To enable email notifications, we need to configure Subversion's hooks. Hooks are scripts that are triggered by specific events within the repository. In this case, we will be using the post-commit hook, which is executed after a successful commit.

To start, we need to create a new file named "post-commit.tmpl" in the hooks directory of our Subversion repository. This file contains the template for the post-commit hook script. We can use any text editor to create this file, but it's recommended to use a code editor to ensure proper formatting.

Once the file is created, we need to add the following code to it:




/usr/bin/svn log -r $REV $REPOS | /usr/bin/mail -s "Code changes" [email address]

Let's break down this code. The first line specifies the shell we will be using to run the script, in this case, "/bin/sh". The next two lines define two variables, "$REPOS" and "$REV", which contain the repository path and the revision number, respectively.

The last line is where the magic happens. We use the "svn log" command to retrieve the commit message for the specific revision and then pipe it to the "mail" command, which sends an email with the subject "Code changes" to the specified email address. You can change the subject and email address to fit your needs.

Once the script is ready, we need to make it executable. In the hooks directory, run the command "chmod +x post-commit.tmpl" to make the script executable. Finally, we need to remove the ".tmpl" extension from the file name, making it "post-commit". This step is crucial as Subversion will only execute files without the ".tmpl" extension.

Now that our post-commit hook is set up, we can test it by making a commit to the repository. Upon a successful commit, an email should be received with the commit message. If you encounter any errors, make sure that the path to the "svn" and "mail" commands is correct and that the script is executable.

It's worth noting that the post-commit hook only sends an email with the commit message. If you want to include a diff of the code changes, you will need to modify the script to use the "svn diff" command instead of "svn log". This will include the actual code changes in the email, providing a more comprehensive overview of the commit.

In conclusion, Subversion's email feature is a valuable tool for teams working on collaborative projects. It allows for better communication and visibility of code changes, leading to a more efficient development process. By setting up the post-commit hook, you can easily configure Subversion to send emails on check-ins and keep your team informed in real-time.

Related Articles

Optimize SVN Checksum Repair

SVN (Subversion) is a popular version control system used by software development teams to manage and track changes to their projects. One o...

Gracefully Stopping svnserve -d

Gracefully Stopping svnserve -d: A Guide to Properly Shutting Down Your Subversion Server Subversion (SVN) is a popular version control syst...