Skip to content

Commit 6cb9ce1

Browse files
zeripathlafriks
authored andcommitted
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
1 parent d93d5d7 commit 6cb9ce1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

modules/git/repo_branch.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ func IsBranchExist(repoPath, name string) bool {
2828

2929
// IsBranchExist returns true if given branch exists in current repository.
3030
func (repo *Repository) IsBranchExist(name string) bool {
31-
_, err := repo.gogitRepo.Reference(plumbing.ReferenceName(BranchPrefix+name), true)
32-
return err == nil
31+
if name == "" {
32+
return false
33+
}
34+
reference, err := repo.gogitRepo.Reference(plumbing.ReferenceName(BranchPrefix+name), true)
35+
if err != nil {
36+
return false
37+
}
38+
return reference.Type() != plumbing.InvalidReference
3339
}
3440

3541
// Branch represents a Git branch.

0 commit comments

Comments
 (0)