views:

562

answers:

2

Here is my problem. I have a build script which adds mappings to a certain workspace dynamically, then unmaps them when it is through. I am worried that if (when) my script fails before the unmapping is done, the mappings will holdover until the next time and screw things up.

So I would like to unmap the entire workspace at the start of the script, and recreate it, but the problem is I don't know specifically what might be there. Through the TFS command line I can unmap easily enough, but you have to know exactly what the mapping is. My question is how is the easiest, best way to get this done?

Thanks for your help!

A: 

My solution was to save the output of this...

$workspace_info = [String[]] (&$tfs_cli workfold /workspace:$workspace_name)

...into a string array, then iterate over it, looking for "$/" which indicates a mapping, and unmap

foreach($wi in $workspace_info) 
{ 
    if($wi.Contains("$/")) 
    { 
        $mapping = $wi
        #minor string manipulation code left out for brevity

        &$tfs_cli /unmap $mapping /workspace:$workspace_name
    }
}
JimDaniel
A: 

If you're sure there won't be any pending changes in the workspace you need to preserve, it's probably easier to delete it entirely and create a new one.

Or if you do want to stick with your algorithm, the Power Tools make it much easier:

$ws = get-tfsworkspace .
$ws.Folders | % { $ws.DeleteMapping($_) }
Richard Berg
Thanks for that. Learn something new everyday...
JimDaniel

related questions