2017-09-14 03:16:22 -05:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-09-14 03:16:22 -05:00
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-04-05 10:30:52 -05:00
|
|
|
"net/http"
|
2017-09-14 03:16:22 -05:00
|
|
|
"strings"
|
2019-09-18 00:39:45 -05:00
|
|
|
"time"
|
2017-09-14 03:16:22 -05:00
|
|
|
|
2022-06-12 10:51:54 -05:00
|
|
|
git_model "code.gitea.io/gitea/models/git"
|
2022-03-29 01:29:02 -05:00
|
|
|
"code.gitea.io/gitea/models/organization"
|
2021-11-28 06:58:28 -05:00
|
|
|
"code.gitea.io/gitea/models/perm"
|
2022-05-11 05:09:36 -05:00
|
|
|
access_model "code.gitea.io/gitea/models/perm/access"
|
2021-12-09 20:27:50 -05:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2017-09-14 03:16:22 -05:00
|
|
|
"code.gitea.io/gitea/modules/base"
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
2019-03-27 04:33:00 -05:00
|
|
|
"code.gitea.io/gitea/modules/git"
|
2017-09-14 03:16:22 -05:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2021-01-26 10:36:53 -05:00
|
|
|
"code.gitea.io/gitea/modules/web"
|
2021-04-06 14:44:05 -05:00
|
|
|
"code.gitea.io/gitea/services/forms"
|
2020-10-13 13:50:57 -05:00
|
|
|
pull_service "code.gitea.io/gitea/services/pull"
|
2021-10-08 12:03:04 -05:00
|
|
|
"code.gitea.io/gitea/services/repository"
|
2017-09-14 03:16:22 -05:00
|
|
|
)
|
|
|
|
|
2023-01-16 03:00:22 -05:00
|
|
|
const (
|
|
|
|
tplProtectedBranch base.TplName = "repo/settings/protected_branch"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ProtectedBranchRules render the page to protect the repository
|
|
|
|
func ProtectedBranchRules(ctx *context.Context) {
|
2023-02-01 17:56:10 -05:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings.branches")
|
2017-09-14 03:16:22 -05:00
|
|
|
ctx.Data["PageIsSettingsBranches"] = true
|
|
|
|
|
2023-01-16 03:00:22 -05:00
|
|
|
rules, err := git_model.FindRepoProtectedBranchRules(ctx, ctx.Repo.Repository.ID)
|
2017-09-14 03:16:22 -05:00
|
|
|
if err != nil {
|
2018-01-10 16:34:17 -05:00
|
|
|
ctx.ServerError("GetProtectedBranches", err)
|
2017-09-14 03:16:22 -05:00
|
|
|
return
|
|
|
|
}
|
2023-01-16 03:00:22 -05:00
|
|
|
ctx.Data["ProtectedBranches"] = rules
|
2017-09-14 03:16:22 -05:00
|
|
|
|
2021-04-05 10:30:52 -05:00
|
|
|
ctx.HTML(http.StatusOK, tplBranches)
|
2017-09-14 03:16:22 -05:00
|
|
|
}
|
|
|
|
|
2023-01-16 03:00:22 -05:00
|
|
|
// SetDefaultBranchPost set default branch
|
|
|
|
func SetDefaultBranchPost(ctx *context.Context) {
|
2023-02-01 17:56:10 -05:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings.branches.update_default_branch")
|
2017-09-14 03:16:22 -05:00
|
|
|
ctx.Data["PageIsSettingsBranches"] = true
|
|
|
|
|
|
|
|
repo := ctx.Repo.Repository
|
|
|
|
|
2021-08-10 19:31:13 -05:00
|
|
|
switch ctx.FormString("action") {
|
2017-09-14 03:16:22 -05:00
|
|
|
case "default_branch":
|
|
|
|
if ctx.HasError() {
|
2021-04-05 10:30:52 -05:00
|
|
|
ctx.HTML(http.StatusOK, tplBranches)
|
2017-09-14 03:16:22 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-08-10 19:31:13 -05:00
|
|
|
branch := ctx.FormString("branch")
|
2017-09-14 03:16:22 -05:00
|
|
|
if !ctx.Repo.GitRepo.IsBranchExist(branch) {
|
2022-03-22 23:54:07 -05:00
|
|
|
ctx.Status(http.StatusNotFound)
|
2017-09-14 03:16:22 -05:00
|
|
|
return
|
|
|
|
} else if repo.DefaultBranch != branch {
|
|
|
|
repo.DefaultBranch = branch
|
|
|
|
if err := ctx.Repo.GitRepo.SetDefaultBranch(branch); err != nil {
|
|
|
|
if !git.IsErrUnsupportedVersion(err) {
|
2018-01-10 16:34:17 -05:00
|
|
|
ctx.ServerError("SetDefaultBranch", err)
|
2017-09-14 03:16:22 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-12-09 20:27:50 -05:00
|
|
|
if err := repo_model.UpdateDefaultBranch(repo); err != nil {
|
2018-01-10 16:34:17 -05:00
|
|
|
ctx.ServerError("SetDefaultBranch", err)
|
2017-09-14 03:16:22 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Trace("Repository basic settings updated: %s/%s", ctx.Repo.Owner.Name, repo.Name)
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success"))
|
2021-11-16 13:18:25 -05:00
|
|
|
ctx.Redirect(setting.AppSubURL + ctx.Req.URL.EscapedPath())
|
2017-09-14 03:16:22 -05:00
|
|
|
default:
|
2018-01-10 16:34:17 -05:00
|
|
|
ctx.NotFound("", nil)
|
2017-09-14 03:16:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SettingsProtectedBranch renders the protected branch setting page
|
|
|
|
func SettingsProtectedBranch(c *context.Context) {
|
2023-01-16 03:00:22 -05:00
|
|
|
ruleName := c.FormString("rule_name")
|
|
|
|
var rule *git_model.ProtectedBranch
|
|
|
|
if ruleName != "" {
|
|
|
|
var err error
|
|
|
|
rule, err = git_model.GetProtectedBranchRuleByName(c, c.Repo.Repository.ID, ruleName)
|
|
|
|
if err != nil {
|
2018-01-10 16:34:17 -05:00
|
|
|
c.ServerError("GetProtectBranchOfRepoByName", err)
|
2017-09-14 03:16:22 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-16 03:00:22 -05:00
|
|
|
if rule == nil {
|
2017-09-14 03:16:22 -05:00
|
|
|
// No options found, create defaults.
|
2023-01-16 03:00:22 -05:00
|
|
|
rule = &git_model.ProtectedBranch{}
|
2017-09-14 03:16:22 -05:00
|
|
|
}
|
|
|
|
|
2023-01-16 03:00:22 -05:00
|
|
|
c.Data["PageIsSettingsBranches"] = true
|
|
|
|
c.Data["Title"] = c.Tr("repo.settings.protected_branch") + " - " + rule.RuleName
|
|
|
|
|
2022-05-11 05:09:36 -05:00
|
|
|
users, err := access_model.GetRepoReaders(c.Repo.Repository)
|
2017-09-14 03:16:22 -05:00
|
|
|
if err != nil {
|
2019-10-08 14:18:17 -05:00
|
|
|
c.ServerError("Repo.Repository.GetReaders", err)
|
2017-09-14 03:16:22 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
c.Data["Users"] = users
|
2023-01-16 03:00:22 -05:00
|
|
|
c.Data["whitelist_users"] = strings.Join(base.Int64sToStrings(rule.WhitelistUserIDs), ",")
|
|
|
|
c.Data["merge_whitelist_users"] = strings.Join(base.Int64sToStrings(rule.MergeWhitelistUserIDs), ",")
|
|
|
|
c.Data["approvals_whitelist_users"] = strings.Join(base.Int64sToStrings(rule.ApprovalsWhitelistUserIDs), ",")
|
2023-01-08 22:50:54 -05:00
|
|
|
contexts, _ := git_model.FindRepoRecentCommitStatusContexts(c, c.Repo.Repository.ID, 7*24*time.Hour) // Find last week status check contexts
|
2023-01-16 03:00:22 -05:00
|
|
|
for _, ctx := range rule.StatusCheckContexts {
|
2019-09-18 00:39:45 -05:00
|
|
|
var found bool
|
2021-04-09 02:40:34 -05:00
|
|
|
for i := range contexts {
|
|
|
|
if contexts[i] == ctx {
|
2019-09-18 00:39:45 -05:00
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
2021-04-09 02:40:34 -05:00
|
|
|
contexts = append(contexts, ctx)
|
2019-09-18 00:39:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Data["branch_status_check_contexts"] = contexts
|
|
|
|
c.Data["is_context_required"] = func(context string) bool {
|
2023-01-16 03:00:22 -05:00
|
|
|
for _, c := range rule.StatusCheckContexts {
|
2019-09-18 00:39:45 -05:00
|
|
|
if c == context {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2017-09-14 03:16:22 -05:00
|
|
|
|
|
|
|
if c.Repo.Owner.IsOrganization() {
|
2022-03-29 01:29:02 -05:00
|
|
|
teams, err := organization.OrgFromUser(c.Repo.Owner).TeamsWithAccessToRepo(c.Repo.Repository.ID, perm.AccessModeRead)
|
2017-09-14 03:16:22 -05:00
|
|
|
if err != nil {
|
2018-01-10 16:34:17 -05:00
|
|
|
c.ServerError("Repo.Owner.TeamsWithAccessToRepo", err)
|
2017-09-14 03:16:22 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
c.Data["Teams"] = teams
|
2023-01-16 03:00:22 -05:00
|
|
|
c.Data["whitelist_teams"] = strings.Join(base.Int64sToStrings(rule.WhitelistTeamIDs), ",")
|
|
|
|
c.Data["merge_whitelist_teams"] = strings.Join(base.Int64sToStrings(rule.MergeWhitelistTeamIDs), ",")
|
|
|
|
c.Data["approvals_whitelist_teams"] = strings.Join(base.Int64sToStrings(rule.ApprovalsWhitelistTeamIDs), ",")
|
2017-09-14 03:16:22 -05:00
|
|
|
}
|
|
|
|
|
2023-01-16 03:00:22 -05:00
|
|
|
c.Data["Rule"] = rule
|
2021-04-05 10:30:52 -05:00
|
|
|
c.HTML(http.StatusOK, tplProtectedBranch)
|
2017-09-14 03:16:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// SettingsProtectedBranchPost updates the protected branch settings
|
2021-01-26 10:36:53 -05:00
|
|
|
func SettingsProtectedBranchPost(ctx *context.Context) {
|
2021-04-06 14:44:05 -05:00
|
|
|
f := web.GetForm(ctx).(*forms.ProtectBranchForm)
|
2023-01-16 03:00:22 -05:00
|
|
|
var protectBranch *git_model.ProtectedBranch
|
|
|
|
if f.RuleName == "" {
|
|
|
|
ctx.Flash.Error(ctx.Tr("repo.settings.protected_branch_required_rule_name"))
|
|
|
|
ctx.Redirect(fmt.Sprintf("%s/settings/branches/edit", ctx.Repo.RepoLink))
|
2017-09-14 03:16:22 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-01-16 03:00:22 -05:00
|
|
|
var err error
|
|
|
|
protectBranch, err = git_model.GetProtectedBranchRuleByName(ctx, ctx.Repo.Repository.ID, f.RuleName)
|
2017-09-14 03:16:22 -05:00
|
|
|
if err != nil {
|
2023-01-16 03:00:22 -05:00
|
|
|
ctx.ServerError("GetProtectBranchOfRepoByName", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if protectBranch == nil {
|
|
|
|
// No options found, create defaults.
|
|
|
|
protectBranch = &git_model.ProtectedBranch{
|
|
|
|
RepoID: ctx.Repo.Repository.ID,
|
|
|
|
RuleName: f.RuleName,
|
2017-09-14 03:16:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-16 03:00:22 -05:00
|
|
|
var whitelistUsers, whitelistTeams, mergeWhitelistUsers, mergeWhitelistTeams, approvalsWhitelistUsers, approvalsWhitelistTeams []int64
|
|
|
|
protectBranch.RuleName = f.RuleName
|
|
|
|
if f.RequiredApprovals < 0 {
|
|
|
|
ctx.Flash.Error(ctx.Tr("repo.settings.protected_branch_required_approvals_min"))
|
|
|
|
ctx.Redirect(fmt.Sprintf("%s/settings/branches/edit?rule_name=%s", ctx.Repo.RepoLink, f.RuleName))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch f.EnablePush {
|
|
|
|
case "all":
|
|
|
|
protectBranch.CanPush = true
|
|
|
|
protectBranch.EnableWhitelist = false
|
|
|
|
protectBranch.WhitelistDeployKeys = false
|
|
|
|
case "whitelist":
|
|
|
|
protectBranch.CanPush = true
|
|
|
|
protectBranch.EnableWhitelist = true
|
|
|
|
protectBranch.WhitelistDeployKeys = f.WhitelistDeployKeys
|
|
|
|
if strings.TrimSpace(f.WhitelistUsers) != "" {
|
|
|
|
whitelistUsers, _ = base.StringsToInt64s(strings.Split(f.WhitelistUsers, ","))
|
2017-09-14 03:16:22 -05:00
|
|
|
}
|
2023-01-16 03:00:22 -05:00
|
|
|
if strings.TrimSpace(f.WhitelistTeams) != "" {
|
|
|
|
whitelistTeams, _ = base.StringsToInt64s(strings.Split(f.WhitelistTeams, ","))
|
2018-12-11 06:28:37 -05:00
|
|
|
}
|
2023-01-16 03:00:22 -05:00
|
|
|
default:
|
|
|
|
protectBranch.CanPush = false
|
|
|
|
protectBranch.EnableWhitelist = false
|
|
|
|
protectBranch.WhitelistDeployKeys = false
|
|
|
|
}
|
2017-09-14 03:16:22 -05:00
|
|
|
|
2023-01-16 03:00:22 -05:00
|
|
|
protectBranch.EnableMergeWhitelist = f.EnableMergeWhitelist
|
|
|
|
if f.EnableMergeWhitelist {
|
|
|
|
if strings.TrimSpace(f.MergeWhitelistUsers) != "" {
|
|
|
|
mergeWhitelistUsers, _ = base.StringsToInt64s(strings.Split(f.MergeWhitelistUsers, ","))
|
2018-11-28 06:26:14 -05:00
|
|
|
}
|
2023-01-16 03:00:22 -05:00
|
|
|
if strings.TrimSpace(f.MergeWhitelistTeams) != "" {
|
|
|
|
mergeWhitelistTeams, _ = base.StringsToInt64s(strings.Split(f.MergeWhitelistTeams, ","))
|
2018-11-28 06:26:14 -05:00
|
|
|
}
|
2023-01-16 03:00:22 -05:00
|
|
|
}
|
2019-09-18 00:39:45 -05:00
|
|
|
|
2023-01-16 03:00:22 -05:00
|
|
|
protectBranch.EnableStatusCheck = f.EnableStatusCheck
|
|
|
|
if f.EnableStatusCheck {
|
|
|
|
protectBranch.StatusCheckContexts = f.StatusCheckContexts
|
|
|
|
} else {
|
|
|
|
protectBranch.StatusCheckContexts = nil
|
|
|
|
}
|
2019-09-18 00:39:45 -05:00
|
|
|
|
2023-01-16 03:00:22 -05:00
|
|
|
protectBranch.RequiredApprovals = f.RequiredApprovals
|
|
|
|
protectBranch.EnableApprovalsWhitelist = f.EnableApprovalsWhitelist
|
|
|
|
if f.EnableApprovalsWhitelist {
|
|
|
|
if strings.TrimSpace(f.ApprovalsWhitelistUsers) != "" {
|
|
|
|
approvalsWhitelistUsers, _ = base.StringsToInt64s(strings.Split(f.ApprovalsWhitelistUsers, ","))
|
2018-12-11 06:28:37 -05:00
|
|
|
}
|
2023-01-16 03:00:22 -05:00
|
|
|
if strings.TrimSpace(f.ApprovalsWhitelistTeams) != "" {
|
|
|
|
approvalsWhitelistTeams, _ = base.StringsToInt64s(strings.Split(f.ApprovalsWhitelistTeams, ","))
|
2017-09-14 03:16:22 -05:00
|
|
|
}
|
2023-01-16 03:00:22 -05:00
|
|
|
}
|
|
|
|
protectBranch.BlockOnRejectedReviews = f.BlockOnRejectedReviews
|
|
|
|
protectBranch.BlockOnOfficialReviewRequests = f.BlockOnOfficialReviewRequests
|
|
|
|
protectBranch.DismissStaleApprovals = f.DismissStaleApprovals
|
|
|
|
protectBranch.RequireSignedCommits = f.RequireSignedCommits
|
|
|
|
protectBranch.ProtectedFilePatterns = f.ProtectedFilePatterns
|
|
|
|
protectBranch.UnprotectedFilePatterns = f.UnprotectedFilePatterns
|
|
|
|
protectBranch.BlockOnOutdatedBranch = f.BlockOnOutdatedBranch
|
|
|
|
|
|
|
|
err = git_model.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{
|
|
|
|
UserIDs: whitelistUsers,
|
|
|
|
TeamIDs: whitelistTeams,
|
|
|
|
MergeUserIDs: mergeWhitelistUsers,
|
|
|
|
MergeTeamIDs: mergeWhitelistTeams,
|
|
|
|
ApprovalsUserIDs: approvalsWhitelistUsers,
|
|
|
|
ApprovalsTeamIDs: approvalsWhitelistTeams,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("UpdateProtectBranch", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: since we only need to recheck files protected rules, we could improve this
|
|
|
|
matchedBranches, err := git_model.FindAllMatchedBranches(ctx, ctx.Repo.GitRepo, protectBranch.RuleName)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("FindAllMatchedBranches", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, branchName := range matchedBranches {
|
|
|
|
if err = pull_service.CheckPRsForBaseBranch(ctx.Repo.Repository, branchName); err != nil {
|
|
|
|
ctx.ServerError("CheckPRsForBaseBranch", err)
|
2020-10-13 13:50:57 -05:00
|
|
|
return
|
|
|
|
}
|
2017-09-14 03:16:22 -05:00
|
|
|
}
|
2023-01-16 03:00:22 -05:00
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.update_protect_branch_success", protectBranch.RuleName))
|
|
|
|
ctx.Redirect(fmt.Sprintf("%s/settings/branches?rule_name=%s", ctx.Repo.RepoLink, protectBranch.RuleName))
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteProtectedBranchRulePost delete protected branch rule by id
|
|
|
|
func DeleteProtectedBranchRulePost(ctx *context.Context) {
|
|
|
|
ruleID := ctx.ParamsInt64("id")
|
|
|
|
if ruleID <= 0 {
|
|
|
|
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID)))
|
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
|
|
|
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
rule, err := git_model.GetProtectedBranchRuleByID(ctx, ctx.Repo.Repository.ID, ruleID)
|
|
|
|
if err != nil {
|
|
|
|
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID)))
|
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
|
|
|
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if rule == nil {
|
|
|
|
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", fmt.Sprintf("%d", ruleID)))
|
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
|
|
|
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := git_model.DeleteProtectedBranch(ctx, ctx.Repo.Repository.ID, ruleID); err != nil {
|
|
|
|
ctx.Flash.Error(ctx.Tr("repo.settings.remove_protected_branch_failed", rule.RuleName))
|
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
|
|
|
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.remove_protected_branch_success", rule.RuleName))
|
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
|
|
|
"redirect": fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink),
|
|
|
|
})
|
2017-09-14 03:16:22 -05:00
|
|
|
}
|
2021-10-08 12:03:04 -05:00
|
|
|
|
|
|
|
// RenameBranchPost responses for rename a branch
|
|
|
|
func RenameBranchPost(ctx *context.Context) {
|
|
|
|
form := web.GetForm(ctx).(*forms.RenameBranchForm)
|
|
|
|
|
|
|
|
if !ctx.Repo.CanCreateBranch() {
|
|
|
|
ctx.NotFound("RenameBranch", nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.HasError() {
|
|
|
|
ctx.Flash.Error(ctx.GetErrMsg())
|
|
|
|
ctx.Redirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-22 02:03:22 -05:00
|
|
|
msg, err := repository.RenameBranch(ctx.Repo.Repository, ctx.Doer, ctx.Repo.GitRepo, form.From, form.To)
|
2021-10-08 12:03:04 -05:00
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("RenameBranch", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg == "target_exist" {
|
|
|
|
ctx.Flash.Error(ctx.Tr("repo.settings.rename_branch_failed_exist", form.To))
|
|
|
|
ctx.Redirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg == "from_not_exist" {
|
|
|
|
ctx.Flash.Error(ctx.Tr("repo.settings.rename_branch_failed_not_exist", form.From))
|
|
|
|
ctx.Redirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.rename_branch_success", form.From, form.To))
|
|
|
|
ctx.Redirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink))
|
|
|
|
}
|