lib/gitlab_git/repository.rb in gitlab_git-10.1.4 vs lib/gitlab_git/repository.rb in gitlab_git-10.2.0

- old
+ new

@@ -108,9 +108,23 @@ # name - The name of the tag as a String. def tag_exists?(name) !!rugged.tags[name] end + # Returns true if the given branch exists + # + # name - The name of the branch as a String. + def branch_exists?(name) + rugged.branches.exists?(name) + + # If the branch name is invalid (e.g. ".foo") Rugged will raise an error. + # Whatever code calls this method shouldn't have to deal with that so + # instead we just return `false` (which is true since a branch doesn't + # exist when it has an invalid name). + rescue Rugged::ReferenceError + false + end + # Returns an Array of branch and tag names def ref_names branch_names + tag_names end