Azure Repos Configuration Options
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In today’s blog post, we will discuss different configuration options available in Azure Repos.
Azure Repos Configuration Options:
All repository settings:
Setting | Default | Description |
Default branch name for new repositories | Off | When enabled, new repositories are initialized with the name of the branch that you specify. You can change the default branch for a particular repository at any time. The default branch name is main. |
Allow users to manage permissions for their created branches | On | New repositories are configured to allow users to manage permissions for their created branches. |
Individual repository settings:
Setting | Default | Description |
Forks | On | Allow users to create forks from the repository. |
Commit mention linking | On | Automatically create links for work items mentioned in a commit comment. |
Commit mention work item resolution | On | Allow mentions in commit comments to close work items. |
Work item transition preferences | On | Remember user preferences for completing work items with pull requests. |
Permissions management | On | Allow users to manage permissions for the branches they created |
Strict Vote Mode | On | Enable Strict Vote Mode for repository which requires Contribute permission to vote in Pull Requests. |
Disable Repository | Off | Disable access to the repository (including builds, pull requests, etc) but keep the repository discoverable with a warning. |
Repository Policies:
Policy | Default | Description |
Commit author email validation | Off | Block pushes with a commit author email that does not match the specified patterns. |
File path validation | Off | Block pushes from introducing file paths that match the specified patterns. |
Case enforcement | Off | Avoid case-sensitivity conflicts by blocking pushes that change name casing on files, folders, branches, and tags. |
Reserved names | Off | Block pushes that introduce files, folders, or branch names that include platform reserved names or incompatible characters. |
Maximum path length | Off | Block pushes that introduce paths that exceed the specified length. |
Maximum file size | Off | Block pushes that contain new or updated files larger than this limit. |
Branch Policies:
Policy | Default | Description |
Require a minimum number of reviewers | Off | Require approval from a specified number of reviewers on pull requests. |
Check for linked work items | Off | Encourage traceability by checking for linked work items on pull requests |
Check for comment resolution | Off | Check to see that all comments have been resolved on pull requests. |
Limit merge types | Off | Control branch history by limiting the available types of merge when pull requests are completed. |
Add Build Validation policies | Off | Add one or more policies to validate code by pre-merging and building pull request changes. Can also enable or disable policies. |
Add Status Check policies | Off | Add one or more policies to require other services to post successful status to complete pull requests. Can also enable or disable policies. |
Automatically included reviewers | Off | Add one or more policies to designate code reviewers to automatically include when pull requests change certain areas of code. Can also enable or disable policies. |
Prerequisites:
How to change default branch name for a repository in Azure Repos?
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Select your organization => Organization settings => Repositories, turn on Default branch name for new repositories, and type your default branch name.
Now if you create a new repository in any of the projects under this organization, the default branch name will be “dev” instead of “main”.
Note: You can also set the default branch name in project level or for individual repositories. And the precedence will be given in individual repository > individual project > organization order.
Set default branch name for your repositories inside an Azure DevOps project:
Set default branch name for an existing repository hosted in Azure Repos:
How to disable a repository in Azure Repos?
You can disable access to a repository without deleting the repository itself.
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Navigate to Your Azure DevOps Organization => Your Azure DevOps Project => Project Settings => Repository => Repository you want to disable => Settings, and enable “Disable Repository”.
How to disable forking of a repository in Azure Repos?
By default, users who have proper access in your Azure DevOps project can create a fork out of your Azure Repos.
But you can disable fork option in Azure Repos as shown below
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Navigate to Your Azure DevOps Organization => Your Azure DevOps Project => Project Settings => Repository => Repository you want to disable forking => Settings, and disable “Forks”.
If you now try to fork this repository, you will get an error “Due to policy, this repository cannot be forked”.
How to enable email validation for a repository in Azure Repos?
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Navigate to Your Azure DevOps Organization => Your Azure DevOps Project => Project Settings => Repository => Select the repository => Policies, and enable “Commit author email validation”. Provide the email id pattern.
Note: You can specify exact emails or use wildcards. Multiple email patterns should use “;” as a separator. Email patterns prefixed with “!” are excluded. Order is important.
Now if you try to commit in this repository with a different email, you will get “The push was rejected because one or more commits contain author email which does not match the policy-specified patterns” error message.
How to enable file path validations for a repository in Azure Repos?
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Navigate to Your Azure DevOps Organization => Your Azure DevOps Project => Project Settings => Repository => Select the repository => Policies, and enable “File path validation”. Provide the file path pattern.
Note: Exact paths begin with “/”. You can specify exact paths and wildcards. You can also specify multiple paths using “;” as a separator. Paths prefixed with “!” are excluded. Order is important.
Now if you try to commit a file in /deb directory in your Azure repo, you will get an error “The push was rejected because one or more commits add a file path /some/path which matches the policy-specified pattern ‘/some/path/*’”
How to enable case sensitivity for a repository in Azure Repos?
The Windows and macOS file systems are case-insensitive (but case-preserving) by default. Most Linux filesystems are case-sensitive. Git was built originally to be the Linux kernel’s version control system, so unsurprisingly, it’s case-sensitive. While many of the issues with a case-insensitive OS have been addressed in Git for Windows, a few quirks remain.
File and folder names
On Linux, checking out a Git repo which contains both “File.txt” and “file.txt” is no problem. Those are distinct filenames. On Windows and macOS, checking out both files will result in the second one overwriting the first one. If two folders differ only by case, their contents will end up mixed together on case-insensitive filesystems.
Branch and tag names:
You can create two branches or tags (known as ‘refs’) that differ only in casing. Git’s internals, as well as Azure DevOps Services/TFS, will treat them as two separate refs. On a user’s machine, Git uses the filesystem to store refs. Fetches and other operations begin to fail because of the ambiguity. Each ref is represented by a small file, and if a ref name contains / characters, the parts before the final / are represented by folders.
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Navigate to Your Azure DevOps Organization => Your Azure DevOps Project => Project Settings => Repository => Select the repository => Policies, and enable “Case enforcement”.
Now if you try to create a file/dir/branch/tag with same name but different case, you will get below errors.
- The path ‘/some/path/somefile’ only differs from an existing file by case.
- Name conflicts with refs/heads/somebranch
- Name conflicts with refs/heads/sometag
How to enable usage of reserved named for a repository in Azure Repos?
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Navigate to Your Azure DevOps Organization => Your Azure DevOps Project => Project Settings => Repository => Select the repository => Policies, and enable “Reserved names”.
Now if you try to create a file or directory or path with reserved names, you will get an error “The push was rejected because COM9 starts with ‘COM9’, which is a reserved file or directory name.”
How to enable maximum path length for a repository in Azure Repos?
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Navigate to Your Azure DevOps Organization => Your Azure DevOps Project => Project Settings => Repository => Select the repository => Policies, and enable “Maximum path length” and provide the max path length.
Now if you try to create a path with more than 10 characters long, you will get an error “The push was rejected because one or more commits contain path ‘/thisisalongpath/test.txt’, which exceeds the maximum path length of 10 characters.”
How to set maximum file size that can be pushed in Azure Repos?
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Navigate to Your Azure DevOps Organization => Your Azure DevOps Project => Project Settings => Repository => Select the repository => Policies, and enable “Maximum file size” and select the max file size from the drop down.
Now if you try to push a file with more than 1 MB of size in your Azure repo, you will get an error “The object will increase this repository size by 4461218 bytes (the limit is 1048576 bytes)”.
How to make approval mandatory for pull requests in Azure Repos?
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Navigate to Your Azure DevOps Organization => Your Azure DevOps Project => Repos => Your Azure Repository => Branches => Your Azure Repository Branch Options => Branch Policies
Enable “Require a minimum number of reviewers” and provide the minimum number of reviewers you want to add for approval of the pull request. In addition, you can also enable below options –
- If Allow requestors to approve their own changes is selected, the creator of the pull request may vote on its approval. If not, they can still vote Approve on their pull request, but their vote won’t count toward the Minimum number of reviewers.
- By default, anyone with push permissions on the source branch may both add commits and vote on the pull request’s approval. By enabling Prohibit the most recent pusher from approving their own changes, you can enforce segregation of duties – having the most recent push automatically makes the pusher’s vote not count.
- If any reviewer rejects the changes, the pull request can’t finish unless you select Allow completion even if some reviewers vote to wait or reject.
- You can reset code reviewer votes when new changes are pushed to the source branch. Select Reset code reviewer votes when there are new changes.
How to make linking to work items mandatory for pull requests in Azure Repos?
Enable associations between pull requests and a work item to ensure that changes to your branch have work item management tracking. Linking work items provides additional context for your changes and ensures that updates go through your work item tracking process.
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Navigate to Your Azure DevOps Organization => Your Azure DevOps Project => Repos => Your Azure Repository => Branches => Your Azure Repository Branch Options => Branch Policies => Enable “Check for linked work items” and select “Required”
How to enable comment resolution for pull requests in Azure Repos?
Enable checks to see that all comments have been resolved on pull requests. If enabled, blocks pull requests from being completed while any comments are active.
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Navigate to Your Azure DevOps Organization => Your Azure DevOps Project => Repos => Your Azure Repository => Branches => Your Azure Repository Branch Options => Branch Policies => Enable “Check for comment resolution” and select “Required”
How to configure merge types for a repository in Azure Repos?
Azure Repos has multiple merge strategies, and by default, all of them are allowed. Select Limit merge types to pick which ones you’ll allow in your repo.
- Basic merge (no fast-forward) – creates a merge commit in the target whose parents are the target and source branches.
- Squash merge – creates a linear history with a single commit in the target branch with the changes from the source branch.
- Rebase and fast-forward – creates a linear history by replaying source commits onto the target branch with no merge commit.
- Rebase with merge commit – replays the source commits onto the target and still creates a merge commit.
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Navigate to Your Azure DevOps Organization => Your Azure DevOps Project => Repos => Your Azure Repository => Branches => Your Azure Repository Branch Options => Branch Policies => Enable “Limit merge types” and select the merge requests types as per your requirements.
How to automatically add approver for pull requests in Azure Repos?
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Navigate to Your Azure DevOps Organization => Your Azure DevOps Project => Repos => Your Azure Repository => Branches => Your Azure Repository Branch Options => Branch Policies => Scroll down the page and click the plus sign under “Automatically included reviewers”
Step 3: Select the approver and click “Save”.
How to make a branch as default branch in Azure Repos?
By default, main branch is the default branch in Azure Repos, but you can set any other branch as default branch.
Step 1: Login to your Azure DevOps account.
https://dev.azure.com/your_new_organization_name
Step 2: Navigate to Your Azure DevOps Organization => Your Azure DevOps Project => Repos => Your Azure Repository => Branches => Branch options => Set as default branch.
There are couple of more branch policy options Build validation and Status check which will be covered during Azure Pipeline.
Hope you have enjoyed this article. To know more about Azure DevOps, please refer below official documentation
https://docs.microsoft.com/en-us/azure/devops/?view=azure-devops