Can not update submodule using GitHttpClient

Mykyta Bondarenko 26 Reputation points
2022-01-19T08:40:29.857+00:00

I try to create a new branch with submodule change Microsoft.TeamFoundation.SourceControl.WebApi.GitHttpClient but get an error: Expected a Blob, but objected [previous-submodule-value] resolved to a Commit (path ‘/external/[submodule-name]’). So, as we can see it wants to get a commit, but as I see there is no way to pass it there like this.

Here is how I do it:

gitClient.CreatePushAsync(new GitPush
{
   RefUpdates = new List<GitRefUpdate>
   {
     new GitRefUpdate { Name = "refs/heads/[new-branch-name]", OldObjectId = baseBranch.ObjectId }
   },
   Commits = new List<GitCommitRef>
   {
      new GitCommitRef
      {
         Comment = "Bump submodule",
         Changes = new List<GitChange>
         {
            new GitChange
            {
               ChangeType = VersionControlChangeType.Edit,
               Item = new GitItem { Path = "/external/[submodule-name]" },
               NewContent = new ItemContent { Content = newHash, ContentType = ItemContentType.RawText }
            }
         }
      }
   }
}, [repo-id]);

I've tried some luck on developer-community, and you may find different useful discussions and links there (if needed), and I was redirected to ask it here. Here is a link to that discussion: https://developercommunity.visualstudio.com/t/Can-not-update-submodule-using-GitHttpCl/1537646?viewtype=all

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,306 questions
{count} vote