Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove Git repository in TFS 2015?

Tags:

tfs

tfs-2015

I'm trying to remove a Git respository in TFS 2015 Update 1. The repository is created inside an existing TFVC team project using the new Git and TFVC in the same project feature. However I can create Git repositories using the TFS portal easily (using the Code tab), I can not find any feature inside the TFS portal or command line based feature to remove a Git repository. Also when I navigate through 'Manage repositories...' I can not find a feature called 'Remove repository'.

I had no luck Googling and searching the MSDN pages on this.

So I do not want to remove the entire team project (because it contains a lot of source code, work items and history), but only an empty Git repository.

Does anyone have a suggestion?

Edit #1 The sub menu that should display the 'Delete repository' option in the administrative pages, does not seem to be enabled when only one Git repository remains in a specific team project (see screenshot). For the record: it is visible when two or more Git repositories are present.

enter image description here

like image 574
Herman Cordes Avatar asked Mar 04 '16 10:03

Herman Cordes


3 Answers

Quite simple actually when there are multiple git repos in a project:

  1. Select the code tab.
  2. Click on the dropdown where it shows your repos.
  3. Select manage repositories.
  4. Click on the context dropdown next to the repo you want to delete.
  5. Select delete repository.

enter image description here

enter image description here

Edit (based on your edit):

TFS 2015 (update 1) indeed has an explicit minimum limit set for the number of Git repos contained within a TFS team project.

The TFS REST api contains functions which together can be used to delete a git repo but it does not delete the 'last' repo in the TFS project.

Here is the general API documentation

Two functions involved with deleting a git repo are:

  1. Get a list of repositories

    (GET VERB) https://{instance}/defaultcollection/[{project}]/_apis/git/repositories?api-version={version}

Which when given a project name returns json containing a list of git repos and their repo ID's.

  1. Delete a repository which when given a repo ID will delete the specified repo.

    (DELETE VERB) https://{instance}/defaultcollection/_apis/git/repositories/{repository}?api-version={version}

Unfortunately there is a catch when invoking the delete repo function:

{
"$id": "1"
"innerException": null
"message": "There must always be at least one repository per Team Project."
"typeName": "Microsoft.TeamFoundation.Git.Server.GitRepositoryMinimumPerProjectThresholdExceededException, Microsoft.TeamFoundation.Git.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
"typeKey": "GitRepositoryMinimumPerProjectThresholdExceededException"
"errorCode": 0
"eventId": 3000
}

Exception documentation on MSDN

Looking at SQL server on a lab instance I have (in my opinion unsupported if misused in a prod environment)

The TFS database contains a stored procedure which deletes git repos called prc_DeleteGitRepositories, it takes 4 arguments which I hunted down either in the database or hitting F12 on the web-ui.

It is invoked as follows:

EXEC prc_DeleteGitRepositories @partitionId=1, 
@teamProjectUri ='vstfs:///Classification/TestProject1/cbcc3093-247d-448a-8c3b-f5d447fc8afa', 
@repositoryId='4111286D-D066-4F3D-89B9-960055D678FE', 
@deleterId='769254d3-1f13-431c-a580-1500dcbffbce'

That however throws the following in the scenario where only 1 git repo exists in the specified project:

Msg 50000, Level 16, State 1, Procedure prc_DeleteGitRepositories, Line 65
%error="1200013";%:<SERVERNAME>.TestCollection.dbo.prc_DeleteGitRepositories: There must always be at least one repository per Team Project.

So to summarize: a potential feature request best suited to uservoice as discussed in our comments on this Q/A.

like image 84
Elmar Avatar answered Oct 29 '22 23:10

Elmar


regarding to documentation of how to manage repos you cannot

You cannot remove a repo if it is the only Git repo in the Team Project. If you need to delete the only Git repo in a Team Project, create a new Git repo first, then delete the repo.

You must have Delete Repository permissions to delete a repo from a team project.

take a look for this link : https://www.visualstudio.com/en-us/docs/git/delete-existing-repo

like image 33
FSD Avatar answered Oct 29 '22 21:10

FSD


You cannot delete it from the UI directly but I have a workaround for you: just create another Repo, then you'll get an option to delete.

So all in all if you have multiple Repo then you can delete one of them but if there is only one, then it cannot be deleted directly from the UI.

like image 26
Abhinav Saxena Avatar answered Oct 29 '22 23:10

Abhinav Saxena