Recently I moved from TFVC to Git Version control. Up until now I have been getting the file items for a specific date using TfvcVersionDescriptor date type like this:
var version = new TfvcVersionDescriptor { VersionType = TfvcVersionType.Date, Version = date };
Is there any way to achieve this using GitHttpClient? I need to generate some trend analysis and getting the list of files for a specific date is very important. If there is no functionality to retrieve by date, is there a work around for this?
Use GitHttpClient.GetCommitsAsync
with a GitQueryCommitsCriteria
object similar to
GitQueryCommitsCriteria searchCriteria = new GitQueryCommitsCriteria()
{
FromDate = new DateTime(2019, 2, 2).ToString(),
ToDate = DateTime.Now.ToString(),
ItemVersion = new GitVersionDescriptor()
{
Version = "master",
VersionType = GitVersionType.Branch
}
};
var commits = await client.GetCommitsAsync(repo.Id, searchCriteria);
It will return a List<GitCommitRef>
with GitCommitRef.CommitId
(SHA-1) to identify the commit.
And then use GitHttpClient.GetItemsAsync
or another variation with
new GitVersionDescriptor()
{
VersionType = GitVersionType.Commit,
Version = commitId // value from above
};
to get the files.