1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-21 08:43:08 +00:00

Lint models/repo_branch.go

This commit is contained in:
Bwko 2016-11-26 01:40:35 +01:00
parent 0a76d260fa
commit ce8c9ef580

View file

@ -8,11 +8,13 @@ import (
"code.gitea.io/git"
)
// Branch holds the branch information
type Branch struct {
Path string
Name string
}
// GetBranchesByPath returns a branch by it's path
func GetBranchesByPath(path string) ([]*Branch, error) {
gitRepo, err := git.OpenRepository(path)
if err != nil {
@ -34,24 +36,27 @@ func GetBranchesByPath(path string) ([]*Branch, error) {
return branches, nil
}
func (repo *Repository) GetBranch(br string) (*Branch, error) {
if !git.IsBranchExist(repo.RepoPath(), br) {
return nil, &ErrBranchNotExist{br}
// GetBranch returns a branch by it's name
func (repo *Repository) GetBranch(branch string) (*Branch, error) {
if !git.IsBranchExist(repo.RepoPath(), branch) {
return nil, &ErrBranchNotExist{branch}
}
return &Branch{
Path: repo.RepoPath(),
Name: br,
Name: branch,
}, nil
}
// GetBranches returns all the branches of a repository
func (repo *Repository) GetBranches() ([]*Branch, error) {
return GetBranchesByPath(repo.RepoPath())
}
func (br *Branch) GetCommit() (*git.Commit, error) {
gitRepo, err := git.OpenRepository(br.Path)
// GetCommit returns all the commits of a branch
func (branch *Branch) GetCommit() (*git.Commit, error) {
gitRepo, err := git.OpenRepository(branch.Path)
if err != nil {
return nil, err
}
return gitRepo.GetBranchCommit(br.Name)
return gitRepo.GetBranchCommit(branch.Name)
}