c# - I get the Error TF401175: The version descriptor <Branch: refsheads.....> could not be resolved to a version

This API call somehow returns TF401175: The version descriptor <Branch: refsheads.....> could n

This API call somehow returns TF401175: The version descriptor <Branch: refs/heads/.....> could not be resolved to a version in the repository ..., even though the branches both definitely exist and I do have the necessary access

I dont know why, but this code looks correct to me. I also tried refs/heads/{sourceBranch} and refs/heads/{targetBranch}, that didnt work either

Can someone help?

public async Task<GitCommitRef[]> GetCommits(string sourceBranch, string targetBranch)
{
    VssConnection conn = new(new Uri(this._azureDevOpsUrl), new VssBasicCredential(string.Empty, pat));

    GitHttpClient client = conn.GetClient<GitHttpClient>();

    List<GitCommitRef> commits = [];

    try
    {
        List<GitCommitRef> res = await client.GetCommitsAsync(projectname, reponame, new GitQueryCommitsCriteria
        {
            ItemVersion = new GitVersionDescriptor
            {
                // I also tried refs/heads/{sourceBranch} and refs/heads/{targetBranch}, didnt work either
                VersionType = GitVersionType.Branch,
                Version = sourceBranch
            },
            CompareVersion = new GitVersionDescriptor
            {
                VersionType = GitVersionType.Branch,
                Version = targetBranch
            }
        });

        if (res != null)
        {
            commits.AddRange(res);
        }
    }
    catch (Exception ex)
    {
        ConsoleEx.Throw($"Error fetching commits: {ex.Message}");
    }

    return commits.ToArray();
}

This API call somehow returns TF401175: The version descriptor <Branch: refs/heads/.....> could not be resolved to a version in the repository ..., even though the branches both definitely exist and I do have the necessary access

I dont know why, but this code looks correct to me. I also tried refs/heads/{sourceBranch} and refs/heads/{targetBranch}, that didnt work either

Can someone help?

public async Task<GitCommitRef[]> GetCommits(string sourceBranch, string targetBranch)
{
    VssConnection conn = new(new Uri(this._azureDevOpsUrl), new VssBasicCredential(string.Empty, pat));

    GitHttpClient client = conn.GetClient<GitHttpClient>();

    List<GitCommitRef> commits = [];

    try
    {
        List<GitCommitRef> res = await client.GetCommitsAsync(projectname, reponame, new GitQueryCommitsCriteria
        {
            ItemVersion = new GitVersionDescriptor
            {
                // I also tried refs/heads/{sourceBranch} and refs/heads/{targetBranch}, didnt work either
                VersionType = GitVersionType.Branch,
                Version = sourceBranch
            },
            CompareVersion = new GitVersionDescriptor
            {
                VersionType = GitVersionType.Branch,
                Version = targetBranch
            }
        });

        if (res != null)
        {
            commits.AddRange(res);
        }
    }
    catch (Exception ex)
    {
        ConsoleEx.Throw($"Error fetching commits: {ex.Message}");
    }

    return commits.ToArray();
}
Share Improve this question edited Mar 14 at 1:53 Knyrps asked Mar 14 at 1:47 KnyrpsKnyrps 1211 silver badge6 bronze badges 2
  • The SDK is a wrapper around the rest api, which may have more useful documentation. learn.microsoft/en-us/rest/api/azure/devops/git/commits/… But I suspect you shouldn't try to use a /refs prefix. – Jeremy Lakeman Commented Mar 14 at 2:25
  • As stated in my answer below, you should pass the name of the branch (e.g., main) rather than the full name of the branch (e.g., refs/heads/main) to the parameters itemVersion.version and compareVersion.version. @Knyrps – Bright Ran-MSFT Commented Mar 21 at 3:03
Add a comment  | 

1 Answer 1

Reset to default 0

The corresponding Azure DevOps REST API of the function 'GetCommitsAsync' called in your code is "Commits - Get Commits". And the corresponding parameter is 'searchCriteria.itemVersion.version'.

Based on the example "On a branch" shared in the documentation of this REST API, the acceptable value of the 'searchCriteria.itemVersion.version' should be the name of the branch (e.g., main) rather than the full name of the branch (e.g., refs/heads/main). Similarly to the parameter 'searchCriteriapareVersion.version'.

I also have attempted this API on my side:

  • If I set the value of 'searchCriteria.itemVersion.version' to be refs/heads/main, I can get the same TF401175 error.

  • If I set the value of 'searchCriteria.itemVersion.version' to be main, it can work fine without any error.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744676957a4587386.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信