Skip to main content.

Monday, Feb 26, 2007

SVN (Subversion) Shared Project Repositories

Today, you will learn how to access a group repository on the CS server which will make it easier for you to manage the source files of your group project. To get started, here is what you need to do:

  1. Follow the instructions at http://subclipse.tigris.org/install.html to download and install the Subclipse plugin for Eclipse. In Step 4, use one or the other of the Name/URL pairs, not both. In Step 6, you may need to unclick the checkbox "Show the latest version of a feature only" if you are using a slightly older version of Eclipse. After installation, Eclipse should restart itself.
  2. (This step may only be necessary when running Eclipse in Windows.) When Eclipse starts (or restarts), go to the "Window" menu and choose "Preferences..." (at the bottom). Expand the "Team" item in the dialog box, and select "SVN". In the button group labeled "SVN interface", choose "SVNKit (Pure Java)". Press the "OK" button.
  3. From your Eclipse workspace. Choose "New..." -> "Project" from the File menu. Under the new project dialog box, don't select "Java Project" as usual. Instead, expand the choices under the "SVN" folder and choose "Checkout Projects from SVN". Then click "Next".
  4. On the next dialog, select the "Create a new repository location" and click "Next". Under "Url" type "svn+ssh://cs.berry.edu/Users/svn/classes/2007_spr/csc121/group1" (or "...group2", depending on which group you are in). Then click "Next" at the bottom of the dialog.
  5. You will get a dialog box asking you to enter SSH credentials - enter your username on the server and password. (If you are doing this on your own computer, you may choose to "Save information" - otherwise, do not, as it will save your password.) Click "OK".
  6. A further dialog box will ask you to Enter SVN Author Name. Under author name, use your login name for the server, for example "nhamid", NOT "Nadeem Abdul Hamid" or whatever your real name is. You may choose to save this setting so that you don't need to enter it again.
  7. In the next dialog ("Select Folder..."), select the "files" folder and click "Next".
  8. Finally, in the "Check Out As..." dialog, choose the "Check out as project configured using the New Project Wizard" and click "Finish".
  9. Now, the New Project Wizard should start, as if you are creating a new project. Go through as usual, selecting "Java Project", then after clicking "Next", give it a name (which can be anything you want, like "Group 1 Project") -- this name is only for your workspace, it does not need to correspond to the name of the folder in the SVN repository.
  10. When the project dialog box finishes, you should see your newly created project, with a file already in it, called "test.txt".
  11. If Eclipse ever asks you to type in your username with relation to the Subversion repository, make sure you use exactly your login name on the server.

What just happened? SVN (Subversion) is a version control system. It is a production quality system in widespread use around the world. I have set up what is called a repository on the CS server. In the repository folder for your group will be stored the official copies of your group's source code files. You will all be able to access and modify the files from the repository at any time. (Of course you probably don't want two people editing the same file at a time -- I will talk about that.)

When you check out a project from the SVN repository, it copies the latest versions of the files in the repository onto your local hard drive. You can make changes to the files in your Eclipse workspace. After editing the files, after you are satisfied that there are no errors, you can 'commit' your modifications to the repository. The others on your team (and yourself) can run an update command every now and then to get the latest versions of all the files from the repository.

SVN does not automatically prevent two people from making changes to the same file and committing them. This can cause conflicts in the version that is stored on the repository. SVN provides some fancy algorithms to try and merge the changes in a meaningful way. To maintain your sanity, you will want to avoid all this. Before beginning to edit a file, you should use the "Team" menu (right-click on a file) to choose the "Lock" operation on a file. This way, if someone else in your group has already locked a file for editing, you will not be able to do so.

When you are done making changes to a file and are ready to share them with the others on your team, choose the "Commit" option on the "Team" menu for a particular file, or for the entire project. (Don't forget to "Unlock" the file too, if you locked it.)

To download the changes that others have made to the repository into your local workspace, choose the "Update" command from the "Team" menu.

Helpful hints for working with CVS:

  • Before opening and editing a file, check if anyone else is by attempting to "Lock" it.
  • Do not commit files that have compile errors in them. This will cause everyone who updates their local copies to get the file with errors -- meaning no one will be able to develop anything until the errors are cleared up.
  • After you are finished editing a file, and there are no errors in it, commit it so that the updated version is saved in the repository. You can commit files as often as you want (subject to the condition above -- i.e. no errors). "Unlock" the file if you are not going to be making any further changes.
  • Update your local copies of the file periodically to get changes that others have made to files.
  • If you really want to discard changes to some file, and revert to the last version that was committed to the repository, choose the "Revert" command from the "Team" submenu for the file. Be very careful about this though -- it will throw away any changes you have made since the last time you retrieved that file from the repository.