diff options
author | Lauris BH <lauris@nix.lv> | 2017-06-21 04:00:03 +0300 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-06-21 09:00:03 +0800 |
commit | 0a5dc640a12d1c0475052b73a721056b53460275 (patch) | |
tree | 0296d1ac30ae82269eed06daed3eb1d9bc468c2d /routers/repo/branch.go | |
parent | 6db387a21e245dc4aa7f009ca60574e42d934ffb (diff) | |
download | gitea-0a5dc640a12d1c0475052b73a721056b53460275.tar.gz gitea-0a5dc640a12d1c0475052b73a721056b53460275.zip |
Make branch deletion URL more like GitHub's, fixes #1397 (#1994)
* Make branch deletion URL more like GitHub's, fixes #1397
* Add PR branch deletion integration test
* Do not allow deleting protected branch
* Change http error code to 403 if user has no write rights to repository
* Add check to not panic if forked repository has alrady been deleted
Diffstat (limited to 'routers/repo/branch.go')
-rw-r--r-- | routers/repo/branch.go | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/routers/repo/branch.go b/routers/repo/branch.go index d040f2a560..fcb6efd010 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -5,11 +5,8 @@ package repo import ( - "code.gitea.io/git" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" - "code.gitea.io/gitea/modules/log" ) const ( @@ -33,59 +30,3 @@ func Branches(ctx *context.Context) { ctx.Data["Branches"] = brs ctx.HTML(200, tplBranch) } - -// DeleteBranchPost responses for delete merged branch -func DeleteBranchPost(ctx *context.Context) { - branchName := ctx.Params(":name") - commitID := ctx.Query("commit") - - defer func() { - redirectTo := ctx.Query("redirect_to") - if len(redirectTo) == 0 { - redirectTo = ctx.Repo.RepoLink - } - - ctx.JSON(200, map[string]interface{}{ - "redirect": redirectTo, - }) - }() - - fullBranchName := ctx.Repo.Owner.Name + "/" + branchName - - if !ctx.Repo.GitRepo.IsBranchExist(branchName) || branchName == "master" { - ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName)) - return - } - - if len(commitID) > 0 { - branchCommitID, err := ctx.Repo.GitRepo.GetBranchCommitID(branchName) - if err != nil { - log.Error(4, "GetBranchCommitID: %v", err) - return - } - - if branchCommitID != commitID { - ctx.Flash.Error(ctx.Tr("repo.branch.delete_branch_has_new_commits", fullBranchName)) - return - } - } - - if err := ctx.Repo.GitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{ - Force: true, - }); err != nil { - log.Error(4, "DeleteBranch: %v", err) - ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName)) - return - } - - issueID := ctx.QueryInt64("issue_id") - if issueID > 0 { - if err := models.AddDeletePRBranchComment(ctx.User, ctx.Repo.Repository, issueID, branchName); err != nil { - log.Error(4, "DeleteBranch: %v", err) - ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName)) - return - } - } - - ctx.Flash.Success(ctx.Tr("repo.branch.deletion_success", fullBranchName)) -} |