1

Using TFS 2015

Question 1: Is there a way to prevent Contributors from deleting a particular branch (e.g. master)?

My tests indicate that there is no way to stop users who have Contribute permission from being able to delete the master branch.

Added to this, there appears to be no way to recover a deleted branch as this is a "destroy" operation.

Please correct me if I am wrong.

Question 2: Is it true that it is impossible to protect branches from deletion by users with Contribute permission?

Question 3: Is it true that there is no way, in TFS 2015, to recover a deleted branch on the remote repository i.e. that TFS 2015 does not perform a logical delete, but rather a destroy?

Banoona
  • 1,470
  • 3
  • 18
  • 32
  • git hooks can be configured in such way that this can be achieved. – Marek R Jun 12 '18 at 15:42
  • @MarekR TFS 2015 doesn't support server side hooks for Git. – Daniel Mann Jun 13 '18 at 00:21
  • By default the user who creates a banch gets additional "branch owner" permissions. That allows them to delete their branch after a pull requests completes. This includes the creator of the master branch. You can configure a Branch Policy or set the permissions after creation. – jessehouwing Jun 13 '18 at 08:12

2 Answers2

0

I think you're operating from a faulty premise. You seem to think that branches have some sort of relationship to the history for that branch. That is incorrect.

A branch is just a pointer to a commit. A commit has children and parents. The history is maintained by that relationship between parent and child commits, not by the branch.

If a branch is deleted, you can simply checkout the commit that the branch pointed to and recreate the branch.

Realistically speaking, this should not be a major problem.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
  • Thanks. But this really isn't completely correct. In TFS 2015, when a git branch is deleted on the server repo, and if there remain no branches, the repository is shown as empty and has no history! Please try it out. git push --delete origin master. – Banoona Jun 14 '18 at 09:19
0
  1. You need to set Rewrite and destroy history (force push) permission to Deny at branch level to protect the branch:

enter image description here

  1. You can do git reflog and find the SHA1 for the commit at the tip of your deleted branch, then just git checkout [sha]. And once you're at that commit, you can just git checkout -b [branchname] to recreate the branch from there.

Useful links:

Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • Yes, agree that this would be a useful permission to set. However, it doesn't work (I have tested numerous times). It doesn't take effect. – Banoona Jun 14 '18 at 13:21
  • If you add the account that you delete branch on the website the screenshot showed, will it work? – Cece Dong - MSFT Jun 15 '18 at 07:37
  • Hi Cece. Sorry but both of your suggestions about restoring the branch aren't really going to work on the remote TFS repository. Fine for local repo git commands, but how do you see this working on the remote? – Banoona Jun 20 '18 at 15:13
  • You may try the solution in this case: https://stackoverflow.com/questions/1992364/git-recover-deleted-remote-branch. Use `git fsck --full --no-reflogs | grep commit` to find the HEAD commit of deleted branch and get them back. – Cece Dong - MSFT Jun 22 '18 at 10:16
  • Again, this assumes that you have a local repo available. – Banoona Jun 22 '18 at 20:26
  • If you don't even have a local repo, then it's not able to restore git branch in TFS 2015. – Cece Dong - MSFT Jun 25 '18 at 09:50