You can set up and view repository configurations in the SourceCraft interface under Repository settings in the Configurations section. Learn more in this article.
Branch policies are rules and restrictions that apply to specific branches and tags in a repository. With policies, you can manage changes, implement code reviews, enforce proper naming and conditions for creating branches and tags, and protect branches from accidental commits or direct pushes.
You specify the policy configuration for a particular repository and store it in the .sourcecraft/branches.yaml file. A configuration stored in the main branch, e.g., master or main, applies to the entire repository. You can also set the configuration at the SourceCraft organization level.
The general policy configuration format in .sourcecraft/branches.yaml is as follows:
Generate a branch policy configuration file named .sourcecraft/branches.yaml, for example:
branch_protection:policies:## Preventing commit history rewrites, edits without ## a pull request, and deletion of the main branch-target:default_branchmessage:"Direct push into main branch is forbidden, create PR first"rules:-prevent_force_push-prevent_non_pr_changes-prevent_deletion## Preventing the creation of branches with names that match filters-target:branchmatches: ["**", "!OO-**/**", "!hotfix/**", "!chore/**", "!release/**"]
message:"Please use proper branch naming"rules:-prevent_creation## Preventing the creation of tags with names that match filters-target:tagmatches:"gitcore-**"message:"Manual tag creation is forbidden, please use Releaser"rules:-prevent_creation
This will return an error saying Direct push into main branch is forbidden, create PR first.
Setting up automatic branch deletion post-merge
You can set up automatic deletion of pull request source branch after its merge with the target branch. For more information, see Automatic branch deletion post-merge.
In the .sourcecraft/branches.yaml file, add a section named pull_request.branch_cleanup and, in matches, specify path filters for branches subject to automatic deletion. Here is an example:
You can override the behavior set in the .sourcecraft/branches.yaml file for a specific pull request by using the Delete source branch when merged option in the Merge settings section. For more information, see Working with pull requests in SourceCraft.
Enabling branch policy bypass for repository administrator
Warning
Only users with the Repository adminrole can override the branch policy rules, e.g., to update the configuration in .sourcecraft/branches.yaml.