Reputation: 37
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?
Upvotes: 1
Views: 1329
Reputation: 12693
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.
Upvotes: 1
Reputation: 28096
For TFVC: You have TfvcVersionDescriptor
which you have been using for long time.
And For Git: The corresponding class is GitVersionDescriptor.
It only accepts three fields: branch, commit, tag
. It doesn't support Date
filed like what TfvcVersionDescriptor
does, we can't control this behavior since it's by design of the SDK.
(You could add feature request about modifying the GitVersionType Enum from the SDK here)
Upvotes: 1
Reputation: 11100
Which date are you interested in?
GitCommit.Author.GitUserDate.Date
GitCommit.Committer.GitUserDate.Date
Because git is designed to be a distributed system, commit's don't have an obvious relationship to datetime values. Sometimes the real-world is messy and there isn't a simple answer.
Upvotes: 1