diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/error.go | 15 | ||||
-rw-r--r-- | models/pull.go | 5 | ||||
-rw-r--r-- | models/repo_branch.go | 57 |
3 files changed, 13 insertions, 64 deletions
diff --git a/models/error.go b/models/error.go index 3dd2c79e85..6458594a03 100644 --- a/models/error.go +++ b/models/error.go @@ -874,21 +874,6 @@ func (err ErrUserDoesNotHaveAccessToRepo) Error() string { // |______ / |__| (____ /___| /\___ >___| / // \/ \/ \/ \/ \/ -// ErrBranchNotExist represents a "BranchNotExist" kind of error. -type ErrBranchNotExist struct { - Name string -} - -// IsErrBranchNotExist checks if an error is a ErrBranchNotExist. -func IsErrBranchNotExist(err error) bool { - _, ok := err.(ErrBranchNotExist) - return ok -} - -func (err ErrBranchNotExist) Error() string { - return fmt.Sprintf("branch does not exist [name: %s]", err.Name) -} - // ErrBranchAlreadyExists represents an error that branch with such name already exists. type ErrBranchAlreadyExists struct { BranchName string diff --git a/models/pull.go b/models/pull.go index 88f9b1f6e8..d059081a44 100644 --- a/models/pull.go +++ b/models/pull.go @@ -1,4 +1,5 @@ // Copyright 2015 The Gogs Authors. All rights reserved. +// Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -165,8 +166,8 @@ func (pr *PullRequest) APIFormat() *api.PullRequest { func (pr *PullRequest) apiFormat(e Engine) *api.PullRequest { var ( - baseBranch *Branch - headBranch *Branch + baseBranch *git.Branch + headBranch *git.Branch baseCommit *git.Commit headCommit *git.Commit err error diff --git a/models/repo_branch.go b/models/repo_branch.go index 1c62a3d67d..0958e23974 100644 --- a/models/repo_branch.go +++ b/models/repo_branch.go @@ -1,4 +1,5 @@ // Copyright 2016 The Gogs Authors. All rights reserved. +// Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -86,53 +87,24 @@ func (repo *Repository) DeleteLocalBranch(branchName string) error { return deleteLocalBranch(repo.LocalCopyPath(), repo.DefaultBranch, branchName) } -// 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 { - return nil, err - } - - brs, err := gitRepo.GetBranches() - if err != nil { - return nil, err - } - - branches := make([]*Branch, len(brs)) - for i := range brs { - branches[i] = &Branch{ - Path: path, - Name: brs[i], - } - } - return branches, nil -} - // CanCreateBranch returns true if repository meets the requirements for creating new branches. func (repo *Repository) CanCreateBranch() bool { return !repo.IsMirror } -// 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} +// GetBranch returns a branch by its name +func (repo *Repository) GetBranch(branch string) (*git.Branch, error) { + gitRepo, err := git.OpenRepository(repo.RepoPath()) + if err != nil { + return nil, err } - return &Branch{ - Path: repo.RepoPath(), - Name: branch, - }, nil + + return gitRepo.GetBranch(branch) } // GetBranches returns all the branches of a repository -func (repo *Repository) GetBranches() ([]*Branch, error) { - return GetBranchesByPath(repo.RepoPath()) +func (repo *Repository) GetBranches() ([]*git.Branch, error) { + return git.GetBranchesByPath(repo.RepoPath()) } // CheckBranchName validates branch name with existing repository branches @@ -257,12 +229,3 @@ func (repo *Repository) CreateNewBranchFromCommit(doer *User, commit, branchName return nil } - -// 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(branch.Name) -} |