Michael McCarthy
Michael McCarthy

Reputation: 1542

TFS API: How Do I Get a File's History?

It is very straightforward to get all changesets, specific changesets, or even look a specific version of a file (given a changeset id) using not only the TFS API but the .NET client libraries.

However, what I can't seem to figure out is given the name/path of a file, and a specific branch, is how to retrieve the changeset history for that file.

I've tried using both the TfvcHttpClient as well as the raw TFS API (building my http GET request by hand) and I cannot seem to find a way to make this happen.

This is very similar to viewing a file's history in Visual Studio 2017:

enter image description here

I'm literally looking for a way via the TFS API to give me this information back.

Is this possible?

Thanks!

Upvotes: 2

Views: 2298

Answers (4)

Reuben
Reuben

Reputation: 173

You can also do this with TfvcHttpClientBase.GetChangesetsAsync and the ItemPath property of TfvcChangesetSearchCriteria

Here's an example in Powershell

 $tfvcSearchCriteria = [Microsoft.TeamFoundation.SourceControl.WebApi.TfvcChangesetSearchCriteria]::new()
 $tfvcSearchCriteria.FollowRenames = $true
 $tfvcSearchCriteria.ItemPath = $ItemPath

 $result = $TfvcHttpClient.GetChangesetsAsync($null, $null, $null, $null, $tfvcSearchCriteria).Result

Upvotes: 0

user8291584
user8291584

Reputation:

Depending on what API version you are using, here is the reference information for changesets.

https://learn.microsoft.com/en-us/rest/api/azure/devops/tfvc/changesets/get%20changesets?view=azure-devops-rest-5.0

the core url is: GET {tfsurl}/{organization}/{project}/_apis/tfvc/changesets?api-version=5.0

Upvotes: 0

D.J.
D.J.

Reputation: 4034

Rest API request:

{tfsurl}/{project}/_api/_versioncontrol/history" 

In the request body:

{repositoryId: "", searchCriteria: "{"itemPath":"$/YourProject/YourFile","itemVersion":"T","top":50}"} 

It will return the history for the itemPath from your body.

Sadly I struggle to find any documentation on this :/

Upvotes: 2

Shamrai Aleksander
Shamrai Aleksander

Reputation: 16133

I can not find any history request for tfvc here - Rest Api TFVC Version Control.

As workaround you can try to run tf.exe history and parse the output.

Upvotes: 0

Related Questions