Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if the file is already in source control

Tags:

c#

.net

tfs

tfs-sdk

I am working with TFS programmatically using classes from Microsoft.TeamFoundation.VersionControl.Client namespace. My goal is to check-in files from the local folder into source control. Some files may already exist in SC and should be Edited, some are new and should be added, some exist in SC and haven't changed, so I don't need to do anything with them.

My problem is that I can't figure out how to check whether a file already exists in source control, so I can't decide in my code whether I should Add or Edit it. None of the Workspace methods seem to do what I need.

The code I have:

foreach (string file in fileList)
{
    workspace.PendEdit(file);
    workspace.PendAdd(file);
}

It does the job, but it looks dumb and feels slow. What is the correct way to do it?

like image 342
Dyppl Avatar asked Aug 23 '12 10:08

Dyppl


1 Answers

I don't know about 'correct', but in one of my tools I make use of VersionControlServer.ServerItemExists in order to get what you 're after.

In your case you would have to check with something like this:

versionControlServer.ServerItemExists(workspace.GetServerItemForLocalItem("filePath"), ItemType.Any)
like image 172
pantelif Avatar answered Sep 28 '22 04:09

pantelif