Microsoft.TeamFoundation.VersionControl.Client.Workspace.PendAdd
For some reason, whenever I call the PendAdd method from the TFS API, it executes with no exceptions yet fails to mark any files as added in my workspace. However, Calling PendEdit consistently works as expected. I’ve verified that the account used both has permission to add within TFS and has full control Windows permissions on the files in question.
Any ideas?
My code (for debugging, I’m attempting four variations on input to the PendAdd method):
public bool AddFile( string filePath, out string status, bool isRecursive = false )
{
Workspace workspace = GetWorkspace( out status );
if( workspace == null )
{
return false;
}
workspace.PendAdd( filePath, isRecursive );
status = "Success";
return true;
}
public bool CheckOutFile( string filePath, out string status )
{
Workspace workspace = GetWorkspace( out status );
if( workspace == null )
{
return false;
}
workspace.PendEdit( filePath );
status = "Success";
return true;
}
...
string status;
// $/Solution/.../foo.cs (non-recursive)
if( TFS.AddFile("$/Solution" + Regex.Split(target, "Solution")[1].Replace('\\', '/'), out status) == false )
{
throw new Exception( "TFS Add failed: " + status );
}
// $/Solution/.../ (recursive)
if( TFS.AddFile("$/Solution" + Regex.Split(target.Substring(0, target.LastIndexOf('\\')), "Solution")[1].Replace('\\', '/'), out status, true) == false )
{
throw new Exception( "TFS Add failed: " + status );
}
// Calls PendEdit with C:\TFS\Solution\...\foo.cs; this works
if( TFS.CheckOutFile(target, out status) == false )
{
throw new Exception( "TFS Checkout failed: " + status );
}
// C:\TFS\Solution\...\foo.cs (non-recursive)
if( TFS.AddFile(target, out status) == false )
{
throw new Exception( "TFS Add failed: " + status );
}
// C:\TFS\Solution\...\ (recursive)
if( TFS.AddFile(target.Substring(0, target.LastIndexOf('\\')), out status, true) == false )
{
throw new Exception( "TFS Add failed: " + status );
}
...
private Workspace GetWorkspace( out string status )
{
Workspace[] workspaces = _versionControlServer.QueryWorkspaces( null, _versionControlServer.AuthorizedUser, Environment.MachineName );
if( workspaces.Length != 1 )
{
status = "You must have exactly 1 local workspace to promote code.";
return null;
}
else
{
status = "You have exactly 1 local workspace.";
}
return workspaces[0];
}
Well, this is odd, but I made a change to allow multiple users to add or edit files through this controller (rather than one hardcoded user) and create a new workspace for each user when necessary, and now everything’s working as originally intended. This is pretty odd, considering that nothing that should have been related to this behaviour was modified in any significant way.
I’m not fully convinced that this isn’t a bug / that I hadn’t previously been hitting some edge case in the code, but as long as my project works (which it does as of now) I’m not really concerned either way.
Relevant Microsoft Connect thread (in case this does turn out to be a problem with TFS and is later resolved).