Setting up Subversion in IntelliJ IDEA

This tutorial will guide you through setting up IntelliJ IDEA to work with Subversion. The new version of IntelliJ IDEA (version 7) has some remarkable improvements and new features concerning version control.We will start from creating a new project, import it into version control, and then checking it out again. If you want to set up Subversion for an existing project in that has already been imported, you can start at Checking out the Project.

Checking in the Project

The first thing you will need to do, is to create a new project in IntelliJ. For this example I named my project myproject.

Now you need to open the Version Control menu and select Import into Subversion…. Click on the + to add a repository. You will be prompted to enter the location to your Subversion repository. In this example, it will be:

http://localhost/svn

When the repository has been successfully added, right click on the repository. Select New and then Remote Folder…. Enter your project’s name (in this case it will be myproject) and click on OK.

Select the folder you have just created and click on Import. You will be prompted to select the project directory to import into Subversion. Select the base directory of the project you have just created and click on OK. It is always important to add a message when you commit to Subversion as this will help you later on when you need to create patches or revert to a previous version of the project. As my message, I entered initial import:

If you are prompted for a password, enter the username and password you set up when installing Subversion. I always select Save credentials which saves some time in entering your password each time.

As this was the initial import, we need to check it out of version control again to start working on it. When you check it out, IntelliJ will automatically set up the version control for the project. Note that the version control will only be set up with a checked out version and not with the project you have created on your hard drive. This means that any changes you make to the original project (the one we created in the first step) will not be versioned. In the next step we will delete the project that we have created and do a fresh checkout from Subversion. You may also just check it out to a different directory, but this may cause confusion so rather rename the original directory.

Close the project in IntelliJ and delete the project files (myproject is the base directory of the project):

rm -rf [your_project_location]/myproject

Checking out the Project
All the previous steps were necessary only for checking in a new project. If you want to start with an existing project from Subversion, you can follow the following steps:

Create a directory for your project (the project name in this case is myproject):

mkdir [your_project_location]/myproject

In IntelliJ, select Version Control from the menu and select Checkout from Version Control > Subversion. Expand the repository we added in the previous section and select the project directory (in this case myproject). Click on Checkout.

You will be asked to select the directory to where the project should be checked out to. Select the directory we created in the previous step and click on OK. The project will be checked out to the directory you have specified.

You will also be prompted to open the newly checked out project. If you open the project, you will notice a Changes tab at the bottom of the screen. From this tab you can commit your changes to Subversion, view the difference between different versions, add different changelists (handy for special configurations), create patches, revert to specific versions, shelve your changes, etc.

Exposing Subversion through Apache

This tutorial will guide you through exposing Subversion with the Apache HTTP Server on Ubuntu so that it can be accessed on a network. We will make use of the WebDAV protocol.

Before we start, you might want to check out:
Installing Subversion on Ubuntu
Installing Apache on Ubuntu

The first step is optional, but can assist you in identifying any errors that may happen through the process. Type the following at the terminal:

tail -f /var/log/apache2/error.log

This will display the Apache error log and will update and display the errors as they happen.

To enable Subversion to be used on the Apache server, you need to install the apache2-svn library which will also install the WebDAV protocol:

sudo apt-get install libapache2-svn

You will also need to add the Apache web user to the Subversion group:

sudo adduser www-data svn

In the previous command, ‘www-data’ is the Apache web user and ’svn’ is the group which has access to Subversion on the system.

Next we need to update the WebDAV protocol configuration. Enter the following at the terminal:

sudo gedit /etc/apache2/mods-available/dav_svn.conf

Uncomment the following lines:

<Location /svn>

DAV svn

SVNPath /var/lib/svn

AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd

Require valid-user

Now you need to edit the file to reflect the settings on your system. ‘SVNPath’ is the location of the Subversion home directory. In my case this should be changed to:

/home/svn

‘AuthUserFile’ should be changed to the location of your Subversion password file. We will create this file in the next step. In this case it will be:

/etc/subversion/passwd

Restart the server by entering the following at the terminal:

sudo /etc/init.d/apache2 restart

Next we will create the Subversion authentication file. This file contains user authentication details. If you have just installed Subversion, the password file will not yet exist and needs to be created using the ‘-c’ switch. Adding any users after that should be done without the ‘-c’ switch to avoid overwriting the password file. Enter the following at the terminal and enter your username in the ‘[username]’ field:

sudo htpasswd -c /etc/subversion/passwd [username]

You will be prompted for your password.

To add more users at a later stage, you can run the following command:

sudo htpasswd /etc/subversion/passwd [second_user_name]

To test that everything has been set up correctly, you can enter the following at the terminal:

svn info http://localhost/svn

This should display some information about your Subversion repository. You can now find the repository at the following location (enter this address in your browser to test):

http://localhost/svn/

Installing Subversion on Ubuntu

We all know how important it is to use version control even if you are working alone on a personal project at home. In this tutorial I will take you through installing Subversion on Ubuntu.

Installing Subversion on Ubuntu is extremely easy. To begin, enter the following at the terminal to update to the latest repositories:

sudo apt-get update

To start the installation enter the following at the terminal:

sudo apt-get install subversion

The first thing you need to do is to create a central repository where your files can be stored. I chose /home/svn. We will use the svnadmin tool which will create the path and also set up the repository:

sudo svnadmin create /home/svn

Next we need to create a group in order to enable access to the Subversion repository. Enter the following command at the terminal to create a group named ’svn’:

sudo addgroup svn

Now you can add yourself to this group:

sudo adduser your_username svn

You will also need to do this for every other user who will need access to the repository. After you have added yourself to the group, you will need to log out and log back in to ensure that you are registered as a member of the newly created group.

To enable access for the svn group to the repository we need to change the group and also set the permissions:

sudo chgrp -R svn /home/svn
sudo chmod -R g+rws /home/svn

And that’s it. You can now set up Subversion with your IDE or any other Subversion client. The repository can be located or accessed at the following two locations:

file:///home/svn
file://localhost/home/svn

You can test it by entering the following at the terminal:

svn info file:///home/svn

This should display some information about the repository.

Also note that this method will only allow local access. If you want to share the repository over a network, you will need to install Apache or some other server to expose the repository directory.