4
votes

My company switched from TFVC to TFS Git. I'm migrating a release automation tool to support the switch.

Among other things, the tool creates a new branch for the release, as well as a new label ("tag" in Git). For TFVC, these operations are performed directly on the TFS server, and do not require a local copy of the repository. Is this still possible to achieve in Git, or would I be forced to clone the repository locally for these operations?

The two libraries I've looked at so far are Microsoft.TeamFoundation.Git.Client which seems to be the official wrapper for TFS Git REST API, and LibGit2Sharp. I am not limited to those libraries, so another option is welcome as well.

We are also in the process of upgrading from TFS 2015 to TFS 2017, so if there is an answer that only targets one of these I'd like to know as well.

EDIT 1

To be clear, by "directly on remote repository" I mean without passing through a local one. The tool is fully automated and if possible I'd rather not require file-system access.

EDIT 2

As mentioned below by @rmcsharry it is now possible to create a tag directly on the remote server. That's a nice improvement, but of course the main goals is to first create a branch directly on the remote, which is definitely possible in the web UI, just not (yet?) via the API. Here's the web UI screenshot:

enter image description here

Without that part I cannot automate the process I mentioned without passing through the local file system, which is my goal.

2
What have you tried? There are documented API's for Git in TFS/VSTS that you can easily find online. What, specific difficulty are you running into?MrHinsh - Martin Hinshelwood
@MrHinsh I've read a lot of documentation for both mentioned libraries. With Microsoft.TeamFountadion.Git.Client I could connect to the remote repository but it seems to expose only a portion of the documented Git REST API, but even in the documentation I can find no way to create a remote branch and tag directly on the remote. With LibGit2Sharp I didn't even manage to connect directly to the remote without first cloning the repository locally, so I couldn't perform ANY operation directly on the remote. Can you point me to any code in either library that operates directly on the remote?tsemer
Use the create refs REST API endpoint: visualstudio.com/en-us/docs/integrate/api/git/…Edward Thomson

2 Answers

5
votes

You can now manually add a Tag to a commit in TFS (directly on the server), which may help.

You have to first select a commit, then click the ... button on the far right, which opens a drop-down menu, one option of which is to create a tag:

enter image description here

This is also exposed via the REST api. See the answer here.


UPDATE in response to EDIT 2 in question

It is also possible to create a branch on the API. The documentation refers to a branch as a 'ref':

Creating a ref is achieved by updating the ref from the nil commit (represented by 40 0s) to a different commit.

The structure is like this (note that {project} is optional):

POST https://{instance}/DefaultCollection
/{project}/_apis/git/repositories
/{repository}/refs?api-version={version}


Content-Type: application/json

[
  {
    "name": {string},
    "oldObjectId": {string},
    "newObjectId": {string}
  }
]

For example:

POST https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection
/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249
/refs?api-version=1.0

with this body, will create a new branch called 'live':

[
  {
    "name": "refs/heads/live",
    "oldObjectId": "0000000000000000000000000000000000000000",
    "newObjectId": "4b223e9c93ec3b6aaa6499f06e3ebb7c702e6106"
  },
]

Documentation here.


My TFS Version is:

enter image description here


1
votes

Currently, you can only create Git tags (local) in VS2015, but can't push it to the remote server. You have to use the git command line: git push --tags to push the tag.

But the feature of Support the ability to push Git Tags to remote has been under plan:

https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/10189500-support-the-ability-to-push-git-tags-to-remote