diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-30 16:26:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-30 16:26:49 +0300 |
commit | a2b7634113a2b2f3b9aad86b1a98c52c380e5e76 (patch) | |
tree | c9c9ebb914be91d9c5996f708721110276a38be1 /lib | |
parent | 2504d16ea735532cdb5a79403221b5fe262eb65f (diff) |
Add latest changes from gitlab-org/security/gitlab@15-10-stable-eev15.10.1
Diffstat (limited to 'lib')
-rw-r--r-- | lib/extracts_ref.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/extracts_ref.rb b/lib/extracts_ref.rb index dba1aad639c..49c9772f760 100644 --- a/lib/extracts_ref.rb +++ b/lib/extracts_ref.rb @@ -5,7 +5,8 @@ # Can be extended for different types of repository object, e.g. Project or Snippet module ExtractsRef InvalidPathError = Class.new(StandardError) - + BRANCH_REF_TYPE = 'heads' + TAG_REF_TYPE = 'tags' # Given a string containing both a Git tree-ish, such as a branch or tag, and # a filesystem path joined by forward slashes, attempts to separate the two. # @@ -91,7 +92,7 @@ module ExtractsRef def ref_type return unless params[:ref_type].present? - params[:ref_type] == 'tags' ? 'tags' : 'heads' + params[:ref_type] == TAG_REF_TYPE ? TAG_REF_TYPE : BRANCH_REF_TYPE end private @@ -154,4 +155,13 @@ module ExtractsRef def repository_container raise NotImplementedError end + + def ambiguous_ref?(project, ref) + return true if project.repository.ambiguous_ref?(ref) + + return false unless ref&.starts_with?('refs/') + + unprefixed_ref = ref.sub(%r{^refs/(heads|tags)/}, '') + project.repository.commit(unprefixed_ref).present? + end end |