Skip to content

Commit

Permalink
IsBranchExist: return false if provided name is empty (go-gitea#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 committed Oct 13, 2019
1 parent d93d5d7 commit 18d0d6d
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 18d0d6d

Please sign in to comment.