Strip reference prefixes on branch creation

Signed-off-by: Matthieu Tardy <matthieu.tardy@gmail.com>
This commit is contained in:
Matthieu Tardy 2017-01-09 07:38:13 +01:00
parent 8ab94120ee
commit 7a399b7061
3 changed files with 12 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
title: Strip reference prefixes on branch creation
merge_request: 8498
author: Matthieu Tardy

View File

@ -5,6 +5,9 @@ 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/')
Gitlab::Utils.system_silent(
%W(#{Gitlab.config.git.bin_path} check-ref-format refs/#{ref_name}))
end

View File

@ -5,6 +5,7 @@ describe Gitlab::GitRefValidator, lib: true do
it { expect(Gitlab::GitRefValidator.validate('implement_@all')).to be_truthy }
it { expect(Gitlab::GitRefValidator.validate('my_new_feature')).to be_truthy }
it { expect(Gitlab::GitRefValidator.validate('#1')).to be_truthy }
it { expect(Gitlab::GitRefValidator.validate('feature/refs/heads/foo')).to be_truthy }
it { expect(Gitlab::GitRefValidator.validate('feature/~new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/^new/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature/:new/')).to be_falsey }
@ -17,4 +18,8 @@ describe Gitlab::GitRefValidator, lib: true do
it { expect(Gitlab::GitRefValidator.validate('feature\new')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature//new')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('feature new')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('refs/heads/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('refs/remotes/')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('refs/heads/feature')).to be_falsey }
it { expect(Gitlab::GitRefValidator.validate('refs/remotes/origin')).to be_falsey }
end