最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论