IsBranchExist: return false if provided name is empty (#8485) (#8492)

* IsBranchExist: return false if provided name is empty

* Ensure that the reference returned is actually of a valid type
This commit is contained in:
zeripath 2019-10-13 18:23:43 +01:00 committed by Lauris BH
parent d93d5d7906
commit 6cb9ce1367
1 changed files with 8 additions and 2 deletions

View File

@ -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.