Fix Repo Permissions

PHOTO EMBED

Mon Mar 06 2023 13:25:41 GMT+0000 (Coordinated Universal Time)

Saved by @rick_m #tf #git

:: "C:\_git\gitpm.cmd" "[PROJECTNAME]" "[REPONAME]"


echo off

set TeamProject=%~1
set GitRepo=%~2

set TeamCollection="https://dev.azure.com/[ORG]/"

if "%TeamProject%"=="" GOTO validation_error
if "%GitRepo%"=="" GOTO validation_error

REM First, block the Create Branch permission at the repository root for the project's contributors.
tf git permission /deny:CreateBranch /group:"[%TeamProject%]\Contributors" /collection:%TeamCollection% /teamproject:"%TeamProject%" /repository:%GitRepo%

REM Then, allow contributors to create branches under features, hotfixes, and users.
tf git permission /allow:CreateBranch /group:"[%TeamProject%]\Contributors" /collection:%TeamCollection% /teamproject:"%TeamProject%" /repository:%GitRepo% /branch:features
tf git permission /allow:CreateBranch /group:"[%TeamProject%]\Contributors" /collection:%TeamCollection% /teamproject:"%TeamProject%" /repository:%GitRepo% /branch:users
tf git permission /allow:CreateBranch /group:"[%TeamProject%]\Contributors" /collection:%TeamCollection% /teamproject:"%TeamProject%" /repository:%GitRepo% /branch:hotfixes
tf git permission /allow:CreateBranch /group:"[%TeamProject%]\Contributors" /collection:%TeamCollection% /teamproject:"%TeamProject%" /repository:%GitRepo% /branch:releases
tf git permission /allow:CreateBranch /group:"[%TeamProject%]\Contributors" /collection:%TeamCollection% /teamproject:"%TeamProject%" /repository:%GitRepo% /branch:save
tf git permission /allow:CreateBranch /group:"[%TeamProject%]\Contributors" /collection:%TeamCollection% /teamproject:"%TeamProject%" /repository:%GitRepo% /branch:archive
tf git permission /allow:CreateBranch /group:"[%TeamProject%]\Contributors" /collection:%TeamCollection% /teamproject:"%TeamProject%" /repository:%GitRepo% /branch:hold
tf git permission /allow:CreateBranch /group:"[%TeamProject%]\Contributors" /collection:%TeamCollection% /teamproject:"%TeamProject%" /repository:%GitRepo% /branch:misc

REM allow administrators to create a branch called development (in case it ever gets deleted accidentally).
tf git permission /allow:CreateBranch /group:"[%TeamProject%]\Project Administrators" /collection:%TeamCollection% /teamproject:"%TeamProject%" /repository:%GitRepo% /branch:development

REM Finally, allow administrators to create a branch called master (in case it ever gets deleted accidentally).
tf git permission /allow:CreateBranch /group:"[%TeamProject%]\Project Administrators" /collection:%TeamCollection% /teamproject:"%TeamProject%" /repository:%GitRepo% /branch:master
GOTO complete

:validation_error
ECHO Both the TeamProject and GitRepo arguments must be valid
ECHO TeamProject = '%TeamProject%'
ECHO GitRepo= '%GitRepo%'
GOTO EOF

:complete
ECHO All done!

:EOF
content_copyCOPY

Must be run in development command