Add a simple way to rename branch like gh #15870
Labels
No Label
backport/done
backport/v1.0
backport/v1.1
backport/v1.10
backport/v1.11
backport/v1.12
backport/v1.13
backport/v1.14
backport/v1.15
backport/v1.2
backport/v1.3
backport/v1.4
backport/v1.5
backport/v1.6
backport/v1.7
backport/v1.8
backport/v1.9
bounty
changelog
dependencies
frontport/done
frontport/main
good first issue
Hacktoberfest
hacktoberfest-accepted
in progress
kind/api
kind/breaking
kind/bug
kind/build
kind/deployment
kind/deprecated
kind/docs
kind/enhancement
kind/feature
kind/lint
kind/misc
kind/moderation
kind/package
kind/proposal
kind/question
kind/refactor
kind/regression
kind/security
kind/summary
kind/testing
kind/translation
kind/ui
kind/upstream-related
kind/usability
kind/ux
lgtm/done
lgtm/need 1
lgtm/need 2
performance/bigrepo
performance/cpu
performance/memory
performance/speed
priority/critical
priority/low
priority/maybe
priority/medium
proposal/rejected
reviewed/confirmed
reviewed/duplicate
reviewed/fixed
reviewed/invalid
reviewed/not-a-bug
reviewed/wontfix
skip-changelog
stale
status/blocked
status/needs-feedback
status/wip
theme/2fa
theme/authentication
theme/avatar
theme/backup-restore
theme/docker
theme/federation
theme/issues
theme/kanban
theme/markdown
theme/migration
theme/mobile
theme/pr
theme/signing
theme/sqlite
theme/timetracker
theme/webhook
theme/wiki
No Milestone
No project
No Assignees
2 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: lunny/gitea#15870
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "rename_branch"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
on ui
@ -591,0 +592,4 @@
// RenamedBranch provide renamed branch log
// will check it when a branch can't be found
type RenamedBranch struct {
Need a condition
ID(repo.ID)
.@ -591,0 +613,4 @@
// RenameBranch rename a branch
func (repo *Repository) RenameBranch(from, to string, gitAction func(isDefault bool) error) (err error) {
sess := db.NewSession(db.DefaultContext)
can you add a time stamp?
can we move this into services so API could potentially use it too?
@ -591,0 +613,4 @@
// RenameBranch rename a branch
func (repo *Repository) RenameBranch(from, to string, gitAction func(isDefault bool) error) (err error) {
sess := db.NewSession(db.DefaultContext)
I don't think it's usefull...
@ -591,0 +613,4 @@
// RenameBranch rename a branch
func (repo *Repository) RenameBranch(from, to string, gitAction func(isDefault bool) error) (err error) {
sess := db.NewSession(db.DefaultContext)
I'm having some prune after time X for admins in mind ...
@ -591,0 +592,4 @@
// RenamedBranch provide renamed branch log
// will check it when a branch can't be found
type RenamedBranch struct {
sess.Close
will automaticallyRollback
if notCommit
, so we can safely remove these lines.I don't think we should put more and more fields in this struct, only those which could be used by all
{username}/{reponame}
routes should be stored on the struct. You can store them intoData
.@ -0,0 +17,4 @@
// get branch setting page
session := loginUser(t, "user2")
req := NewRequest(t, "GET", "/user2/repo1/settings/branches")
resp := session.MakeRequest(t, req, http.StatusOK)
That can be refactored once #16052 gets merged. Will then look like
if I understand the refactoring taken there correctly.
@ -0,0 +26,4 @@
"to": "main",
}
req = NewRequestWithValues(t, "POST", "/user2/repo1/settings/rename_branch", postData)
session.MakeRequest(t, req, http.StatusFound)
Will then be
@ -0,0 +30,4 @@
// check new branch link
req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/main/README.md", postData)
session.MakeRequest(t, req, http.StatusOK)
And this will be
@ -0,0 +34,4 @@
// check old branch link
req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/master/README.md", postData)
resp = session.MakeRequest(t, req, http.StatusFound)
And this will also be
@ -591,0 +626,4 @@
_, err = sess.ID(repo.ID).Cols("default_branch").Update(repo)
if err != nil {
return err
}
Am I seeing this wrong, or is it a bad idea to automatically apply branch protection to a "new" branch without testing if that branch should be protected?
Because in the current implementation, if I see this correctly, the following would lead to an inconsistent state:
m.*
main
is a protected branchmain
->default
.default
now has branch protection even though it shouldn't.Furthermore, if I see that correctly, the type of branch protection also needs to be switched then if this branch is covered by another rule.
@ -288,0 +296,4 @@
return
}
if ctx.HasError() {
I would like a
, ok
check here to ensure that the returned form isn't accidentally of another type.Because in that case, gitea would most likely panic here which I doubt is wanted.
@ -80,0 +83,4 @@
{{.i18n.Tr "repo.settings.rename_branch"}}
</h4>
<div class="ui attached segment">
<form class="ui form" action="{{$.Repository.Link}}/settings/rename_branch" method="post">
That is one approach.
I would have guessed that you choose a branch, then a dialog pops up where the base branch is already set, and then you enter the target branch name.
But this approach should also work, but might be a bit less user-friendly.
@ -288,0 +296,4 @@
return
}
if ctx.HasError() {
Don't worry,
middleware.Validate
will check form before this handle.@ -591,0 +626,4 @@
_, err = sess.ID(repo.ID).Cols("default_branch").Update(repo)
if err != nil {
return err
}
sadly, gitea don't have the feature to protect more than one branches by one rule.
each branch protect rule only applied to one brach. so when the branch was renamed.
the old config is not usefull, which should be binded to new branch or be removed, I think bind it
to new branch is better.
@ -591,0 +626,4 @@
_, err = sess.ID(repo.ID).Cols("default_branch").Update(repo)
if err != nil {
return err
}
Ah, thanks for the clarification. I did not need to set up branch protection on Gitea until now, I thought it was implemented just as in GitHub using a pattern for branches. Gitea's approach definitely has its advantages as well as its disadvantages.
In that case, I completely understand why you keep the branch protection. Makes total sense.
@ -612,6 +612,7 @@ func RegisterRoutes(m *web.Route) {
m.Combo("/*").Get(repo.SettingsProtectedBranch).
Post(bindIgnErr(forms.ProtectBranchForm{}), context.RepoMustNotBeArchived(), repo.SettingsProtectedBranchPost)
}, repo.MustBeNotEmpty)
m.Post("/rename_branch", bindIgnErr(forms.RenameBranchForm{}), context.RepoMustNotBeArchived(), repo.RenameBranchPost)
As far as I have seen, the underscore (
_
) syntax is uncommon for routes. What about/branches/rename
instead? That would then beCombined with a change inside the UI dialog.
@ -612,6 +612,7 @@ func RegisterRoutes(m *web.Route) {
m.Combo("/*").Get(repo.SettingsProtectedBranch).
Post(bindIgnErr(forms.ProtectBranchForm{}), context.RepoMustNotBeArchived(), repo.SettingsProtectedBranchPost)
}, repo.MustBeNotEmpty)
m.Post("/rename_branch", bindIgnErr(forms.RenameBranchForm{}), context.RepoMustNotBeArchived(), repo.RenameBranchPost)
well I dont mind since it's only a web route - if you like to group settings bit more refactor pulls are welcome :)