Skip to content

feat: Branch protection rules

  • Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA

Description

This MR lets GitLab Workflow provide the branch protection rules for the current repository to VS Code, so it will provide a warning when making a new commit. More information of how it works is in the description of #1543 (closed).

This implementation will validate the push rules against the current user's access level, and will not mark a branch as protected if the user is allowed to push. I think this is the best way to make this change as unobtrusive as possible, particularly when dealing with personal projects where users may not be aware of GitLab's default behavior. Merge rules are not used, so repository owners can set Push permissions to "No one" to enforce this feature and require Merge Requests for all changes to protected branches.

There is also a new user setting that disables this new behavior entirely.

Related Issues

Resolves #1543 (closed)

How has this been tested?

This can be tested by opening any repository as a user without full access rights. Creating a repository and setting protected branches with "Allowed to Push and Merge" to "No one" also works.

Changing branch protection rules in GitLab requires reopening the folder in VS Code to apply the latest settings.

Screenshots (if appropriate)

image

This indicator appears when a protected branch is checked out in a GitLab repository, and the current user does not have push rights.

What CHANGELOG entry will this MR create?

  • fix: Bug fix fixes - a user-facing issue in production - included in changelog
  • feature: New feature - a user-facing change which adds functionality - included in changelog
  • BREAKING CHANGE: (fix or feature that would cause existing functionality to change) - should bump major version, mentioned in the changelog
  • None - other non-user-facing changes
Edited by Lennard Sprong

Merge request reports

Loading