Click here to Skip to main content
Click here to Skip to main content
Go to top

SVN Shelve

, 23 Sep 2008
Rate this:
Please Sign up or sign in to vote.
A simple utility to shelve your projects under SVN.

Introduction

SVNShelve is a small utility, which works on top of SVN (Subversion) and lets you easily follow a best practice: committing your code changes on the server at the end of each day. Backing up your changes ensures that you don't lose your work because of a hardware failure or another type of failure.

With this small utility, you save a copy of your current changes to a separate folder on your local hard drive, which can be sub-versioned in another SVN repository for backup, at the end of the day. However, as part of this process, you indicate that the source code isn't ready for others to retrieve. The code is put on the shelf, so to speak. Only you will be able to access the shelved version. That way, your daily changes to the source code are backed up, but other team members won't be able to access the unfinished code.

One reason why you might need more than one source file is if you have different versions of an application. For example, when you begin to work on version 2.0, which is located in the SVN trunk or branch 2.0 of an application, you might need to switch your working folder and work on version 1.0 located in the branch 1.0. What can be done? The developer could create a separate folder and place branch 1.0 into this folder, but in that case, the developer has to change the references to this folder, let's say in IIS, shortcuts, and other types of references. With this small utility, the developer will be able to shelve the current work (put it aside) and switch the working folder to branch 1.0 and continue to work on version 1.0 of the application. After it is complete, the developer can switch back to version 2.0 and restore the shelved modified files the way they were before.

Another reason is to archive your ideas. Let's say you are working on the project and trying to implement a complex logic. When you are close to the end, you realize that what you have done is not working the way you expected, and you have to go the other way to solve this problem. You can not commit your work because it will break the project, or make it unstable. So, all work you have done has to be reverted, and you have to start from scratch. But wait, with this small utility, you can save your work for future references and start from scratch. Any time you want to return to this almost failed idea of yours, you can restore it from the shelf and continue your fight to make it right. And, you can do it as many times as you want with the SvnShelve utility.

And even more! With this utility, you will be able to share your unfinished code with someone else in your team. Just make sure your shelved folder is under the SVN repository. You can shelve your changes, which will be committed in the shelve repository under your folder, and another developer can load your shelve folder into his/her local drive, point SvnShelve to load shelves from this new folder, and restore the shelve you just created. So, you can share unfinished code, which you can not commit into a main project branch or trunk.

Using the SvnShelve Utility

The source code for this utility is attached. Please do not mind the code style. It is not a pretty as I would like it to be, but this utility was created in a short time (couple of hours) just because I was tired of waiting for this simple functionality to be implemented in TortoiseSVN.

When you first start the application, it will show you the folder selection screen, where you have to pick the folder where you will store the shelves. You can create a new folder in this screen:

ShelveFolder.jpg

After you pick the folder, the main screen will appear:

MainScreen.jpg

As you see on the screenshot above and others, I erased some sensitive information, but initially, you will not see any items in the Shelves list, because you have not created any shelves yet. When you click the button [Shelve], you will be prompted to select a folder you want to shelve:

PickFolderToShelve.jpg

After clicking the [OK] button, this folder will be analyzed for any modifications, and if there are any modifications, a new screen appears:

ShelveScreen.jpg

which will show the list of modified files. You must type some description (at least 10 characters). Now, you can shelve this folder by clicking the [Shelve] button. What will happen? All the modified files will be copied into a folder you dedicated for shelving, under a GUID-like folder name. After all the files and folders are copied, you will be prompted about reverting all the changes you have done to the source folder. You can answer "No" and all the modifications will stay the way they are, but if you answer "Yes", then all the modifications will be reverted. Do not worry, all modifications have been backed up to your shelf you just created.

How do we restore the shelf?

After you shelve your project, you will see it in the list of Shelves on the main screen. When you select this shelf, you click the [Restore] button. What will happen? The original folder will be updated to a revision the shelf was created from, and all the files from the selected shelf will be copied back to the original folder the way they were before you shelved it. At the end of the operation, you will be prompted to delete the shelf.

That is all.

At some time, you might be prompted to enter your SVN login name and password:

SVNLogin.jpg

If you place your Shelve folder under SVN, you will be prompted to commit the new shelf.

History

  • 9/24/08 - Uploaded a new ZIP file: added status windows. Shelf commit on create- and delete-shelf. Fixed delete-shelf when under SVN control.
  • 9/25/08 - Integrated with TortoiseSVN to view logs, diff, and repository. Added the ability to open the containing folder. Added icons in the file list.

License

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

Share

About the Author

Oleg Vorkunov
Software Developer (Senior) VORLAN Group, Inc.
United States United States
writing code for the past 20 years, and now decided to share some thoughts. Smile | :)
Also known as Oleg Vorkunov.

Comments and Discussions

 
GeneralMy vote of 5 PinmemberJohn Slagel20-Jul-11 7:21 
QuestionThis is GREAT! PinmemberJohn Slagel20-Jul-11 7:20 
GeneralFolder 'c:\svnroot\code' is not a working copy PinmemberCedrick Collomb15-Apr-11 19:11 
GeneralRe: Folder 'c:\svnroot\code' is not a working copy PinmemberJohn Slagel20-Jul-11 7:15 
I had the same problem, I use TortoiseSVN and don't even have a command line SVN client.
Well, you need to install a command line svn client in your path.
Based on a Google search and seeing recommendations, I download Slik SVN and that seemed to do the trick:
 
http://www.sliksvn.com/en/download
GeneralRe: Folder 'c:\svnroot\code' is not a working copy PinmemberNirajan Singh31-Jan-12 1:14 
Generalsvn cp PinmemberSteveKing23-Sep-08 19:29 
General[Message Deleted] PinmemberOleg Vorkunov24-Sep-08 3:38 
GeneralRe: svn cp PinmemberSteveKing24-Sep-08 5:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 23 Sep 2008
Article Copyright 2008 by Oleg Vorkunov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid