MRothaus
MRothaus

Reputation: 45

Query if my workspace has the latest files using the TFS Api

I want to programmatically find out if a workspace has the latest files. I don't want to do a Workspace.Get(), because that performs the equivalent of "Get Latest". I just want to know if my workspace needs a "Get Latest" or not.

I'm doing this check during a Build.I plan on having a method like so:

public static bool HasLatestFiles(Workspace ws)
{
    bool hasChanges = false;

    /* need correct code to query if ws has latest files */

    return hasChanges;
}

What is the correct code to use?

Upvotes: 4

Views: 698

Answers (1)

jessehouwing
jessehouwing

Reputation: 115037

Use Workspace.Get(LatestVersionSpec.Instance, GetOptions.Preview) then check the GetStatus.NoActionNeeded that is yielded by the Get operation.

So:

public static bool HasLatestFiles(Workspace ws)
{
    GetStatus result = ws.Get(LatestVersionSpec.Instance, GetOptions.Preview);

    bool hasLatestFiles = result.NoActionNeeded;

    return hasLatestFiles;
}

Upvotes: 8

Related Questions