question

mykyta-bondarenko avatar image
1 Vote"
mykyta-bondarenko asked mykyta-bondarenko commented

Can not update submodule using GitHttpClient

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

dotnet-csharp
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I've also tried to use just REST API to check if it's smth wrong with the nuget or API itself, and I got the same error as I did before. Here is a response:
{ "$id": "1", "innerException": null, "message": "Expected a Blob, but objectId [old-hash] resolved to a Commit (path '/external/[name]')\r\nParameter name: newPush", "typeName": "Microsoft.TeamFoundation.SourceControl.WebServer.InvalidArgumentValueException, Microsoft.TeamFoundation.SourceControl.WebServer", "typeKey": "InvalidArgumentValueException", "errorCode": 0, "eventId": 0 }

Here is my request's body
{ "refUpdates": [ { "name": "refs/heads/bump-submodule", "oldObjectId": "[base-hash]" } ], "commits": [ { "comment": "Bump submodule", "changes": [ { "changeType": "edit", "item": { "path": "/external/[name]" }, "newContent": { "content": "[new-hash]", "contentType": "rawtext" } } ] } ] }

0 Votes 0 ·

We are experiencing the same issue. Even when you obtain Item via client.GetItemAsync and try to update the content it raised Expected a Blob, but objectId ** resolved to a Commit. For some reason the backend seems to misinterpret the submodule item as a commit. I found this https://stackoverflow.com/questions/22764951/how-do-i-update-a-git-submodule-without-checking-it-out to update the submodule via commandline.
205442-image.png

dev.azure does show the content of the item in a format we should be able to update as text in the commit window of adding the submodules.


0 Votes 0 ·
image.png (9.7 KiB)

Hi @TomdeGoede-5202
Thanks for your reply. Yeah, it should help, but this flow requires cloning a repository, but with only api access, it should have been able to run without this extra step.

0 Votes 0 ·

0 Answers