December 30, 2006

Using Subversion with IntelliJ

Although IntelliJ comes with built-in support for Subversion (and CVS..), it's not really clear how to start working on a new Version Controlled project.
Searching the web, I couldn't find a tutorial that covers this topic, and the JetBrains site only has this not uninformative article http://www.jetbrains.com/idea/features/version_control.html

If you're unfamiliar with SVN or want to know more about it, there's a great online book available at http://svnbook.red-bean.com/

Prerequisites
1. Have an SVN service installed on your server (possibly via Apache) you can get SVN at http://subversion.tigris.com/
2. Have a repository filled with code.
3. Have IntelliJ 5.5 or 6 installed (http://www.jetbrains.com/idea/

Recommendation
Install the TortoiseSVN application (http://tortoisesvn.tigris.org/).
This application integrates with the windows explorer and enables communication with an SVN service (local or remote), essentially, it contains all the functionality that IntelliJ has, and more.

Now that we got that out of the way, let's start deploying the code and configuring the project.

Step 1: Checkout
Checkout means that we will be copying the latest (HEAD) version of the version controlled project to a local folder (also called a working copy).

  1. Close all the open projects in your IntelliJ Environment.
  2. Choose the checkout a new VCS (Version Controlled Source) – the bottom left link, and then choose the SVN.
    A new window should appear, which should contain a list of links to your SVN repositories. Choose the correct link or rather, If you have none, you can add a link by clicking the golden plus sign.
  3. Create a new local directory for the project and checkout the source files to that local directory.

This step can also be done without IntelliJ, if you've installed TortoiseSVN.
Moreover, if you browse to that directory, you will see it (and each sub-folder) contains a hidden .svn directory. Do not delete these directories!

Step 2: New Project
Using IntelliJ, create a new project and select the directory you've created in the previous step. Follow the New project wizard.
Notice that IntelliJ should detect the source files you've checked out (I tried this with Java files, so I don't know if it detects other types) .

Step 3: Link to the SVN
1. Go to module settings (File / Settings) or press Ctrl+Alt+S
2. Choose Version Control
3. Set the Default Version Control to Subversion (last in the list)

Outcome
There are a few things to notice after performing this step,
  1. Notice that the file names are now colored in black and that if you change the content of a file and save it, the file name will turn blue, indicating that the local version does not match the controlled version in the remote server.
  2. The Version Control Menu Item in the main menu contains more options
  3. If you right-click a file or directory, there's a subversion sub-menu you can expand that contains options such as commit (or check-in on IntelliJ5), update, compare, etc'.

Final Notes
  1. If you're developing a web-app, (possibly under Tomcat), you might want to checkout under the DocumentRoot, or map a location to you code.
  2. Don't commit your .iml, .ipr, .iws (which are Marron Colored)
  3. you might need to link libraries, this can be done by right-clicking a module / Module Settings
  4. I've been using Subversion with 5 other developers, one of which is using NetBeans and all the others are using IntelliJ.
  5. I've also written a post on how to install SVN on Eclipse available at http://levinboim.blogspot.com/2006/09/setting-up-subversion-with-eclipse-on.html

-- Tomer