Skip to content

Allow configuring default PR base branch (fixes #36412)#36425

Merged
wxiaoguang merged 32 commits intogo-gitea:mainfrom
tototomate123:main
Feb 7, 2026
Merged

Allow configuring default PR base branch (fixes #36412)#36425
wxiaoguang merged 32 commits intogo-gitea:mainfrom
tototomate123:main

Conversation

@tototomate123
Copy link
Copy Markdown
Contributor

Summary

This adds a per-repository default PR base branch and wires it through PR entry points. It updates compare links and recently pushed branch prompts to respect the configured base branch, and prevents auto-merge cleanup from deleting the configured base branch on same-repo PRs.

Behavior changes

  • New PR compare links on repo home/issue list and branch list honor the configured default PR base branch.
  • The "recently pushed new branches" prompt now compares against the configured base branch.
  • Auto-merge branch cleanup skips deleting the configured base branch (same-repo PRs only).

Testing

Not run (local UI verification only).


Reviewer question: I added a guard in services/repository/branch.go (DeleteBranchAfterMerge flow) to avoid auto-deleting the configured default PR base branch for same-repo PRs. Is that desired, or is branch protection expected to cover this?

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 21, 2026
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/migrations labels Jan 21, 2026
@wxiaoguang
Copy link
Copy Markdown
Contributor

Is there a reason why "default" branch can't be used as PR base branch?

@TheFox0x7
Copy link
Copy Markdown
Contributor

The linked issue explains it a bit - the idea is to support a setup where you have main branch, staging branch and the dev ones and while the repository main is the first one from the list, the staging is the base one for PRs.
You could set the default to staging branch as a workaround but it's not really the main one for the workflow.

@tototomate123
Copy link
Copy Markdown
Contributor Author

Is there a reason why "default" branch can't be used as PR base branch?

Yeah, changing the default branch changes more than just PR targets. Plus, when the PR UI tries to load the diff between the "default" branch and the staging branch (which your team normally PRs to), it tends to get really laggy (making the workflow of PRing the staging branch rather tedious).

@wxiaoguang
Copy link
Copy Markdown
Contributor

The linked issue explains it a bit

Sorry but I didn't find the linked issue ... Did I miss something? What I saw on my side:

Details image

@TheFox0x7
Copy link
Copy Markdown
Contributor

it's in the title - #36412

@wxiaoguang
Copy link
Copy Markdown
Contributor

it's in the title - #36412

Hmm, totally missed that.

But still don't understand the details ... in that case, why not set dev to be the default branch, and only keep main for release purpose?

changing the default branch changes more than just PR targets.

What else would it affect?

when the PR UI tries to load the diff between the "default" branch and the staging branch (which your team normally PRs to), it tends to get really laggy

If the default branch is dev, then it isn't a problem anymore?

@tototomate123
Copy link
Copy Markdown
Contributor Author

But still don't understand the details ... in that case, why not set dev to be the default branch, and only keep main for release purpose?

Because the default branch is the repo's canonical ref, not just "the default PR target". It affects what git clone checks out, what the web UI shows by default (file tree/README), and what various tools/integrations assume when they operate on "the repo" without an explicit ref.

changing the default branch changes more than just PR targets.

What else would it affect?

Clone defaults, the repository home view/default ref in the UI, and integrations/automation that implicitly use the default branch (for example links that omit a ref, docs references, or CI setups that follow the default branch unless configured otherwise). Many repos also want the default branch to represent the stable/releasable line for external consumers and casual viewers.

If the default branch is dev, then it isn't a problem anymore?

It avoids the PR-base mismatch, but at the cost of making an integration branch the repo's canonical branch. A common workflow keeps main stable for releases while PRs land in dev/staging. Flipping the default branch to dev has broader side effects than desired and changes what the repo "looks like" to everyone by default.

A configurable default PR base branch solves the actual pain point: it reduces mistakes (accidentally opening PRs against main), fixes compare links/prompts, and supports multi-branch workflows without redefining the repo's canonical branch.

@wxiaoguang
Copy link
Copy Markdown
Contributor

Thank you for the clarification, it makes sense.

@github-actions github-actions bot added the modifies/api This PR adds API routes or modifies them label Jan 21, 2026
@tototomate123 tototomate123 marked this pull request as ready for review January 21, 2026 19:08
@tototomate123
Copy link
Copy Markdown
Contributor Author

Thank you for the clarification, it makes sense.

Thanks for taking a look, glad the motivation makes sense.

Just to confirm: this is fully opt-in (per-repo default PR base branch), so there’s no behavior change unless the setting is configured. The changes mostly wire that base through the existing PR entry points (compare links / recently pushed prompt), and add a small safety guard to avoid auto-deleting the configured base branch in same-repo PR cleanup.

Do you have any concerns with the current approach, or would you like any adjustments (naming/UI wording, docs, tests, or the branch-cleanup guard behavior)?

@lunny
Copy link
Copy Markdown
Member

lunny commented Jan 21, 2026

If we want to add an option for pull request ,it should be in the repo_unit table and the migration is unnecessary.

tototomate123 and others added 2 commits January 22, 2026 17:33
Signed-off-by: Louis <116039387+tototomate123@users.noreply.github.com>
@tototomate123
Copy link
Copy Markdown
Contributor Author

If we want to add an option for pull request ,it should be in the repo_unit table and the migration is unnecessary.

Done - moved the setting into the PR repo_unit config and removed the migration.

@silverwind silverwind requested a review from Copilot January 23, 2026 13:54
@wxiaoguang
Copy link
Copy Markdown
Contributor

diff --git a/models/git/branch.go b/models/git/branch.go

Feel free to help to edit this PR and add necessary tests.

@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented Feb 3, 2026

diff --git a/models/git/branch.go b/models/git/branch.go

Feel free to help to edit this PR and add necessary tests.

@lunny if you don't have plan to make more changes to this PR, it can be merged as-is. I don't really see anything seriously wrong would happen (at the worst, a 404 page indicates the repo admin to update the PR target branch). You can also make improvements in following up PRs.

By the way, your suggestion is still not complete, it fails a repo with no PR unit. So if you'd like to make more changes, it also needs tests with good coverage.

@silverwind
Copy link
Copy Markdown
Member

How does the UI look for the new field? Is it acceptable looking on the repo settings page?

@wxiaoguang
Copy link
Copy Markdown
Contributor

How does the UI look for the new field? Is it acceptable looking on the repo settings page?

I have done enough and it is acceptable to me. If you don't like it, you can do more.

@silverwind
Copy link
Copy Markdown
Member

How does the UI look for the new field? Is it acceptable looking on the repo settings page?

I have done enough and it is acceptable to me. If you don't like it, you can do more.

I'm just asking for a screenshot.

@silverwind
Copy link
Copy Markdown
Member

@tototomate123 never raise pull request from a the default branch, these are hard to collaborate on.

@silverwind
Copy link
Copy Markdown
Member

I guess it looks ok but there is a inconsistency in the capitalization with the label above:

image

@silverwind
Copy link
Copy Markdown
Member

silverwind commented Feb 3, 2026

There is one UI issue: The dropdown cannot be cleared so the default value can not be restored once changed.

@silverwind
Copy link
Copy Markdown
Member

silverwind commented Feb 3, 2026

It appears fomantic should support a ui dropdown selection clearable to make a x icon show as seen in https://fomantic-ui.com/modules/dropdown.html#clearable-selection, but I can not get this to work for some reason, maybe it only works for multiple.

@silverwind
Copy link
Copy Markdown
Member

silverwind commented Feb 3, 2026

Maybe we should just have a "Default Branch" instead of empty option. Then there is no strange UX with clearable dropdown.

@wxiaoguang
Copy link
Copy Markdown
Contributor

There is one UI issue: The dropdown cannot be cleared so the default value can not be restored once changed.

Do you have plan to make more changes? I see most "dropdown (select)" elements don't have the ability to "restore" after their values are changed, not only in Gitea, but in all desktop/web apps.

@tototomate123
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. Sorry for opening PRs from the default branch, won't happen again in the future.

Is there anything else left before merge? I saw the default branch selection UI change landed in wxiaoguang's commits, so I don't think more is needed on my side?
image

@wxiaoguang
Copy link
Copy Markdown
Contributor

@lunny @silverwind anything else to change?

@lunny
Copy link
Copy Markdown
Member

lunny commented Feb 6, 2026

It would be better to display a dedicated lock icon or hide the delete button in the branch list to indicate the default target branch for pull requests, and to improve the error message. The current message states that I am deleting the default branch, but I am actually deleting v2, which is not the default branch or pull request branch according to this UI.

image

@wxiaoguang
Copy link
Copy Markdown
Contributor

It would be better to display a dedicated lock icon or hide the delete button in the branch list to indicate the default target branch for pull requests, and to improve the error message. The current message states that I am deleting the default branch, but I am actually deleting v2, which is not the default branch or pull request branch according to this UI.

The error message is clear enough. You can check your repo's pull requests settings.

If any one still have plans to improve, just edit directly or make changes in following up PRs.

To me, these "problems" are quite trivial and I don't need such feature, so I won't spend more time on it.

@silverwind
Copy link
Copy Markdown
Member

I will test this one more time soon, hold on a bit with the merge.

Copy link
Copy Markdown
Member

@silverwind silverwind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI looks ok to me now. Maybe still wait on @lunny's approval before merge.

@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 Feb 6, 2026
@wxiaoguang wxiaoguang enabled auto-merge (squash) February 7, 2026 01:07
@wxiaoguang wxiaoguang merged commit e2104a1 into go-gitea:main Feb 7, 2026
24 checks passed
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 9, 2026
* giteaofficial/main:
  Refactor merge conan and container auth preserve actions taskID (go-gitea#36560)
  Fix assignee sidebar links and empty placeholder after go-gitea#32465 refactor (go-gitea#36559)
  Fix various version parsing problems (go-gitea#36553)
  Fix highlight diff result (go-gitea#36539)
  Refactor Nuget Auth to reuse Basic Auth Token Validation (go-gitea#36558)
  Update go dependencies (go-gitea#36548)
  Prevent navigation keys from triggering actions during IME composition (go-gitea#36540)
  Fix various mermaid bugs (go-gitea#36547)
  Add `elk` layout support to mermaid (go-gitea#36486)
  Allow configuring default PR base branch (fixes go-gitea#36412) (go-gitea#36425)
  [skip ci] Updated translations via Crowdin
  Color command/error logs in Actions log (go-gitea#36538)
  Add paging headers (go-gitea#36521)
  Fix issues filter dropdown showing empty label scope section (go-gitea#36535)
  [SECURITY] fix: Adjust the toolchain version (go-gitea#36537)
  Hide `add-matcher` and `remove-matcher` from actions job logs (go-gitea#36520)
  Improve timeline entries for WIP prefix changes in pull requests (go-gitea#36518)
Sirherobrine23 pushed a commit to Sirherobrine23/gitea that referenced this pull request Mar 4, 2026
…itea#36425)

This adds a per-repository default PR base branch and wires it through
PR entry points. It updates compare links and recently pushed branch
prompts to respect the configured base branch, and prevents auto-merge
cleanup from deleting the configured base branch on same-repo PRs.

## Behavior changes
- New PR compare links on repo home/issue list and branch list honor the
configured default PR base branch.
- The "recently pushed new branches" prompt now compares against the
configured base branch.
- Auto-merge branch cleanup skips deleting the configured base branch
(same-repo PRs only).

---------

Signed-off-by: Louis <116039387+tototomate123@users.noreply.github.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: silverwind <me@silverwind.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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/templates This PR modifies the template files type/feature Completely new functionality. Can only be merged if feature freeze is not active.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants