diff options
author | Thomas Boerger <thomas@webhippie.de> | 2016-11-27 12:14:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-27 12:14:25 +0100 |
commit | fe3908d099a10f4673a2cec35cb7bfc673c72269 (patch) | |
tree | 5e13d73f6b1192b095520afd39ba358a4e1d5b30 /models | |
parent | e23a9d22e5ea87d2141680501708ec03fda040f8 (diff) | |
parent | ce8c9ef58060c64894229d2f11aed98517e39fbf (diff) | |
download | gitea-fe3908d099a10f4673a2cec35cb7bfc673c72269.tar.gz gitea-fe3908d099a10f4673a2cec35cb7bfc673c72269.zip |
Merge pull request #268 from Bwko/lint/repo_branch
Lint models/repo_branch.go
Diffstat (limited to 'models')
-rw-r--r-- | models/repo_branch.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/models/repo_branch.go b/models/repo_branch.go index 075e590fdf..fcfd3e8ecb 100644 --- a/models/repo_branch.go +++ b/models/repo_branch.go @@ -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) } |