littlemisslilycane
littlemisslilycane

Reputation: 37

Azure Devops Git - Get version by date

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

Answers (3)

riQQ
riQQ

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

LoLance
LoLance

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

Jeremy Lakeman
Jeremy Lakeman

Reputation: 11100

Which date are you interested in?

  • when the original author wrote their patch GitCommit.Author.GitUserDate.Date
  • when this commit object was created GitCommit.Committer.GitUserDate.Date
  • when a pull request was created / pushed
  • when this branch was updated

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

Related Questions