tfs-2015azure-devopstfvc

Create TFS Source Branch using Visual Studio Online / TFS 2015 Api


Does anyone know how to create a branch using the VSO Api. The documentation for Branches doesn't include a "create".

I have been experimenting with doing it via the ChangeSet Api without much success.

This is TFVC, not Git.


Solution

  • The REST API apparently does allow one to create branches. The confusion is that people think that this would be a PUT operation on the Branches endpoint of some kind. It is not.

    In the REST API, a branch is just one more kind of change that is checked in as part of a changeset.

    It took me a long time to discover this, myself; and I was using the old SOAP API in the belief, shared by everyone else it appears from what I can find in Q&As on the WWW, that this wasn't part of the REST API. Of course, using the SOAP API prohibits using .NET 5, because the assemblies only come for .NET Framework. An abandonware API on an abandonware runtime is not a satisfactory way to talk to source control. ☺

    The terrible Azure DevOps documentation gives no clue as to this, except for 1 obscure not-even-a-complete-sentence hidden in a minor class: "List of merge sources in case of rename or branch creation." The only other clue is what appears in the JSON, from a get changeset changes, that describes the changeset of an already-made branch. The (also abandoned) Azure DevOps sample code does not contain examples for even deleting an item, let alone branching.

    Changesets are checked in via the changeset creation endpoint. The individual change is a TfvcChange in the changeset's list of changes where:

    Branching an entire tree appears to be a matter of branching the directory and all of the files and directories in the directory.

    In C♯ or PowerShell, this is a TfvcChange with a VersionControlChangeType of Branch, in a TfvcChangeset passed to TfvcHttpClientBase.CreateChangesetAsync().