2009-03-13

How to: Easy SVN for code sharing

Upplagd av Johan

So, I thought I'd share this one, because I find it very useful in all sorts of projects that involve code. If you're not familiar with SVN, it is a way of keeping track of code when more than one person is involved in programing. It keeps track of changes, conflicts (multiple persons edited the same line) and lets more than one person edit a file at the same time. This tutorial will mainly go into how to set up a SVN using a program called Dropbox.

Dropbox is a small program that sits in your systray and keeps a folder on your hard drive synchronized with a server online. Everything you put in the folder is automatically uploaded to the server and you can access the files online. If you have the program running on more than one computer, the second computer automatically updates the content of the Dropbox folder when someone put a file in it on the first computer. Dropbox also lets you share folders with other Dropbox users, which is perfect when you need to share documents and code between group members in a small project.

The basic idea here is to avoid having to create a webserver, which is usually needed when using SVN. Instead we will use a shared folder in the Dropbox to store the SVN-information. So here we go, step by step (this is based on Windows but should be very similar on other OS):

  1. Let every group member register for a Dropbox account here (it's free and available for Windows, Mac and Linux!). Download and install the program.
  2. Create a folder somewhere in your Dropbox folder. This folder will function as the home folder for your project. Mind you that you should NOT put your folder in the folder "Photos", nor in the folder "Public". Other than that, you may put it wherever you like.
  3. Right click the Dropbox icon in your systray (you know the thing in the lower right of your screen if you're using Windows) and choose "Web Interface".
  4. Now hopefully your browser launches and you find yourself in your personal Dropbox page. If you scroll down you will find a web representation of your Dropbox folder. Navigate your way into the folder you created in step 2. Just below the text that say something similar to "My Dropbox >> My New Project Folder" you find a little text saying "Share this". Click it and invite all the group members to share the folder.
  5. When they accepted the invite, you all have a way to share whatever files you wish. Now it's time for the SVN-part!
  6. Go to this page and download TortoiseSVN. Install the program.
  7. Open your Dropbox by double clicking the icon in the systray and navigate to where your project folder is located.
  8. Now, create a new folder inside your project folder called "SVN" (doesn't have to be called this, but it is clearest this way). Right click the new folder and "TortoiseSVN->Create repository here".
  9. The program will now create a SVN-file structure for you. One important thing to remember with SVN is that YOU MAY NOT ALTER THE CONTENTS OF THE SVN-FOLDER IN ANY WAY WHAT SO EVER. This will ruin the SVN most likely, so it's best not to mock around in that folder at all.
  10. When the program is finished you have a SVN that is ready to use. Now all you have to do is to hook up your favorite coding environment to the SVN-folder. I'll show you how to do this in Eclipse, but it should be perfectly possible to use any other environment of your choice.
  11. Let's assume that you already have Eclipse downloaded, installed and running. Fire up a web browser and navigate to this page. We're going to install a plugin to Eclipse called Subclipse, which is for handling SVN. At the mentioned home page, look for "Download and Install" and well there, look for where it says"Eclipse update site URL". There will probably be a few different versions display there, so find the one that matches the version of Eclipse (use "Help->About" in Eclipse to see what version you run) that you have. Copy the URL.
  12. In Eclipse, go to "Help->Software Updates" (note: the exact name and location of that menu option may variate, but what you're looking for is the place where you can install new plugins. If you have problems installing Subclipse, try checking the help section on their web page). Click on "Available Software" and then "Add Site". Paste the URL you copied and click OK.
  13. The new site will now appear in the list of software sources. Fill in the box and click the button named "Install" (for some very stupid reason it's located to the upper right in my Eclipse version, very poor HCI indeed). Click your way through the installation and restart Eclipse when asked.
  14. Now we're almost finished! When Eclipse finished restarting, click "File->New->Other", find "SVN" in the list and click "Checkout Projects from SVN". Click "next".
  15. In the next screen you'll be asked if you want to use existing repository location or to create a new one. This has nothing to do with what we did before with Tortoise, so hit "create a new repository location" and hit next.
  16. Now you are asked to fill in a URL. The URL should be in the format "file:///C:/Path%20To/Dropbox/My%20Dropbox/ProjectFolder/SVN/". That is, "file:///" (yes, there should be three of them) and then the file path to the SVN-folder that we created using TortoiseSVN in step 8. You need to replace every backslash with a normal slash and all the blank spaces in the file path with "%20".
  17. If you done it all correctly, you should now be able to press next without any problems. If you are having problems clicking next, check the file path again. If it appears to be correct, try to install Subclipse again, we had some problems with it not installing correctly at the first attempt. The problem was cured by simply installing it again though.
  18. In the next screen, you need to mark the line saying "file:///C:/...."-someting (it has a yellow little icon next to it), and then next.
  19. Keep clicking next and following the instructions. At some point you'll be asked if you really want to check out the head revision, click yes. If every thing goes as planned, you should finally end up with a new project in your workspace, this will be your course project.
  20. For the rest of the group members, repeat steps 11-19.
I will not go through the use of SVN here, there are plenty of guides out there if you need them. Basically it all comes down to the TEAM-submenu that you get if you right click your project in the Eclipse workspace. There you can commit (upload) code, update code (download whats in the SVN-server that others have committed) and handle conflicts (click "mark as resolved" from the TEAM-submenu of the file that contained the conflict).

That's it, enjoy the SVN and the lack of troubles that usually come when people hack away at the same code at the same time... =)

0 kommentarer: