Skip to content

Commit

Permalink
IsBranchExist: return false if provided name is empty (#8485)
Browse files Browse the repository at this point in the history
* IsBranchExist: return false if provided name is empty

* Ensure that the reference returned is actually of a valid type
  • Loading branch information
zeripath authored and lafriks committed Oct 13, 2019
1 parent f858b89 commit c888ebf
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions modules/git/repo_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c888ebf

Please sign in to comment.