diff options
author | zeripath <art27@cantab.net> | 2019-10-13 17:29:08 +0100 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-10-13 19:29:08 +0300 |
commit | c888ebfba713b4d5be88c427a34d29153be52076 (patch) | |
tree | 4f1a73a65d48d525028505f7eab31259f17a171e /modules | |
parent | f858b89b130352265d59b5d46af626373796b74e (diff) | |
download | gitea-c888ebfba713b4d5be88c427a34d29153be52076.tar.gz gitea-c888ebfba713b4d5be88c427a34d29153be52076.zip |
IsBranchExist: return false if provided name is empty (#8485)
* IsBranchExist: return false if provided name is empty
* Ensure that the reference returned is actually of a valid type
Diffstat (limited to 'modules')
-rw-r--r-- | modules/git/repo_branch.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/modules/git/repo_branch.go b/modules/git/repo_branch.go index 3e1261d294..a2bf9ac973 100644 --- a/modules/git/repo_branch.go +++ b/modules/git/repo_branch.go @@ -28,8 +28,14 @@ func IsBranchExist(repoPath, name string) bool { // IsBranchExist returns true if given branch exists in current repository. func (repo *Repository) IsBranchExist(name string) bool { - _, err := repo.gogitRepo.Reference(plumbing.ReferenceName(BranchPrefix+name), true) - return err == nil + if name == "" { + return false + } + reference, err := repo.gogitRepo.Reference(plumbing.ReferenceName(BranchPrefix+name), true) + if err != nil { + return false + } + return reference.Type() != plumbing.InvalidReference } // Branch represents a Git branch. |