branch.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "github.com/gogits/git-module"
  7. "github.com/gogits/gogs/modules/base"
  8. "github.com/gogits/gogs/modules/context"
  9. )
  10. const (
  11. BRANCH base.TplName = "repo/branch"
  12. )
  13. func Branches(ctx *context.Context) {
  14. ctx.Data["Title"] = "Branches"
  15. ctx.Data["IsRepoToolbarBranches"] = true
  16. brs, err := ctx.Repo.GitRepo.GetBranches()
  17. if err != nil {
  18. ctx.Handle(500, "repo.Branches(GetBranches)", err)
  19. return
  20. } else if len(brs) == 0 {
  21. ctx.Handle(404, "repo.Branches(GetBranches)", nil)
  22. return
  23. }
  24. ctx.Data["Branches"] = brs
  25. ctx.HTML(200, BRANCH)
  26. }
  27. func DeleteBranchPost(ctx *context.Context) {
  28. branchName := ctx.Params(":name")
  29. if err := ctx.Repo.GitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
  30. Force: false,
  31. }); err != nil {
  32. ctx.Handle(500, "DeleteBranch", err)
  33. return
  34. }
  35. redirectTo := ctx.Query("redirect_to")
  36. if len(redirectTo) == 0 {
  37. redirectTo = ctx.Repo.RepoLink
  38. }
  39. ctx.Redirect(redirectTo)
  40. }