Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow force push to protected branches #28086

Merged
merged 48 commits into from
Jul 5, 2024

Conversation

henrygoodman
Copy link
Contributor

@henrygoodman henrygoodman commented Nov 16, 2023

Fixes #22722

Problem

Currently, it is not possible to force push to a branch with branch protection rules in place. There are often times where this is necessary (CI workflows/administrative tasks etc).

The current workaround is to rename/remove the branch protection, perform the force push, and then reinstate the protections.

Solution

Provide an additional section in the branch protection rules to allow users to specify which users with push access can also force push to the branch. The default value of the rule will be set to Disabled, and the UI is intuitive and very similar to the Push section.

It is worth noting in this implementation that allowing force push does not override regular push access, and both will need to be enabled for a user to force push.

This applies to manual force push to a remote, and also in Gitea UI updating a PR by rebase (which requires force push)

This modifies the BranchProtection API structs to add:

  • enable_force_push bool
  • enable_force_push_whitelist bool
  • force_push_whitelist_usernames string[]
  • force_push_whitelist_teams string[]
  • force_push_whitelist_deploy_keys bool

Updated Branch Protection UI:

image

Pull Request Update branch by Rebase option enabled with source branch test being a protected branch:

image
image

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 16, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 16, 2023
@github-actions github-actions bot added modifies/translation modifies/api This PR adds API routes or modifies them labels Nov 16, 2023
@henrygoodman henrygoodman marked this pull request as ready for review November 16, 2023 08:48
@henrygoodman henrygoodman force-pushed the allow-force-push-protected-branches branch from 99d45bd to 1febb6e Compare November 16, 2023 09:08
@henrygoodman henrygoodman force-pushed the allow-force-push-protected-branches branch 2 times, most recently from 1a45601 to 90026dd Compare November 16, 2023 14:40
@henrygoodman
Copy link
Contributor Author

Will be able to fix CI compliance Sunday night

@henrygoodman henrygoodman force-pushed the allow-force-push-protected-branches branch from 90026dd to 03326ad Compare November 20, 2023 04:28
@henrygoodman henrygoodman force-pushed the allow-force-push-protected-branches branch from 52fb6a3 to f28ecbe Compare November 24, 2023 12:55
@henrygoodman
Copy link
Contributor Author

henrygoodman commented Nov 24, 2023

Small refactor in commit f28ecbe seemed necessary due to make lint showing duplicated code error, despite the 2 functions in question being quite distinct. I don't think my implementation is particularly elegant, but the almighty linter must be appeased😢

@lunny lunny added this to the 1.22.0 milestone Nov 24, 2023
@Nova-Logic
Copy link

this is very needed feature for our git workflow

@lunny
Copy link
Member

lunny commented Jan 24, 2024

Please fix the lint error

@github-actions github-actions bot added modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin modifies/frontend modifies/docs modifies/migrations labels Jan 31, 2024
@wxiaoguang wxiaoguang dismissed their stale review July 5, 2024 04:48

wait for more "naming" changes.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels Jul 5, 2024
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jul 5, 2024
@henrygoodman henrygoodman force-pushed the allow-force-push-protected-branches branch from d341dc9 to 534a1fe Compare July 5, 2024 05:56
@6543 6543 added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jul 5, 2024
@6543 6543 enabled auto-merge (squash) July 5, 2024 11:36
@6543 6543 merged commit 12cb1d2 into go-gitea:main Jul 5, 2024
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jul 5, 2024
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jul 6, 2024
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  Allow force push to protected branches (go-gitea#28086)
  Refactor login page (go-gitea#31530)
@phild5
Copy link

phild5 commented Aug 21, 2024

I'm running 1.22.0 and i'm looking all over the place for this. Where and how do i enable it? Doesn't show up on my branch protection screen.

@henrygoodman
Copy link
Contributor Author

henrygoodman commented Aug 21, 2024

I'm running 1.22.0 and i'm looking all over the place for this. Where and how do i enable it? Doesn't show up on my branch protection screen.

This is not integrated as part of 1.22.0, it is on the roadmap for 1.23.0 (might have to look around for an ETA). If you switch to nightly build it will also have changes based on current main branch, but it is not as stable as official releases

@henrygoodman henrygoodman deleted the allow-force-push-protected-branches branch August 21, 2024 12:07
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Oct 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code modifies/migrations modifies/templates This PR modifies the template files modifies/translation size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow force pushing to protected branch
7 participants