From 18d0d6d2a3e06d857c080f6052590caaa115cc7d Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 13 Oct 2019 17:29:08 +0100 Subject: [PATCH] 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 --- modules/git/repo_branch.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/git/repo_branch.go b/modules/git/repo_branch.go index 3e1261d294cf8..a2bf9ac973e49 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.