5,693,062 members and growing! (17,835 online)
Email Password   helpLost your password?
General Reading » Book Chapters » General     Beginner License: The Code Project Open License (CPOL)

Using Subversion with TortoiseSVN

By Prathapachandran.v

This article will give a detailed idea about the subversion usage using TortoiseSVN
Windows, Visual Studio, Dev

Posted: 2 Oct 2007
Updated: 27 Jun 2008
Views: 19,136
Bookmarked: 69 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
31 votes for this Article.
Popularity: 5.51 Rating: 3.69 out of 5
2 votes, 6.5%
1
4 votes, 12.9%
2
2 votes, 6.5%
3
10 votes, 32.3%
4
13 votes, 41.9%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

Subversion is an open source application which is used to build version control system. This document will give a detailed idea about the installation and usage of subversion by using the tool TortoiseSVN.

Install Subversion Client

TortoiseSVN is a very useful and very easy tool for doing all the subversion repository operations and is freely available.

For installing TortoiseSVN, do the following steps.

  1. Download TortoiseSVN from http://tortoisesvn.net/downloads
  2. Install the application by double clicking the .msi file.
  3. Restart the computer.

Accessing the Repository

Right click on the desktop and from the menu select TortoiseSVN->Repo Browser as shown in the figure

Screenshot - image003.gif

In the coming screen type the url of the repository say [http://MyServerName/svn/MyRepos or svn://MyServerName/MyRepos] and clicks OK.

Screenshot - image004.gif

It will display an authentication screen as shown below with provision to provide user id and password to login to repository. The subversion administrator will provide a user id and password for your repository access.

Screenshot - image005.gif

Check save authentication for saving the user name and password and click on [OK]. Now the following screen will appear displaying the repository contents.

Screenshot - image006.gif

Checking Out a Working Copy

To obtain a working copy you need to do a checkout from a repository. For checking out a project, right click on any folder inside the repo browser as shown.

Screenshot - image007.jpg

Or

Select a directory in windows explorer where you want to place your working copy. Right click to pop up the context menu and select the command SVNCheckout... as shown below.

Screenshot - image008.jpg

Now it will bring another popup shown below.

Screenshot - image009.jpg

Provide the directory name and press OK. It will checkout (getting the latest version) the selected repository to the checkout directory.If you enter a folder name that does not yet exist, then a directory with that name is created. You should only check out into an empty directory.

Icon Overlay

One of the most visible features of TortoiseSVN is the icon overlays which appear on files in your working copy.

Screenshot - image010.jpg

Icon Explaination

  1. A fresh checked out working copy has a green checkmark as overlay. That means the Subversion status is normal.

Screenshot - image011.jpg

  1. As soon as you start editing a file, the status changes to modified and the icon overlay then changes to a red exclamation mark. That way you can easily see which files were changed since you last updated your working copy and need to be committed.

Screenshot - image012.jpg

  1. If during an update a conflict occurs then the icon changes to a yellow exclamation mark.

Screenshot - image013.jpg

  1. If you have set the svn:needs-lock property on a file, Subversion makes that file read-only until you get a lock on that file. Read-only files have this overlay to indicate that you have to get a lock first before you can edit that file.

Screenshot - image014.jpg

  1. If you hold a lock on a file, and the Subversion status is normal, this icon overlay reminds you that you should release the lock if you are not using it to allow others to commit their changes to the file.

Screenshot - image015.jpg

  1. This icon shows you that some files or folders inside the current folder have been scheduled to be deleted from version control or a file under version control is missing in a folder.

Screenshot - image016.jpg

  1. The plus sign tells you that a file or folder has been scheduled to be added to version control.

Screenshot - image017.jpg

Sending Your Changes to the Repository

Sending the changes you made to your working copy is known as committing the changes. But before you commit you have to make sure that your working copy is up to date. You can either use TortoiseSVN → Update directly. Or you can use TortoiseSVN → Check for Modifications first, to see which files have changed locally or on the server.

If your working copy is up to date and there are no conflicts, you are ready to commit your changes. Select any file and/or folders you want to commit, then TortoiseSVN → Commit....

Screenshot - image018.jpg

Now tortoiseSVN commit dialog will come.

Screenshot - image019.jpg

Clicking on OK will commit your changes to repository.

Update Your Working Copy with Changes from Others

Periodically, you should ensure that changes done by others get incorporated in your local working copy. The process of getting changes from the server to your local copy is known as updating. Updating may be done on single files, a set of selected files, or recursively on entire directory hierarchies. To update, select the files and/or directories you want, right click and select TortoiseSVN → Update in the explorer context menu.

Screenshot - image020.jpg

A window will pop up displaying the progress of the update as it runs.

Screenshot - image021.jpg

Changes done by others will be merged into your files, keeping any changes you may have done to the same files. The repository is not affected by an update.

The progress dialog uses colour coding to highlight different update actions

Screenshot - image001.gif Purple

New item added to your WC.

Screenshot - image001.gif Dark red

Redundant item deleted from your WC, or missing item replaced in your WC.

Screenshot - image001.gif Green

Changes from repository successfully merged with your local changes.

Screenshot - image001.gif Bright red

Changes from repository merged with local changes, resulting in conflicts which you need to resolve.

Screenshot - image001.gif Black

Unchanged item in your WC updated with newer version from the repository.

Adding New Files and Directories

If you created new files and/or directories during your development process then you need to add them to source control too. Select the file(be) and/or directory from your working directory and use TortoiseSVN → Add.

Screenshot - image022.jpg

Now it will bring a popup as shown below.

Screenshot - image023.jpg

Select the required file(be) and folder(be) and click on OK. After you added the files/directories to source control the file appears with an added icon overlay which means you first have to commit your working copy to make those files/directories available to other developers

To add files from outside your working copy you can use the drag-and-drop handler:

1) Select the files you want to add

2) Right-drag them to the new location inside the working copy

3) Release the right mouse button

4) Select Context Menu SVN Add files to this WC. The files will then be copied to the working copy and added to version control after clicking the commit menu item.

Screenshot - image024.jpg

Another way to add the files and folder is by using the repo browser; you can directly drag and drop any item into the required location. But it will not update your working copy. You can use TortoiseSVN→SVN Update option to reflect the newly added items to the working copy.

Adding New Files and Directories

Delete

If you delete a file/directory using TSVN, the file is removed from your working copy and marked for deletion. The file'be parent folder shows a "deleted" icon overlay. You can always get the file back, if you call TortoiseSVN → Revert on the parent folder.

Move

If you want to move files inside a working copy, use the drag-and-drop handler again:

1) Select the files or directories you want to move

2) Right-drag them to the new location inside the working copy

3) Release the right mouse button

4) In the popup menu select Context Menu → SVN Move versioned files here

Screenshot - image025.jpg

After moving, renaming or deleting, use SVNCommit option to commit the changes to the repository.

If a file is deleted via the explorer instead of using the TortoiseSVN context menu, the commit dialog shows those files and lets you remove them from version control too before the commit. However, if you update your working copy, Subversion will spot the missing file and replace it with the latest version from the repository. If you need to delete a version-controlled file, always use TortoiseSVN → Delete so that Subversion doesn't have to guess what you really want to do.

If a folder is deleted via the explorer instead of using the TortoiseSVN context menu, your working copy will be broken and you will be unable to commit. If you update your working copy, Subversion will replace the missing folder with the latest version from the repository and you can then delete it the correct way using TortoiseSVN → Delete.

You can directly delete any file or folder by using TortoiseSVN repo browser.

Deny Multiple Checkout

By default, the subversion provides a local copy to all the users and each user can do their modification. Now the problem is, if a user submits their modification after the submission of another user, the subversion will show a message showing out of date, and so we have to merge those changes to the previous version. That means subversion works best without locking, using the "Copy-Modify-Merge" methods. But the main problem is in the case of "unmergeable" files, for example, graphics files, if two people change the same file, merging is not possible, so one of them will lose their changes.

For avoiding this problem, a method called "Locking" which allows only a single user can modify the repository item.

This can be achieved by doing the following steps.

Set the svn:needs-lockPropery to the File(be) or Directory

Screenshot - image026.jpg

From the propery list window select [Add] button.

Screenshot - image027.jpg

From the property name combo box, select svn:need-lock property.

Screenshot - image028.jpg

Click on [OK] and submit your changes to the repository by select TortoiseSVN → SVNCommit which is explained above. Now the icon of the property set item is displayed as shown below.

Screenshot - image029.jpg

NB: - For setting the svn:need-lock property for a folder, there is a small difference. I.e, the add property dialog will not display this property in the combo box. So we have to type the property into the editable combo box and check the apply property recursively (if required) for recursively apply the property. The property will not be displayed in the property editor of the folder that we applied, but it will list only for the individual subfiles.

We cannot edit a file with the svn:needs-lock propery (files with grey checked icon).

Getting Lock

A user cannot edit a file which has the property svn:needs-lock (The files become readonly). So for editing the document, right click on the readonly file and select TortoiseSVN → Get lock and commit the changes to the repository.

Screenshot - image030.jpg

Now the locked user gets the privilege to modify the file and submit his changes to the repository. All other users cannot edit the file and submit it to the repository (like VSS).

Make the Checkin Comments Mandatory

For this purpose, rightclick on the directory in the working folder and select the property add editor.

Screenshot - image031.jpg

Select the tsvn:logminimize property and set the minimum required length to our required size say 25 and commit the changes to the repository.

Screenshot - image032.jpg

Now each user can commit their changes to this particular directory only after entering comments with minimum 25 charectors length, because the [OK] button will be enabled only after entering a comment with the specified length.

Settings the Comment Marker

In the above section, we set the minimum comment length and make the comment mandatory. But a user cannot know how much lenth the comment required to enter and for this purpose we can mark the width of the comment.

Take the add properties editor and select the property tsvn:logwidthmarker as shown and set the value same as the log width.

Screenshot - image033.jpg

Commit your changes to the repository. Now in all the commit operation in the directory, the commit dialog will mark the width as shown below.

Screenshot - image034.jpg

Integrate with Bug Tracking System

It is very common in Software Development for changes to be related to a specific bug or issue ID. Users of bug tracking systems (issue trackers) would like to associate the changes they make in Subversion with a specific ID in their issue tracker. This type of associativity is mainly required in the case of code file, in which for each bug fix, we can commit the URL of the bug system also to the subversion.

TortoiseSVN can help the user in two ways:

  1. When the user enters a log message, a well defined line including the issue number associated with the commit can be added automatically. This reduces the risk that the user enters the issue number in a way the bug tracking tools can't parse correctly.
  2. When the user browses the log messages, TortoiseSVN creates a link out of each bug ID in the log message which fires up the browser to the issue mentioned.

For integrating TortoiseSVN with bug tracking system, do the following.

Identify the URL

Normally a URL for a bug tracking system has an id part. For example consider the URL http://tortoisesvn.tigris.org/issues/show_bug.cgi?id=12534

Here we can change the id to a TortoiseSVN internal variable %BUGID%. So the final URL takes the form

http://tortoisesvn.tigris.org/issues/show_bug.cgi?id=%BUGID%.

Apply the URL

For applying the URL to the subversion working folder, rightclick on a particular working folder, select properties and invoke property add dialog.

image035.jpg

Select the bugtraq:url property and enter the above preapared URL as value of the property. Click on [OK] and again add another property bugtraq:message and set the same URL as value and click on [OK].

Now the property list dialog should be looking as shown below.

image037.jpg

Commit your changes to repository and your integration with bugtracking system is almost completed.

Integartion in action

For each commit operation in subversion, you will get the commit dialog box with a bug-id/Issue-Nr edit box as shown below.

image038.jpg

If you have an issue id for the commit, then enter the bug id only in the edit box (else keep it blank) and enter the comments in the message and press [OK].

If you put an issue id say 12324 and comment say This is a bug message., and while taking TortoiseSVN Show Log, the dialog will be displayed as shown below. On clicking the link in the description, it will automatically open the bug tracking system and direct to the mentioned bug. If you did not put any id, then there should not be any URL in the description.

image039.jpg

Changing the bug number label

For changing the label of the bug-id/Issue-Nr edit box in the Commit dialog, select the property bugtraq:label and enter the display text and commit your changes to repository.

image040.jpg

The resulting dialog should look like shown below.

image041.jpg

For displaying a warning message box for the blank bug id input (by default no message), you can set the property bugtraq:warnifnoissue to yes as shown below.

image042.jpg

Now it will show a message as shown below on committing your changes.

image043.jpg

Conclusion

This article will give a basic idea about the usage of Subversion with the help of a subversion client tool named TortoiseSVN. For getting a detailed idea about TortoiseSVN and all its features and settings, refer the TortoiseSVN user manual. For finding the TortoiseSVN FAQ, visit http://tortoisesvn.net/faq.

About Author

Prathap.jpg

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Prathapachandran.v


I have been working as a software engineer for 4 years. Working experience is mainly in C# windows platform.
Skill Sets
============
.NET Technologies : C#,WPF
Other Languages : Visual C++, Visual Basic
Reporting Tools : Crystal Reports
RDBMS : SQL-Server 2000
Obfuscation Tool : Dotfuscator
Installation Tool : Install Shield 10
Occupation: Web Developer
Location: India India

Other popular Book Chapters articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 15 of 15 (Total in Forum: 15) (Refresh)FirstPrevNext
Questioncustomize optionmemberamirjamili@hotmail.com1:45 28 Nov '08  
GeneralGood Work!memberJijo raj3:54 26 Aug '08  
GeneralRe: Good Work!memberPrathapachandran.v19:11 26 Aug '08  
GeneralGood articlememberN a v a n e e t h8:07 28 Jun '08  
GeneralRe: Good articlememberPrathapachandran.v19:35 29 Jun '08  
GeneralProblem With "Get lock"memberzinki8:53 10 Jun '08  
GeneralRe: Problem With "Get lock"memberpmorelfourrier5:17 19 Jun '08  
QuestionError with TortoiseSVN1.4.8memberJulie Boby2:50 14 Apr '08  
Questionsvn plugin for vs2005 ?membernorbert_barbosa2:32 3 Oct '07  
AnswerRe: svn plugin for vs2005 ?memberPrathapachandran.v4:27 3 Oct '07  
AnswerRe: svn plugin for vs2005 ?memberSir Kot4:55 10 Oct '07  
AnswerRe: svn plugin for vs2005 ?memberPatje4:22 27 Jun '08  
AnswerRe: svn plugin for vs2005 ?memberSnakefoot10:35 11 Jul '08  
Generaldownload linkmemberSteveKing20:40 2 Oct '07  
GeneralRe: download linkmemberPrathapachandran.v23:27 2 Oct '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 27 Jun 2008
Editor: Sean Ewington
Copyright 2007 by Prathapachandran.v
Everything else Copyright © CodeProject, 1999-2008
Web17 | Advertise on the Code Project