Search code examples
c#.nettfs-sdk

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?


Solution

  • 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;
    }