Share via

How to update a submodule using `GitHttpClient` or `pushes` endpoint

Mykyta Bondarenko 26 Reputation points
2023-11-16T15:06:58.76+00:00

Updating a submodule using GitHttpClient from microsoft.teamfoundationserver.client package doesn't work. As it doesn't work using RES API.
Here is how to reproduce it using the code:
We have a base branch here called branch and a repository entity called gitRepo

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

But, also, it doesn't work using the API:

POST: https://dev.azure.com/[param1]/[param2]/_apis/git/repositories/[param3]/pushes?api-version=7.1-preview.2

{
    "refUpdates": [
        {
            "name": "refs/heads/bump-submodule-dev",
            "oldObjectId": "[oldObjectId]"
        }
    ],
    "commits": [
        {
            "comment": "Update submodule.",
            "changes": [
                {
                    "changeType": "edit",
                    "item": {
                        "path": "/external/[submodule-name]"
                    },
                    "newContent": {
                        "content": "[new-hash]",
                        "contentType": "rawText"
                    }
                }
            ]
        }
    ]
}

What I get in a response is:

{
    "$id": "1",
    "innerException": 
    "message": "Expected a Blob, but objectId [hash] resolved to a Commit (path '/external/[submodule-name]')\r\nParameter name: newPush",
    "typeName": "Microsoft.TeamFoundation.SourceControl.WebServer.InvalidArgumentValueException, Microsoft.TeamFoundation.SourceControl.WebServer",
    "typeKey": "InvalidArgumentValueException",
    "errorCode": 0,
    "eventId": 0
}
Community Center | Not monitored
0 comments No comments

Answer accepted by question author

MayankBargali-MSFT 71,016 Reputation points Moderator
2023-11-17T10:29:51.37+00:00

Hi @Mykyta Bondarenko

Welcome to Microsoft Q&A! Thanks for posting the question.

DevOps is currently not supported in the Q&A forums, the supported products are listed over here https://docs.microsoft.com/en-us/answers/products (more to be added later on).

You can ask the experts in the dedicated forum over here:

https://stackoverflow.com/questions/tagged/devops

https://developercommunity.visualstudio.com/spaces/21/index.html

Please 'Accept Answer' if it helped so that it can help others in the community looking for help on similar topics.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.