4

I'm attempting to use Azure DevOps Services Rest API to create a new branch from master but I've been unsuccessful.

Docs: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/refs/update-refs?view=azure-devops-rest-5.1#examples

Endpoint: https://dev.azure.com/{{organization}}/{{project}}/_apis/git/repositories/{{repositoryId}}/refs?api-version={{api-version}}

Body:

[
  {
    "name": "refs/heads/new-test-branch-from-api-call",
    "oldObjectId": "{{masterObjectId}}",
    "newObjectId": "{{newObjectId}}"
  }
]

Results:

{
    "$id": "1",
    "innerException": null,
    "message": "TF401035: The object '****************************************' does not exist.",
    "typeName": "Microsoft.TeamFoundation.Git.Server.GitObjectDoesNotExistException, Microsoft.TeamFoundation.Git.Server",
    "typeKey": "GitObjectDoesNotExistException",
    "errorCode": 0,
    "eventId": 3000
}

A comment on this post states that this is the route to take. Also states that the repositoryId should be used and the newObjectId which results in:

{
    "$id": "1",
    "innerException": null,
    "message": "An object ID must be 40 characters long and only have hex digits. Passed in object ID: ********-****-****-****-************.",
    "typeName": "System.ArgumentException, mscorlib",
    "typeKey": "ArgumentException",
    "errorCode": 0,
    "eventId": 0
}
torek
  • 448,244
  • 59
  • 642
  • 775

1 Answers1

2

newObjectId is the object id of the existing branch. Really not sure why this is named new when it is actually older. Very odd.

[
  {
    "name": "refs/heads/new-test-branch-from-api-call",
    "newObjectId": "{{BranchObjectIdGoesHere}}",
    "oldObjectId": "0000000000000000000000000000000000000000"
  }
]
  • 2
    Presumably they call it "new" because it's the new *value* that the corresponding *ref* needs to hold. That's also the Git terminology, though anything involving json data like this is outside Git. – torek Jan 14 '22 at 06:18