Commit 928c81e2 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'use-rugged-for-reference-validator' into 'master'

Use rugged to validate ref name

Closes #49043

See merge request gitlab-org/gitlab-ce!20669
parents ae3cdf93 8ea9c815
......@@ -7,11 +7,11 @@ module Gitlab
# Returns true for a valid reference name, false otherwise
def validate(ref_name)
return false if ref_name.start_with?('refs/heads/')
return false if ref_name.start_with?('refs/remotes/')
not_allowed_prefixes = %w(refs/heads/ refs/remotes/ -)
return false if ref_name.start_with?(*not_allowed_prefixes)
return false if ref_name == 'HEAD'
%W(#{Gitlab.config.git.bin_path} check-ref-format --branch #{ref_name}))
Rugged::Reference.valid_name? "refs/heads/#{ref_name}"
......@@ -14,7 +14,10 @@ ALLOWED = [
# The only place where Rugged code is still allowed in production
# Needed to avoid using the git binary to validate a branch name
rugged_lines = IO.popen(%w[git grep -i -n rugged -- app config lib], &:read).lines
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment