diff --git a/app/models/repository.rb b/app/models/repository.rb index 1992f49bbbe39674f7d3e051fa02ead71aee7cf4..e9555628d642101d6cdbb51c112d7bd6fa3d3de7 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -238,16 +238,20 @@ def ambiguous_ref?(ref) def has_ambiguous_refs? return false unless branch_names.present? && tag_names.present? - with_slash, no_slash = (branch_names + tag_names).partition { |ref| ref.include?('/') } + with_slash = [] + no_slash = [] + (branch_names + tag_names).each do |ref| + slash_index = ref.index('/') + if slash_index.present? + with_slash << ref.first(slash_index) + else + no_slash << ref + end + end return false if with_slash.empty? - prefixes = no_slash.map { |ref| Regexp.escape(ref) }.join('|') - prefix_regex = %r{^(#{prefixes})/} - - with_slash.any? do |ref| - prefix_regex.match?(ref) - end + with_slash.intersect?(no_slash) end cache_method :has_ambiguous_refs?