问题
We use Git hosted in Azure DevOps for all of our source code. So far we have used Git Hooks to ensure that team members follow a branch naming convention {branchtype}/{username}/{friendlyname}/{workitemtype}{workitemid}
.
Examples:
- dev/dparkar/addauth/ta123456
- hf/jsmith/memoryleak/bu11111
The branch naming convention allow us to clearly understand whether it's a regular development branch or a hotfix branch and which work item it is associated with, among other things.
To setup Git Hooks locally, team members were required to run a script locally before starting to contribute. This was fine as the script was doing additional setup besides just setting up Git Hooks. But we don't need that additional setup anymore and therefore we are looking to remove the script completely.
Is there a way to force branch naming conventions on the server side?
I noticed there is documentation for Pull Request Status Server, but was wondering if there is something OOTB which just needs to be configured in Azure DevOps.
回答1:
There are two kinds of git hooks:
- Client-side hooks, works for the local git repo.
- Server-side hooks, works for the remote repo (VSTS git repo as you used).
More details about git hooks, you can refer Customizing Git - Git Hooks in git book.
For now, only client-side hooks (such as pre-push hook, pre-commit hook etc) are supported for VSTS git repo.
The Server-side hooks is not available for now (but already in our backlog) for VSTS git repo, you can also find it in this user voice. Once server-side hooks are available in future, such as you can use pre-receive hook (or post-receive hook) to check and force convert branch name in remote repo.
Besides, the link in your question is using VSTS web hook which is quite different from git hooks. And of course you can check and force convert branch name by web hook, but you additional website to receive information and convert branch name. Detail steps as below:
Add a web hook in VSTS service Hooks Tab -> Trigger by code push event -> input your own website url -> Test -> make sure it can connect successful -> Finish.
Once new changes are pushed to VSTS git repo, the web hook will be triggered, and send information to your website. Then you can check and convert branch name in your website and push again.
回答2:
TFS 2018 and Azure Repos allow you to require branches be created in folders.
See https://docs.microsoft.com/en-us/azure/devops/repos/git/require-branch-folders?view=azure-devops for instructions how to configure permissions to enable this.
来源:https://stackoverflow.com/questions/47664386/force-a-branch-naming-convention-in-azure-devops-git