2018-10-22 07:00:50 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-13 15:58:45 +00:00
|
|
|
# Gitaly note: JV: does not need to be migrated, works without a repo.
|
|
|
|
|
2014-07-27 14:40:00 +00:00
|
|
|
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-07-17 13:12:29 +00:00
|
|
|
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-01-09 06:38:13 +00:00
|
|
|
|
2018-07-17 13:12:29 +00:00
|
|
|
Rugged::Reference.valid_name? "refs/heads/#{ref_name}"
|
2014-07-27 14:40:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|