debian-mirror-gitlab/lib/gitlab/git_ref_validator.rb

24 lines
644 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
# Gitaly note: JV: does not need to be migrated, works without a repo.
2015-04-26 12:48:37 +05:30
module Gitlab
module GitRefValidator
extend self
# Validates a given name against the git reference specification
#
# Returns true for a valid reference name, false otherwise
def validate(ref_name)
2018-11-18 11:00:15 +05:30
not_allowed_prefixes = %w(refs/heads/ refs/remotes/ -)
return false if ref_name.start_with?(*not_allowed_prefixes)
return false if ref_name == 'HEAD'
2017-08-17 22:00:37 +05:30
2018-12-23 12:14:25 +05:30
begin
Rugged::Reference.valid_name?("refs/heads/#{ref_name}")
rescue ArgumentError
return false
end
2015-04-26 12:48:37 +05:30
end
end
end