You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitea/models
Henry Goodman 12cb1d2998
Allow force push to protected branches (#28086)
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:

<img width="943" alt="image"
src="https://github.com/go-gitea/gitea/assets/79623665/7491899c-d816-45d5-be84-8512abd156bf">

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


![image](https://github.com/go-gitea/gitea/assets/79623665/e018e6e9-b7b2-4bd3-808e-4947d7da35cc)
<img width="1038" alt="image"
src="https://github.com/go-gitea/gitea/assets/79623665/57ead13e-9006-459f-b83c-7079e6f4c654">

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
7 months ago
..
actions Drop `IDOrderDesc` for listing Actions task and always order by `id DESC` (#31150) 8 months ago
activities Fix web notification icon not updated once you read all notifications (#31447) 7 months ago
admin Next round of `db.DefaultContext` refactor (#27089) 1 year ago
asymkey Enable more `revive` linter rules (#30608) 9 months ago
auth Add Passkey login support (#31504) 7 months ago
avatars Replace 10 more gt- classes with tw- (#29945) 10 months ago
db [Refactor] Unify repo search order by logic (#30876) 8 months ago
dbfs Enable `unparam` linter (#31277) 8 months ago
fixtures Fix wrong display of recently pushed notification (#25812) 8 months ago
git Allow force push to protected branches (#28086) 7 months ago
issues Refactor issue label selection (#31497) 7 months ago
migrations Allow force push to protected branches (#28086) 7 months ago
organization Fix wrong display of recently pushed notification (#25812) 8 months ago
packages Fix package list performance (#30520) 10 months ago
perm Clarify permission "HasAccess" behavior (#30585) 10 months ago
project Rename project board -> column to make the UI less confusing (#30170) 8 months ago
pull Add support for sha256 repositories (#23894) 1 year ago
repo Refactor repo unit "disabled" check (#31389) 8 months ago
secret Make runs-on support variable expression (#29468) 11 months ago
shared/types Refactor locale&string&template related code (#29165) 12 months ago
system Refactor deletion (#28610) 1 year ago
unit Refactor repo unit "disabled" check (#31389) 8 months ago
unittest Add some tests to clarify the "must-change-password" behavior (#30693) 9 months ago
user Fix duplicate sub-path for avatars (#31365) 8 months ago
webhook Store webhook event in database (#29145) 11 months ago
error.go Add merge style `fast-forward-only` (#28954) 12 months ago
fixture_generation.go Replace more db.DefaultContext (#27628) 1 year ago
fixture_test.go Replace more db.DefaultContext (#27628) 1 year ago
main_test.go make writing main test easier (#27270) 1 year ago
org.go Add user blocking (#29028) 11 months ago
org_team.go Clarify permission "HasAccess" behavior (#30585) 10 months ago
org_team_test.go Add user blocking (#29028) 11 months ago
org_test.go Add user blocking (#29028) 11 months ago
repo.go Refactor deletion (#28610) 1 year ago
repo_test.go Penultimate round of `db.DefaultContext` refactor (#27414) 1 year ago
repo_transfer.go chore: use errors.New to replace fmt.Errorf with no parameters will much better (#30621) 9 months ago