There are times when you won't be ready to commit your source code into the core repository. For example, say that you are working on solving a bug and you haven't completed the task by the end of the workday. Shelving enables you to store files and code aside on a temporary basis. The collections of stored pending changes that haven't been committed to the server are called shelvesets.
The security settings for a shelveset are determined by the item permissions. You must have read and pending change permission for the item changes you wish to unshelve.
The process of creating a shelveset is fast and easy. To begin, access the Pending Checkin window by clicking View Other Windows Pending Changes, as shown in Figure 20-20. Check the item you want to shelve and click the Shelve button.
The Shelve dialog box will appear with the files you have selected. (Be sure to give it a descriptive name to differentiate it from the other shelvesets.) You now have the option of unchecking the items, preserving pending changes locally, or clicking the Shelve button. You also have the option of evaluating policies and check-in notes before shelving. Shelvesets contain the same level of information as a changeset, including associated work items, comments, and check-in notes. Keep in mind that, unlike with a changeset, the changes are not versioned. Shelvesets can be permanently deleted (which is something you can't do with changesets). You can't link directly to a shelveset from a work item and policies can't be enforced on shelving.
When would you want to use this feature? There are a few scenarios: Say that a project manager asks you to drop what you are doing and work on a bug fix. Your current work can be set aside temporarily. Say that you have code that isn't quite ready to be checked in but needs a code review. You can shelve your pending changes to allow other team members to work with it. Shelving is also useful as a backup mechanism and is used as a way to reassign unfinished code to another team member.
Shelvesets are available to individual users and to administrators. That means if you fall off the planet, the administrator will be able to take your work and reassign it to another developer, thus assuring business continuity. Any user can also create as many shelvesets as the user wants.
Unshelving source files is as easy as shelving. First, bring up the Pending Changes window (as shown at the beginning of this section) and click the Unshelve button. The Unshelve window will appear with the option to select an owner and the name of a shelveset (see Figure 20-21). You also have the option of deleting shelvesets or reading more details.
Once you select a shelveset, you then have the option of preserving the shelveset on the server. You can also choose whether you want to restore the work items and check-in notes (see Figure 20-22). When you unshelve your code, all the pending check-in information is also restored. If you made any changes to your workspace (for example, renamed or moved a folder in your workspace), the unshelved folder will also be renamed and moved. Shelved files that are marked for deletion are deleted in the workspace.