Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Workspace fix #328

Merged
merged 12 commits into from

2 participants

@spraints
Owner

Fixes #327.

@spraints
Owner

@szmartynuska - thanks for getting this started! How does this look?

@szmartynuska

Finally got around to check it and now the temp workspace is properly deleted. Found another issue though - cleaning up workspace while having more than one mapping doesn't realy work because it tries to compare mappings' paths with (by default) path to internal directory ".git\tfs\default\workspace". Made a fix at szmartynuska@46b75dc5d9a086fb90d4a6421dbbd504b7d3481c. It now deletes all mappings to any folder in the working directory path, which is required for the MappingConflictException not to be thrown.

spraints added some commits
@spraints spraints tweak c13a1de
@spraints spraints Interweave some comments.
I'm normally not big on comments, but I thought I could validate my
reading of the code and answer future questions at the same time.
4d33862
@spraints
Owner

@szmartynuska - I pulled in your change, and made a couple of tweaks. Could you look over the comments in 4d33862 and let me know if they look right?

@szmartynuska

They sound ok, as far as I'm concerned.

@spraints spraints merged commit 9467fad into master

1 check passed

Details default The Travis build passed
@spraints spraints deleted the workspace-fix branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 1, 2013
  1. Deleting automatically created workspace after an exception.

    Szymon Martynuska authored
Commits on Mar 4, 2013
  1. white-space fix

    Szymon Martynuska authored
Commits on Mar 9, 2013
  1. Deleting automatically created workspace after an exception.

    Szymon Martynuska authored Szymon Martynuska committed
  2. white-space fix

    Szymon Martynuska authored Szymon Martynuska committed
  3. Merge branch 'workspaceFix' of https://github.com/szmartynuska/git-tfs

    Szymon Martynuska authored
    …into workspaceFix
Commits on Mar 19, 2013
  1. @spraints

    Tighten up GetWorkspace.

    spraints authored
  2. @spraints
  3. @spraints
Commits on Apr 2, 2013
Commits on Apr 4, 2013
  1. @spraints

    tweak

    spraints authored
  2. @spraints

    Interweave some comments.

    spraints authored
    I'm normally not big on comments, but I thought I could validate my
    reading of the code and answer future questions at the same time.
Commits on Apr 5, 2013
  1. @spraints
This page is out of date. Refresh to see the latest.
View
25 GitTfs.VsCommon/TfsHelper.Common.cs
@@ -217,16 +217,22 @@ public void WithWorkspace(string localDirectory, IGitTfsRemote remote, TfsChange
private Workspace GetWorkspace(string localDirectory, string repositoryPath)
{
+ var workspace = VersionControl.CreateWorkspace(GenerateWorkspaceName());
try
{
- var 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);
+ workspace.Delete();
+ throw new GitTfsException(e.Message).WithRecommendation("Run 'git tfs cleanup-workspaces' to remove the workspace.");
}
+ catch
+ {
+ workspace.Delete();
+ throw;
+ }
+ return workspace;
}
private string GenerateWorkspaceName()
@@ -238,6 +244,10 @@ private string GenerateWorkspaceName()
public void CleanupWorkspaces(string workingDirectory)
{
+ // workingDirectory is the path to a TFS workspace managed by git-tfs.
+ // By default, this will be something like `.git/tfs/default/workspace`.
+ // If `git-tfs.workspace-dir` is set, workingDirectory will be that path.
+
Trace.WriteLine("Looking for workspaces mapped to @\"" + workingDirectory + "\"...", "cleanup-workspaces");
var workspace = VersionControl.TryGetWorkspace(workingDirectory);
if (workspace != null)
@@ -245,12 +255,19 @@ public void CleanupWorkspaces(string workingDirectory)
Trace.WriteLine("Found mapping in workspace \"" + workspace.DisplayName + "\".", "cleanup-workspaces");
if (workspace.Folders.Length == 1)
{
+ // Normally, the workspace will have one mapping, mapped to the git-tfs
+ // workspace folder. In that case, we just delete the workspace.
_stdout.WriteLine("Removing workspace \"" + workspace.DisplayName + "\".");
workspace.Delete();
}
else
{
- foreach (var mapping in workspace.Folders.Where(f => Path.GetFullPath(f.LocalItem).ToLower() == Path.GetFullPath(workingDirectory).ToLower()))
+ // If something outside of git-tfs set up a workspace, the workspace
+ // might be set at a higher directory. If there is more than one mapping
+ // in the workspace, we only need to remove the one that includes the working
+ // directory that we want to set.
+ var fullWorkingDirectoryPath = Path.GetFullPath(workingDirectory);
+ foreach (var mapping in workspace.Folders.Where(f => fullWorkingDirectoryPath.StartsWith(Path.GetFullPath(f.LocalItem), StringComparison.CurrentCultureIgnoreCase)))
{
_stdout.WriteLine("Removing @\"" + mapping.LocalItem + "\" from workspace \"" + workspace.DisplayName + "\".");
workspace.DeleteMapping(mapping);
View
9 GitTfs.VsFake/TfsHelper.VsFake.cs
@@ -291,6 +291,10 @@ public string OwnerName
#endregion
}
+ public void CleanupWorkspaces(string workingDirectory)
+ {
+ }
+
#endregion
#region unimplemented
@@ -340,11 +344,6 @@ public int ListShelvesets(ShelveList shelveList, IGitTfsRemote remote)
throw new NotImplementedException();
}
- public void CleanupWorkspaces(string workingDirectory)
- {
- throw new NotImplementedException();
- }
-
public bool CanGetBranchInformation { get { return false; } }
public int GetRootChangesetForBranch(string tfsPathBranchToCreate, string tfsPathParentBranch = null)
View
37 GitTfs/Core/GitTfsRemote.cs
@@ -132,7 +132,15 @@ private string WorkingDirectory
{
get
{
- return Repository.GetConfig("git-tfs.workspace-dir") ?? Path.Combine(Dir, "workspace");
+ return Repository.GetConfig("git-tfs.workspace-dir") ?? DefaultWorkingDirectory;
+ }
+ }
+
+ private string DefaultWorkingDirectory
+ {
+ get
+ {
+ return Path.Combine(Dir, "workspace");
}
}
@@ -340,7 +348,7 @@ private void AssertIndexClean(string treeish)
private LogEntry Apply(string lastCommit, ITfsChangeset changeset)
{
LogEntry result = null;
- WithTemporaryIndex(() => Tfs.WithWorkspace(WorkingDirectory, this, changeset.Summary, workspace =>
+ WithTemporaryIndex(() => WithWorkspace(changeset.Summary, workspace =>
{
GitIndexInfo.Do(Repository, index => result = changeset.Apply(lastCommit, index, workspace));
result.Tree = Repository.CommandOneline("write-tree");
@@ -352,7 +360,7 @@ private LogEntry Apply(string lastCommit, ITfsChangeset changeset)
private LogEntry CopyTree(string lastCommit, ITfsChangeset changeset)
{
LogEntry result = null;
- WithTemporaryIndex(() => Tfs.WithWorkspace(WorkingDirectory, this, changeset.Summary, workspace => {
+ WithTemporaryIndex(() => WithWorkspace(changeset.Summary, workspace => {
GitIndexInfo.Do(Repository, index => result = changeset.CopyTree(index, workspace));
result.Tree = Repository.CommandOneline("write-tree");
}));
@@ -478,8 +486,7 @@ public void Unshelve(string shelvesetOwner, string shelvesetName, string destina
public void Shelve(string shelvesetName, string head, TfsChangesetInfo parentChangeset, bool evaluateCheckinPolicies)
{
- Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset,
- workspace => Shelve(shelvesetName, head, parentChangeset, evaluateCheckinPolicies, workspace));
+ WithWorkspace(parentChangeset, workspace => Shelve(shelvesetName, head, parentChangeset, evaluateCheckinPolicies, workspace));
}
public bool HasShelveset(string shelvesetName)
@@ -496,8 +503,7 @@ private void Shelve(string shelvesetName, string head, TfsChangesetInfo parentCh
public long CheckinTool(string head, TfsChangesetInfo parentChangeset)
{
var changeset = 0L;
- Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset,
- workspace => changeset = CheckinTool(head, parentChangeset, workspace));
+ WithWorkspace(parentChangeset, workspace => changeset = CheckinTool(head, parentChangeset, workspace));
return changeset;
}
@@ -521,19 +527,28 @@ private void PendChangesToWorkspace(string head, string parent, ITfsWorkspaceMod
public long Checkin(string head, TfsChangesetInfo parentChangeset, CheckinOptions options)
{
var changeset = 0L;
- Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset,
- workspace => changeset = Checkin(head, parentChangeset.GitCommit, workspace, options));
+ WithWorkspace(parentChangeset, workspace => changeset = Checkin(head, parentChangeset.GitCommit, workspace, options));
return changeset;
}
public long Checkin(string head, string parent, TfsChangesetInfo parentChangeset, CheckinOptions options)
{
var changeset = 0L;
- Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset,
- workspace => changeset = Checkin(head, parent, workspace, options));
+ WithWorkspace(parentChangeset, workspace => changeset = Checkin(head, parent, workspace, options));
return changeset;
}
+ private void WithWorkspace(TfsChangesetInfo parentChangeset, Action<ITfsWorkspace> action)
+ {
+ // If there isn't a custom workspace, and a workspace is lingering from a previous
+ // git-tfs run, clean it up. If the user is using a custom workspace dir, leave
+ // it for them to explicitly clean up, in case they're doing something unsupported
+ // with it.
+ Tfs.CleanupWorkspaces(DefaultWorkingDirectory);
+
+ Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset, action);
+ }
+
private long Checkin(string head, string parent, ITfsWorkspace workspace, CheckinOptions options)
{
PendChangesToWorkspace(head, parent, workspace);
Something went wrong with that request. Please try again.