浏览代码

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
tags/v1.10.0-rc1
zeripath 4 年前
父节点
当前提交
c888ebfba7
共有 1 个文件被更改,包括 8 次插入2 次删除
  1. 8
    2
      modules/git/repo_branch.go

+ 8
- 2
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.

正在加载...
取消
保存