'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]);
Does anyone know how to handle it?
UPD:
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" } } ] } ] }
Solution 1:[1]
It's not a direct answer but solved the problem for me when I encountered this. This post gives a clear explanation of how to do it locally from the commandline. Simply clone the project locally including submodules, cd into the submodule and use
git checkout <the commit hash you want to update the submodule to>
When you then check in you see only one updated file which is the reference to the submodule, rather than all the files updated within the submodule, and when you check the submodule file in devops you now see the updated hash.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Craig Graham |
