2

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!

Michael McCarthy
  • 1,502
  • 3
  • 18
  • 45

4 Answers4

2

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 :/

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
D.J.
  • 3,644
  • 2
  • 15
  • 22
  • Yes, you are right. There is the same answer here: https://stackoverflow.com/questions/50857789/vsts-release-api-documentation – Shamrai Aleksander Apr 02 '19 at 22:08
  • @D.J. this did it! INSANE how there is no documentation on this. Something that most devs will do (look at changes history from a file perspective) is not documented. If it's not documented, then how did you know? – Michael McCarthy Apr 03 '19 at 01:28
  • 2
    @MichaelMcCarthy if i know the web-portal of tfs/devops can provide me a function or data that i can't find in the rest-api documentation i open the webdeveloper-tools and trace the requests and responses from my browser. this may work but i had to rely on this too many times for my liking :/ – D.J. Apr 03 '19 at 07:11
0

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.

Shamrai Aleksander
  • 13,096
  • 3
  • 24
  • 31
0

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

  • Whilst this may theoretically answer the question, [it would be preferable](//meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Anton Menshov Jun 22 '19 at 04:39
0

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
Reuben
  • 143
  • 1
  • 6