mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-09-07 07:03:21 +00:00
Merge pull request #268 from Bwko/lint/repo_branch
Lint models/repo_branch.go
This commit is contained in:
commit
fe3908d099
1 changed files with 12 additions and 7 deletions
|
@ -8,11 +8,13 @@ import (
|
||||||
"code.gitea.io/git"
|
"code.gitea.io/git"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Branch holds the branch information
|
||||||
type Branch struct {
|
type Branch struct {
|
||||||
Path string
|
Path string
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBranchesByPath returns a branch by it's path
|
||||||
func GetBranchesByPath(path string) ([]*Branch, error) {
|
func GetBranchesByPath(path string) ([]*Branch, error) {
|
||||||
gitRepo, err := git.OpenRepository(path)
|
gitRepo, err := git.OpenRepository(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -34,24 +36,27 @@ func GetBranchesByPath(path string) ([]*Branch, error) {
|
||||||
return branches, nil
|
return branches, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repository) GetBranch(br string) (*Branch, error) {
|
// GetBranch returns a branch by it's name
|
||||||
if !git.IsBranchExist(repo.RepoPath(), br) {
|
func (repo *Repository) GetBranch(branch string) (*Branch, error) {
|
||||||
return nil, &ErrBranchNotExist{br}
|
if !git.IsBranchExist(repo.RepoPath(), branch) {
|
||||||
|
return nil, &ErrBranchNotExist{branch}
|
||||||
}
|
}
|
||||||
return &Branch{
|
return &Branch{
|
||||||
Path: repo.RepoPath(),
|
Path: repo.RepoPath(),
|
||||||
Name: br,
|
Name: branch,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBranches returns all the branches of a repository
|
||||||
func (repo *Repository) GetBranches() ([]*Branch, error) {
|
func (repo *Repository) GetBranches() ([]*Branch, error) {
|
||||||
return GetBranchesByPath(repo.RepoPath())
|
return GetBranchesByPath(repo.RepoPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br *Branch) GetCommit() (*git.Commit, error) {
|
// GetCommit returns all the commits of a branch
|
||||||
gitRepo, err := git.OpenRepository(br.Path)
|
func (branch *Branch) GetCommit() (*git.Commit, error) {
|
||||||
|
gitRepo, err := git.OpenRepository(branch.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return gitRepo.GetBranchCommit(br.Name)
|
return gitRepo.GetBranchCommit(branch.Name)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue