提交 d68c23a0 编写于 作者: S Sean McGivern

Merge branch '26470-branch-names-with-reference-prefixes-results-in-buggy-branches' into 'master'

Strip reference prefixes on branch creation

Closes #26470

See merge request !8498
---
title: Strip reference prefixes on branch creation
merge_request: 8498
author: Matthieu Tardy
......@@ -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
......
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册