[UPDATE 7/25/14] Added equivalent API calls.
When you run get for your entire workspace without any argument, you are requesting that the server give you the latest set of files. Later you might wonder what changeset was used in that get. To figure that out, you can use the following history command from the root (top) of your workspace.
tf history . /r /noprompt /stopafter:1 /version:W
Here’s what that command means. The “. /r” part says to look at the current directory recursively, which is why you must run it from the root (top directory) of your workspace. Here I’ve specified “/noprompt” so that I don’t get dialog, but that’s optional. The “/stopafter:1” option tells tf to print only one changeset.
The version option is the part that tells the history command to consider history only up to what you have in your workspace. The “W” means workspace, and without the workspace name and owner being specified it means the current workspace. The version option could also be written as “/version:1~W” to explicitly state that you are interested in history only up to what is in your workspace. The “1~” is implicit when it is not specified. Changeset 1 is when the root of the repository ($/) was created.
Since the history command sorts the changesets from highest to lowest, the result is that the command displays the highest changeset version of all files currently in your workspace.
Here’s the code to do the equivalent using the Version Control client API.
// The workspace info for the provided path WorkspaceInfo wsInfo = Workstation.Current.GetLocalWorkspaceInfo(filePath); // Get the TeamProjectCollection and VersionControl server associated with the // WorkspaceInfo TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(wsInfo.ServerUri); VersionControlServer vcServer = tpc.GetService<VersionControlServer>(); // Now get the actual Workspace OM object Workspace ws = vcServer.GetWorkspace(wsInfo); // We are interested in the current version of the workspace VersionSpec versionSpec = new WorkspaceVersionSpec(ws); QueryHistoryParameters historyParams = new QueryHistoryParameters(filePath, RecursionType.Full); historyParams.ItemVersion = versionSpec; historyParams.VersionEnd = versionSpec; historyParams.MaxResults = 1; Changeset changeset = vcServer.QueryHistory(historyParams).FirstOrDefault();
0 comments
Be the first to start the discussion.