repo_branch.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright 2016 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 models
  5. import (
  6. "fmt"
  7. "github.com/gogits/git-module"
  8. )
  9. type Branch struct {
  10. Path string
  11. Name string
  12. }
  13. func GetBranchesByPath(path string) ([]*Branch, error) {
  14. gitRepo, err := git.OpenRepository(path)
  15. if err != nil {
  16. return nil, err
  17. }
  18. brs, err := gitRepo.GetBranches()
  19. if err != nil {
  20. return nil, err
  21. }
  22. branches := make([]*Branch, len(brs))
  23. for i := range brs {
  24. branches[i] = &Branch{
  25. Path: path,
  26. Name: brs[i],
  27. }
  28. }
  29. return branches, nil
  30. }
  31. func (repo *Repository) GetBranch(br string) (*Branch, error) {
  32. if !git.IsBranchExist(repo.RepoPath(), br) {
  33. return nil, ErrBranchNotExist{br}
  34. }
  35. return &Branch{
  36. Path: repo.RepoPath(),
  37. Name: br,
  38. }, nil
  39. }
  40. func (repo *Repository) GetBranches() ([]*Branch, error) {
  41. return GetBranchesByPath(repo.RepoPath())
  42. }
  43. func (br *Branch) GetCommit() (*git.Commit, error) {
  44. gitRepo, err := git.OpenRepository(br.Path)
  45. if err != nil {
  46. return nil, err
  47. }
  48. return gitRepo.GetBranchCommit(br.Name)
  49. }
  50. // ProtectBranch contains options of a protected branch.
  51. type ProtectBranch struct {
  52. ID int64
  53. RepoID int64 `xorm:"UNIQUE(protect_branch)"`
  54. Name string `xorm:"UNIQUE(protect_branch)"`
  55. Protected bool
  56. RequirePullRequest bool
  57. }
  58. // GetProtectBranchOfRepoByName returns *ProtectBranch by branch name in given repostiory.
  59. func GetProtectBranchOfRepoByName(repoID int64, name string) (*ProtectBranch, error) {
  60. protectBranch := &ProtectBranch{
  61. RepoID: repoID,
  62. Name: name,
  63. }
  64. has, err := x.Get(protectBranch)
  65. if err != nil {
  66. return nil, err
  67. } else if !has {
  68. return nil, ErrBranchNotExist{name}
  69. }
  70. return protectBranch, nil
  71. }
  72. // IsBranchOfRepoRequirePullRequest returns true if branch requires pull request in given repository.
  73. func IsBranchOfRepoRequirePullRequest(repoID int64, name string) bool {
  74. protectBranch, err := GetProtectBranchOfRepoByName(repoID, name)
  75. if err != nil {
  76. return false
  77. }
  78. return protectBranch.Protected && protectBranch.RequirePullRequest
  79. }
  80. // UpdateProtectBranch saves branch protection options.
  81. // If ID is 0, it creates a new record. Otherwise, updates existing record.
  82. func UpdateProtectBranch(protectBranch *ProtectBranch) (err error) {
  83. if protectBranch.ID == 0 {
  84. if _, err = x.Insert(protectBranch); err != nil {
  85. return fmt.Errorf("Insert: %v", err)
  86. }
  87. return
  88. }
  89. _, err = x.Id(protectBranch.ID).AllCols().Update(protectBranch)
  90. return err
  91. }
  92. // GetProtectBranchesByRepoID returns a list of *ProtectBranch in given repostiory.
  93. func GetProtectBranchesByRepoID(repoID int64) ([]*ProtectBranch, error) {
  94. protectBranches := make([]*ProtectBranch, 0, 2)
  95. return protectBranches, x.Where("repo_id = ?", repoID).Asc("name").Find(&protectBranches)
  96. }
PANIC: session(release): write data/sessions/4/0/405b9b86f2f1be79: no space left on device

PANIC

session(release): write data/sessions/4/0/405b9b86f2f1be79: no space left on device
github.com/go-macaron/session@v0.0.0-20190805070824-1a3cdc6f5659/session.go:199 (0x8b2934)
gopkg.in/macaron.v1@v1.3.9/context.go:79 (0x83d0a0)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/context.go:112 (0x84fdb5)
gopkg.in/macaron.v1@v1.3.9/recovery.go:161 (0x84fda8)
gopkg.in/macaron.v1@v1.3.9/logger.go:40 (0x840c73)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/router.go:187 (0x850fc6)
gopkg.in/macaron.v1@v1.3.9/router.go:303 (0x8493e5)
gopkg.in/macaron.v1@v1.3.9/macaron.go:220 (0x841fca)
net/http/server.go:2836 (0x7a79b2)
net/http/server.go:1924 (0x7a341b)
runtime/asm_amd64.s:1373 (0x46f9f0)