Skip to content

Commit

Permalink
Deleting automatically created workspace after an exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Martynuska authored and Szymon Martynuska committed Mar 9, 2013
1 parent 1045a29 commit 2803f4c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions GitTfs.VsCommon/TfsHelper.Common.cs
Expand Up @@ -217,19 +217,26 @@ public void WithWorkspace(string localDirectory, IGitTfsRemote remote, TfsChange

private Workspace GetWorkspace(string localDirectory, string repositoryPath)
{
Workspace workspace = null;
try
{
var workspace = VersionControl.CreateWorkspace(GenerateWorkspaceName());
workspace.CreateMapping(new WorkingFolder(repositoryPath, localDirectory));
return workspace;
workspace = VersionControl.CreateWorkspace(GenerateWorkspaceName());
workspace.CreateMapping(new WorkingFolder(repositoryPath, localDirectory));
return workspace;
}
catch (MappingConflictException e)
{
throw new GitTfsException(e.Message, new[] {"Run 'git tfs cleanup-workspaces' to remove the workspace."}, e);
if (workspace != null) workspace.Delete();
throw new GitTfsException(e.Message, new[] { "Run 'git tfs cleanup-workspaces' to remove the workspace." }, e);
}
catch
{
if (workspace != null) workspace.Delete();
throw;
}
}

private string GenerateWorkspaceName()
private string GenerateWorkspaceName()
{
return "git-tfs-" + Guid.NewGuid();
}
Expand Down

0 comments on commit 2803f4c

Please sign in to comment.