aboutsummaryrefslogtreecommitdiff
path: root/routers/repo/branch.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-12-21 00:49:44 -0500
committerUnknwon <u@gogs.io>2016-12-21 00:49:44 -0500
commit44ed991726fa9290088c1ba6ed48f18d34116536 (patch)
tree663e43976a83e5215faca312d2c053bc5d0d1e32 /routers/repo/branch.go
parent34b92cdb440e175884b45df7197a65b086ff0eac (diff)
parent73fedc727538381d4e1048ee03be6b45e977a076 (diff)
Merge branch 'develop' of https://github.com/tanapoln/gogs into develop
Diffstat (limited to 'routers/repo/branch.go')
1 files changed, 39 insertions, 0 deletions
diff --git a/routers/repo/branch.go b/routers/repo/branch.go
index 00f30b0f..97bfbc26 100644
--- a/routers/repo/branch.go
+++ b/routers/repo/branch.go
@@ -5,8 +5,11 @@
package repo
import (
+ "github.com/gogits/git-module"
+
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
+ "github.com/gogits/gogs/modules/log"
)
const (
@@ -29,3 +32,39 @@ func Branches(ctx *context.Context) {
ctx.Data["Branches"] = brs
ctx.HTML(200, 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.Redirect(redirectTo)
+ }()
+
+ if !ctx.Repo.GitRepo.IsBranchExist(branchName) {
+ 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.pulls.delete_branch_has_new_commits"))
+ return
+ }
+ }
+
+ if err := ctx.Repo.GitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
+ Force: false,
+ }); err != nil {
+ log.Error(4, "DeleteBranch: %v", err)
+ return
+ }
+}